-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgameobject.py
46 lines (38 loc) · 1.03 KB
/
gameobject.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
from observe import Observable
from constants import GAMEOBJ_LAYER
class GameObject(Observable):
"""
A renderable object in the game
"""
def __init__(self, x, y, img, layer=GAMEOBJ_LAYER):
Observable.__init__(self)
self.x = x
self.y = y
self.image = img
self.width = self.image.get_width()
self.height = self.image.get_height()
self.layer = layer
# allows for movement speed independent of frame rate
self.frame_tick = 0
def update(self):
pass
def render(self, screen):
screen.blit(self.image, (self.x, self.y))
def on_tick(self, event):
"""
Event handler for clock ticks
:param event:
:return:
"""
diff = event.kwargs.get("diff")
if diff is not None:
self.frame_tick = diff
else:
self.frame_tick = 0
def on_collide(self, event):
"""
Event handler for collisions
:param event:
:return:
"""
pass