示例#1
0
    def handleMessage(self, m):
        self._handleMessageSanityCheck()

        if isinstance(m, 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())

        elif isinstance(m, _TouchedMessage):
            if not self._powersGiven and not self.picked:
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    node.handleMessage(
                        PowerupMessage(self.powerupType, sourceNode=self.node))

        elif isinstance(m, bs.DieMessage):
            if self.node.exists():
                if (m.immediate):
                    self.node.delete()
                else:
                    curve = bs.animate(self.node, "modelScale", {0: 1, 100: 0})
                    if some.show_powerup_name: curve1 = bs.animate(self._powText, "scale", {
                        0: 0.01,
                        100: 0
                    })
                    if hasattr(self, 'nodeLight'):
                        curve2 = bs.animate(self.nodeLight, "radius", {
                            0: 0.5,
                            100: 0
                        })
                    bs.gameTimer(100, self.node.delete)

        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())

        elif isinstance(m, bs.PickedUpMessage):
            self.picked = True

        elif isinstance(m, bs.DroppedMessage):
            self.picked = False

        elif isinstance(m, bs.HitMessage):
            # dont die on punches (thats annoying)
            msg = m
            if some.interactive_powerups:
	            self.node.handleMessage("impulse", msg.pos[0], msg.pos[1],
	                                    msg.pos[2], msg.velocity[0],
	                                    msg.velocity[1], msg.velocity[2],
	                                    msg.magnitude, msg.velocityMagnitude,
	                                    msg.radius, 0, msg.velocity[0],
	                                    msg.velocity[1], msg.velocity[2])
            if m.hitType != 'punch':
                self.handleMessage(bs.DieMessage())
        else:
            bs.Actor.handleMessage(self, m)
示例#2
0
文件: Pick.py 项目: Esie-Eyen/BSMods
 def handleMessage(self, m):
     if isinstance(m, bs.PlayerSpazDeathMessage):
         player = m.spaz.getPlayer()
         self.respawnPlayer(player)
     if isinstance(m, bs.FlagPickedUpMessage):
         if m.flag is self.red:
             if self._red:
                 self.pickFlag()
                 self._score()
                 m.node.handleMessage(bs.DieMessage())
             if not self._red: m.node.handleMessage(bs.FreezeMessage())
         elif m.flag is self.green:
             if self._green:
                 self.pickFlag()
                 self._score()
                 m.node.handleMessage(bs.DieMessage())
             if not self._green: m.node.handleMessage(bs.FreezeMessage())
         elif m.flag is self.blue:
             if self._blue:
                 self.pickFlag()
                 self._score()
                 m.node.handleMessage(bs.DieMessage())
             if not self._blue: m.node.handleMessage(bs.FreezeMessage())
         if any(team.gameData['score'] >= self._scoreToWin
                for team in self.teams):
             bs.gameTimer(500, self.endGame)
示例#3
0
    def handleMessage(self, m):
        self._handleMessageSanityCheck()

        if isinstance(m, 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())

        elif isinstance(m, _TouchedMessage):
            if not self._powersGiven:
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    #We won't tell the spaz about the bunny.  It'll just happen.
                    if self.powerupType == 'bunny':
                        p = node.getDelegate().getPlayer()
                        if not 'bunnies' in p.gameData:
                            p.gameData['bunnies'] = BuddyBunny.BunnyBotSet(p)
                        p.gameData['bunnies'].doBunny()
                        self._powersGiven = True
                        self.handleMessage(bs.DieMessage())
                    #a Spaz doesn't know what to do with a snoball powerup. All the snowball functionality
                    #is handled through SnoBallz.py to minimize modifications to the original game files
                    elif self.powerupType == 'snoball':
                        spaz = node.getDelegate()
                        SnoBallz.snoBall().getFactory().giveBallz(spaz)
                        self._powersGiven = True
                        self.handleMessage(bs.DieMessage())
                    else:
                        node.handleMessage(
                            PowerupMessage(self.powerupType,
                                           sourceNode=self.node))

        elif isinstance(m, bs.DieMessage):
            if self.node.exists():
                if (m.immediate):
                    self.node.delete()
                else:
                    curve = bs.animate(self.node, "modelScale", {0: 1, 100: 0})
                    bs.gameTimer(100, self.node.delete)

        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())

        elif isinstance(m, bs.HitMessage):
            # dont die on punches (thats annoying)
            if m.hitType != 'punch':
                self.handleMessage(bs.DieMessage())
        else:
            bs.Actor.handleMessage(self, m)
