-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSimonSays.py
184 lines (163 loc) · 8.64 KB
/
SimonSays.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#SimonSays
# you had really better do what Simon says...
import bs
import random
def bsGetAPIVersion():
return 4
def bsGetGames():
return [SimonSays]
class SimonSays(bs.TeamGameActivity):
@classmethod
def getName(cls):
return "Simon Says"
@classmethod
def getDescription(cls, sessionType):
return "You had better do what Simon says..."
@classmethod
def getScoreInfo(cls):
return{'scoreType':'points'}
@classmethod
def getSettings(cls, sessionType):
return [("Epic Mode", {'default': False}),
("Enable Jumping", {'default': False}),
("Enable Punching", {'default': False}),
("Enable Picking Up", {'default': False})]
@classmethod
def getSupportedMaps(cls, sessionType):
return ["Courtyard"]
@classmethod
def supportsSessionType(cls, sessionType):
return True if issubclass(sessionType, bs.FreeForAllSession) else False
def __init__(self,settings):
bs.TeamGameActivity.__init__(self,settings)
if self.settings['Epic Mode']: self._isSlowMotion = True
self.info = bs.NodeActor(bs.newNode('text',
attrs={'vAttach': 'bottom',
'hAlign': 'center',
'vrDepth': 0,
'color': (0,.2,0),
'shadow': 1.0,
'flatness': 1.0,
'position': (0,0),
'scale': 0.8,
'text': "Created by MattZ45986 on Github",
}))
self.roundNum = 0
self.simon = False
self.time = 5000
self._r1 = 2
n1 = bs.newNode('locator',attrs={'shape':'circle','position':(-4,0,-6),
'color':(1,0,0),'opacity':0.5,
'drawBeauty':True,'additive':True})
n2 = bs.newNode('locator',attrs={'shape':'circle','position':(0,0,-6),
'color':(0,1,0),'opacity':0.5,
'drawBeauty':True,'additive':True})
n3 = bs.newNode('locator',attrs={'shape':'circle','position':(4,0,-6),
'color':(0,0,1),'opacity':0.5,
'drawBeauty':True,'additive':True})
n4 = bs.newNode('locator',attrs={'shape':'circle','position':(-4,0,-2),
'color':(1,1,0),'opacity':0.5,
'drawBeauty':True,'additive':True})
n5 = bs.newNode('locator',attrs={'shape':'circle','position':(0,0,-2),
'color':(0,1,1),'opacity':0.5,
'drawBeauty':True,'additive':True})
n6 = bs.newNode('locator',attrs={'shape':'circle','position':(4,0,-2),
'color':(1,0,1),'opacity':0.5,
'drawBeauty':True,'additive':True})
n7 = bs.newNode('locator',attrs={'shape':'circle','position':(-4,0,2),
'color':(.5,.5,.5),'opacity':0.5,
'drawBeauty':True,'additive':True})
n8 = bs.newNode('locator',attrs={'shape':'circle','position':(0,0,2),
'color':(.5,.325,0),'opacity':0.5,
'drawBeauty':True,'additive':True})
n9 = bs.newNode('locator',attrs={'shape':'circle','position':(4,0,2),
'color':(1,1,1),'opacity':0.5,
'drawBeauty':True,'additive':True})
bs.animateArray(n1,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n2,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n3,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n4,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n5,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n6,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n7,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n8,'size',1,{0:[0.0],200:[self._r1*2.0]})
bs.animateArray(n9,'size',1,{0:[0.0],200:[self._r1*2.0]})
self.options = ["red", "green", "blue", "yellow", "teal", "purple", "gray", "orange", "white", "top", "bottom", "middle row", "left", "right", "center column", "outside"]
def onTransitionIn(self):
bs.TeamGameActivity.onTransitionIn(self,music='FlagCatcher')
def onPlayerJoin(self, player):
if self.hasBegun():
bs.screenMessage(bs.Lstr(resource='playerDelayedJoinText', subs=[('${PLAYER}', player.getName(full=True))]),
color=(0, 1, 0))
def onBegin(self):
s = self.settings
bs.TeamGameActivity.onBegin(self)
for team in self.teams:
team.gameData['score'] = 0
for player in self.players:
player.gameData['score'] = 0
self.spawnPlayerSpaz(player,self.getMap().getFFAStartPosition(self.players))
player.actor.connectControlsToPlayer(enableBomb=False, enablePunch = s["Enable Punching"], enablePickUp = s["Enable Picking Up"], enableRun = True, enableJump = s["Enable Jumping"])
self.explainGame()
def explainGame(self):
bs.screenMessage("Follow the commands...")
bs.screenMessage("but only when Simon says!")
bs.gameTimer(5000, self.callRound)
def callRound(self):
self.roundNum += 1
self.num = random.randint(0, 15)
num = self.num
self.simon = random.choice([True, False])
if num < 9: line = "Run to the " + self.options[num] + " circle!"
elif num < 15: line = "Run to the " + self.options[num] + "!"
else: line = "Run outside of the circles!"
if self.simon: line = "Simon says " + line[0].lower() + line[1:]
self.text = bs.PopupText(line, position=(0, 5, -4), color=(1, 1, 1), randomOffset=0.5, offset=(0, 0, 0), scale=2.0).autoRetain()
self.time -= 100
bs.gameTimer(self.time, self.checkRound)
def checkRound(self):
for player in self.players:
if player.isAlive():
safe = True if self.options[self.num] in self.inCircle(player.actor.node.positionCenter) else False
if ((self.simon and safe == False) or ((not self.simon) and safe == True)):
player.getTeam().gameData["score"] = self.roundNum
player.actor.handleMessage(bs.DieMessage())
self.callRound()
def inCircle(self, pos):
circles = []
x = pos[0]
z = pos[2]
if (x + 4) ** 2 + (z + 6) ** 2 < 4: circles.append("red")
elif (x) ** 2 + (z + 6) ** 2 < 4: circles.append("green")
elif (x - 4) ** 2 + (z + 6) ** 2 < 4: circles.append("blue")
elif (x + 4) ** 2 + (z + 2) ** 2 < 4: circles.append("yellow")
elif (x) ** 2 + (z + 2) ** 2 < 4: circles.append("teal")
elif (x - 4) ** 2 + (z + 2) ** 2 < 4: circles.append("purple")
elif (x + 4) ** 2 + (z - 2) ** 2 < 4: circles.append("gray")
elif (x) ** 2 + (z - 2) ** 2 < 4: circles.append("orange")
elif (x - 4) ** 2 + (z - 2) ** 2 < 4: circles.append("white")
else: circles.append("outside")
if x < -2: circles.append("left")
if x > 2: circles.append("right")
if x > -2 and x < 2: circles.append("center column")
if z > 0: circles.append("bottom")
if z < -4: circles.append("top")
if z < 0 and z > -4: circles.append("middle row")
return circles
def handleMessage(self, m):
if isinstance(m, bs.PlayerSpazDeathMessage): self.checkEnd()
else: bs.TeamGameActivity.handleMessage(self, m)
def onPlayerJoin(self, player):
if self.hasBegun():
bs.screenMessage(bs.Lstr(resource='playerDelayedJoinText',subs=[('${PLAYER}',player.getName(full=True))]),color=(0,1,0))
return
def checkEnd(self):
i = 0
for player in self.players:
if player.isAlive(): i += 1
if i < 2: self.endGame()
def endGame(self):
results = bs.TeamGameResults()
for team in self.teams:
results.setTeamScore(team, team.gameData['score'])
self.end(results=results)