forked from helloworldC2/VirtualRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.py
More file actions
61 lines (40 loc) · 1.08 KB
/
Entity.py
File metadata and controls
61 lines (40 loc) · 1.08 KB
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
import Tile
class Entity(object):
def __init__(self,level,x,y):
self.level=level
self.x=x
self.y=y
self.centreX = x
self.centreY = y
self.ticks = 0
def tick(self):
self.ticks+=1
def move(self,xa,ya):
if xa != 0 and ya != 0:
self.move(xa, 0)
self.move(0, ya)
return True
if not self.hasCollided(xa, ya):
if ya < 0:
self.movingDir = 0
if ya > 0:
self.movingDir = 1
if xa < 0:
self.movingDir = 2
if xa > 0:
self.movingDir = 3
if self.ticks%self.getTileUnder().getSpeed() ==0:
self.x += xa
self.y += ya
return False
return True
def getTileUnder(self):
return self.level.getTile(self.centreX>>5, self.centreY>>5)
def hasCollided(self,xa, ya):
return False
def isSolidTile(self,xa, ya, x, y):
lastTile = self.level.getTile((self.x + x) >>5, (self.y + y) >>5)
nextTile = self.level.getTile((self.x + x + xa) >>5,(self.y + y + ya) >> 5)
if lastTile != nextTile and nextTile.isSolid:
return True
return False