示例#4
0
 def onBegin(self):
     self.bombSurvivor = None
     self.light = None
     self.set = False
     #Do normal stuff: calls to the main class to operate everything that usually would be done
     bs.TeamGameActivity.onBegin(self)
     self.b = []
     self.queueLine = []
     self.playerIndex = 0
     for player in self.players:
         player.gameData['dead'] = False
         if player.actor is not None:
             player.actor.handleMessage(bs.DieMessage())
             player.actor.node.delete()
         self.queueLine.append(player)
     self.spawnPlayerSpaz(
         self.queueLine[self.playerIndex % len(self.queueLine)], (0, 3, -2))
     self.lastPrize = 'none'
     self.currentPlayer = self.queueLine[0]
     #Declare a set of bots (enemies) that we will use later
     self._bots = bs.BotSet()
     #make another scoreboard? IDK why I did this, probably to make it easier to refer to in the future
     self._scoredis = bs.ScoreBoard()
     #for each team in the game's directory, give them a score of zero
     for team in self.teams:
         team.gameData['score'] = 0
     #Now we go ahead and put that on the scoreboard
     for player in self.queueLine:
         self._scoredis.setTeamValue(player.getTeam(),
                                     player.getTeam().gameData['score'])
     self.resetFlags()
    def handleMessage(self, m):
        if not self.node.exists(): return
        if isinstance(m, bs.OutOfBoundsMessage):
            self.node.delete()
        elif isinstance(m, bs.DieMessage):
            self.node.delete()

        # TODO - add functoional for speed-up on picked up
        elif isinstance(m, bs.PickedUpMessage):
            bs.Blast(position=self.node.position,
                     blastType='impact',
                     blastRadius=0.8).autoRetain()
            bs.playSound(self.touchedSound,
                         position=self.node.position,
                         volume=4)
            self.x, self.y, self.z = m.node.position
            # I SAID DON'T TOUCH!
            self.speedMul = 3.0
            self.hp -= 10 + random.randint(-3, 3)
            if self.hp < 0:
                bs.Blast(position=self.node.position,
                         blastRadius=0.5,
                         blastType='tnt')
                self.handleMessage(bs.DieMessage())
        elif isinstance(m, bs.DroppedMessage):
            self.speedMul = 1.0
        else:
            bs.Actor.handleMessage(self, m)
    def _handleHitOwnFlag(self,team,val):

        # keep track of when each player is touching their own flag so we can award points when returned
        srcNode = bs.getCollisionInfo('sourceNode')
        try: player = srcNode.getDelegate().getPlayer()
        except Exception: player = None
        if player is not None and player.exists():
            if val: player.gameData['touchingOwnFlag'] += 1
            else: player.gameData['touchingOwnFlag'] -= 1

        # if return-time is zero, just kill it immediately.. otherwise keep track of touches and count down
        if float(self.settings['Flag Touch Return Time']) <= 0.0:
            if not team.gameData['homeFlagAtBase'] and team.gameData['flag']._heldCount == 0:
                # use a node message to kill the flag instead of just killing our team's.
                # (avoids redundantly killing new flags if multiple body parts generate callbacks in one step)
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    self._awardPlayersTouchingOwnFlag(team)
                    node.handleMessage(bs.DieMessage())
        # takes a non-zero amount of time to return
        else:
            if val:
                team.gameData['flagReturnTouches'] += 1
                if team.gameData['flagReturnTouches'] == 1:
                    team.gameData['touchReturnTimer'] = bs.Timer(100,call=bs.Call(self._touchReturnUpdate,team),repeat=True)
                    team.gameData['touchReturnTimerTicking'] = None
            else:
                team.gameData['flagReturnTouches'] -= 1
                if team.gameData['flagReturnTouches'] == 0:
                    team.gameData['touchReturnTimer'] = None
                    team.gameData['touchReturnTimerTicking'] = None
            if team.gameData['flagReturnTouches'] < 0:
                bs.printError('CTF: flagReturnTouches < 0; this shouldn\'t happen.')
 def onPlayerLeave(self, player):
     bs.screenMessage(str(len(self.flags)))
     message = str(player.getName(icon=False)) + " has chickened out!"
     bs.screenMessage(message, color=player.color)
     player.actor.handleMessage(bs.DieMessage())
     if len(self.players) == 1: self.endGame()
     self.checkEnd()
    def handleMessage(self, m):
        super(self.__class__, self).handleMessage(m)

        if isinstance(m, bs.DieMessage):
            self.node.delete()
        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())
        elif isinstance(m, bs.DroppedMessage):
            bs.gameTimer(
                200, bs.WeakCall(self.handleMessage, doorStartUseMessage()))
        elif isinstance(m, doorStartUseMessage):
            self.canUse = True
        elif isinstance(m, doorHitSpazMessage):
            if not self.canUse:
                return
            if self._used:
                return
            oppoNode = bs.getCollisionInfo("opposingNode")
            if oppoNode is not None and oppoNode.exists():
                activity = self._activity()
                pos = self.getFactory().getRandomPosition(activity)
                oppoNode.handleMessage(bs.StandMessage(pos))
                bs.Blast(position=pos, blastRadius=1.0,
                         blastType='smoke').autoRetain()
                bs.playSound(bs.getSound('shieldDown'))

            self._disappear()
    def __init__(self, pos=(0, 1, 0), sourcePlayer=None):

        bs.Actor.__init__(self)

        factory = self.getFactory()

        self.targetSound = factory.targetSound
        self.popSound = factory.popSound

        if sourcePlayer is None:
            self.sourcePlayers = [bs.Player(None)]
        else:
            self.sourcePlayers = [sourcePlayer]

        self.node = bs.newNode(
            'prop',
            delegate=self,
            attrs={
                'body': 'sphere',
                'position': pos,
                'velocity': (0, 0, 1),  # Не менять на (0, 0, 0)!
                'model': factory.botModel,
                'colorTexture': factory.botTexture,
                'reflection': u'powerup',
                'reflectionScale': (10, 10, 0),
                'shadowSize': 0.5,
                'extraAcceleration': (0, 20, 0),
                'materials': [bs.getSharedObject("objectMaterial")]
            })
        bs.gameTimer(30000, bs.WeakCall(self.handleMessage, bs.DieMessage()))
        self._updTimer = bs.Timer(500, bs.WeakCall(self._update), repeat=True)
