-
Notifications
You must be signed in to change notification settings - Fork 0
/
moving_object.py
65 lines (55 loc) · 1.23 KB
/
moving_object.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Class to work with moving objects
"""
from variables import *
from pygame import Vector2
class MovingObj:
def __init__(self , groups):
self.clicked = False
self.acceleration = Vector2(0 , 0)
self.moving_velocity = Vector2(0,0)
moving_objects_group.add(self)
for group in groups:
group.add(self)
def click_down(self , event):
"""
for debug
:param event: pg.Event
:return: Bool
"""
if self.rect.collidepoint(event.pos):
self.clicked = True
return self.clicked
def move(self):
"""
for debug
:return: None
"""
if self.clicked:
mouse_move = pg.mouse.get_rel()
self.rect.move_ip(mouse_move)
self.to_move_point = pg.Vector2(pg.mouse.get_pos())
self.rect.move_ip(self.moving_velocity)
def click_up(self , event):
"""
for debug
:return: None
"""
self.clicked = False
def update(self):
"""
updates the object acceleration and velocity
:return:
"""
self.calc_acceleration()
self.calc_velocity()
def calc_acceleration(self):
pass
def calc_velocity(self):
"""
sums the velocity to the acceleration, zeroes the acceleration, and does a dragging of the velocity
:return:
"""
self.moving_velocity += self.acceleration
self.moving_velocity *= .9
self.acceleration *= 0