Пример #1
0
 def _flashPuckSpawn(self):
     light = bs.newNode('light',
                        attrs={'position': self._puckSpawnPos,
                               'heightAttenuated':False,
                               'color': (1,0,0)})
     bs.animate(light, 'intensity', {0:0, 250:1, 500:0}, loop=True)
     bs.gameTimer(1000, light.delete)
Пример #2
0
 def do_delete(self):
     if self.node is not None and self.node.exists():
         if hasattr(self, "light") and self.light.exists():
             bs.animate(self.light, "radius", {0: 0.078, 100: 0})
             bs.gameTimer(100, self.light.delete)
         if hasattr(self, "powerupHurt") and self.powerupHurt.exists():
             bs.gameTimer(100, self.powerupHurt.delete)
Пример #3
0
 def recurringText():
     t = bs.newNode('text',
                    attrs={
                        'text': texts[randrange(count)],
                        'scale': 0.95,
                        'maxWidth': 0,
                        'position': (0, 120),
                        'shadow': 1,
                        'flatness': 1.0,
                        'hAlign': 'center',
                        'vAttach': 'bottom'
                    })
     bs.animate(t, 'opacity', {0: 0.0, 500: 1.0, 6500: 1.0, 7000: 0.0})
     multiColor = {
         0: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
             (0 + random.random() * 1.0)),
         500: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
               (0 + random.random() * 1.0)),
         1000: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
                (0 + random.random() * 1.0)),
         1500: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
                (0 + random.random() * 1.0)),
         2000: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
                (0 + random.random() * 1.0)),
         2500: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
                (0 + random.random() * 1.0)),
         3000: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
                (0 + random.random() * 1.0)),
         3500: ((0 + random.random() * 1.0), (0 + random.random() * 1.0),
                (0 + random.random() * 1.0))
     }
     bsUtils.animateArray(t, 'color', 3, multiColor, True)
     bs.gameTimer(7000, t.delete)
Пример #4
0
 def onPunchPress(self):
     """
     Called to 'press punch' on this spaz;
     used for player or AI connections.
     Override for land grab: catch double-punch to switch bombs!
     """
     if not self.node.exists() or self.frozen or self.node.knockout > 0.0: return
     
     if self.punchCallback is not None:
         self.punchCallback(self)
     t = bs.getGameTime()
     self._punchedNodes = set() # reset this..
     ########This catches punches and switches between bombs and mines
     #if t - self.lastPunchTime < 500:
     if self.landMineCount < 1:
         self.landMineCount = 1
         bs.animate(self.node,"billboardOpacity",{0:0.0,100:1.0,400:1.0})
     else:
         self.landMineCount = 0
         bs.animate(self.node,"billboardOpacity",{0:1.0,400:0.0})
     if t - self.lastPunchTime > self._punchCooldown:
         self.lastPunchTime = t
         self.node.punchPressed = True
         if not self.node.holdNode.exists():
             bs.gameTimer(100,bs.WeakCall(self._safePlaySound,self.getFactory().swishSound,0.8))
Пример #5
0
	def _hideScoreText(self):
		try:
			exists = self._scoreText.exists()
		except Exception:
			exists = False
		if exists:
			bs.animate(self._scoreText, 'scale', {0: self._scoreText.scale, 200: 0})
	def setScoreText(self, text):
		"""
		Utility func to show a message over the flag; handy for scores.
		"""
		if not self.node.exists():
			return
		try:
			exists = self._scoreText.exists()
		except Exception:
			exists = False
		if not exists:
			startScale = 0.0
			math = bs.newNode('math', owner=self.node, attrs={'input1': (0, 0.6, 0), 'operation':'add'})
			self.node.connectAttr('position', math, 'input2')
			self._scoreText = bs.newNode('text',
										  owner=self.node,
										  attrs={'text':text,
												 'inWorld':True,
												 'scale':0.02,
												 'shadow':0.5,
												 'flatness':1.0,
												 'hAlign':'center'})
			math.connectAttr('output', self._scoreText, 'position')
		else:
			startScale = self._scoreText.scale
			self._scoreText.text = text
		self._scoreText.color = bs.getSafeColor((1.0, 1.0, 0.4))
		bs.animate(self._scoreText, 'scale', {0: startScale, 200: 0.02})
		self._scoreTextHideTimer = bs.Timer(1000, bs.WeakCall(self._hideScoreText))