示例#10
0
    def handleMessage(self, m):
        if isinstance(m, bs.DieMessage):
            self.node.delete()
            activity = self._activity()
            if activity and not m.immediate:
                activity.handleMessage(PuckDeathMessage(self))

        # if we go out of bounds, move back to where we started...
        elif isinstance(m, bs.OutOfBoundsMessage):
            self.node.handleMessage(bs.DieMessage())

        elif isinstance(m, bs.HitMessage):
            self.node.handleMessage("impulse", m.pos[0], m.pos[1], m.pos[2],
                                    m.velocity[0], m.velocity[1],
                                    m.velocity[2], 1.0 * m.magnitude,
                                    1.0 * m.velocityMagnitude, m.radius, 0,
                                    m.forceDirection[0], m.forceDirection[1],
                                    m.forceDirection[2])

            # if this hit came from a player, log them as the last to touch us
            if m.sourcePlayer is not None:
                activity = self._activity()
                if activity:
                    if m.sourcePlayer in activity.players:
                        self.lastPlayersToTouch[
                            m.sourcePlayer.getTeam().getID()] = m.sourcePlayer
        else:
            bs.Actor.handleMessage(self, m)
示例#11
0
 def handleMessage(self, m):
     super(self.__class__, self).handleMessage(m)
     if isinstance(m, bs.DieMessage):
         self.node.delete()
         self.node2.delete()
     elif isinstance(m, bs.OutOfBoundsMessage):
         self.handleMessage(bs.DieMessage())
