-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameobjects.py
80 lines (59 loc) · 1.81 KB
/
gameobjects.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from globalconst import *
import math
class GameObject(object):
def __init__(self, x, y, tile = None):
self.x = x
self.y = y
self.rotation = 0
self.tile = tile
self.spawnx = x
self.spawny = y
self.xdir = 0
self.ydir = 0
self.facedir = LEFT
self.speed = 1
self.v = [0.0, 0.0]
self.width = TILE_W
self.height = TILE_H
self.rotationDir = 0
self.rotationSpeed = 0
def getSprite(self):
return self.tile
def move(self, xdir = None, ydir = None):
if xdir is not None:
self.xdir = xdir
if ydir is not None:
self.ydir = ydir
def stop(self, left, right, up, down):
if left and self.xdir < 0:
self.xdir = 0
if right and self.xdir > 0:
self.xdir = 0
if up and self.ydir < 0:
self.ydir = 0
if down and self.ydir > 0:
self.ydir = 0
def rotate(self, direction):
self.rotationDir = direction
def update(self, gamestate):
pass
def updateLocal(self,gamestate):
pass
def reset(self):
self.x = self.spawnx
self.y = self.spawny
self.v = [0.0, 0.0]
self.rotation = 0
def draw(self, screen, tiles, gamestate):
pass
def interact(self, gamestate, release=False):
pass
def collides(self, game_object):
if self.x < game_object.x + game_object.width and \
self.x + self.width > game_object.x and \
self.y < game_object.y + game_object.height and \
self.y + self.height > game_object.y:
#debugList.append([self.x, self.y])
#debugList.append([game_object.x, game_object.y])
return True
return False