Пример #7
0
 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 __init__(self, incTime=1000):

		lightY = 150

		self.pos = 0

		self._beep1Sound = bs.getSound('raceBeep1')
		self._beep2Sound = bs.getSound('raceBeep2')

		self.lights = []
		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', {10:0, 1000:1.0})
			self.lights.append(l)

		self.lights[0].color = (0.2, 0, 0)
		self.lights[1].color = (0.2, 0, 0)
		self.lights[2].color = (0.2, 0.05, 0)
		self.lights[3].color = (0.0, 0.3, 0)


		self.cases = {1: self._doLight1, 2: self._doLight2, 3: self._doLight3, 4: self._doLight4}
		self.incTimer = None
		self.incTime = incTime
Пример #9
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())
	def _hideScoreText(self):
		try:
			exists = self._scoreText.exists()
		except Exception:
			exists = False
		if exists:
			bs.animate(self._scoreText, 'scale', {0: self._scoreText.scale, 200: 0})
	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 _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())
Пример #13
0
 def setScoreText(self,text):
     """
     Utility func to show a message over the flag; handy for scores.
     """
     if not self.node.exists(): return
     try: exists = self._scoreText.exists()
     except Exception: exists = False
     if not exists:
         startScale = 0.0
         math = bs.newNode('math',owner=self.node,attrs={'input1':(0,1.4,0),'operation':'add'})
         self.node.connectAttr('position',math,'input2')
         self._scoreText = bs.newNode('text',
                                       owner=self.node,
                                       attrs={'text':text,
                                              'inWorld':True,
                                              'scale':0.02,
                                              'shadow':0.5,
                                              'flatness':1.0,
                                              'hAlign':'center'})
         math.connectAttr('output',self._scoreText,'position')
     else:
         startScale = self._scoreText.scale
         self._scoreText.text = text
     self._scoreText.color = bs.getSafeColor(self.node.color)
     bs.animate(self._scoreText,'scale',{0:startScale,200:0.02})
     self._scoreTextHideTimer = bs.Timer(1000,bs.WeakCall(self._hideScoreText))
Пример #14
0
 def handlePlayerDied(self):
     if not self.node.exists(): return
     if self._showDeath:
         bs.animate(self.node,'opacity',{0:1.0,50:0.0,100:1.0,150:0.0,200:1.0,250:0.0,
                                         300:1.0,350:0.0,400:1.0,450:0.0,500:1.0,550:0.2})
         lives = self._player.gameData['lives']
         if lives == 0: bs.gameTimer(600,self.updateForLives)
Пример #15
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)
 def __init__(self,position = (0,0.5,0),owner = None,prefix = 'ADMIN',prefixColor = (1,1,1),prefixAnim = {0:(1,1,1),500:(0.5,0.5,0.5)},prefixAnimate = True,particles = True):
     self.position = position
     self.owner = owner        
     ###
     
     def a():
         self.emit()
         ##
     if particles:
         self.timer = bs.Timer(10,bs.Call(a),repeat = True)
         
     #prefix
     m = bs.newNode('math', owner=self.owner, attrs={'input1': (0, 1.35, 0), 'operation': 'add'})
     self.owner.connectAttr('position', m, 'input2')
     
     self._Text = bs.newNode('text',
                                   owner=self.owner,
                                   attrs={'text':prefix, #prefix text
                                          'inWorld':True,
                                          'shadow':1.2,
                                          'flatness':1.0,
                                          'color':prefixColor,
                                          'scale':0.0,
                                          'hAlign':'center'})
                                          
     m.connectAttr('output', self._Text, 'position')
     
     bs.animate(self._Text, 'scale', {0: 0.0, 1000: 0.01}) #smooth prefix spawn
     
     #animate prefix
     if prefixAnimate:
         bsUtils.animateArray(self._Text, 'color',3, prefixAnim,True) #animate prefix color