示例#12
0
 def _onCapsulePlayerCollide(self):
     if not self.hasEnded():
         capsuleNode, playerNode = bs.getCollisionInfo('sourceNode','opposingNode')
         if capsuleNode is not None and playerNode is not None:
             capsule = capsuleNode.getDelegate()
             spaz = playerNode.getDelegate()
             player = spaz.getPlayer() if hasattr(spaz,'getPlayer') else None
             if player is not None and player.exists() and capsule is not None:
                 if player.isAlive():
                     if capsuleNode.colorTexture == self._capsuleLuckyTex:
                         player.gameData['capsules'] += 4
                         bsUtils.PopupText('BONUS!',
                                           color=(1,1,0),
                                           scale=1.5,
                                           position=(capsuleNode.position)).autoRetain()
                         bs.playSound(self._luckyCollectSound,1.0,position=capsuleNode.position)
                         bs.emitBGDynamics(position=capsuleNode.position,velocity=(0,0,0),count=int(6.4+random.random()*24),scale=1.2, spread=2.0,chunkType='spark');
                         bs.emitBGDynamics(position=capsuleNode.position,velocity=(0,0,0),count=int(4.0+random.random()*6),emitType='tendrils');
                     else:
                         player.gameData['capsules'] += 1
                         bs.playSound(self._collectSound,0.6,position=capsuleNode.position)
                     # create a flash
                     light = bs.newNode('light',
                                     attrs={'position': capsuleNode.position,
                                             'heightAttenuated':False,
                                             'radius':0.1,
                                             'color':(1,1,0)})
                     
                     # Create a short text informing about your inventory
                     self._handleCapsuleStorage(playerNode.position,player)
                     
                     bs.animate(light,'intensity',{0:0,100:0.5,200:0},loop=False)
                     bs.gameTimer(200,light.delete)
                     capsule.handleMessage(bs.DieMessage())
示例#13
0
    def _touchReturnUpdate(self, team):

        # count down only while its away from base and not being held
        if (team.gameData['homeFlagAtBase']
                or team.gameData['flag']._heldCount > 0):
            team.gameData['touchReturnTimerTicking'] = None
            return  # no need to return when its at home
        else:
            if team.gameData['touchReturnTimerTicking'] is None:
                team.gameData['touchReturnTimerTicking'] = bs.NodeActor(
                    bs.newNode('sound',
                               attrs={
                                   'sound': self._tickingSound,
                                   'positional': False,
                                   'loop': True
                               }))
        flag = team.gameData['flag']
        flag._touchReturnTime -= 0.1
        if flag._counter.exists():
            flag._counter.text = "%.1f" % flag._touchReturnTime
            flag._counter.color = (1, 1, 0, 1)
            flag._counter.scale = 0.02

        if flag._touchReturnTime <= 0.0:
            self._awardPlayersTouchingOwnFlag(team)
            flag.handleMessage(bs.DieMessage())
