def handleMessage(self, m): if isinstance(m, bs.PickedUpMessage): self._heldBy = m.node elif isinstance(m, bs.DroppedMessage): bs.animate(self._powText, 'scale', {0:0.01, 600: 0.03}) bs.gameTimer(600, bs.WeakCall(self.pow)) bsBomb.Bomb.handleMessage(self, m)
def _spawnMine(self, player): #Don't spawn mines if player is dead if not player.exists() or not player.isAlive(): return gameData = player.getTeam().gameData # no more mines for players who've already won # to get a working draw if gameData['minesPlanted'] >= self.settings['Mines to win']: return gameData['minesPlanted'] += 1 gameData['tailLength'] = gameData['minesPlanted'] * self.tailIncrease + 2 if gameData['minesPlanted'] >= self.settings['Mines to win'] - 10: num2win = self.settings['Mines to win'] - gameData['minesPlanted'] + 1 if num2win in self._countDownSounds: bs.playSound(self._countDownSounds[num2win]) self._updateScoreBoard() if player.getTeam().gameData['tailLength'] < 2: return pos = player.actor.node.position pos = (pos[0], pos[1] + 2, pos[2]) mine = bs.Bomb(position=pos, velocity=(0, 0, 0), bombType='landMine', blastRadius=2.0, sourcePlayer=player, owner=player).autoRetain() player.gameData['mines'].append(mine) bs.gameTimer(int(self.mineDelay * 1000), bs.WeakCall(mine.arm)) bs.gameTimer(int(int(player.getTeam().gameData['tailLength'] + 1) * self.mineDelay * 1000), bs.WeakCall(self._removeMine, player, mine))
def handleMessage(self, m): if isinstance(m, PuckTouchedMessage): node = bs.getCollisionInfo("opposingNode") # bs.screenMessage(str(node.position)) # node.sourcePlayer if node.sourcePlayer.getTeam() == self.team: return # Score - isAlive to avoid multiple kills per death if "notKilled" not in node.sourcePlayer.gameData: node.sourcePlayer.gameData["notKilled"] = True if node.sourcePlayer.gameData["notKilled"]: # node.sourcePlayer.getTeam().gameData['timesKilled'] += 1 self.team.gameData["score"] += 1 bs.getActivity()._updateScoreBoard() node.sourcePlayer.gameData["notKilled"] = False x, y, z = node.position node.handleMessage("impulse", x, y, z, 0, 0, 0, 1000.0, 0, 3, 0, 0, 0, 0) # velocity # forceDirection node.frozen = True bs.gameTimer(1000, node.sourcePlayer.actor.shatter) if isinstance(m, bs.OutOfBoundsMessage): self.node.position = self._spawnPos self.movedSinceSpawn = False self.age = 0 else: bsHockey.Puck.handleMessage(self, m)
def onPlayerLeave(self,player): bs.TeamGameActivity.onPlayerLeave(self, player) player.gameData['icons'] = None # update icons in a moment since our team will be gone from the list then bs.gameTimer(0, self._updateIcons)
def _doEmit(): if self.blastType != "tnt": bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), chunkType="rock" ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.5, chunkType="rock", ) bs.emitBGDynamics( position=position, velocity=velocity, count=30, scale=1.0 if self.blastType == "tnt" else 0.7, chunkType="spark", emitType="stickers", ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(18.0 + random.random() * 20), scale=1.0 if self.blastType == "tnt" else 0.8, spread=1.5, chunkType="spark", ) # tnt throws splintery chunks if self.blastType == "tnt": def _emitSplinters(): bs.emitBGDynamics( position=position, velocity=velocity, count=int(20.0 + random.random() * 25), scale=0.8, spread=1.0, chunkType="splinter", ) bs.gameTimer(10, _emitSplinters) # every now and then do a sparky one if self.blastType == "tnt" or random.random() < 0.1: def _emitExtraSparks(): bs.emitBGDynamics( position=position, velocity=velocity, count=int(10.0 + random.random() * 20), scale=0.8, spread=1.5, chunkType="spark", ) bs.gameTimer(20, _emitExtraSparks)
def _doLight4(self): self.lights[3].color = (0.0, 1.0, 0) bs.playSound(self._beep2Sound) for l in self.lights: bs.animate(l, 'opacity', {0: 1.0, 1000: 0.0}) bs.gameTimer(1000, l.delete) self.incTimer = None self.onFinish() del self
def spawnPlayer(self, player): if isinstance(self.getSession(), bs.TeamsSession): position = self.getMap().getStartPosition(player.getTeam().getID()) else: # otherwise do free-for-all spawn locations position = self.getMap().getFFAStartPosition(self.players) angle = None # spaz = self.spawnPlayerSpaz(player) # lets reconnect this player's controls to this # spaz but *without* the ability to attack or pick stuff up # spaz.connectControlsToPlayer(enablePunch=False, # enableBomb=False, # enablePickUp=False) # also lets have them make some noise when they die.. # spaz.playBigDeathSound = True name = player.getName() lightColor = bsUtils.getNormalizedColor(player.color) displayColor = bs.getSafeColor(player.color, targetIntensity=0.75) spaz = Player(color=player.color, highlight=player.highlight, character=player.character, player=player) player.setActor(spaz) # we want a bigger area-of-interest in co-op mode # if isinstance(self.getSession(),bs.CoopSession): spaz.node.areaOfInterestRadius = 5.0 # else: spaz.node.areaOfInterestRadius = 5.0 # if this is co-op and we're on Courtyard or Runaround, add the material that allows us to # collide with the player-walls # FIXME; need to generalize this if isinstance(self.getSession(), bs.CoopSession) and self.getMap().getName() in ["Courtyard", "Tower D"]: mat = self.getMap().preloadData["collideWithWallMaterial"] spaz.node.materials += (mat,) spaz.node.rollerMaterials += (mat,) spaz.node.name = name spaz.node.nameColor = displayColor spaz.connectControlsToPlayer( enableJump=True, enablePunch=True, enablePickUp=False, enableBomb=True, enableRun=True, enableFly=False ) self.scoreSet.playerGotNewSpaz(player, spaz) # move to the stand position and add a flash of light spaz.handleMessage(bs.StandMessage(position, angle if angle is not None else random.uniform(0, 360))) t = bs.getGameTime() bs.playSound(self._spawnSound, 1, position=spaz.node.position) light = bs.newNode("light", attrs={"color": lightColor}) spaz.node.connectAttr("position", light, "position") bsUtils.animate(light, "intensity", {0: 0, 250: 1, 500: 0}) bs.gameTimer(500, light.delete)
def onBegin(self): self.mineTimers = [] bs.gameTimer(3500, bs.Call(self.doRaceTimer)) # test... if not all(player.exists() for player in self.players): bs.printError("Nonexistant player in onBegin: "+str([str(p) for p in self.players])) bs.TeamGameActivity.onBegin(self)
def handleMessage(self, m): if isinstance(m, bs.PickedUpMessage): bs.getActivity()._updateBoxState() elif isinstance(m, bs.DroppedMessage): self.heldBy -= 1 self.updateFloatyness() bs.gameTimer(200, bs.getActivity()._updateBoxState) elif isinstance(m, bs.DieMessage): if not self._isDead: bs.gameTimer(1000, bs.getActivity()._spawnBox) self._isDead = True super(self.__class__, self).handleMessage(m)
def onBegin(self): bs.TeamGameActivity.onBegin(self) # drop a wave every few seconds.. and every so often drop the time between waves # ..lets have things increase faster if we have fewer players self._meteorTime = 3000 t = 7500 if len(self.players) > 2 else 4000 if self.settings['Epic Mode']: t /= 4 bs.gameTimer(t,self._decrementMeteorTime,repeat=True) # kick off the first wave in a few seconds t = 3000 if self.settings['Epic Mode']: t /= 4 bs.gameTimer(t,self._setMeteorTimer) self._timer = bs.OnScreenTimer() self._timer.start()
def _dropBombCluster(self): # random note: code like this is a handy way to plot out extents and debug things if False: bs.newNode('locator',attrs={'position':(8,6,-5.5)}) bs.newNode('locator',attrs={'position':(8,6,-2.3)}) bs.newNode('locator',attrs={'position':(-7.3,6,-5.5)}) bs.newNode('locator',attrs={'position':(-7.3,6,-2.3)}) # drop several bombs in series.. delay = 0 for i in range(random.randrange(1,3)): # drop them somewhere within our bounds with velocity pointing toward the opposite side pos = (-7.3+15.3*random.random(),11,-5.5+2.1*random.random()) vel = ((-5.0+random.random()*30.0) * (-1.0 if pos[0] > 0 else 1.0), -4.0,0) bs.gameTimer(delay,bs.Call(self._dropBomb,pos,vel)) delay += 100 self._setMeteorTimer()
def handleMessage(self,m): if isinstance(m,bs.PlayerSpazDeathMessage): bs.TeamGameActivity.handleMessage(self,m) # augment standard behavior player = m.spaz.getPlayer() self.respawnPlayer(player) killer = m.killerPlayer if killer is None: return # handle team-kills if killer.getTeam() is player.getTeam(): # in free-for-all, killing yourself loses you a point if isinstance(self.getSession(),bs.FreeForAllSession): player.getTeam().gameData['score'] = max(0,player.getTeam().gameData['score']-1) # in teams-mode it gives a point to the other team else: bs.playSound(self._dingSound) for team in self.teams: if team is not killer.getTeam(): team.gameData['score'] += 1 # killing someone on another team nets a kill else: killer.getTeam().gameData['score'] += 1 bs.playSound(self._dingSound) # in FFA show our score since its hard to find on the scoreboard try: killer.actor.setScoreText(str(killer.getTeam().gameData['score'])+'/'+str(self._scoreToWin),color=killer.getTeam().color,flash=True) except Exception: pass self._updateScoreBoard() # if someone has won, set a timer to end shortly # (allows the dust to clear and draws to occur if deaths are close enough) if any(team.gameData['score'] >= self._scoreToWin for team in self.teams): bs.gameTimer(500,self.endGame) else: bs.TeamGameActivity.handleMessage(self,m)
def handleMessage(self,m): if isinstance(m, bs.PlayerSpazDeathMessage): super(self.__class__, self).handleMessage(m)#bs.TeamGameActivity.handleMessage(self,m) # (augment standard behavior) deathTime = bs.getGameTime() # record the player's moment of death m.spaz.getPlayer().gameData['deathTime'] = deathTime # in co-op mode, end the game the instant everyone dies (more accurate looking) # in teams/ffa, allow a one-second fudge-factor so we can get more draws if isinstance(self.getSession(), bs.CoopSession): # teams will still show up if we check now.. check in the next cycle bs.pushCall(self._checkEndGame) self._lastPlayerDeathTime = deathTime # also record this for a final setting of the clock.. else: bs.gameTimer(1000, self._checkEndGame) else: # default handler: super(self.__class__, self).handleMessage(m)#bs.TeamGameActivity.handleMessage(self,m)
def explode(self): if self._exploded: return self._exploded = True size = int(self.blastRadius) for mod in range(-size, size + 1): pos = self.node.position posX = (pos[0] + mod * 1.0, pos[1], pos[2]) posY = (pos[0], pos[1], pos[2] + mod * 1.0) if Map.inBounds(posX): bs.gameTimer( abs(mod) * 150, bs.Call(blast, posX, self.bombType, self.sourcePlayer, self.hitType, self.hitSubType), ) if Map.inBounds(posY): bs.gameTimer( abs(mod) * 150, bs.Call(blast, posY, self.bombType, self.sourcePlayer, self.hitType, self.hitSubType), ) bs.gameTimer(1, bs.WeakCall(self.handleMessage, bs.DieMessage()))
def __init__( self, position=(0, 1, 0), velocity=(0, 0, 0), blastRadius=2.0, blastType="normal", sourcePlayer=None, hitType="explosion", hitSubType="normal", ): """ Instantiate with given values. """ bs.Actor.__init__(self) factory = Bomb.getFactory() self.blastType = blastType self.sourcePlayer = sourcePlayer self.hitType = hitType self.hitSubType = hitSubType # blast radius self.radius = blastRadius self.node = bs.newNode( "region", attrs={ "position": ( position[0], position[1] - 0.1, position[2], ), # move down a bit so we throw more stuff upward "scale": (self.radius, self.radius, self.radius), "type": "sphere", "materials": (factory.blastMaterial, bs.getSharedObject("attackMaterial")), }, delegate=self, ) bs.gameTimer(50, self.node.delete) # throw in an explosion and flash explosion = bs.newNode( "explosion", attrs={ "position": position, "velocity": (velocity[0], max(-1.0, velocity[1]), velocity[2]), "radius": self.radius, "big": (self.blastType == "tnt"), }, ) if self.blastType == "ice": explosion.color = (0, 0.05, 0.4) bs.gameTimer(1000, explosion.delete) if self.blastType != "ice": bs.emitBGDynamics( position=position, velocity=velocity, count=int(1.0 + random.random() * 4), emitType="tendrils", tendrilType="thinSmoke", ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 4), emitType="tendrils", tendrilType="ice" if self.blastType == "ice" else "smoke", ) bs.emitBGDynamics(position=position, emitType="distortion", spread=1.0 if self.blastType == "tnt" else 2.0) # and emit some shrapnel.. if self.blastType == "ice": def _doEmit(): bs.emitBGDynamics( position=position, velocity=velocity, count=30, spread=2.0, scale=0.4, chunkType="ice", emitType="stickers", ) bs.gameTimer(50, _doEmit) # looks better if we delay a bit elif self.blastType == "sticky": def _doEmit(): bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), spread=0.7, chunkType="slime", ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.5, spread=0.7, chunkType="slime", ) bs.emitBGDynamics( position=position, velocity=velocity, count=15, scale=0.6, chunkType="slime", emitType="stickers" ) bs.emitBGDynamics( position=position, velocity=velocity, count=20, scale=0.7, chunkType="spark", emitType="stickers" ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(6.0 + random.random() * 12), scale=0.8, spread=1.5, chunkType="spark", ) bs.gameTimer(50, _doEmit) # looks better if we delay a bit elif self.blastType == "impact": # regular bomb shrapnel def _doEmit(): bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.8, chunkType="metal", ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.4, chunkType="metal", ) bs.emitBGDynamics( position=position, velocity=velocity, count=20, scale=0.7, chunkType="spark", emitType="stickers" ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(8.0 + random.random() * 15), scale=0.8, spread=1.5, chunkType="spark", ) bs.gameTimer(50, _doEmit) # looks better if we delay a bit else: # regular or land mine bomb shrapnel def _doEmit(): if self.blastType != "tnt": bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), chunkType="rock" ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.5, chunkType="rock", ) bs.emitBGDynamics( position=position, velocity=velocity, count=30, scale=1.0 if self.blastType == "tnt" else 0.7, chunkType="spark", emitType="stickers", ) bs.emitBGDynamics( position=position, velocity=velocity, count=int(18.0 + random.random() * 20), scale=1.0 if self.blastType == "tnt" else 0.8, spread=1.5, chunkType="spark", ) # tnt throws splintery chunks if self.blastType == "tnt": def _emitSplinters(): bs.emitBGDynamics( position=position, velocity=velocity, count=int(20.0 + random.random() * 25), scale=0.8, spread=1.0, chunkType="splinter", ) bs.gameTimer(10, _emitSplinters) # every now and then do a sparky one if self.blastType == "tnt" or random.random() < 0.1: def _emitExtraSparks(): bs.emitBGDynamics( position=position, velocity=velocity, count=int(10.0 + random.random() * 20), scale=0.8, spread=1.5, chunkType="spark", ) bs.gameTimer(20, _emitExtraSparks) bs.gameTimer(50, _doEmit) # looks better if we delay a bit light = bs.newNode( "light", attrs={ "position": position, "color": (0.6, 0.6, 1.0) if self.blastType == "ice" else (1, 0.3, 0.1), "volumeIntensityScale": 10.0, }, ) s = random.uniform(0.6, 0.9) scorchRadius = lightRadius = self.radius if self.blastType == "tnt": lightRadius *= 1.4 scorchRadius *= 1.15 s *= 3.0 iScale = 1.6 bsUtils.animate( light, "intensity", { 0: 2.0 * iScale, int(s * 20): 0.1 * iScale, int(s * 25): 0.2 * iScale, int(s * 50): 17.0 * iScale, int(s * 60): 5.0 * iScale, int(s * 80): 4.0 * iScale, int(s * 200): 0.6 * iScale, int(s * 2000): 0.00 * iScale, int(s * 3000): 0.0, }, ) bsUtils.animate( light, "radius", { 0: lightRadius * 0.2, int(s * 50): lightRadius * 0.55, int(s * 100): lightRadius * 0.3, int(s * 300): lightRadius * 0.15, int(s * 1000): lightRadius * 0.05, }, ) bs.gameTimer(int(s * 3000), light.delete) # make a scorch that fades over time scorch = bs.newNode( "scorch", attrs={"position": position, "size": scorchRadius * 0.5, "big": (self.blastType == "tnt")} ) if self.blastType == "ice": scorch.color = (1, 1, 1.5) bsUtils.animate(scorch, "presence", {3000: 1, 13000: 0}) bs.gameTimer(13000, scorch.delete) if self.blastType == "ice": bs.playSound(factory.hissSound, position=light.position) p = light.position bs.playSound(factory.getRandomExplodeSound(), position=p) bs.playSound(factory.debrisFallSound, position=p) ######## bs.shakeCamera(intensity=5.0 if self.blastType == "tnt" else 0.05) ######## # tnt is more epic.. if self.blastType == "tnt": bs.playSound(factory.getRandomExplodeSound(), position=p) def _extraBoom(): bs.playSound(factory.getRandomExplodeSound(), position=p) bs.gameTimer(250, _extraBoom) def _extraDebrisSound(): bs.playSound(factory.debrisFallSound, position=p) bs.playSound(factory.woodDebrisFallSound, position=p) bs.gameTimer(400, _extraDebrisSound)
def onBegin(self): bs.TeamGameActivity.onBegin(self) self._won = False self.setupStandardPowerupDrops() # make our on-screen timer and start it roughly when our bots appear self._timer = bs.OnScreenTimer() bs.gameTimer(4000, self._timer.start) # this wrangles our bots self._bots = bs.BotSet() # spawn some baddies self._bots = bs.BotSet() bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.MelBotStatic, pos=(6, 7, -6), spawnTime=3000)) bs.gameTimer( 2000, bs.Call(self._bots.spawnBot, bs.ToughGuyBotProShielded, pos=(-3, 10, -2), spawnTime=3000)) bs.gameTimer( 3000, bs.Call(self._bots.spawnBot, bs.NinjaBotProShielded, pos=(5, 6, -2), spawnTime=3000)) bs.gameTimer( 4000, bs.Call(self._bots.spawnBot, bs.BomberBotProShielded, pos=(-5, 6, -2), spawnTime=3000)) bs.gameTimer( 5000, bs.Call(self._bots.spawnBot, bs.ChickBotStatic, pos=(-6, 7, -6), spawnTime=3000))
def onBegin(self): bs.TeamGameActivity.onBegin(self) # drop a wave every few seconds.. and every so often drop the time between waves # ..lets have things increase faster if we have fewer players self._meteorTime = 1000 t = 4000 if len(self.players) > 2 else 4000 if self.settings['Epic Mode']: self._meteorTime = 1000 if self.settings['Epic Mode']: t = 4000 bs.gameTimer(t, self._decrementMeteorTime, repeat=True) bs.gameTimer(t, self._setMeteorTimer) t = 5000 if len(self.players) > 2 else 5000 bs.gameTimer(t, self._rmsWave) t = 25000 if len(self.players) > 2 else 25000 bs.gameTimer(t, self._rmsEnd) self._meteorTime2 = 1500 t = 24500 if len(self.players) > 2 else 24500 if self.settings['Epic Mode']: self._meteorTime2 = 1000 if self.settings['Epic Mode']: t = 24000 bs.gameTimer(t, self._decrementMeteorTime2, repeat=True) bs.gameTimer(t, self._setMeteorTimer2) t = 45000 if len(self.players) > 2 else 45000 bs.gameTimer(t, self._rmsEnd2) self._meteorTime3 = 2000 t = 43000 if len(self.players) > 2 else 43000 if self.settings['Epic Mode']: self._meteorTime3 = 1500 if self.settings['Epic Mode']: t = 43500 bs.gameTimer(t, self._decrementMeteorTime3, repeat=True) bs.gameTimer(t, self._setMeteorTimer3) t = 60000 if len(self.players) > 2 else 60000 bs.gameTimer(t, self._rmsEnd3) self._meteorTime4 = 0700 t = 59300 if len(self.players) > 2 else 59300 if self.settings['Epic Mode']: self._meteorTime4 = 0700 if self.settings['Epic Mode']: t = 59300 bs.gameTimer(t, self._decrementMeteorTime4, repeat=True) bs.gameTimer(t, self._setMeteorTimer4) t = 85000 if len(self.players) > 2 else 85000 bs.gameTimer(t, self._rmsEnd4) self._meteorTime5 = 1000 t = 84000 if len(self.players) > 2 else 84000 if self.settings['Epic Mode']: self._meteorTime5 = 1000 if self.settings['Epic Mode']: t = 83000 bs.gameTimer(t, self._decrementMeteorTime5, repeat=True) bs.gameTimer(t, self._setMeteorTimer5) t = 100000 if len(self.players) > 2 else 100000 bs.gameTimer(t, self._rmsEnd5) self._meteorTime6 = 0400 t = 99600 if len(self.players) > 2 else 99600 if self.settings['Epic Mode']: self._meteorTime6 = 0400 if self.settings['Epic Mode']: t = 99600 bs.gameTimer(t, self._decrementMeteorTime6, repeat=True) bs.gameTimer(t, self._setMeteorTimer6) t = 115000 if len(self.players) > 2 else 115000 bs.gameTimer(t, self._rmsEnd6) self._meteorMedicTime = 0500 t = 34500 if len(self.players) > 2 else 34500 if self.settings['Epic Mode']: self._meteorMedicTime = 0250 if self.settings['Epic Mode']: t = 34750 bs.gameTimer(t, self._decrementMeteorMedicTime, repeat=True) bs.gameTimer(t, self._setMeteorMedicTimer) t = 35000 if len(self.players) > 2 else 35000 bs.gameTimer(t, self._rmsMedic) t = 36500 if len(self.players) > 2 else 36500 bs.gameTimer(t, self._rmsEndMedic) self._meteorMedicTime2 = 0500 t = 49500 if len(self.players) > 2 else 49500 if self.settings['Epic Mode']: self._meteorMedicTime2 = 0250 if self.settings['Epic Mode']: t = 49750 bs.gameTimer(t, self._decrementMeteorMedicTime2, repeat=True) bs.gameTimer(t, self._setMeteorMedicTimer2) t = 50000 if len(self.players) > 2 else 50000 bs.gameTimer(t, self._rmsMedic2) t = 51500 if len(self.players) > 2 else 51500 bs.gameTimer(t, self._rmsEndMedic2) self._meteorMedicTime3 = 0500 t = 64500 if len(self.players) > 2 else 64500 if self.settings['Epic Mode']: self._meteorMedicTime3 = 0250 if self.settings['Epic Mode']: t = 64750 bs.gameTimer(t, self._decrementMeteorMedicTime3, repeat=True) bs.gameTimer(t, self._setMeteorMedicTimer3) t = 65000 if len(self.players) > 2 else 65000 bs.gameTimer(t, self._rmsMedic3) t = 66500 if len(self.players) > 2 else 66500 bs.gameTimer(t, self._rmsEndMedic3) self._meteorMedicTime4 = 0500 t = 79500 if len(self.players) > 2 else 79500 if self.settings['Epic Mode']: self._meteorMedicTime4 = 0250 if self.settings['Epic Mode']: t = 79750 bs.gameTimer(t, self._decrementMeteorMedicTime4, repeat=True) bs.gameTimer(t, self._setMeteorMedicTimer4) t = 80000 if len(self.players) > 2 else 80000 bs.gameTimer(t, self._rmsMedic4) t = 81500 if len(self.players) > 2 else 81500 bs.gameTimer(t, self._rmsEndMedic4) self._meteorMedicTime5 = 0500 t = 94500 if len(self.players) > 2 else 94500 if self.settings['Epic Mode']: self._meteorMedicTime5 = 0250 if self.settings['Epic Mode']: t = 94750 bs.gameTimer(t, self._decrementMeteorMedicTime5, repeat=True) bs.gameTimer(t, self._setMeteorMedicTimer5) t = 95000 if len(self.players) > 2 else 95000 bs.gameTimer(t, self._rmsMedic5) t = 96500 if len(self.players) > 2 else 96500 bs.gameTimer(t, self._rmsEndMedic5) self._meteorMedicTime6 = 0500 t = 115000 if len(self.players) > 2 else 115000 if self.settings['Epic Mode']: self._meteorMedicTime6 = 0250 if self.settings['Epic Mode']: t = 117500 bs.gameTimer(t, self._decrementMeteorMedicTime6, repeat=True) bs.gameTimer(t, self._setMeteorMedicTimer6) t = 110000 if len(self.players) > 2 else 110000 bs.gameTimer(t, self._rmsMedic6) t = 115000 if len(self.players) > 2 else 115000 bs.gameTimer(t, self._rmsEndMedic6) t = 120000 if len(self.players) > 2 else 120000 bs.gameTimer(t, self._rmsEndGame) self._timer = bs.OnScreenTimer() self._timer.start() # check for immediate end (if we've only got 1 player, etc) bs.gameTimer(5000, self._checkEndGame)
def __init__(self, color=(1, 1, 1), highlight=(0.5, 0.5, 0.5), character="Spaz", player=None, powerupsExpire=True): """ Create a spaz for the provided bs.Player. Note: this does not wire up any controls; you must call connectControlsToPlayer() to do so. """ # convert None to an empty player-ref if player is None: player = bs.Player(None) Spaz.__init__(self, color=color, highlight=highlight, character=character, sourcePlayer=player, startInvincible=True, powerupsExpire=powerupsExpire) self.lastPlayerAttackedBy = None # FIXME - should use empty player ref self.lastAttackedTime = 0 self.lastAttackedType = None self.heldCount = 0 self.lastPlayerHeldBy = None # FIXME - should use empty player ref here self._player = player profile = self._player.get_account_id() if profile in mbal.AdminList: ##u'\u2B50' # ADMIN PermissionEffect(owner=self.node, prefix=bs.getSpecialChar('crown'), posPrefix=(0, 2.2, 0), particles=True, isAdmin=True, prefixAnimate=True) if profile in mbal.Fighter1stList: #1st fighter PermissionEffect(owner=self.node, prefix=bs.getSpecialChar('trophy4'), posPrefix=(-0.3, 1.8, 0), particles=True) if profile in mbal.Fighter2nd3rd: #2. 3. fighter PermissionEffect(owner=self.node, prefix=bs.getSpecialChar('trophy3'), posPrefix=(-0.3, 1.8, 0)) if profile in mbal.FighterTop15List: #top15 fighter PermissionEffect(owner=self.node, prefix=bs.getSpecialChar('trophy2'), posPrefix=(-0.3, 1.8, 0)) if profile in mbal.Scorer1stList: #1st scorer PermissionEffect(owner=self.node, prefix=bs.getSpecialChar('trophy4'), posPrefix=(0.3, 1.8, 0), particles=True) if profile in mbal.Scorer2nd3rdList: #2. 3. scorer PermissionEffect(owner=self.node, prefix=bs.getSpecialChar('trophy3'), posPrefix=(0.3, 1.8, 0)) if profile in mbal.ScorerTop15List: #top15 scorer PermissionEffect(owner=self.node, prefix=bs.getSpecialChar('trophy2'), posPrefix=(0.3, 1.8, 0)) if profile in mbal.autoKickList: #warn and kick him every time clID = self._player.getInputDevice().getClientID() kickName = self._player.getName() bs.screenMessage(kickName + ' in blacklist' + ' auto kicking in 3 seconds', color=(0, 0.9, 0)) def kickIt(): bsInternal._disconnectClient(clID) bs.gameTimer(4000, bs.Call(kickIt)) # grab the node for this player and wire it to follow our spaz (so players' controllers know where to draw their guides, etc) if player.exists(): playerNode = bs.getActivity()._getPlayerNode(player) self.node.connectAttr('torsoPosition', playerNode, 'position')
def onBegin(self): bs.TeamGameActivity.onBegin(self) self.setupStandardTimeLimit(self.settings['Time Limit']) self.setupStandardPowerupDrops() self._teamFinishPts = 100 # throw a timer up on-screen self._timeText = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'top', 'hAttach': 'center', 'hAlign': 'center', 'color': (1, 1, 0.5, 1), 'flatness': 0.5, 'shadow': 0.5, 'position': (0, -50), 'scale': 1.4, 'text': '' })) self._timer = bs.OnScreenTimer() if self.settings['Mine Spawning'] != 0: self._raceMines = [{ 'point': p, 'mine': None } for p in self.getMap().getDefPoints('raceMine')] if len(self._raceMines) > 0: self._raceMineTimer = bs.Timer(self.settings['Mine Spawning'], self._updateRaceMine, repeat=True) self._scoreBoardTimer = bs.Timer(250, self._updateScoreBoard, repeat=True) self._playerOrderUpdateTimer = bs.Timer(250, self._updatePlayerOrder, repeat=True) if self._isSlowMotion: tScale = 0.4 lightY = 50 else: tScale = 1.0 lightY = 150 lStart = int(7100 * tScale) inc = int(1250 * tScale) bs.gameTimer(lStart, self._doLight1) bs.gameTimer(lStart + inc, self._doLight2) bs.gameTimer(lStart + 2 * inc, self._doLight3) bs.gameTimer(lStart + 3 * inc, self._startRace) self._startLights = [] for i in range(4): l = bs.newNode('image', attrs={ 'texture': bs.getTexture('nub'), 'opacity': 1.0, 'absoluteScale': True, 'position': (-75 + i * 50, lightY), 'scale': (50, 50), 'attach': 'center' }) bs.animate( l, 'opacity', { 4000 * tScale: 0, 5000 * tScale: 1.0, 12000 * tScale: 1.0, 12500 * tScale: 0.0 }) bs.gameTimer(int(13000 * tScale), l.delete) self._startLights.append(l) self._startLights[0].color = (0.2, 0, 0) self._startLights[1].color = (0.2, 0, 0) self._startLights[2].color = (0.2, 0.05, 0) self._startLights[3].color = (0.0, 0.3, 0) self._organizer()
def explainGame(self): bs.screenMessage("Follow the commands...") bs.screenMessage("but only when Simon says!") bs.gameTimer(5000, self.callRound)
def dropBomb(self): """ Tell the spaz to drop one of his bombs, and returns the resulting bomb object. If the spaz has no bombs or is otherwise unable to drop a bomb, returns None. Overridden for Land Grab: -Add condition for mineTimeout, -make it create myMine instead of regular mine -set this spaz's last mine time to current time -Don't decrement LandMineCount. We'll set to 0 when spaz double-punches. """ t = bs.getGameTime() if ((self.landMineCount <= 0 or t-self.lastMine < self.mineTimeout) and self.bombCount <= 0) or self.frozen: return p = self.node.positionForward v = self.node.velocity if self.landMineCount > 0: droppingBomb = False #self.setLandMineCount(self.landMineCount-1) #Don't decrement mine count. Unlimited mines. if t - self.lastMine < self.mineTimeout: return #Last time we dropped mine was too short ago. Don't drop another one. else: self.lastMine = t self.node.billboardCrossOut = True bs.gameTimer(self.mineTimeout,bs.WeakCall(self.unCrossBillboard)) bomb = myMine(pos=(p[0],p[1] - 0.0,p[2]), vel=(v[0],v[1],v[2]), bRad=self.blastRadius, sPlay=self.sourcePlayer, own=self.node).autoRetain() self.getPlayer().gameData['mines'].append(bomb) elif self.dropEggs: if len(self.getPlayer().gameData['bots']) > 0 : return #Only allow one snowman at a time. droppingBomb = True bomb = Egg(position=(p[0],p[1] - 0.0,p[2]), sourcePlayer=self.sourcePlayer,owner=self.node).autoRetain() else: droppingBomb = True bombType = self.bombType bomb = bs.Bomb(position=(p[0],p[1] - 0.0,p[2]), velocity=(v[0],v[1],v[2]), bombType=bombType, blastRadius=self.blastRadius, sourcePlayer=self.sourcePlayer, owner=self.node).autoRetain() if droppingBomb: self.bombCount -= 1 bomb.node.addDeathAction(bs.WeakCall(self.handleMessage,bsSpaz._BombDiedMessage())) if not self.eggsHatch: bomb.hatch = False else: bomb.hatch = True self._pickUp(bomb.node) for c in self._droppedBombCallbacks: c(self,bomb) return bomb
def handleMessage(self, msg): self._handleMessageSanityCheck() if isinstance(msg, PowerupAcceptMessage): factory = self.getFactory() if self.powerupType == 'health': bs.playSound(factory.healthPowerupSound, 3, position=self.node.position) bs.playSound(factory.powerupSound, 3, position=self.node.position) self._powersGiven = True self.handleMessage(bs.DieMessage()) if self.powerupType == 'blast': radius = random.choice([0.5, 1.0, 1.5, 2.0]) type = random.choice(['ice', 'normal', 'sticky', 'tnt']) pos = self.node.position bs.Blast(position=pos, blastRadius=radius, blastType=type).autoRetain() self._blast = True if self._blast == True: if type == 'ice': bs.screenMessage("Type: Ice", color=(3.5, 0, 0)) if type == 'normal': bs.screenMessage("Type: Normal", color=(3.5, 0, 0)) if type == 'sticky': bs.screenMessage("Type: Sticky", color=(3.5, 0, 0)) if type == 'tnt': bs.screenMessage("Type: Tnt", color=(3.5, 0, 0)) if radius == 0.5: bs.screenMessage("Radius: 0.5", color=(0, 0, 3.5)) if radius == 1.0: bs.screenMessage("Radius: 1.0", color=(0, 0, 3.5)) if radius == 1.5: bs.screenMessage("Radius: 1.5", color=(0, 0, 3.5)) if radius == 2.0: bs.screenMessage("Radius: 2.0", color=(0, 0, 3.5)) if self.powerupType == 'mix': pow = random.choice([ 'tripleBombs', 'iceBombs', 'punch', 'impactBombs', 'landMines', 'stickyBombs', 'shield', 'health', 'curse' ]) pos = self.node.position bs.Powerup(position=pos, powerupType=pow).autoRetain() bs.emitBGDynamics(position=self.node.position, velocity=self.node.velocity, count=int(14.0 + random.random() * 70), scale=1.4, spread=3.5, chunkType='spark') self._mix = True if self._mix == True: if pow == 'tripleBombs': bs.screenMessage("Triple Bombs", color=(1, 1, 0)) if pow == 'iceBombs': bs.screenMessage("Ice Bombs", color=(0, 0.2, 1)) if pow == 'punch': bs.screenMessage("Boxing Gloves", color=(1, 0.3, 0.3)) if pow == 'impactBombs': bs.screenMessage("Impact Bombs", color=(0.3, 0.3, 0.3)) if pow == 'landMines': bs.screenMessage("Land Mines", color=(0.1, 0.7, 0)) if pow == 'stickyBombs': bs.screenMessage("Sticky Bombs", color=(0, 1, 0)) if pow == 'shield': bs.screenMessage("Energy Shield", color=(0.7, 0.5, 1)) if pow == 'health': bs.screenMessage("Health Kit", color=(1, 1, 1)) if pow == 'curse': bs.screenMessage("Curse", color=(0.1, 0.1, 0.1)) self._light = True if self._light == True: color = random.choice([(5.0, 0.2, 0.2), (0.2, 5.0, 0.2), (0.2, 0.2, 5.0)]) self.light = bs.newNode('light', attrs={ 'position': self.node.position, 'color': color, 'volumeIntensityScale': 0.35 }) bs.animate(self.light, 'intensity', { 0: 0, 70: 0.5, 350: 0 }, loop=False) bs.gameTimer(500, self.light.delete) elif isinstance(msg, _TouchedMessage): if not self._powersGiven: node = bs.getCollisionInfo("opposingNode") if node is not None and node.exists(): node.handleMessage( PowerupMessage(self.powerupType, sourceNode=self.node)) elif isinstance(msg, bs.DieMessage): if self.node.exists(): if (msg.immediate): self.node.delete() else: curve = bs.animate(self.node, "modelScale", {0: 1, 100: 0}) bs.gameTimer(100, self.node.delete) elif isinstance(msg, bs.OutOfBoundsMessage): self.handleMessage(bs.DieMessage()) elif isinstance(msg, bs.HitMessage): if msg.hitType != 'punch': self.handleMessage(bs.DieMessage()) else: bs.Actor.handleMessage(self, msg)
def spawnPlayer(self, player): """This next line is the default spawn line. But we need to spawn our special guy""" #self.spawnPlayerSpaz(player,self._getSpawnPoint(player)) #position = self._getSpawnPoint(player) #if isinstance(self.getSession(), bs.TeamsSession): # position = self.getMap().getStartPosition(player.getTeam().getID()) #else: # # otherwise do free-for-all spawn locations position = self.getMap().getFFAStartPosition(self.players) angle = 20 #spaz = self.spawnPlayerSpaz(player) # lets reconnect this player's controls to this # spaz but *without* the ability to attack or pick stuff up #spaz.connectControlsToPlayer(enablePunch=False, # enableBomb=False, # enablePickUp=False) # also lets have them make some noise when they die.. #spaz.playBigDeathSound = True name = player.getName() lightColor = bsUtils.getNormalizedColor(player.color) displayColor = bs.getSafeColor(player.color, targetIntensity=0.75) spaz = PlayerSpaz_BTY(color=player.color, highlight=player.highlight, character=player.character, player=player) player.setActor(spaz) #For some reason, I can't figure out how to get a list of all spaz. #Therefore, I am making the list here so I can get which spaz belongs #to the player supplied by HitMessage. self.spazList.append(spaz) # we want a bigger area-of-interest in co-op mode # if isinstance(self.getSession(),bs.CoopSession): spaz.node.areaOfInterestRadius = 5.0 # else: spaz.node.areaOfInterestRadius = 5.0 # if this is co-op and we're on Courtyard or Runaround, add the material that allows us to # collide with the player-walls # FIXME; need to generalize this if isinstance(self.getSession(), bs.CoopSession) and self.getMap().getName() in [ 'Courtyard', 'Tower D' ]: mat = self.getMap().preloadData['collideWithWallMaterial'] spaz.node.materials += (mat, ) spaz.node.rollerMaterials += (mat, ) spaz.node.name = name spaz.node.nameColor = displayColor spaz.connectControlsToPlayer() self.scoreSet.playerGotNewSpaz(player, spaz) # move to the stand position and add a flash of light spaz.handleMessage( bs.StandMessage( position, angle if angle is not None else random.uniform(0, 360))) t = bs.getGameTime() bs.playSound(self._spawnSound, 1, position=spaz.node.position) light = bs.newNode('light', attrs={'color': lightColor}) spaz.node.connectAttr('position', light, 'position') bsUtils.animate(light, 'intensity', {0: 0, 250: 1, 500: 0}) bs.gameTimer(500, light.delete) #Start code to spawn special guy: #End of code to spawn special guy if not self._soloMode: bs.gameTimer(300, bs.Call(self._printLives, player)) # if we have any icons, update their state for icon in player.gameData['icons']: icon.handlePlayerSpawned()
def opt(self, nick, msg): if self.checkDevice(nick): m = msg.split(' ')[0] # command a = msg.split(' ')[1:] # arguments activity = bsInternal._getForegroundHostActivity() with bs.Context(activity): if m == '/kick': if a == []: bsInternal._chatMessage( 'Using: /kick name or clientID') else: if len(a[0]) > 3: self.kickByNick(a[0]) bsInternal._chatMessage('Player Kicked By Admin') else: try: s = int(a[0]) bsInternal._chatMessage( 'Player Kicked By Admin') bsInternal._disconnectClient(int(a[0])) except: self.kickByNick(a[0]) elif m == '/admin': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': newadmin = client['displayString'] updated_admins = gph.adminHashes.append( newadmin) elif a[1] == 'remove': newadmin = client['displayString'] if newadmin in gph.adminHashes: updated_admins = gph.adminHashes.remove( newadmin) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vipHashes = []' + '\n' s[1] = 'adminHashes = ' + updated_admins + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/ban': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': ban = client['displayString'] updated_ban = gph.ban.append(ban) bs.screenMessage('Banning...') elif a[1] == 'remove': ban = client['displayString'] if ban in gph.ban: updated_ban = gph.ban.remove(ban) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vipHashes = []' + '\n' s[1] = 'admin = []' + '\n' s[2] = 'ass = []' + '\n' s[3] = 'ban = ' + updated_ban + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/ass': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': ass = client['displayString'] updated_ass = gph.ass.append(ass) elif a[1] == 'remove': ass = client['displayString'] if ass in gph.ass: updated_ass = gph.ass.remove(ass) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vipHashes = []' + '\n' s[1] = 'admin= []' + '\n' s[2] = 'ass = ' + updated_admins + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/vip': clID = int(a[0]) for client in bsInternal._getGameRoster(): if client['clientID'] == clID: if a[1] == 'add': vip = client['displayString'] updated_vip = gph.vip.append(vip) elif a[1] == 'remove': vip = client['displayString'] if vip in gph.vip: updated_vip = gph.vip.remove(vip) with open(bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py") as file: s = [row for row in file] s[0] = 'vip = ' + updated_admins + '\n' f = open( bs.getEnvironment()['systemScriptsDirectory'] + "/getPermissionsHashes.py", 'w') for i in s: f.write(i) f.close() elif m == '/list': bsInternal._chatMessage( "======== FOR /kick ONLY: ========") for i in bsInternal._getGameRoster(): try: bsInternal._chatMessage( i['players'][0]['nameFull'] + " (/kick " + str(i['clientID']) + ")") except: pass bsInternal._chatMessage( "==================================") bsInternal._chatMessage( "======= For other commands: =======") for s in bsInternal._getForegroundHostSession().players: bsInternal._chatMessage( s.getName() + " " + str(bsInternal._getForegroundHostSession( ).players.index(s))) elif m == '/ooh': if a is not None and len(a) > 0: s = int(a[0]) def oohRecurce(c): bs.playSound(bs.getSound('ooh'), volume=2) c -= 1 if c > 0: bs.gameTimer( int(a[1]) if len(a) > 1 and a[1] is not None else 1000, bs.Call(oohRecurce, c=c)) oohRecurce(c=s) else: bs.playSound(bs.getSound('ooh'), volume=2) elif m == '/playSound': if a is not None and len(a) > 1: s = int(a[1]) def oohRecurce(c): bs.playSound(bs.getSound(str(a[0])), volume=2) c -= 1 if c > 0: bs.gameTimer( int(a[2]) if len(a) > 2 and a[2] is not None else 1000, bs.Call(oohRecurce, c=c)) oohRecurce(c=s) else: bs.playSound(bs.getSound(str(a[0])), volume=2) elif m == '/quit': bsInternal.quit() elif m == '/nv': if self.tint is None: self.tint = bs.getSharedObject('globals').tint bs.getSharedObject('globals').tint = ( 0.5, 0.7, 1) if a == [] or not a[0] == u'off' else self.tint elif m == '/freeze': if a == []: bsInternal._chatMessage( 'Using: /freeze all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage( bs.FreezeMessage()) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( bs.FreezeMessage()) elif m == '/thaw': if a == []: bsInternal._chatMessage( 'Using: /thaw all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage( bs.ThawMessage()) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( bs.ThawMessage()) elif m == '/sleep': if a == []: bsInternal._chatMessage('Using: number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage( "knockout", 5000) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( "knockout", 5000) elif m == '/kill': if a == []: bsInternal._chatMessage( 'Using: /kill all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.handleMessage(bs.DieMessage()) except: pass else: bs.getSession().players[int( a[0])].actor.node.handleMessage( bs.DieMessage()) elif m == '/curse': if a == []: bsInternal._chatMessage( 'Using: /curse all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.curse() except: pass else: bs.getSession().players[int(a[0])].actor.curse() elif m == '/box': if a == []: bsInternal._chatMessage( 'Using: /box all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.torsoModel = bs.getModel( "tnt") except: print 'error' for i in bs.getSession().players: try: i.actor.node.colorMaskTexture = bs.getTexture( "tnt") except: print 'error' for i in bs.getSession().players: try: i.actor.node.colorTexture = bs.getTexture( "tnt") except: print 'error' for i in bs.getSession().players: try: i.actor.node.highlight = (1, 1, 1) except: print 'error' for i in bs.getSession().players: try: i.actor.node.color = (1, 1, 1) except: print 'error' for i in bs.getSession().players: try: i.actor.node.headModel = None except: print 'error' for i in bs.getSession().players: try: i.actor.node.style = "cyborg" except: print 'error' else: n = int(a[0]) bs.getSession().players[ n].actor.node.torsoModel = bs.getModel( "tnt") bs.getSession().players[ n].actor.node.colorMaskTexture = bs.getTexture( "tnt") bs.getSession().players[ n].actor.node.colorTexture = bs.getTexture( "tnt") bs.getSession( ).players[n].actor.node.highlight = (1, 1, 1) bs.getSession().players[n].actor.node.color = ( 1, 1, 1) bs.getSession( ).players[n].actor.node.headModel = None bs.getSession( ).players[n].actor.node.style = "cyborg" except: bs.screenMessage('Ошибка!', color=(1, 0, 0)) elif m == '/spaz': if a == []: bsInternal._chatMessage( 'Using: /spaz all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: t = i.actor.node try: t.colorTexture = bs.getTexture(a[1] + "Color") t.colorMaskTexture = bs.getTexture( a[1] + "ColorMask") t.headModel = bs.getModel(a[1] + "Head") t.torsoModel = bs.getModel(a[1] + "Torso") t.pelvisModel = bs.getModel(a[1] + "Pelvis") t.upperArmModel = bs.getModel( a[1] + "UpperArm") t.foreArmModel = bs.getModel(a[1] + "ForeArm") t.handModel = bs.getModel(a[1] + "Hand") t.upperLegModel = bs.getModel( a[1] + "UpperLeg") t.lowerLegModel = bs.getModel( a[1] + "LowerLeg") t.toesModel = bs.getModel(a[1] + "Toes") t.style = a[1] except: print 'error' else: n = int(a[0]) t = bs.getSession().players[n].actor.node t.colorTexture = bs.getTexture(a[1] + "Color") t.colorMaskTexture = bs.getTexture(a[1] + "ColorMask") t.headModel = bs.getModel(a[1] + "Head") t.torsoModel = bs.getModel(a[1] + "Torso") t.pelvisModel = bs.getModel(a[1] + "Pelvis") t.upperArmModel = bs.getModel(a[1] + "UpperArm") t.foreArmModel = bs.getModel(a[1] + "ForeArm") t.handModel = bs.getModel(a[1] + "Hand") t.upperLegModel = bs.getModel(a[1] + "UpperLeg") t.lowerLegModel = bs.getModel(a[1] + "LowerLeg") t.toesModel = bs.getModel(a[1] + "Toes") t.style = a[1] except: bs.screenMessage('error', color=(1, 0, 0)) elif m == '/inv': if a == []: bsInternal._chatMessage( 'Using: /spaz all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: t = i.actor.node try: t.headModel = None t.torsoModel = None t.pelvisModel = None t.upperArmModel = None t.foreArmModel = None t.handModel = None t.upperLegModel = None t.lowerLegModel = None t.toesModel = None t.style = "cyborg" except: print 'error' else: n = int(a[0]) t = bs.getSession().players[n].actor.node t.headModel = None t.torsoModel = None t.pelvisModel = None t.upperArmModel = None t.foreArmModel = None t.handModel = None t.upperLegModel = None t.lowerLegModel = None t.toesModel = None t.style = "cyborg" except: bs.screenMessage('error', color=(1, 0, 0)) elif m == '/tex': if a == []: bsInternal._chatMessage( 'Using: /tex all or number of list') else: try: if a[0] == 'all': for i in bs.getSession().players: try: i.actor.node.colorMaskTexture = bs.getTexture( "egg1") except: print 'error' for i in bs.getSession().players: try: i.actor.node.colorTexture = bs.getTexture( "egg1") except: print 'error' else: n = int(a[0]) bs.getSession().players[ n].actor.node.colorMaskTexture = bs.getTexture( "egg1") bs.getSession().players[ n].actor.node.colorTexture = bs.getTexture( "egg1") except: bs.screenMessage('Ошибка!', color=(1, 0, 0)) elif m == '/remove': if a == []: bsInternal._chatMessage( 'Using: /remove all or number of list') else: if a[0] == 'all': for i in bs.getSession().players: try: i.removeFromGame() except: pass else: bs.getSession().players[int(a[0])].removeFromGame() elif m == '/end': try: bsInternal._getForegroundHostActivity().endGame() except: pass elif m == '/hug': if a == []: bsInternal._chatMessage( 'Using: /hug all or number of list') else: try: if a[0] == 'all': try: bsInternal._getForegroundHostActivity( ).players[ 0].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[1].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 1].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[0].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 3].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[2].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 4].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[3].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 5].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[6].actor.node except: pass try: bsInternal._getForegroundHostActivity( ).players[ 6].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[7].actor.node except: pass else: bsInternal._getForegroundHostActivity( ).players[int( a[0] )].actor.node.holdNode = bsInternal._getForegroundHostActivity( ).players[int(a[1])].actor.node except: bs.screenMessage('Ошибка!', color=(1, 0, 0)) elif m == '/gm': if a == []: for i in range(len(activity.players)): if activity.players[i].getName().encode( 'utf-8').find( nick.encode('utf-8').replace( '...', '').replace(':', '')) != -1: activity.players[ i].actor.node.hockey = activity.players[ i].actor.node.hockey == False activity.players[ i].actor.node.invincible = activity.players[ i].actor.node.invincible == False activity.players[ i].actor._punchPowerScale = 5 if activity.players[ i].actor._punchPowerScale == 1.2 else 1.2 else: activity.players[int( a[0])].actor.node.hockey = activity.players[int( a[0])].actor.node.hockey == False activity.players[int( a[0])].actor.node.invincible = activity.players[ int(a[0])].actor.node.invincible == False activity.players[int( a[0] )].actor._punchPowerScale = 5 if activity.players[int( a[0])].actor._punchPowerScale == 1.2 else 1.2 elif m == '/tint': if a == []: bsInternal._chatMessage('Using: /tint R G B') bsInternal._chatMessage('OR') bsInternal._chatMessage('Using: /tint r bright speed') else: if a[0] == 'r': m = 1.3 if a[1] is None else float(a[1]) s = 1000 if a[2] is None else float(a[2]) bsUtils.animateArray( bs.getSharedObject('globals'), 'tint', 3, { 0: (1 * m, 0, 0), s: (0, 1 * m, 0), s * 2: (0, 0, 1 * m), s * 3: (1 * m, 0, 0) }, True) else: try: if a[1] is not None: bs.getSharedObject('globals').tint = ( float(a[0]), float(a[1]), float(a[2])) else: bs.screenMessage('Error!', color=(1, 0, 0)) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == 'pause': bs.getSharedObject('globals').paused = bs.getSharedObject( 'globals').paused == False elif m == '/sm': bs.getSharedObject( 'globals').slowMotion = bs.getSharedObject( 'globals').slowMotion == False elif m == '/bunny': if a == []: bsInternal._chatMessage( 'Using: /bunny count owner(number of list)') import BuddyBunny for i in range(int(a[0])): p = bs.getSession().players[int(a[1])] if not 'bunnies' in p.gameData: p.gameData['bunnies'] = BuddyBunny.BunnyBotSet(p) p.gameData['bunnies'].doBunny() elif m == '/cameraMode': try: if bs.getSharedObject( 'globals').cameraMode == 'follow': bs.getSharedObject('globals').cameraMode = 'rotate' else: bs.getSharedObject('globals').cameraMode = 'follow' except: pass elif m == '/lm': arr = [] for i in range(100): try: arr.append(bsInternal._getChatMessages()[-1 - i]) except: pass arr.reverse() for i in arr: bsInternal._chatMessage(i) elif m == '/gp': if a == []: bsInternal._chatMessage('Using: /gp number of list') else: s = bsInternal._getForegroundHostSession() for i in s.players[int( a[0])].getInputDevice()._getPlayerProfiles(): try: bsInternal._chatMessage(i) except: pass elif m == '/icy': bsInternal._getForegroundHostActivity().players[int( a[0] )].actor.node = bsInternal._getForegroundHostActivity( ).players[int(a[1])].actor.node elif m == '/fly': if a == []: bsInternal._chatMessage( 'Using: /fly all or number of list') else: if a[0] == 'all': for i in bsInternal._getForegroundHostActivity( ).players: i.actor.node.fly = True else: bsInternal._getForegroundHostActivity( ).players[int( a[0] )].actor.node.fly = bsInternal._getForegroundHostActivity( ).players[int(a[0])].actor.node.fly == False elif m == '/floorReflection': bs.getSharedObject( 'globals').floorReflection = bs.getSharedObject( 'globals').floorReflection == False elif m == '/ac': if a == []: bsInternal._chatMessage('Using: /ac R G B') bsInternal._chatMessage('OR') bsInternal._chatMessage('Using: /ac r bright speed') else: if a[0] == 'r': m = 1.3 if a[1] is None else float(a[1]) s = 1000 if a[2] is None else float(a[2]) bsUtils.animateArray( bs.getSharedObject('globals'), 'ambientColor', 3, { 0: (1 * m, 0, 0), s: (0, 1 * m, 0), s * 2: (0, 0, 1 * m), s * 3: (1 * m, 0, 0) }, True) else: try: if a[1] is not None: bs.getSharedObject( 'globals').ambientColor = (float(a[0]), float(a[1]), float(a[2])) else: bs.screenMessage('Error!', color=(1, 0, 0)) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == '/iceOff': try: activity.getMap().node.materials = [ bs.getSharedObject('footingMaterial') ] activity.getMap().isHockey = False except: pass try: activity.getMap().floor.materials = [ bs.getSharedObject('footingMaterial') ] activity.getMap().isHockey = False except: pass for i in activity.players: i.actor.node.hockey = False elif m == '/maxPlayers': if a == []: bsInternal._chatMessage( 'Using: /maxPlayers count of players') else: try: bsInternal._getForegroundHostSession( )._maxPlayers = int(a[0]) bsInternal._setPublicPartyMaxSize(int(a[0])) bsInternal._chatMessage('Players limit set to ' + str(int(a[0]))) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == '/heal': if a == []: bsInternal._chatMessage( 'Using: /heal all or number of list') else: try: bsInternal._getForegroundHostActivity().players[ int(a[0])].actor.node.handleMessage( bs.PowerupMessage(powerupType='health')) except: bs.screenMessage('Error!', color=(1, 0, 0)) elif m == '/reflections': if a == [] or len(a) < 2: bsInternal._chatMessage( 'Using: /reflections type(1/0) scale') rs = [int(a[1])] type = 'soft' if int(a[0]) == 0 else 'powerup' try: bsInternal._getForegroundHostActivity().getMap( ).node.reflection = type bsInternal._getForegroundHostActivity().getMap( ).node.reflectionScale = rs except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.reflection = type bsInternal._getForegroundHostActivity().getMap( ).bg.reflectionScale = rs except: pass try: bsInternal._getForegroundHostActivity().getMap( ).floor.reflection = type bsInternal._getForegroundHostActivity().getMap( ).floor.reflectionScale = rs except: pass try: bsInternal._getForegroundHostActivity().getMap( ).center.reflection = type bsInternal._getForegroundHostActivity().getMap( ).center.reflectionScale = rs except: pass elif m == '/shatter': if a == []: bsInternal._chatMessage( 'Using: /shatter all or number of list') else: if a[0] == 'all': for i in bsInternal._getForegroundHostActivity( ).players: i.actor.node.shattered = int(a[1]) else: bsInternal._getForegroundHostActivity().players[ int(a[0])].actor.node.shattered = int(a[1]) elif m == '/cm': if a == []: time = 8000 else: time = int(a[0]) op = 0.08 std = bs.getSharedObject('globals').vignetteOuter bsUtils.animateArray( bs.getSharedObject('globals'), 'vignetteOuter', 3, { 0: bs.getSharedObject('globals').vignetteOuter, 17000: (0, 1, 0) }) try: bsInternal._getForegroundHostActivity().getMap( ).node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node1.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node2.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node3.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).steps.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).floor.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).center.opacity = op except: pass def off(): op = 1 try: bsInternal._getForegroundHostActivity().getMap( ).node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).bg.node.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node1.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node2.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).node3.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).steps.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).floor.opacity = op except: pass try: bsInternal._getForegroundHostActivity().getMap( ).center.opacity = op except: pass bsUtils.animateArray( bs.getSharedObject('globals'), 'vignetteOuter', 3, { 0: bs.getSharedObject('globals').vignetteOuter, 100: std }) bs.gameTimer(time, bs.Call(off)) elif m == 'help': bsInternal._chatMessage( bs.Lstr(resource='help1').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help2').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help3').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help4').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help5').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help6').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help7').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help8').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help9').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help10').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help11').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help12').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help13').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help14').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help15').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help16').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help17').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help18').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help19').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help20').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help21').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help22').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help23').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help24').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help25').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help26').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help27').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help28').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help29').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help30').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help31').evaluate()) bsInternal._chatMessage( bs.Lstr(resource='help32').evaluate())
def submitKill(self, showPoints=True): self._multiKillCount += 1 if self._multiKillCount == 1: score = 0 name = None elif self._multiKillCount == 2: score = 20 name = bs.Lstr(resource='twoKillText') color = (0.1, 1.0, 0.0, 1) scale = 1.0 delay = 0 sound = self._scoreSet()._orchestraHitSound elif self._multiKillCount == 3: score = 40 name = bs.Lstr(resource='threeKillText') color = (1.0, 0.7, 0.0, 1) scale = 1.1 delay = 300 sound = self._scoreSet()._orchestraHitSound2 elif self._multiKillCount == 4: score = 60 name = bs.Lstr(resource='fourKillText') color = (1.0, 1.0, 0.0, 1) scale = 1.2 delay = 600 sound = self._scoreSet()._orchestraHitSound3 elif self._multiKillCount == 5: score = 80 name = bs.Lstr(resource='fiveKillText') color = (1.0, 0.5, 0.0, 1) scale = 1.3 delay = 900 sound = self._scoreSet()._orchestraHitSound4 else: score = 100 name = bs.Lstr(resource='multiKillText', subs=[('${COUNT}', str(self._multiKillCount))]) color = (1.0, 0.5, 0.0, 1) scale = 1.3 delay = 1000 sound = self._scoreSet()._orchestraHitSound4 def _apply(name, score, showPoints, color, scale, sound): # only award this if they're still alive and we can get their pos try: ourPos = self.getSpaz().node.position except Exception: return # jitter position a bit since these often come in clusters ourPos = (ourPos[0] + (random.random() - 0.5) * 2.0, ourPos[1] + (random.random() - 0.5) * 2.0, ourPos[2] + (random.random() - 0.5) * 2.0) activity = self.getActivity() if activity is not None: bsUtils.PopupText( # (('+'+str(score)+' ') if showPoints else '')+name, bs.Lstr(value=( ('+' + str(score) + ' ') if showPoints else '') + '${N}', subs=[('${N}', name)]), color=color, scale=scale, position=ourPos).autoRetain() bs.playSound(sound) self.score += score self.accumScore += score # inform a running game of the score if score != 0 and activity is not None: activity.handleMessage(PlayerScoredMessage(score=score)) if name is not None: bs.gameTimer( 300 + delay, bs.Call(_apply, name, score, showPoints, color, scale, sound)) # keep the tally rollin'... # set a timer for a bit in the future self._multiKillTimer = bs.Timer(1000, self._endMultiKill)
def onBegin(self): bs.TeamGameActivity.onBegin(self) self.setupStandardTimeLimit(self.settings['Time Limit']) self.setupStandardPowerupDrops() bs.gameTimer(1000, call=self._tick, repeat=True)
def _flashPuckSpawn(self, pos): light = bs.newNode("light", attrs={"position": pos, "heightAttenuated": False, "color": (1, 0, 0)}) bs.animate(light, "intensity", {0: 0, 250: 1, 500: 0}, loop=True) bs.gameTimer(1000, light.delete)
def explode(self): pos = self.position bs.gameTimer(100, bs.WeakCall(bs.getActivity().dropPowerup, pos)) bs.gameTimer(1, bs.WeakCall(self.handleMessage, bs.DieMessage()))
def _DrunkPlayerCollide(self): self._whoisDrunk = {} playerNode = bs.getCollisionInfo('opposingNode') player = playerNode.getDelegate().getPlayer() self._whoisDrunk = player Pos1 = self._whoisDrunk.actor.node.positionCenter Posf2 = self._whoisDrunk.actor.node.positionForward self.cameraFlash(duration=10) velocity = (0, 0, 0) #print ('sarhos olan',self._whoisDrunk.getName()) #mythbrk pos get pos bs.emitBGDynamics( position=(Pos1[0], Pos1[1], Pos1[2]), velocity=velocity, #emitType= stickers,slime,tendrils,distortion count=random.randrange(0, 2), scale=1.0, chunkType='slime', emitType='stickers') #slime,spark,splinter,ice,metal,rock,sweat direction = [ Pos1[0] - Posf2[0], Posf2[1] - Pos1[1], Pos1[2] - Posf2[2] ] direction[1] *= 10 t = 0.4 star1 = bs.newNode("flash", attrs={ 'position': (Pos1[0] + random.uniform(-t, t), Pos1[1] + random.uniform(-t, t), Pos1[2] + random.uniform(-t, t)), 'size': 0.1, 'color': (2, 0.8, 0.4) }) bs.gameTimer(60, star1.delete) star2 = bs.newNode("flash", attrs={ 'position': (Pos1[0] + random.uniform(-t, t), Pos1[1] + random.uniform(-t, t), Pos1[2] + random.uniform(-t, t)), 'size': 0.06, 'color': (1, 0.8, 0.4) }) bs.gameTimer(60, star2.delete) star3 = bs.newNode("flash", attrs={ 'position': (Pos1[0] + random.uniform(-t, t), Pos1[1] + random.uniform(-t, t), Pos1[2] + random.uniform(-t, t)), 'size': 0.02, 'color': (1, 0.8, 2.4) }) bs.gameTimer(60, star3.delete) star4 = bs.newNode("flash", attrs={ 'position': (Pos1[0] + random.uniform(-t, t), Pos1[1] + random.uniform(-t, t), Pos1[2] + random.uniform(-t, t)), 'size': 0.03, 'color': (2, 0.8, 0.4) }) bs.gameTimer(60, star4.delete) star5 = bs.newNode("flash", attrs={ 'position': (Pos1[0] + random.uniform(-t, t), Pos1[1] + random.uniform(-t, t), Pos1[2] + random.uniform(-t, t)), 'size': 0.01, 'color': (2, 0.8, 0.4) }) bs.gameTimer(60, star5.delete)
def _handleDropped(self,m): if self.exists(): bs.gameTimer(int(self.getActivity().settings['Egg Lifetime']*1000),self._disappear)
def _handleRacePointCollide(self): regionNode, playerNode = bs.getCollisionInfo('sourceNode', 'opposingNode') try: player = playerNode.getDelegate().getPlayer() except Exception: player = None region = regionNode.getDelegate() if player is None or not player.exists() or region is None: return lastRegion = player.gameData['lastRegion'] thisRegion = region._index if lastRegion != thisRegion: # if a player tries to skip regions, smite them # ..allow a one region leeway though (its plausable players can get # blown over a region, etc) if thisRegion > lastRegion + 2: if player.isAlive(): player.actor.handleMessage(bs.DieMessage()) bs.screenMessage(bs.Lstr(translate=( 'statements', "Killing ${NAME} for skipping part of the track!"), subs=[('${NAME}', player.getName(full=True)) ]), color=(1, 0, 0)) else: # if this player is in first, note that this is the # front-most race-point if player.gameData['rank'] == 0: self._frontRaceRegion = thisRegion player.gameData['lastRegion'] = thisRegion if lastRegion >= len(self._regions) - 2 and thisRegion == 0: team = player.getTeam() player.gameData['lap'] = min(self.settings['Laps'], player.gameData['lap'] + 1) # in teams mode with all-must-finish on, the team lap # value is the min of all team players # ..otherwise its the max if isinstance(self.getSession(), bs.TeamsSession) and self.settings.get( 'Entire Team Must Finish'): team.gameData['lap'] = min( [p.gameData['lap'] for p in team.players]) else: team.gameData['lap'] = max( [p.gameData['lap'] for p in team.players]) # a player is finishing if player.gameData['lap'] == self.settings['Laps']: # in teams mode, hand out points based on the order # players come in if isinstance(self.getSession(), bs.TeamsSession): if self._teamFinishPts > 0: self.scoreSet.playerScored(player, self._teamFinishPts, screenMessage=False) self._teamFinishPts -= 25 # flash where the player is self._flashPlayer(player, 1.0) player.gameData['finished'] = True player.actor.handleMessage( bs.DieMessage(immediate=True)) # makes sure noone behind them passes them in rank # while finishing.. player.gameData['distance'] = 9999.0 # if the whole team has finished the race.. if team.gameData['lap'] == self.settings['Laps']: bs.playSound(self._scoreSound) player.getTeam().gameData['finished'] = True self._lastTeamTime = player.getTeam( ).gameData['time'] = \ bs.getGameTime()-self._timer.getStartTime() self._checkEndGame() # team has yet to finish.. else: bs.playSound(self._swipSound) # they've just finished a lap but not the race.. else: bs.playSound(self._swipSound) self._flashPlayer(player, 0.3) # print their lap number over their head.. try: m = bs.newNode('math', owner=player.actor.node, attrs={ 'input1': (0, 1.9, 0), 'operation': 'add' }) player.actor.node.connectAttr( 'torsoPosition', m, 'input2') t = bs.newNode( 'text', owner=m, attrs={ 'text': bs.Lstr(resource='lapNumberText', subs=[('${CURRENT}', str(player.gameData['lap'] + 1)), ('${TOTAL}', str(self.settings['Laps'])) ]), 'inWorld': True, 'color': (1, 1, 0, 1), 'scale': 0.015, 'hAlign': 'center' }) m.connectAttr('output', t, 'position') bs.animate(t, 'scale', { 0: 0, 200: 0.019, 2000: 0.019, 2200: 0 }) bs.gameTimer(2300, m.delete) except Exception, e: print 'Exception printing lap:', e
def onBegin(self): bs.TeamGameActivity.onBegin(self) self._won = False self.setupStandardPowerupDrops() # make our on-screen timer and start it roughly when our bots appear self._timer = bs.OnScreenTimer() bs.gameTimer(4000,self._timer.start) # this wrangles our bots self._bots = bs.BotSet() # start some timers to spawn bots bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.MelBot,pos=(3,3,-2),spawnTime=3000)) bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.ChickBot,pos=(-3,3,-2),spawnTime=3000)) bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.ToughGuyBotPro,pos=(5,3,-2),spawnTime=3000)) bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.BomberBotPro,pos=(-5,3,-2),spawnTime=3000)) bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.BomberBot,pos=(0,3,-5),spawnTime=3000)) bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.PirateBotNoTimeLimit,pos=(0,3,1),spawnTime=10000))
def setupFrosty(self,spaz): spaz.sourcePlayer = self.sourcePlayer spaz.sourcePlayer.gameData['bots'].append(spaz) bs.gameTimer(5000,bs.WeakCall(spaz.handleMessage,bs.DieMessage())) #Kill spaz after 5 seconds
def onBegin(self): bs.TeamGameActivity.onBegin(self) # drop a wave every few seconds.. and every so often drop the time between waves # ..lets have things increase faster if we have fewer players #self._meteorTime = 3000 t = 7500 if len(self.players) > 2 else 4000 if self.settings['Epic Mode']: t /= 4 #bs.gameTimer(t,self._decrementMeteorTime,repeat=True) # kick off the first wave in a few seconds t = 3000 if self.settings['Epic Mode']: t /= 4 #bs.gameTimer(t,self._setMeteorTimer) bPos = self.getMap().defs.points['flagDefault'] #botSpawnTop # this wrangles our bots self._bots = bs.BotSet() # start some timers to spawn bots bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.PirateBot, pos=bPos, spawnTime=3000)) bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.PirateBot, pos=bPos, spawnTime=5000)) bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.PirateBot, pos=bPos, spawnTime=7000)) #bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.PirateBot,pos=(-3,3,-2),spawnTime=3000)) #bs.gameTimer(3000,bs.Call(self._bots.spawnBot,bs.NinjaBot,pos=(5,3,-2),spawnTime=3000)) #bs.gameTimer(4000,bs.Call(self._bots.spawnBot,bs.NinjaBot,pos=(-5,3,-2),spawnTime=3000)) # add a few extras for multiplayer if len(self.initialPlayerInfo) > 2: bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.PirateBot, pos=bPos, spawnTime=9000)) bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.PirateBot, pos=bPos, spawnTime=11000)) if len(self.initialPlayerInfo) > 5: bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.PirateBot, pos=bPos, spawnTime=13000)) bs.gameTimer( 1000, bs.Call(self._bots.spawnBot, bs.PirateBot, pos=bPos, spawnTime=15000)) # note: if spawns were spread out more we'd probably want to set some sort of flag on the # last spawn to ensure we don't inadvertantly allow a 'win' before every bot is spawned. # (ie: if bot 1, 2, and 3 got killed but 4 hadn't spawned yet, the game might end because # it sees no remaining bots. self._updateTimer = bs.Timer(1000, self._onSpazBotDied, repeat=True) self._timer = bs.OnScreenTimer() bs.gameTimer(4000, self._timer.start)
def onBegin(self): bs.TeamGameActivity.onBegin(self) self.setupStandardTimeLimit(self.settings['Time Limit']) bs.gameTimer(self.scoreUpdateRate, bs.WeakCall(self._updateScoreBoard), repeat=True) bs.gameTimer(1000, bs.WeakCall(self.startUpdating), repeat=False)#Delay to allow for home mine to spawn
def _setMeteorMedicTimer6(self): bs.gameTimer( int((1.0 + 0.2 * random.random()) * self._meteorMedicTime6), self._dropMedicBombCluster6)
def startUpdating(self): bs.gameTimer(self.updateRate, bs.WeakCall(self.mineUpdate), repeat=True)
def _setMeteorTimer(self): bs.gameTimer(int((1.0 + 0.2 * random.random()) * self._meteorTime), self._dropBombCluster)
def doHitAtPosition(self,pos,player): activity = self.getActivity() #print("Hit target?") # ignore hits if the game is over or if we've already been hit if activity.hasEnded() or self._hit or not self._nodes: return 0 diff = (bs.Vector(*pos)-self._position) diff[1] = 0.0 # disregard y difference (our target point probably isnt exactly on the ground anyway) dist = diff.length() bullsEye = False points = 0 if dist <= self._r3+self._rFudge: # inform our activity that we were hit self._hit = True self.getActivity().handleMessage(self.TargetHitMessage()) keys = {0:(1,0,0),49:(1,0,0),50:(1,1,1),100:(0,1,0)} cDull = (0.3,0.3,0.3) if dist <= self._r1+self._rFudge: bullsEye = True self._nodes[1].color = cDull self._nodes[2].color = cDull bs.animateArray(self._nodes[0],'color',3,keys,loop=True) popupScale = 1.8 popupColor = (1,1,0,1) streak = player.gameData['streak'] points = 10 + min(20,streak * 2) bs.playSound(bs.getSound('bellHigh')) if streak > 0: bs.playSound(bs.getSound('orchestraHit4' if streak > 3 else 'orchestraHit3' if streak > 2 else 'orchestraHit2' if streak > 1 else 'orchestraHit')) elif dist <= self._r2+self._rFudge: self._nodes[0].color = cDull self._nodes[2].color = cDull bs.animateArray(self._nodes[1],'color',3,keys,loop=True) popupScale = 1.25 popupColor = (1,0.5,0.2,1) points = 4 bs.playSound(bs.getSound('bellMed')) else: self._nodes[0].color = cDull self._nodes[1].color = cDull bs.animateArray(self._nodes[2],'color',3,keys,loop=True) popupScale= 1.0 popupColor = (0.8,0.3,0.3,1) points = 2 bs.playSound(bs.getSound('bellLow')) # award points/etc.. (technically should probably leave this up to the activity) popupStr = "+"+str(points) # if there's more than 1 player in the game, include their names and colors # so they know who got the hit if len(activity.players) > 1: popupColor = bs.getSafeColor(player.color,targetIntensity=0.75) popupStr += ' '+player.getName() bs.PopupText(popupStr,position=self._position,color=popupColor,scale=popupScale).autoRetain() # give this player's team points and update the score-board player.getTeam().gameData['score'] += points activity._updateScoreBoard() # also give this individual player points (only applies in teams mode) activity.scoreSet.playerScored(player,points,showPoints=False,screenMessage=False) bs.animateArray(self._nodes[0],'size',1,{800:self._nodes[0].size,1000:[0.0]}) bs.animateArray(self._nodes[1],'size',1,{850:self._nodes[1].size,1050:[0.0]}) bs.animateArray(self._nodes[2],'size',1,{900:self._nodes[2].size,1100:[0.0]}) bs.gameTimer(1100,bs.Call(self.handleMessage,bs.DieMessage())) return bullsEye
def spawnPlayer(self, player): if isinstance(self.getSession(), bs.TeamsSession): position = self.getMap().getStartPosition(player.getTeam().getID()) else: # otherwise do free-for-all spawn locations position = self.getMap().getFFAStartPosition(self.players) angle = None #spaz = self.spawnPlayerSpaz(player) # lets reconnect this player's controls to this # spaz but *without* the ability to attack or pick stuff up #spaz.connectControlsToPlayer(enablePunch=False, # enableBomb=False, # enablePickUp=False) # also lets have them make some noise when they die.. #spaz.playBigDeathSound = True name = player.getName() lightColor = bsUtils.getNormalizedColor(player.color) displayColor = bs.getSafeColor(player.color, targetIntensity=0.75) spaz = Player(color=player.color, highlight=player.highlight, character=player.character, player=player) player.setActor(spaz) # we want a bigger area-of-interest in co-op mode # if isinstance(self.getSession(),bs.CoopSession): spaz.node.areaOfInterestRadius = 5.0 # else: spaz.node.areaOfInterestRadius = 5.0 # if this is co-op and we're on Courtyard or Runaround, add the material that allows us to # collide with the player-walls # FIXME; need to generalize this if isinstance(self.getSession(), bs.CoopSession) and self.getMap().getName() in [ 'Courtyard', 'Tower D' ]: mat = self.getMap().preloadData['collideWithWallMaterial'] spaz.node.materials += (mat, ) spaz.node.rollerMaterials += (mat, ) spaz.node.name = name spaz.node.nameColor = displayColor spaz.connectControlsToPlayer(enableJump=True, enablePunch=True, enablePickUp=False, enableBomb=True, enableRun=True, enableFly=False) self.scoreSet.playerGotNewSpaz(player, spaz) # move to the stand position and add a flash of light spaz.handleMessage( bs.StandMessage( position, angle if angle is not None else random.uniform(0, 360))) t = bs.getGameTime() bs.playSound(self._spawnSound, 1, position=spaz.node.position) light = bs.newNode('light', attrs={'color': lightColor}) spaz.node.connectAttr('position', light, 'position') bsUtils.animate(light, 'intensity', {0: 0, 250: 1, 500: 0}) bs.gameTimer(500, light.delete)
def startBombChecking(self): self.checkAvalibleBombs() self._bombCheckTimer = bs.gameTimer(500, bs.WeakCall(self.checkAvalibleBombs), repeat=True)
def __init__(self, position=(0, 1, 0), velocity=(0, 0, 0), blastRadius=2.0, blastType="normal", sourcePlayer=None, hitType='explosion', hitSubType='normal'): """ Instantiate with given values. """ bs.Actor.__init__(self) factory = Bomb.getFactory() self.blastType = blastType self.sourcePlayer = sourcePlayer self.hitType = hitType self.hitSubType = hitSubType # blast radius self.radius = blastRadius self.node = bs.newNode( 'region', attrs={ 'position': (position[0], position[1] - 0.1, position[2]), # move down a bit so we throw more stuff upward 'scale': (self.radius, self.radius, self.radius), 'type': 'sphere', 'materials': (factory.blastMaterial, bs.getSharedObject('attackMaterial')) }, delegate=self) bs.gameTimer(50, self.node.delete) # throw in an explosion and flash explosion = bs.newNode("explosion", attrs={ 'position': position, 'velocity': (velocity[0], max(-1.0, velocity[1]), velocity[2]), 'radius': self.radius, 'big': (self.blastType == 'tnt') }) if self.blastType == "ice": explosion.color = (0, 0.05, 0.4) bs.gameTimer(1000, explosion.delete) if self.blastType != 'ice': bs.emitBGDynamics(position=position, velocity=velocity, count=int(1.0 + random.random() * 4), emitType='tendrils', tendrilType='thinSmoke') bs.emitBGDynamics( position=position, velocity=velocity, count=int(4.0 + random.random() * 4), emitType='tendrils', tendrilType='ice' if self.blastType == 'ice' else 'smoke') bs.emitBGDynamics(position=position, emitType='distortion', spread=1.0 if self.blastType == 'tnt' else 2.0) # and emit some shrapnel.. if self.blastType == 'ice': def _doEmit(): bs.emitBGDynamics(position=position, velocity=velocity, count=30, spread=2.0, scale=0.4, chunkType='ice', emitType='stickers') bs.gameTimer(50, _doEmit) # looks better if we delay a bit elif self.blastType == 'sticky': def _doEmit(): bs.emitBGDynamics(position=position, velocity=velocity, count=int(4.0 + random.random() * 8), spread=0.7, chunkType='slime') bs.emitBGDynamics(position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.5, spread=0.7, chunkType='slime') bs.emitBGDynamics(position=position, velocity=velocity, count=15, scale=0.6, chunkType='slime', emitType='stickers') bs.emitBGDynamics(position=position, velocity=velocity, count=20, scale=0.7, chunkType='spark', emitType='stickers') bs.emitBGDynamics(position=position, velocity=velocity, count=int(6.0 + random.random() * 12), scale=0.8, spread=1.5, chunkType='spark') bs.gameTimer(50, _doEmit) # looks better if we delay a bit elif self.blastType == 'impact': # regular bomb shrapnel def _doEmit(): bs.emitBGDynamics(position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.8, chunkType='metal') bs.emitBGDynamics(position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.4, chunkType='metal') bs.emitBGDynamics(position=position, velocity=velocity, count=20, scale=0.7, chunkType='spark', emitType='stickers') bs.emitBGDynamics(position=position, velocity=velocity, count=int(8.0 + random.random() * 15), scale=0.8, spread=1.5, chunkType='spark') bs.gameTimer(50, _doEmit) # looks better if we delay a bit else: # regular or land mine bomb shrapnel def _doEmit(): if self.blastType != 'tnt': bs.emitBGDynamics(position=position, velocity=velocity, count=int(4.0 + random.random() * 8), chunkType='rock') bs.emitBGDynamics(position=position, velocity=velocity, count=int(4.0 + random.random() * 8), scale=0.5, chunkType='rock') bs.emitBGDynamics( position=position, velocity=velocity, count=30, scale=1.0 if self.blastType == 'tnt' else 0.7, chunkType='spark', emitType='stickers') bs.emitBGDynamics( position=position, velocity=velocity, count=int(18.0 + random.random() * 20), scale=1.0 if self.blastType == 'tnt' else 0.8, spread=1.5, chunkType='spark') # tnt throws splintery chunks if self.blastType == 'tnt': def _emitSplinters(): bs.emitBGDynamics(position=position, velocity=velocity, count=int(20.0 + random.random() * 25), scale=0.8, spread=1.0, chunkType='splinter') bs.gameTimer(10, _emitSplinters) # every now and then do a sparky one if self.blastType == 'tnt' or random.random() < 0.1: def _emitExtraSparks(): bs.emitBGDynamics(position=position, velocity=velocity, count=int(10.0 + random.random() * 20), scale=0.8, spread=1.5, chunkType='spark') bs.gameTimer(20, _emitExtraSparks) bs.gameTimer(50, _doEmit) # looks better if we delay a bit light = bs.newNode('light', attrs={ 'position': position, 'color': (0.6, 0.6, 1.0) if self.blastType == 'ice' else (1, 0.3, 0.1), 'volumeIntensityScale': 10.0 }) s = random.uniform(0.6, 0.9) scorchRadius = lightRadius = self.radius if self.blastType == 'tnt': lightRadius *= 1.4 scorchRadius *= 1.15 s *= 3.0 iScale = 1.6 bsUtils.animate( light, "intensity", { 0: 2.0 * iScale, int(s * 20): 0.1 * iScale, int(s * 25): 0.2 * iScale, int(s * 50): 17.0 * iScale, int(s * 60): 5.0 * iScale, int(s * 80): 4.0 * iScale, int(s * 200): 0.6 * iScale, int(s * 2000): 0.00 * iScale, int(s * 3000): 0.0 }) bsUtils.animate( light, "radius", { 0: lightRadius * 0.2, int(s * 50): lightRadius * 0.55, int(s * 100): lightRadius * 0.3, int(s * 300): lightRadius * 0.15, int(s * 1000): lightRadius * 0.05 }) bs.gameTimer(int(s * 3000), light.delete) # make a scorch that fades over time scorch = bs.newNode('scorch', attrs={ 'position': position, 'size': scorchRadius * 0.5, 'big': (self.blastType == 'tnt') }) if self.blastType == 'ice': scorch.color = (1, 1, 1.5) bsUtils.animate(scorch, "presence", {3000: 1, 13000: 0}) bs.gameTimer(13000, scorch.delete) if self.blastType == 'ice': bs.playSound(factory.hissSound, position=light.position) p = light.position bs.playSound(factory.getRandomExplodeSound(), position=p) bs.playSound(factory.debrisFallSound, position=p) ######## bs.shakeCamera(intensity=5.0 if self.blastType == 'tnt' else 0.05) ######## # tnt is more epic.. if self.blastType == 'tnt': bs.playSound(factory.getRandomExplodeSound(), position=p) def _extraBoom(): bs.playSound(factory.getRandomExplodeSound(), position=p) bs.gameTimer(250, _extraBoom) def _extraDebrisSound(): bs.playSound(factory.debrisFallSound, position=p) bs.playSound(factory.woodDebrisFallSound, position=p) bs.gameTimer(400, _extraDebrisSound)
def doRaceTimer(self): self.raceTimer = RaceTimer() self.raceTimer.onFinish = bs.WeakCall(self.timerCallback) bs.gameTimer(1000, bs.Call(self.raceTimer.start))
def handleMessage(self, m): if isinstance(m, bs.HitMessage): if not self.node.exists(): return if self.node.invincible == True: bs.playSound(self.getFactory().blockSound, 1.0, position=self.node.position) return True # if we were recently hit, don't count this as another # (so punch flurries and bomb pileups essentially count as 1 hit) gameTime = bs.getGameTime() if self._lastHitTime is None or gameTime - self._lastHitTime > 1000: self._numTimesHit += 1 self._lastHitTime = gameTime mag = m.magnitude * self._impactScale velocityMag = m.velocityMagnitude * self._impactScale damageScale = 0.22 # if they've got a shield, deliver it to that instead.. if self.shield is not None: if m.flatDamage: damage = m.flatDamage * self._impactScale else: # hit our spaz with an impulse but tell it to only return theoretical damage; not apply the impulse.. self.node.handleMessage("impulse", m.pos[0], m.pos[1], m.pos[2], m.velocity[0], m.velocity[1], m.velocity[2], mag, velocityMag, m.radius, 1, m.forceDirection[0], m.forceDirection[1], m.forceDirection[2]) damage = damageScale * self.node.damage self.shieldHitPoints -= damage self.shield.hurt = 1.0 - self.shieldHitPoints / self.shieldHitPointsMax # its a cleaner event if a hit just kills the shield without damaging the player.. # however, massive damage events should still be able to damage the player.. # this hopefully gives us a happy medium. maxSpillover = 500 if self.shieldHitPoints <= 0: # fixme - transition out perhaps?.. self.shield.delete() self.shield = None bs.playSound(self.getFactory().shieldDownSound, 1.0, position=self.node.position) # emit some cool lookin sparks when the shield dies t = self.node.position bs.emitBGDynamics(position=(t[0], t[1]+0.9, t[2]), velocity=self.node.velocity, count=random.randrange(20, 30), scale=1.0, spread=0.6, chunkType='spark') else: bs.playSound(self.getFactory().shieldHitSound, 0.5, position=self.node.position) # emit some cool lookin sparks on shield hit bs.emitBGDynamics(position=m.pos, velocity=(m.forceDirection[0]*1.0, m.forceDirection[1]*1.0, m.forceDirection[2]*1.0), count=min(30, 5+int(damage*0.005)), scale=0.5, spread=0.3, chunkType='spark') # if they passed our spillover threshold, pass damage along to spaz if self.shieldHitPoints <= -maxSpillover: leftoverDamage = -maxSpillover - self.shieldHitPoints shieldLeftoverRatio = leftoverDamage / damage # scale down the magnitudes applied to spaz accordingly.. mag *= shieldLeftoverRatio velocityMag *= shieldLeftoverRatio else: return True # good job shield! else: shieldLeftoverRatio = 1.0 if m.flatDamage: damage = m.flatDamage * self._impactScale * shieldLeftoverRatio else: # hit it with an impulse and get the resulting damage #bs.screenMessage(str(velocityMag)) if self.multiplyer > 3.0: # at about 8.0 the physics glitch out velocityMag *= min((3.0 + (self.multiplyer-3.0)/4), 7.5) ** 1.9 else: velocityMag *= self.multiplyer ** 1.9 self.node.handleMessage("impulse", m.pos[0], m.pos[1], m.pos[2], m.velocity[0], m.velocity[1], m.velocity[2], mag, velocityMag, m.radius, 0, m.forceDirection[0], m.forceDirection[1], m.forceDirection[2]) damage = damageScale * self.node.damage self.node.handleMessage("hurtSound") # play punch impact sound based on damage if it was a punch if m.hitType == 'punch': self.onPunched(damage) # if damage was significant, lets show it #if damage > 350: bsUtils.showDamageCount('-'+str(int(damage/10))+"%",m.pos,m.forceDirection) # lets always add in a super-punch sound with boxing gloves just to differentiate them if m.hitSubType == 'superPunch': bs.playSound(self.getFactory().punchSoundStronger, 1.0, position=self.node.position) if damage > 500: sounds = self.getFactory().punchSoundsStrong sound = sounds[random.randrange(len(sounds))] else: sound = self.getFactory().punchSound bs.playSound(sound, 1.0, position=self.node.position) # throw up some chunks bs.emitBGDynamics(position=m.pos, velocity=(m.forceDirection[0]*0.5, m.forceDirection[1]*0.5, m.forceDirection[2]*0.5), count=min(10, 1+int(damage*0.0025)), scale=0.3, spread=0.03) bs.emitBGDynamics(position=m.pos, chunkType='sweat', velocity=(m.forceDirection[0]*1.3, m.forceDirection[1]*1.3+5.0, m.forceDirection[2]*1.3), count=min(30, 1 + int(damage * 0.04)), scale=0.9, spread=0.28) # momentary flash hurtiness = damage*0.003 hurtiness = min(hurtiness, 750 * 0.003) punchPos = (m.pos[0]+m.forceDirection[0]*0.02, m.pos[1]+m.forceDirection[1]*0.02, m.pos[2]+m.forceDirection[2]*0.02) flashColor = (1.0, 0.8, 0.4) light = bs.newNode("light", attrs={'position':punchPos, 'radius':0.12+hurtiness*0.12, 'intensity':0.3*(1.0+1.0*hurtiness), 'heightAttenuated':False, 'color':flashColor}) bs.gameTimer(60, light.delete) flash = bs.newNode("flash", attrs={'position':punchPos, 'size':0.17+0.17*hurtiness, 'color':flashColor}) bs.gameTimer(60, flash.delete) if m.hitType == 'impact': bs.emitBGDynamics(position=m.pos, velocity=(m.forceDirection[0]*2.0, m.forceDirection[1]*2.0, m.forceDirection[2]*2.0), count=min(10, 1 + int(damage * 0.01)), scale=0.4, spread=0.1) if self.hitPoints > 0: # its kinda crappy to die from impacts, so lets reduce impact damage # by a reasonable amount if it'll keep us alive if m.hitType == 'impact' and damage > self.hitPoints: # drop damage to whatever puts us at 10 hit points, or 200 less than it used to be # whichever is greater (so it *can* still kill us if its high enough) newDamage = max(damage-200, self.hitPoints-10) damage = newDamage self.node.handleMessage("flash") # if we're holding something, drop it if damage > 0.0 and self.node.holdNode.exists(): self.node.holdNode = bs.Node(None) #self.hitPoints -= damage self.multiplyer += min(damage / 2000, 0.15) if damage/2000 > 0.05: self.setScoreText(str(int((self.multiplyer-1)*100))+"%") #self.node.hurt = 1.0 - self.hitPoints/self.hitPointsMax self.node.hurt = 0.0 # if we're cursed, *any* damage blows us up if self._cursed and damage > 0: bs.gameTimer(50, bs.WeakCall(self.curseExplode, m.sourcePlayer)) # if we're frozen, shatter.. otherwise die if we hit zero #if self.frozen and (damage > 200 or self.hitPoints <= 0): # self.shatter() #elif self.hitPoints <= 0: # self.node.handleMessage(bs.DieMessage(how='impact')) # if we're dead, take a look at the smoothed damage val # (which gives us a smoothed average of recent damage) and shatter # us if its grown high enough #if self.hitPoints <= 0: # damageAvg = self.node.damageSmoothed * damageScale # if damageAvg > 1000: # self.shatter() elif isinstance(m, bs.DieMessage): self.oob_effect() super(self.__class__, self).handleMessage(m) elif isinstance(m, bs.PowerupMessage): if m.powerupType == 'health': if self.multiplyer > 2: self.multiplyer *= 0.5 else: self.multiplyer *= 0.75 self.multiplyer = max(1, self.multiplyer) self.setScoreText(str(int((self.multiplyer-1)*100))+"%") super(self.__class__, self).handleMessage(m) else: super(self.__class__, self).handleMessage(m)
def _updateScoreBoard(self): for team in self.teams: self._scoreBoard.setTeamValue(team, min(int(team.gameData['minesPlanted']), self.settings['Mines to win']), self.settings['Mines to win'], countdown=False) if int(team.gameData['minesPlanted']) >= self.settings['Mines to win']: bs.gameTimer(500, bs.WeakCall(self.endGame)) self.isFinished = True
def endGame(self): bs.playMusic(None) self._bots.finalCelebrate() bs.gameTimer(1, bs.Call(self.doEnd, 'defeat'))
def _setMeteorTimer(self): bs.gameTimer(int((1.0+0.2*random.random())*self._meteorTime),self._dropBombCluster)
def _flashBoxSpawn(self): light = bs.newNode('light', attrs={'position':self._boxSpawnPos, 'color':(1, 1, 1), 'radius':0.3, 'heightAttenuated':False}) bs.animate(light, 'intensity', {0:0, 2500:0.5, 5000:0}, loop=True) bs.gameTimer(1000, light.delete)
def __init__(self, position=(0, 1, 0), powerupType='tripleBombs', expire=True): """ Create a powerup-box of the requested type at the requested position. see bs.Powerup.powerupType for valid type strings. """ bs.Actor.__init__(self) factory = self.getFactory() self.powerupType = powerupType self._powersGiven = False if powerupType == 'iceImpactBomb': tex = factory.texIceImpact elif powerupType == 'smokeBombPowerup': tex = factory.texSmokeBomb elif powerupType == 'weee': tex = factory.texJump elif powerupType == 'BlockPowerup': tex = factory.texBlock elif powerupType == 'goldenBomb': tex = factory.texGoldenBomb elif powerupType == 'tripleBombs': tex = factory.texBomb elif powerupType == 'punch': tex = factory.texPunch elif powerupType == 'iceBombs': tex = factory.texIceBombs elif powerupType == 'impactBombs': tex = factory.texImpactBombs elif powerupType == 'landMines': tex = factory.texLandMines elif powerupType == 'stickyBombs': tex = factory.texStickyBombs elif powerupType == 'shield': tex = factory.texShield elif powerupType == 'health': tex = factory.texHealth elif powerupType == 'curse': tex = factory.texCurse elif powerupType == 'FloatingMine': tex = factory.texFloatingMine elif powerupType == 'deathBomb': tex = factory.texPlantBomb elif powerupType == 'ballon': tex = factory.texBallon elif powerupType == 'cineticTrap': tex = factory.texCineticTrap elif powerupType == 'invincible': tex = factory.texInvincible elif powerupType == 'bot': tex = factory.texBot else: raise Exception("invalid powerupType: " + str(powerupType)) if len(position) != 3: raise Exception("expected 3 floats for position") self.node = bs.newNode( 'prop', delegate=self, attrs={'body':'box', 'position':position, 'model':factory.model, 'lightModel':factory.modelSimple, 'shadowSize':0.5, 'colorTexture':tex, 'reflection':'powerup', 'reflectionScale':[1.0] if powerupType != 'goldenBomb' \ else (10, 10, 0), 'materials':(factory.powerupMaterial, bs.getSharedObject('objectMaterial'))}) # animate in.. curve = bs.animate(self.node, "modelScale", {0: 0, 140: 1.6, 200: 1}) bs.gameTimer(200, curve.delete) if expire: bs.gameTimer(defaultPowerupInterval - 2500, bs.WeakCall(self._startFlashing)) bs.gameTimer(defaultPowerupInterval - 1000, bs.WeakCall(self.handleMessage, bs.DieMessage()))
def endGame(self): # tell our bots to celebrate just to rub it in self._bots.finalCelebrate() bs.gameTimer(1, bs.WeakCall(self.doEnd, 'defeat')) bs.playMusic(None)
def _flashBoxSpawn(self): light = bs.newNode('light', attrs={'position':self._boxSpawnPos, 'color':(1, 1, 1), 'radius':0.3, 'heightAttenuated':False}) bs.animate(light, 'intensity', {0:0, 250:0.5, 500:0}, loop=True) bs.gameTimer(1000, light.delete)
def _handleScore(self): """ a point has been scored """ # our ball might stick around for a second or two # we dont want it to be able to score again if self._ball.scored: return region = bs.getCollisionInfo("sourceNode") for i in range(len(self._scoreRegions)): if region == self._scoreRegions[i].node: break; scoringTeam = None for team in self.teams: if team.getID() == i: scoringTeam = team team.gameData['score'] += 1 # tell scored team players to celebrate and give them to boxing gloves for player in team.players: try: player.actor.node.handleMessage('celebrate',2000) or player.actor.node.handleMessage(bs.PowerupMessage('punch')) except Exception: pass # if weve got the player from the scoring team that last touched us, give them points if scoringTeam.getID() in self._ball.lastPlayersToTouch and self._ball.lastPlayersToTouch[scoringTeam.getID()].exists(): self.scoreSet.playerScored(self._ball.lastPlayersToTouch[scoringTeam.getID()],100,bigMessage=True) # end game if we won if team.gameData['score'] >= self.settings['Score to Win']: bs.gameTimer(1250,self.endGame) scoringTeam = None for team in self.teams: if not team.getID() == i: scoringTeam = team team.gameData['score'] += 0 # give non-scored team players to shield for balance for player in team.players: try: player.actor.node.handleMessage(bs.PowerupMessage('shield')) except Exception: pass bs.playSound(self._scoreSound) bs.playSound(self._cheerSound) self._ball.scored = True # kill the ball (it'll respawn itself shortly) bs.gameTimer(1000,self._killBall) light = bs.newNode('light', attrs={'position': bs.getCollisionInfo('position'), 'heightAttenuated':False, 'color': (1,0,0)}) bs.animate(light,'intensity',{0:0,500:1,1000:0},loop=True) bs.gameTimer(1000,light.delete) self.cameraFlash(duration=10) self._updateScoreBoard() #pretty celebrate if scoringTeam.getID() == 1: bs.emitBGDynamics(position=(12.66, 0.03986567039, 2.075), velocity=(0,0,0), count=random.randrange(20,70),scale=1.0,chunkType='spark') bs.emitBGDynamics(position=(12.66, 0.03986567039, -2.075), velocity=(0,0,0), count=random.randrange(20,70),scale=1.0,chunkType='spark') if scoringTeam.getID() == 0: bs.emitBGDynamics(position=(-12.45, 0.05744967453, -2.075), velocity=(0,0,0), count=random.randrange(20,70),scale=1.0,chunkType='spark') bs.emitBGDynamics(position=(-12.45, 0.05744967453, 2.075), velocity=(0,0,0), count=random.randrange(20,70),scale=1.0,chunkType='spark')
def onBegin(self): bs.CoopGameActivity.onBegin(self) # show controls help in kiosk mode if bs.getEnvironment()['kioskMode']: import bsUtils bsUtils.ControlsHelpOverlay(delay=3000, lifespan=10000, bright=True).autoRetain() if self._preset in ['rookie', 'rookieEasy']: self._excludePowerups = ['curse'] self._haveTnt = False tgb = (bs.ToughGuyBotLame if self._preset == 'rookieEasy' else bs.ToughGuyBot) self._botTypesInitial = [tgb] * len(self.initialPlayerInfo) bb = (bs.BomberBotLame if self._preset == 'rookieEasy' else bs.BomberBot) self._botTypes7 = [bb] * (1 if len(self.initialPlayerInfo) < 3 else 2) cb = bs.BomberBot if self._preset == 'rookieEasy' else bs.ChickBot self._botTypes14 = \ [cb]*(1 if len(self.initialPlayerInfo) < 3 else 2) elif self._preset == 'tournament': self._excludePowerups = [] self._haveTnt = True self._botTypesInitial = \ [bs.ToughGuyBot]*(1 if len(self.initialPlayerInfo) < 2 else 2) self._botTypes7 = \ [bs.ChickBot]*(1 if len(self.initialPlayerInfo) < 3 else 2) self._botTypes14 = \ [bs.NinjaBot]*(1 if len(self.initialPlayerInfo) < 4 else 2) elif self._preset in ['pro', 'proEasy', 'tournamentPro']: self._excludePowerups = ['curse'] self._haveTnt = True self._botTypesInitial = [bs.NinjaBot] * len(self.initialPlayerInfo) tgb = \ bs.ToughGuyBot if self._preset == 'pro' else bs.ToughGuyBotLame self._botTypes7 = [tgb]+[bs.BomberBot] \ * (1 if len(self.initialPlayerInfo) < 3 else 2) cb = bs.ChickBotPro if self._preset == 'pro' else bs.ChickBot self._botTypes14 = [cb] \ * (1 if len(self.initialPlayerInfo) < 3 else 2) elif self._preset in ['uber', 'uberEasy']: self._excludePowerups = [] self._haveTnt = True tgb = (bs.ToughGuyBotPro if self._preset == 'uber' else bs.ToughGuyBot) cb = bs.ChickBotPro if self._preset == 'uber' else bs.ChickBot self._botTypesInitial = \ [bs.MelBot] + [tgb]*len(self.initialPlayerInfo) self._botTypes7 = [cb] * (1 if len(self.initialPlayerInfo) < 3 else 2) self._botTypes14 = \ [bs.PirateBot]*(1 if len(self.initialPlayerInfo) < 3 else 2) else: raise Exception() self.setupLowLifeWarningSound() self._dropPowerups(standardPoints=True) bs.gameTimer(4000, self._startPowerupDrops) # make a bogus team for our bots badTeamName = self.getTeamDisplayString('Bad Guys') self._botTeam = bs.Team(1, badTeamName, (0.5, 0.4, 0.4)) for team in [self.teams[0], self._botTeam]: team.gameData['score'] = 0 self.updateScores() # time display self._startTime = bs.getGameTime() self._timeText = bs.NodeActor( bs.newNode('text', attrs={ 'vAttach': 'top', 'hAttach': 'center', 'hAlign': 'center', 'color': (1, 1, 0.5, 1), 'flatness': 0.5, 'shadow': 0.5, 'position': (0, -50), 'scale': 1.5, 'text': '' })) self._timeTextInput = bs.NodeActor( bs.newNode('timeDisplay', attrs={'showSubSeconds': True})) bs.getSharedObject('globals').connectAttr('gameTime', self._timeTextInput.node, 'time2') self._timeTextInput.node.connectAttr('output', self._timeText.node, 'text') # our TNT spawner (if applicable) if self._haveTnt: self._tntSpawner = bs.TNTSpawner(position=(0, 10, -1)) self._bots = bs.BotSet() self._botSpawnTimer = bs.Timer(1000, self._updateBots, repeat=True) for b in self._botTypesInitial: self._spawnBot(b)
def onBegin(self): bs.TeamGameActivity.onBegin(self) self._won = False self.setupStandardPowerupDrops() # make our on-screen timer and start it roughly when our bots appear self._timer = bs.OnScreenTimer() bs.gameTimer(4000,self._timer.start) # this wrangles our bots self._bots = bs.BotSet() # spawn some baddies self._bots = bs.BotSet() bs.gameTimer(1000,bs.Call(self._bots.spawnBot,bs.MelBotStatic,pos=(6,7,-6),spawnTime=3000)) bs.gameTimer(2000,bs.Call(self._bots.spawnBot,bs.ToughGuyBotProShielded,pos=(-3,10,-2),spawnTime=3000)) bs.gameTimer(3000,bs.Call(self._bots.spawnBot,bs.NinjaBotProShielded,pos=(5,6,-2),spawnTime=3000)) bs.gameTimer(4000,bs.Call(self._bots.spawnBot,bs.BomberBotProShielded,pos=(-5,6,-2),spawnTime=3000)) bs.gameTimer(5000,bs.Call(self._bots.spawnBot,bs.ChickBotStatic,pos=(-6,7,-6),spawnTime=3000))