-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameInterface.py
More file actions
50 lines (35 loc) · 1.35 KB
/
Copy pathgameInterface.py
File metadata and controls
50 lines (35 loc) · 1.35 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
#gameInterface.py
#
from carGame import *
from myPyGameBase import *
class GameInterface:
def __init__(self, gameInstance):
self.gameInstance = gameInstance
self.dots = list()
def activateGameAction(self, actionName):
self.gameInstance.actions[actionName] = 1
def deactivateGameAction(self, actionName):
self.gameInstance.actions[actionName] = 0
def getAheadView(self, dist, angle = 0.0):
game = self.gameInstance
dirRadians = game.car.direction
checkPoint = Point(dist, 0.0)
checkPoint.rotateAbout(Point(0, 0), -1.0 * (dirRadians + angle))
collissionRect = game.car.rect.copy()
collissionRect += checkPoint
self.dots.append(Dot(self.gameInstance, collissionRect.center()))
result = game.lvlmap.rectCollidingOnMap(collissionRect)
return result
def getCenterView(self, dist):
return self.getAheadView(dist)
def getLeftView(self, dist, angle):
return self.getAheadView(dist, angle)
def getRightView(self, dist, angle):
return self.getAheadView(dist, -1.0 * angle)
def hitTerrain(self):
return self.gameInstance.lvlmap.rectCollidingOnMap( \
self.gameInstance.car.rect)
def draw(self):
for dot in self.dots:
dot.draw()
self.dots = list()