示例#14
0
    def _tick(self):
        # if either flag is away from base and not being held, tick down its
        # respawn timer
        for team in self.teams:
            flag = team.gameData['flag']

            if not team.gameData['homeFlagAtBase'] and flag._heldCount == 0:
                timeOutCountingDown = True
                flag._timeOutRespawnTime -= 1
                if flag._timeOutRespawnTime <= 0:
                    flag.handleMessage(bs.DieMessage())
            else:
                timeOutCountingDown = False

            if flag.node.exists() and flag._counter.exists():
                t = flag.node.position
                flag._counter.position = (t[0], t[1] + 1.3, t[2])

                # if there's no self-touches on this flag, set its text
                # to show its auto-return counter.  (if there's self-touches
                # its showing that time)
                if team.gameData['flagReturnTouches'] == 0:
                    flag._counter.text = str(flag._timeOutRespawnTime) if (
                        timeOutCountingDown
                        and flag._timeOutRespawnTime <= 10) else ''
                    flag._counter.color = (1, 1, 1, 0.5)
                    flag._counter.scale = 0.014
 def __init__(self,
              position=(0, 1, 0),
              velocity=(0, 0, 0),
              deathTimeout=(False, 0)):
     bs.Actor.__init__(self)
     activity = self.getActivity()
     self.rType = randint(0, 2)
     self.color = self.getColor(self.rType)
     self.material = self.getMaterial(self.rType)
     self.bodyNode = bs.newNode(
         'prop',
         delegate=self,
         attrs={
             'extraAcceleration': (0, 16, 0),
             'body': 'sphere',
             'position': position,
             'velocity': velocity,
             'materials':
             [bs.getSharedObject('objectMaterial'), self.material]
         })
     self.node = bs.newNode('shield',
                            owner=self.bodyNode,
                            attrs={
                                'color': self.color,
                                'radius': 0.7
                            })
     self.bodyNode.connectAttr('position', self.node, 'position')
     if deathTimeout[0]:
         bs.gameTimer(deathTimeout[1],
                      bs.Call(self.handleMessage, bs.DieMessage()))
示例#16
0
 def handleSafeZoneEnter(self):
     self.checkEnd()
     zoneNode, playerNode = bs.getCollisionInfo("sourceNode",
                                                "opposingNode")
     try:
         player = playerNode.getDelegate().getPlayer()
     except Exception:
         return
     if player.isAlive() and player.actor.node.getDelegate().isShark:
         player.actor.handleMessage(bs.DieMessage())
         self.sharkify(player)
     elif player.isAlive() and not player.actor.node.getDelegate().isShark:
         if player.actor.node.positionCenter[
                 0] < 0 and player.actor.node.getDelegate().nextZone == 1:
             player.getTeam().gameData['score'] += 10
             self.scoreSet.playerScored(player,
                                        10,
                                        screenMessage=False,
                                        display=False)
             self.updateScore()
             player.actor.node.getDelegate().nextZone = 2
         elif player.actor.node.positionCenter[
                 0] > 0 and player.actor.node.getDelegate().nextZone == 2:
             player.getTeam().gameData['score'] += 10
             self.scoreSet.playerScored(player,
                                        10,
                                        screenMessage=False,
                                        display=False)
             self.updateScore()
             player.actor.node.getDelegate().nextZone = 1
示例#17
0
    def curseExplodeNoShrapnel(self, sourcePlayer=None):
        """
        Explode the poor spaz as happens when
        a curse timer runs out. Less shrapnel for surviveCurse, just explode.
        Otherwise, shrapnel hits other players too much. Player shrapnel causes instant
        curse explosion of other players.  Over too quickly.
        I could probably figure out how to prevent.  However, too lazy.
        Making immediate=True in the DieMessage prevents shrapnel. 
        However, spaz node disappears instantly and no cleanup happens.
        """
        # convert None to an empty player-ref
        if sourcePlayer is None: sourcePlayer = bs.Player(None)

        if self._cursed and self.node.exists():
            #self.shatter(extreme=True)
            self.handleMessage(bs.DieMessage(immediate=False))
            activity = self._activity()
            if activity:
                bs.Blast(position=self.node.position,
                         velocity=self.node.velocity,
                         blastRadius=3.0,
                         blastType='normal',
                         sourcePlayer=sourcePlayer if sourcePlayer.exists()
                         else self.sourcePlayer).autoRetain()
            self._cursed = False