Пример #17
0
 def _flashMine(self,pos):
     light = bs.newNode("light",
                        attrs={'position':pos,
                               'color':(1,0.2,0.2),
                               'radius':0.1,
                               'heightAttenuated':False})
     bs.animate(light,"intensity",{0:0,100:1.0,200:0},loop=True)
     bs.gameTimer(1000,light.delete)
Пример #18
0
 def _flashBase(self,team,length=2000):
     light = bs.newNode('light',
                        attrs={'position': team.gameData['basePos'],
                               'heightAttenuated': False,
                               'radius':0.3,
                               'color': team.color})
     bs.animate(light,"intensity",{0:0,250:2.0,500:0},loop=True)
     bs.gameTimer(length,light.delete)
Пример #19
0
    def _handlescore(self):
        """ a point has been scored """

        # our puck might stick around for a second or two
        # we dont want it to be able to score again
        if self._puck.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 all players to celebrate
                for player in team.players:
                    try:
                        player.actor.node.handleMessage('celebrate', 2000)
                    except Exception:
                        pass

                # if weve got the player from the scoring
                # team that last touched us, give them points
                if (scoringteam.getID() in self._puck.lastplayerstotouch
                        and self._puck.lastplayerstotouch[
                            scoringteam.getID()].exists()):
                    self.scoreSet.playerScored(
                        self._puck.lastplayerstotouch[scoringteam.getID()],
                        100,
                        bigMessage=True)

                # end game if we won
                if team.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()

        bs.playSound(self._foghornsound)
        bs.playSound(self._cheersound)

        self._puck.scored = True

        # kill the puck (it'll respawn itself shortly)
        bs.gameTimer(1000, self._killpuck)

        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()
Пример #20
0
 def move_hold_node(self, v='height'):
     if getattr(self, '_c', None) is not None and self._c.exists():
         l = [0, 1, 2] if v == 'all' else [1] if v == 'height' else [0, 2]
         for c in l:
             val = getattr(self._c, 'input' + str(c))
             bs.animate(self._c, 'input' + str(c), {
                 0: val,
                 500: val + self._c_move[c]
             })
Пример #21
0
 def _flashPlayer(self,player,scale):
     pos = player.actor.node.position
     light = bs.newNode('light',
                        attrs={'position':pos,
                               'color':(1,1,0),
                               'heightAttenuated':False,
                               'radius':0.4})
     bs.gameTimer(500,light.delete)
     bs.animate(light,'intensity',{0:0,100:1.0*scale,500:0})
Пример #22
0
 def _flashFlag(self, flag, length=1000):
     light = bs.newNode('light',
                        attrs={
                            'position': flag.node.position,
                            'heightAttenuated': False,
                            'color': flag.light.color
                        })
     bs.animate(light, "intensity", {0: 0, 250: 1, 500: 0}, loop=True)
     bs.gameTimer(length, light.delete)
	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
Пример #24
0
 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
Пример #25
0
    def _handleScore(self):
        """ a point has been scored """

        # our flag might stick around for a second or two
        # we dont want it to be able to score again
        if self._flag.scored:
            return

        # see which score region it was..
        region = bs.getCollisionInfo("sourceNode")
        for i in range(len(self.scoreRegions)):
            if region == self.scoreRegions[i].node:
                break

        for team in [self.teams[0], self._botTeam]:
            if team.getID() == i:
                team.gameData['score'] += 7

                # tell all players (or bots) to celebrate
                if i == 0:
                    for player in team.players:
                        try:
                            player.actor.node.handleMessage('celebrate', 2000)
                        except Exception:
                            pass
                else:
                    self._bots.celebrate(2000)

        # if the good guys scored, add more enemies
        if i == 0:
            if self.teams[0].gameData['score'] == 7:
                for t in self._botTypes7:
                    self._spawnBot(t)
            elif self.teams[0].gameData['score'] == 14:
                for t in self._botTypes14:
                    self._spawnBot(t)

        bs.playSound(self._scoreSound)
        if i == 0: bs.playSound(self._cheerSound)
        else: bs.playSound(self._booSound)

        #kill the flag (it'll respawn shortly)
        self._flag.scored = True

        bs.gameTimer(200, self._killFlag)

        self.updateScores()
        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)
        if i == 0: self.cameraFlash(duration=10)
