-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameObject.py
35 lines (25 loc) · 971 Bytes
/
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
__author__ = 'unit978'
from MathUtil import Vector2
from pygame import Rect, draw
class GameObject:
def __init__(self):
self.position = Vector2(0, 0)
self.velocity = Vector2(0, 0)
# RGB
self.color = (255, 255, 255)
self.boundingBox = Rect(0, 0, 1, 1)
self.tag = "gameobject"
# Update the game object at every delta_time interval.
def update(self, delta_time):
# Kinematics: v = dr / dt
# dr = v * dt
# -------------------------------------------
# delta pos = vel * dt
# new position = current position + delta pos
# current position = new position
self.position += self.velocity * delta_time
# Update the position of the bounding box so it goes with the game object.
self.boundingBox.topleft = self.position.to_tuple()
# Render to screen.
def render(self, screen):
draw.rect(screen, self.color, self.boundingBox)