示例#18
0
    def __init__(self,settings):
        bs.TeamGameActivity.__init__(self,settings)
        self._scoreBoard = bs.ScoreBoard()

        self._cheerSound = bs.getSound("cheer")
        self._chantSound = bs.getSound("crowdChant")
        self._foghornSound = bs.getSound("foghorn")
        self._swipSound = bs.getSound("swip")
        self._whistleSound = bs.getSound("refWhistle")
        self._puckModel = bs.getModel("puck")
        self._puckTex = bs.getTexture("puckColor")
        self._puckSound = bs.getSound("metalHit")

        self._puckMaterial = bs.Material()
        self._puckMaterial.addActions(actions=( ("modifyPartCollision","friction",0.5)))
        self._puckMaterial.addActions(conditions=("theyHaveMaterial",bs.getSharedObject('pickupMaterial')),
                                      actions=( ("modifyPartCollision","collide",False) ) )
        self._puckMaterial.addActions(conditions=( ("weAreYoungerThan",100),'and',
                                                   ("theyHaveMaterial",bs.getSharedObject('objectMaterial')) ),
                                      actions=( ("modifyNodeCollision","collide",False) ) )
        self._puckMaterial.addActions(conditions=("theyHaveMaterial",bs.getSharedObject('footingMaterial')),
                                      actions=(("impactSound",self._puckSound,0.2,5)))
        # keep track of which player last touched the puck
        self._puckMaterial.addActions(conditions=("theyHaveMaterial",bs.getSharedObject('playerMaterial')),
                                      actions=(("call","atConnect",self._handlePuckPlayerCollide),))
        # we want the puck to kill powerups; not get stopped by them
        self._puckMaterial.addActions(conditions=("theyHaveMaterial",bs.Powerup.getFactory().powerupMaterial),
                                      actions=(("modifyPartCollision","physical",False),
                                               ("message","theirNode","atConnect",bs.DieMessage())))
        self._scoreRegionMaterial = bs.Material()
        self._scoreRegionMaterial.addActions(conditions=("theyHaveMaterial",self._puckMaterial),
                                             actions=(("modifyPartCollision","collide",True),
                                                      ("modifyPartCollision","physical",False),
                                                      ("call","atConnect",self._handleScore)))
示例#19
0
    def _tick(self):
        if self.node.exists():

            # grab our initial position after one tick (in case we fall)
            if self._initialPosition is None:
                self._initialPosition = self.node.position

                # keep track of when we first move; we don't count down until then
            if not self._hasMoved:
                t = self.node.position
                if max(abs(t[i] - self._initialPosition[i]) for i in range(3)) > 1.0:
                    self._hasMoved = True

            if self._heldCount > 0 or not self._hasMoved:
                self._count = self._droppedTimeout
                self._counter.text = ''
            else:
                self._count -= 1
                if self._count <= 10:
                    t = self.node.position
                    self._counter.position = (t[0],t[1]+1.3,t[2])
                    self._counter.text = str(self._count)
                    if self._count < 1: self.handleMessage(bs.DieMessage())
                else:
                    self._counter.text = ''