Пример #26
0
 def _flashBillboard(self, tex, spaz):
     spaz.node.billboardOpacity = 1.0
     spaz.node.billboardTexture = tex
     spaz.node.billboardCrossOut = False
     bs.animate(spaz.node, "billboardOpacity", {
         0: 0.0,
         100: 1.0,
         400: 1.0,
         500: 0.0
     })
Пример #27
0
 def _flashFlagSpawn(self):
     light = bs.newNode('light',
                        attrs={
                            'position': self._flagSpawnPos,
                            '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)
Пример #28
0
    def _handleScore(self):
        """ a point has been scored """

        # our flag might stick around for a second or two
        # make sure it doesn't score again
        if self._flag.scored: return

        region = bs.getCollisionInfo("sourceNode")
        for i in range(len(self._scoreRegions)):
            if region == self._scoreRegions[i].node:
                break

        for team in self.teams:
            if team.getID() == i:
                team.gameData['score'] += 1

                # tell all players to celebrate
                for player in team.players:
                    try:
                        player.actor.node.handleMessage('celebrate', 2000)
                    except Exception:
                        pass

                # if someone on this team was last to touch it, give them points
                if (self._flag.lastHoldingPlayer is not None
                        and self._flag.lastHoldingPlayer.exists()
                        and team == self._flag.lastHoldingPlayer.getTeam()):
                    self.scoreSet.playerScored(self._flag.lastHoldingPlayer,
                                               50,
                                               bigMessage=True)

                # end game if we won
                if team.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()

        bs.playSound(self._scoreSound)
        bs.playSound(self._cheerSound)

        self._flag.scored = True

        # kill the flag (it'll respawn shortly)
        bs.gameTimer(1000, self._killFlag)
        bs.gameTimer(3000, self._spawnFlag)

        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()
Пример #29
0
    def _handleReachedEnd(self):
        n = bs.getCollisionInfo("opposingNode")
        spaz = n.getDelegate()

        if not spaz.isAlive():
            return  # ignore bodies flying in..

        self._flawless = False
        p = spaz.node.position
        bs.playSound(self._badGuyScoreSound, position=p)
        light = bs.newNode('light',
                           attrs={
                               'position': p,
                               'radius': 0.5,
                               'color': (1, 0, 0)
                           })
        bs.animate(light, 'intensity', {0: 0, 100: 1, 500: 0}, loop=False)
        bs.gameTimer(1000, light.delete)
        spaz.handleMessage(bs.DieMessage(immediate=True, how='goal'))

        if self._lives > 0:
            self._lives -= 1
            if self._lives == 0:
                self._bots.stopMoving()
                self.continueOrEndGame()

            self._livesText.node.text = str(self._lives)
            t = 0

            def _safeSetAttr(node, attr, value):
                if node.exists():
                    setattr(node, attr, value)

            for i in range(4):
                bs.gameTimer(
                    t,
                    bs.Call(_safeSetAttr, self._livesText.node, 'color',
                            (1, 0, 0, 1.0)))
                bs.gameTimer(
                    t, bs.Call(_safeSetAttr, self._livesBG.node, 'opacity',
                               0.5))
                t += 125
                bs.gameTimer(
                    t,
                    bs.Call(_safeSetAttr, self._livesText.node, 'color',
                            (1.0, 1.0, 0.0, 1.0)))
                bs.gameTimer(
                    t, bs.Call(_safeSetAttr, self._livesBG.node, 'opacity',
                               1.0))
                t += 125
            bs.gameTimer(
                t,
                bs.Call(_safeSetAttr, self._livesText.node, 'color',
                        (0.8, 0.8, 0.8, 1.0)))
Пример #30
0
 def __init__(self, position=(0,1,0), velocity=(0,0.5,0),lucky=False):
     bs.Actor.__init__(self)
     self._luckyAppearSound = bs.getSound('ding')
     
     activity = self.getActivity()
     
     # spawn just above the provided point
     self._spawnPos = (position[0], position[1], position[2])
     if lucky:
         bs.playSound(self._luckyAppearSound,1.0,self._spawnPos)
         self.capsule = bs.newNode("prop",
                             attrs={'model': activity._capsuleModel,
                                     'colorTexture': activity._capsuleLuckyTex,
                                     'body':'crate',
                                     'reflection':'powerup',
                                     'modelScale':0.8,
                                     'bodyScale':0.65,
                                     'density':6.0,
                                     'reflectionScale':[0.15],
                                     'shadowSize': 0.65,
                                     'position':self._spawnPos,
                                     'velocity':velocity,
                                     'materials': [bs.getSharedObject('objectMaterial'),activity._capsuleMaterial]
                                     },
                             delegate=self)
         bs.animate(self.capsule,"modelScale",{0:0, 100:0.9, 160:0.8})
         self.lightCapsule = bs.newNode('light',
                                         attrs={'position':self._spawnPos,
                                             'heightAttenuated':False,
                                             'radius':0.5,
                                             'color':(0.2,0.2,0)})
     else:
         self.capsule = bs.newNode("prop",
                             attrs={'model': activity._capsuleModel,
                                     'colorTexture': activity._capsuleTex,
                                     'body':'capsule',
                                     'reflection':'soft',
                                     'modelScale':0.6,
                                     'bodyScale':0.3,
                                     'density':4.0,
                                     'reflectionScale':[0.15],
                                     'shadowSize': 0.6,
                                     'position':self._spawnPos,
                                     'velocity':velocity,
                                     'materials': [bs.getSharedObject('objectMaterial'),activity._capsuleMaterial]
                                     },
                             delegate=self)
         bs.animate(self.capsule,"modelScale",{0:0, 100:0.6, 160:0.5})
         self.lightCapsule = bs.newNode('light',
                                         attrs={'position':self._spawnPos,
                                             'heightAttenuated':False,
                                             'radius':0.1,
                                             'color':(0.2,1,0.2)})
     self.capsule.connectAttr('position',self.lightCapsule,'position')
Пример #31
0
    def setboxScoreText(self, t, color=(1, 1, 0.4), flash=False):
        """
        Utility func to show a message momentarily over our spaz that follows him around;
        Handy for score updates and things.
        """
        colorFin = bs.getSafeColor(color)[:3]
        if not self.node.exists(): return
        try:
            exists = self._scoreText.exists()
        except Exception:
            exists = False
        if not exists:
            startScale = 0.0
            m = bs.newNode('math',
                           owner=self.node,
                           attrs={
                               'input1': (0, 1.4, 0),
                               'operation': 'add'
                           })
            self.node.connectAttr('position', m, 'input2')
            self._scoreText = bs.newNode('text',
                                         owner=self.node,
                                         attrs={
                                             'text': t,
                                             'inWorld': True,
                                             'shadow': 1.0,
                                             'flatness': 1.0,
                                             'color': colorFin,
                                             'scale': 0.02,
                                             'hAlign': 'center'
                                         })
            m.connectAttr('output', self._scoreText, 'position')
        else:
            self._scoreText.color = colorFin
            startScale = self._scoreText.scale
            self._scoreText.text = t
        if flash:
            combine = bs.newNode("combine",
                                 owner=self._scoreText,
                                 attrs={'size': 3})
            sc = 1.8
            offs = 0.5
            t = 300
            for i in range(3):
                c1 = offs + sc * colorFin[i]
                c2 = colorFin[i]
                bs.animate(combine, 'input' + str(i), {
                    0.5 * t: c2,
                    0.75 * t: c1,
                    1.0 * t: c2
                })
            combine.connectAttr('output', self._scoreText, 'color')

        bs.animate(self._scoreText, 'scale', {0: startScale, 200: 0.02})
Пример #32
0
    def handleMessage(self, m):
        """ handle high-level game messages """

        # respawn dead players
        if isinstance(m, bs.PlayerSpazDeathMessage):

            player = m.spaz.getPlayer()

            self.scoreSet.playerLostSpaz(player)

            respawnTime = 2000 + len(self.initialPlayerInfo) * 1000

            # respawn them shortly
            player.gameData['respawnTimer'] = bs.Timer(
                respawnTime, bs.Call(self.spawnPlayerIfExists, player))
            player.gameData['respawnIcon'] = bs.RespawnIcon(
                player, respawnTime)

            # augment standard behavior
            bs.CoopGameActivity.handleMessage(self, m)

        elif isinstance(m, bs.SpazBotDeathMessage):
            # every time a bad guy dies, spawn a new one
            bs.gameTimer(3000, bs.Call(self._spawnBot, (type(m.badGuy))))

        elif isinstance(m, bs.SpazBotPunchedMessage):
            if self._preset in ['rookie', 'rookieEasy']:
                if m.damage >= 500:
                    self._awardAchievement('Super Punch')
            elif self._preset in ['pro', 'proEasy']:
                if m.damage >= 1000:
                    self._awardAchievement('Super Mega Punch')

        # respawn dead flags
        elif isinstance(m, bs.FlagDeathMessage):
            m.flag.respawnTimer = bs.Timer(3000, self._spawnFlag)
            self._flagRespawnLight = bs.NodeActor(
                bs.newNode('light',
                           attrs={
                               'position': self._flagSpawnPos,
                               'heightAttenuated': False,
                               'radius': 0.15,
                               'color': (1.0, 1.0, 0.3)
                           }))
            bs.animate(self._flagRespawnLight.node,
                       "intensity", {
                           0: 0,
                           250: 0.15,
                           500: 0
                       },
                       loop=True)
            bs.gameTimer(3000, self._flagRespawnLight.node.delete)
        else:
            bs.CoopGameActivity.handleMessage(self, m)
Пример #33
0
            def _changePhrase(self):

                global gLastNewsFetchTime
                
                if time.time()-gLastNewsFetchTime > 100.0:
                    self._fetchNews()
                    self._text = None
                else:
                    if self._text is not None:
                        if len(self._phrases) == 0:
                            for p in self._usedPhrases:
                                self._phrases.insert(0,p)
                        val = self._phrases.pop()
                        if val == '__ACH__':
                            vr = bs.getEnvironment()['vrMode']
                            bsUtils.Text(
                                bs.Lstr(resource='nextAchievementsText'),
                                color=(1,1,1,1) if vr else (0.95,0.9,1,0.4),
                                hostOnly=True,
                                maxWidth=200,
                                position=(-300, -35),
                                hAlign='right',
                                transition='fadeIn',
                                scale=0.9 if vr else 0.7,
                                flatness=1.0 if vr else 0.6,
                                shadow=1.0 if vr else 0.5,
                                hAttach="center",
                                vAttach="top",
                                transitionDelay=1000,
                                transitionOutDelay=self._messageDuration)\
                                   .autoRetain()
                            import bsAchievement
                            achs = [a for a in bsAchievement.gAchievements
                                    if not a.isComplete()]
                            if len(achs) > 0:
                                a = achs.pop(random.randrange(min(4,len(achs))))
                                a.createDisplay(-180, -35, 1000,
                                                outDelay=self._messageDuration,
                                                style='news')
                            if len(achs) > 0:
                                a = achs.pop(random.randrange(min(8,len(achs))))
                                a.createDisplay(180, -35, 1250,
                                                outDelay=self._messageDuration,
                                                style='news')
                        else:
                            s = self._messageSpacing
                            keys = {s:0, s+1000:1.0,
                                    s+self._messageDuration-1000:1.0,
                                    s+self._messageDuration:0.0}
                            bs.animate(self._text.node, "opacity",
                                       dict([[k,v] for k,v in keys.items()]))
                            self._text.node.text = val
Пример #34
0
    def _handleBaseCollide(self,team):

        cval = bs.getCollisionInfo('opposingNode')
        try: player = cval.getDelegate().getPlayer()
        except Exception: return
        if player is None or not player.exists(): return
        
        # if its another team's player, they scored
        playerTeam = player.getTeam()
        if playerTeam is not team:

            # (prevent multiple simultaneous scores)
            if bs.getGameTime() != self._lastScoreTime:
                self._lastScoreTime = bs.getGameTime()

                self.scoreSet.playerScored(player,50,bigMessage=True)

                bs.playSound(self._scoreSound)
                self._flashBase(team)

                # move all players on the scoring team back to their start
                # and add flashes of light so its noticable
                for p in playerTeam.players:
                    if p.isAlive():
                        pos = p.actor.node.position
                        light = bs.newNode('light',
                                           attrs={'position':pos,
                                                  'color':playerTeam.color,
                                                  'heightAttenuated':False,
                                                  'radius':0.4})
                        bs.gameTimer(500,light.delete)
                        bs.animate(light,'intensity',{0:0,100:1.0,500:0})

                        newPos = self.getMap().getStartPosition(playerTeam.getID())
                        light = bs.newNode('light',
                                           attrs={'position':newPos,
                                                  'color':playerTeam.color,
                                                  'radius':0.4,
                                                  'heightAttenuated':False})
                        bs.gameTimer(500,light.delete)
                        bs.animate(light,'intensity',{0:0,100:1.0,500:0})
                        p.actor.handleMessage(bs.StandMessage(newPos,random.uniform(0,360)))

                # have teammates celebrate
                for player in playerTeam.players:
                    try: player.actor.node.handleMessage('celebrate',2000)
                    except Exception: pass

                playerTeam.gameData['score'] += 1
                self._updateScoreBoard()
                if playerTeam.gameData['score'] >= self.settings['Score to Win']:
                    self.endGame()
	def setPowText(self, color=(1, 1, 0.4)):
		m = bs.newNode('math', owner=self.node, attrs={'input1': (0, 0.7, 0), 'operation': 'add'})
		self.node.connectAttr('position', m, 'input2')
		self._powText = bs.newNode('text',
									  owner=self.node,
									  attrs={'text':'POW!',
											 'inWorld':True,
											 'shadow':1.0,
											 'flatness':1.0,
											 'color':color,
											 'scale':0.0,
											 'hAlign':'center'})
		m.connectAttr('output', self._powText, 'position')
		bs.animate(self._powText, 'scale', {0: 0.0, 1000: 0.01})
	def _setChosenOnePlayer(self, player):
		try:
			for p in self.players: p.gameData['FrozenLight'] = None
			bs.playSound(self._swipSound)
			if player is None or not player.exists():
				self._flag = bs.Flag(color=(1,0.9,0.2),
									 position=self._flagSpawnPos,
									 touchable=False)
				self._chosenOnePlayer = None

				l = bs.newNode('light',
							   owner=self._flag.node,
							   attrs={'position': self._flagSpawnPos,
									  'intensity':0.6,
									  'heightAttenuated':False,
									  'volumeIntensityScale':0.1,
									  'radius':0.1,
									  'color': (1.2,1.2,0.4)})

				self._flashFlagSpawn()
			else:
				if player.actor is not None:
					self._flag = None
					self._chosenOnePlayer = player

					if player.actor.node.exists():
						if self.settings['Frozen One Gets Gloves']: player.actor.handleMessage(bs.PowerupMessage('punch'))

						player.actor.frozen = True
						player.actor.node.frozen = 1
						# use a color that's partway between their team color and white
						color = [0.3+c*0.7 for c in bs.getNormalizedColor(player.getTeam().color)]
						l = player.gameData['FrozenLight'] = bs.NodeActor(bs.newNode('light',
																					 attrs={"intensity":0.6,
																							"heightAttenuated":False,
																							"volumeIntensityScale":0.1,
																							"radius":0.13,
																							"color": color}))

						bs.animate(l.node, 'intensity', {0:1.0, 200:0.4, 400:1.0}, loop=True)
						player.actor.node.connectAttr('position',l.node,'position')
		except Exception, e:
			import traceback
			print 'EXC in _setChosenOnePlayer'
			traceback.print_exc(e)
			traceback.print_stack()
 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 _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)