-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrigger.py
54 lines (54 loc) · 2.22 KB
/
Trigger.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
from cmu_graphics import *
from ClassFunctions import *
from LevelLists import *
from Character import *
class Trigger:
triggerList = []
def __init__(self, x1, y1, x2, y2, lW, triggersTrue, triggersFalse, level, room):
self.shape = Line(x1, y1, x2, y2, lineWidth = lW, visible = False)
self.level = level
self.room = room
self.triggersTrue = triggersTrue
for i in self.triggersTrue:
if i in obstacleGroupList[self.level - 1][self.room]:
i.obstacle = True
i.ground = False
elif i in groundGroupList[self.level - 1][self.room]:
i.ground = True
i.obstacle = False
self.triggersFalse = triggersFalse
self.triggered = False
Trigger.triggerList[level - 1][room].append(self)
def trigger(self):
if not self.triggered:
for i in self.triggersTrue:
if i.ground:
currentGroup(groundGroupList).add(i)
elif i.obstacle:
currentGroup(obstacleGroupList).add(i)
for i in self.triggersFalse:
if i.ground:
if i in currentGroup(groundGroupList):
currentGroup(groundGroupList).remove(i)
elif i.obstacle:
if i in currentGroup(obstacleGroupList):
currentGroup(obstacleGroupList).remove(i)
if self.shape.hitsShape(character.shape):
self.triggered = True
else:
for i in self.triggersTrue:
if i.ground:
if i in currentGroup(groundGroupList):
currentGroup(groundGroupList).remove(i)
elif i.obstacle:
if i in currentGroup(obstacleGroupList):
currentGroup(obstacleGroupList).remove(i)
for i in self.triggersFalse:
if i.ground:
currentGroup(groundGroupList).add(i)
elif i.obstacle:
currentGroup(obstacleGroupList).add(i)
def reset(self):
if self.level == app.level and self.room == app.room:
self.triggered = False
self.trigger()