示例#20
0
 def handleMessage(self, msg):
     self._handleMessageSanityCheck()
     if isinstance(msg, bs.DieMessage):
         if self.node.exists():
             self.node.delete()
             if not msg.immediate:
                 self.getActivity().handleMessage(FlagDeathMessage(self))
     elif isinstance(msg, bs.HitMessage):
         self.node.handleMessage("impulse", msg.pos[0], msg.pos[1], msg.pos[2],
                                 msg.velocity[0], msg.velocity[1], msg.velocity[2],
                                 msg.magnitude, msg.velocityMagnitude, msg.radius, 0,
                                 msg.forceDirection[0], msg.forceDirection[1], msg.forceDirection[2])
     elif isinstance(msg, bs.OutOfBoundsMessage):
         # we just kill ourselves when out-of-bounds.. would we ever not want this?..
         self.handleMessage(bs.DieMessage(how='fall'))
     elif isinstance(msg, bs.PickedUpMessage):
         self._heldCount += 1
         if self._heldCount == 1 and self._counter is not None:
             self._counter.text = ''
         a = self.getActivity()
         if a is not None: a.handleMessage(FlagPickedUpMessage(self, msg.node))
     elif isinstance(msg, bs.DroppedMessage):
         self._heldCount -= 1
         if self._heldCount < 0:
             print 'Flag held count < 0'
             self._heldCount = 0
         a = self.getActivity()
         if a is not None: a.handleMessage(FlagDroppedMessage(self, msg.node))
     else:
         bs.Actor.handleMessage(self, msg)
 def _onEggPlayerCollide(self):
     if not self.hasEnded():
         eggNode, playerNode = bs.getCollisionInfo(
             'sourceNode', 'opposingNode')
         if eggNode is not None and playerNode is not None:
             egg = eggNode.getDelegate()
             spaz = playerNode.getDelegate()
             player = (spaz.getPlayer()
                       if hasattr(spaz, 'getPlayer') else None)
             if player is not None and player.exists() and egg is not None:
                 player.getTeam().gameData['score'] += 1
                 # displays a +1 (and adds to individual player score in
                 # teams mode)
                 self.scoreSet.playerScored(player, 1, screenMessage=False)
                 if self._maxEggs < 5:
                     self._maxEggs += 1.0
                 elif self._maxEggs < 10:
                     self._maxEggs += 0.5
                 elif self._maxEggs < 30:
                     self._maxEggs += 0.3
                 self._updateScoreBoard()
                 bs.playSound(self._collectSound, 0.5,
                              position=egg.node.position)
                 # create a flash
                 light = bs.newNode('light',
                                    attrs={'position': eggNode.position,
                                           'heightAttenuated': False,
                                           'radius': 0.1,
                                           'color': (1, 1, 0)})
                 bs.animate(light, 'intensity', {
                            0: 0, 100: 1.0, 200: 0}, loop=False)
                 bs.gameTimer(200, light.delete)
                 egg.handleMessage(bs.DieMessage())
示例#22
0
 def mineUpdate(self):
     #print self.mineCount
     #purge dead mines, update their animantion, check if players died
     for m in self.mines:
         if not m.exists():
             self.mines.remove(m)
         else:
             #First, check if any player is within the current death zone
             for player in self.players:
                 if not player.actor is None:
                     if player.actor.isAlive():
                         p1 = player.actor.node.position
                         p2 = m.node.position
                         diff = (bs.Vector(p1[0] - p2[0], 0.0,
                                           p1[2] - p2[2]))
                         dist = (diff.length())
                         if dist < m.rad:
                             player.actor.handleMessage(bs.DieMessage())
             #Now tell the circle to grow to the new size
             if m.rad < self.maxSize:
                 bs.animateArray(
                     m.zone, 'size', 1, {
                         0: [m.rad * 2],
                         self.updateRate: [(m.rad + self.growthRate) * 2]
                     })
                 #Tell the circle to be the new size. This will be the new check radius next time.
                 m.rad += self.growthRate
     #make a new mine if needed.
     if self.mineCount < self.maxMines:
         pos = self.getRandomPowerupPoint()
         self.mineCount += 1
         self._flashMine(pos)
         bs.gameTimer(950, bs.Call(self._makeMine, pos))
示例#23
0
    def onPlayerLeave(self, player):
        bs.TeamGameActivity.onPlayerLeave(self, player)

        # a player leaving disqualifies the team if 'Entire Team Must Finish'
        # is on (otherwise in teams mode everyone could just leave except the
        # leading player to win)
        if isinstance(self.getSession(), bs.TeamsSession
                      ) and self.settings.get('Entire Team Must Finish'):
            # FIXME translate this
            bs.screenMessage(bs.Lstr(
                translate=('statements',
                           '${TEAM} is disqualified because ${PLAYER} left'),
                subs=[('${TEAM}', player.getTeam().name),
                      ('${PLAYER}', player.getName(full=True))]),
                             color=(1, 1, 0))
            player.getTeam().gameData['finished'] = True
            player.getTeam().gameData['time'] = None
            player.getTeam().gameData['lap'] = 0
            bs.playSound(bs.getSound("boo"))
            for player in player.getTeam().players:
                player.gameData['lap'] = 0
                player.gameData['finished'] = True
                try:
                    player.actor.handleMessage(bs.DieMessage())
                except Exception:
                    pass

        # delay by one tick so team/player lists will be updated
        bs.gameTimer(1, self._checkEndGame)
示例#24
0
    def handleMessage(self, m):
        bs.Actor.handleMessage(self, m)

        if isinstance(m, BarTooSmallToFinishMessage):
            self.handleMessage(bs.DieMessage())
            if self.decreaseFinishCallback:
                self.decreaseFinishCallback()
        elif isinstance(m, bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())
        elif isinstance(m, bs.DieMessage):
            if self._died: return
            self._died = True
            del self.changeColorMaxTimer
            del self.startDecreaseTimer
            del self.changeColorNormalTimer
            del self.decreaseFinishTimer
            self.node.delete()
示例#25
0
 def checkRound(self):
     for player in self.players:
         if player.isAlive():
             safe = True if self.options[self.num] in self.inCircle(player.actor.node.positionCenter) else False
             if ((self.simon and safe == False) or ((not self.simon) and safe == True)):
                 player.getTeam().gameData["score"] = self.roundNum
                 player.actor.handleMessage(bs.DieMessage())
     self.callRound()
示例#26
0
 def onPlayerLeave(self, player):
      # augment default behavior...
     for m in player.gameData['mines']:
         m.handleMessage(bs.DieMessage())
     player.gameData['mines'] = []
     bs.TeamGameActivity.onPlayerLeave(self, player)
     # a departing player may trigger game-over
     self._checkEndGame()
示例#27
0
    def __init__(self,
                 position=(0, 1, 0),
                 powerupType='tripleBombs',
                 expire=True):

        bs.Actor.__init__(self)

        factory = self.getFactory()
        self.powerupType = powerupType
        self._powersGiven = False

        if 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 == 'blast': tex = factory.texBlast
        elif powerupType == 'mix': tex = factory.texMix
        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],
                                   'materials':
                                   (factory.powerupMaterial,
                                    bs.getSharedObject('objectMaterial'))
                               })

        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()))
示例#28
0
    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())

        elif isinstance(msg, _TouchedMessage):
            if not self._powersGiven:
                node = bs.getCollisionInfo("opposingNode")
                if node is not None and node.exists():
                    if self.powerupType == 'Bunny':
                        p = node.getDelegate().getPlayer()
                        if 'bunnies' not in p.gameData:
                            p.gameData['bunnies'] = BuddyBunny.BunnyBotSet(p)
                        p.gameData['bunnies'].doBunny()
                        self._powersGiven = True
                        self.handleMessage(bs.DieMessage())
                    else:
                        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)
            if self.nodeLight.exists():
                self.nodeLight.delete()

        elif isinstance(msg ,bs.OutOfBoundsMessage):
            self.handleMessage(bs.DieMessage())

        elif isinstance(msg, bs.HitMessage):
            # dont die on punches (thats annoying)
            if msg.hitType != 'punch':
                self.handleMessage(bs.DieMessage())
        else:
            bs.Actor.handleMessage(self, msg)
示例#29
0
    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())

        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':
                if self.powerupType == 'curse':
                    bs.Blast(position=self.node.position,
                             velocity=(0, 0, 0),
                             blastRadius=1,
                             blastType="normal",
                             sourcePlayer=None,
                             hitType='explosion',
                             hitSubType='normal').autoRetain()
                    self.handleMessage(bs.DieMessage())
            else:
                self.handleMessage(bs.DieMessage())
        else:
            bs.Actor.handleMessage(self, msg)
 def handleMessage(self, m):
     if isinstance(m, bs.OutOfBoundsMessage):
         self.handleMessage(bs.DieMessage())
         self.initNode()
     if isinstance(m, bs.DieMessage):
         if self.node is not None:
             self.node.delete()
             self.node = None
     bs.Actor.handleMessage(self, m)