Пример #1
0
 def lightningBolt(self,position = (0,10,0),radius = 10):
     bs.shakeCamera(3)
     self.tint = bs.getSharedObject('globals').tint
     light = bs.newNode('light',
                     attrs={'position':position,
                         'color': (0.2,0.2,0.4),
                         'volumeIntensityScale': 1.0,
                         'radius':radius})
     bsUtils.animate(light,"intensity",{0:1,50:radius,150:radius/2,250:0,260:radius,410:radius/2,510:0})
     bsUtils.animateArray(bs.getSharedObject('globals'),"tint",3,{0:self.tint,200:(0.2,0.2,0.2),510:self.tint})
     bs.playSound(bs.getSound('grom'),volume = 10,position = (0,10,0))
Пример #2
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', 1000)
                    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.shakeCamera(intensity=0.0)
        bs.playSound(self._glSound)
        bs.playSound(self._cheerSound)

        self._puck.scored = True

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

        self._updateScoreBoard()
Пример #3
0
	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)
Пример #4
0
    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

        # set our position a bit lower so we throw more things upward
        self.node = bs.newNode('region', delegate=self, attrs={
            'position':(position[0], position[1]-0.1, position[2]),
            'scale':(self.radius,self.radius,self.radius),
            'type':'sphere',
            'materials':(factory.blastMaterial if self.blastType not in ['dirt'] else factory.dirtMaterial, bs.getSharedObject('attackMaterial'))})

        if self.blastType == 'dirt': 
            def a():
                for i in getattr(self, 'dirt_nodes', []):
                    if i.exists(): i.handleMessage(DirtBombOutMessage())
                self.node.delete()
            bs.gameTimer(7000, bs.Call(a))
        else: bs.gameTimer(10, 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 if self.blastType != 'qq' else 0.8,
            'big':(self.blastType == 'tnt')})
        if self.blastType == "ice":
            explosion.color = (0, 0.05, 0.4)
        elif self.blastType == "firework":
            explosion.color = (0.6, 1, 1)
        elif self.blastType == "killLaKill":
            explosion.color = (0.3, 0.3, 0.3)
        elif self.blastType == "boss":
            explosion.color = (1.1, 1.1, 1)
        else:
            explosion.color = (1,0.8,0)
        if self.blastType != 'boss':
            bs.gameTimer(1000, explosion.delete)
        else:
            bs.gameTimer(500, explosion.delete)

        if self.blastType != 'ice':
            bs.emitBGDynamics(position=position, velocity=velocity,
                              count=int(1.0+random.random()*4),
                              emitType='tendrils',tendrilType='thinSmoke')
        elif self.blastType == 'killLaKill':
            bs.emitBGDynamics(
                position=position, emitType='distortion',
                spread=550.0)
            bs.emitBGDynamics(
                position=position, velocity=velocity,
                count=int(4.0+random.random()*40), emitType='tendrils',
                tendrilType='ice' if self.blastType == 'ice' else 'smoke')
        if self.blastType != 'qq':
            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

        if self.blastType == 'poison':
            def _doEmit():
                bs.emitBGDynamics(position=position, velocity=velocity,
                                  count=30, spread=2.0, scale=0.4,
                                  chunkType='rock', emitType='stickers');
            bs.gameTimer(50, _doEmit) # looks better if we delay a bit

        elif self.blastType == 'firework':
            def _doEmit():
                bs.emitBGDynamics(position=position, velocity=(1.1 + random.random(), 1.8 + random.random(), 1.1 + random.random()),
                                  count = 360 + random.randrange(0,40), spread=0.8, scale=0.7,
                                  chunkType = 'spark');
            bs.gameTimer(45, _doEmit) 

        elif self.blastType == 'killLaKill':
            def _doEmit():
                bs.emitBGDynamics(position=position, velocity=velocity,
                                  count=15, scale=0.6, chunkType='metal',
                                  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) 

        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 == 'dirt':
            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.gameTimer(50,_doEmit)

        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,
            'volumeIntensityScale': 10.0,
            'color': ((0.6, 0.6, 1.0) if self.blastType == 'ice'
                      else (1, 0.3, 0.1))})

        s = random.uniform(0.6,0.9)
        scorchRadius = lightRadius = self.radius
        if self.blastType == 'tnt':
            lightRadius *= 1.4
            scorchRadius *= 1.15
            s *= 3.0
        elif self.blastType == 'qq':
            scorchRadius *= 0.5
        elif self.blastType == 'boss':
            scorchRadius = 0
            lightRadius = 0.35

        iScale = 1.6
        if self.blastType not in ['firework', 'qq']:
            bsUtils.animate(light,"intensity", {
                0:0, 10:0.5, 20:1.0, 2000:0.5, 2750:0})
            bsUtils.animate(light,"radius", {
                0:0, 10:0.5, 20:1.0, 2000:0.5, 2750:0})
            bs.gameTimer(2750,light.delete)
        if self.blastType == 'qq':
            bsUtils.animate(light,"intensity", {
                0:0, 10:0.5, 20:0.55, 700:1, 900:0})
            bsUtils.animate(light,"radius", {
                0:0, 10:0.5, 20:0.55, 700:0.6, 900:0})
            bs.gameTimer(900,light.delete)
        if self.blastType == 'firework':
            bsUtils.animate(light,"intensity", {
                0:0, 10:0.5, 20:1.0, 1200:0.5, 4000:0})
            bsUtils.animate(light,"radius", {
                0:0, 10:0.5, 20:1.0, 1200:0.5, 4000:0})
            bs.gameTimer(4000,light.delete)

        # make a scorch that fades over time
        scorch = bs.newNode('scorch', attrs={
            'position':position,
            'size':scorchRadius*0.5 if self.blastType != "dirt" else scorchRadius*1.2,
            'big':(self.blastType in ['dirt','tnt'])})
        if self.blastType == 'ice':
            scorch.color = (1,1,1.5)
        elif self.blastType == 'dirt':
            scorch.color = (0.5, 0.1, 0.02)
        else:
            scorch.color = (light.color[0]-0.05, light.color[1]-0.05, light.color[2]-0.07)

        if self.blastType not in ['firework', 'dirt']:
            bsUtils.animate(scorch,"presence",{0:0, 60:0.55, 2000:1, 5000:0})
            bs.gameTimer(13000,scorch.delete)
        elif self.blastType in ['dirt']:
            bsUtils.animate(scorch,"presence",{0:0, 60:0.55, 2000:1, 6700:1, 7250:0})
            bs.gameTimer(7250,scorch.delete)
        else:
            bsUtils.animate(scorch,"presence",{3000:1, 10000:1, 26000:0})
            bs.gameTimer(26000,scorch.delete)

        p = light.position
        if self.blastType == 'ice':
            bs.playSound(factory.hissSound,position=p)

        elif self.blastType == 'firework':
            bs.playSound(factory.hissSound,position=p)

        elif self.blastType == 'killLaKill':
            bs.playSound(factory.getRandomExplodeSound(),position=p)
        else:  
            bs.playSound(factory.getRandomExplodeSound(),position=p)
            bs.playSound(factory.debrisFallSound,position=p)

        if self.blastType == 'tnt':
            intensity=5.0
        elif self.blastType == 'killLaKill':
            intensity=6.1
        elif self.blastType == 'firework':
            intensity=0.5
        elif self.blastType == 'qq':
            intensity=0.32
        elif self.blastType == 'boss':
            intensity=0.1
        elif self.blastType == 'dirt': 
            intensity=0.2
        else:
            intensity=1.0

        bs.shakeCamera(intensity)

        # 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 __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)
Пример #6
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")
                spaz = node.getDelegate()
                if spaz is not None and spaz.exists() and spaz.isAlive(
                ):  # pass deadbodies error
                    if self.powerupType == 'superStar':
                        tex = bs.Powerup.getFactory().texSuperStar
                        self._flashBillboard(tex, spaz)

                        def colorChanger():
                            if spaz.isAlive():
                                spaz.node.color = (random.random() * 2,
                                                   random.random() * 2,
                                                   random.random() * 2)
                                spaz.node.highlight = (random.random() * 2,
                                                       random.random() * 2,
                                                       random.random() * 2)

                        def checkStar(val):
                            self._powersGiven = True
                            if spaz.isAlive():
                                setattr(spaz.node, 'invincible', val)
                            if val and spaz.isAlive():
                                if spaz.node.frozen:
                                    spaz.node.handleMessage(bs.ThawMessage())
                                bs.playSound(
                                    bs.Powerup.getFactory().superStarSound,
                                    position=spaz.node.position)
                                spaz.colorSet = bs.Timer(100,
                                                         bs.Call(colorChanger),
                                                         repeat=True)
                                if spaz._cursed:
                                    spaz._cursed = False
                                    # remove cursed material
                                    factory = spaz.getFactory()
                                    for attr in [
                                            'materials', 'rollerMaterials'
                                    ]:
                                        materials = getattr(spaz.node, attr)
                                        if factory.curseMaterial in materials:
                                            setattr(
                                                spaz.node, attr,
                                                tuple(m for m in materials
                                                      if m !=
                                                      factory.curseMaterial))
                                    spaz.node.curseDeathTime = 0
                            if not val and spaz.isAlive():
                                spaz.node.color = spaz.getPlayer().color
                                spaz.node.highlight = spaz.getPlayer(
                                ).highlight
                                spaz.colorSet = None
                                bs.playSound(
                                    bs.Powerup.getFactory().powerdownSound,
                                    position=spaz.node.position)
                                spaz.node.billboardOpacity = 0.0

                        checkStar(True)
                        if self._powersGiven == True:
                            spaz.node.miniBillboard1Texture = tex
                            t = bs.getGameTime()
                            spaz.node.miniBillboard1StartTime = t
                            spaz.node.miniBillboard1EndTime = t + gMythBPowerUpsWearOffTime
                            spaz._starWearOffTimer = bs.Timer(
                                gMythBPowerUpsWearOffTime,
                                bs.Call(checkStar, False))
                            spaz._starWearOffFlashTimer = bs.Timer(
                                gMythBPowerUpsWearOffTime - 2000,
                                bs.WeakCall(self._powerUpWearOffFlash, tex,
                                            spaz))
                            self.handleMessage(bs.DieMessage())
                    elif self.powerupType == 'speed':
                        if bs.getActivity(
                        )._map.isHockey:  #dont give speed if map is already hockey.
                            self.handleMessage(bs.DieMessage(immediate=True))
                        if not bs.getActivity()._map.isHockey:
                            spaz = node.getDelegate()
                            tex = bs.Powerup.getFactory().texSpeed
                            self._flashBillboard(tex, spaz)

                            def checkSpeed(val):
                                self._powersGiven = True
                                if spaz.isAlive():
                                    setattr(spaz.node, 'hockey', val)
                                if val and spaz.isAlive():
                                    bs.playSound(
                                        bs.Powerup.getFactory().speedSound,
                                        position=spaz.node.position)
                                if not val and spaz.isAlive():
                                    bs.playSound(
                                        bs.Powerup.getFactory().powerdownSound,
                                        position=spaz.node.position)
                                    spaz.node.billboardOpacity = 0.0

                            checkSpeed(True)
                            if self._powersGiven == True:
                                spaz.node.miniBillboard3Texture = tex
                                t = bs.getGameTime()
                                spaz.node.miniBillboard3StartTime = t
                                spaz.node.miniBillboard3EndTime = t + gMythBPowerUpsWearOffTime
                                spaz._speedWearOffTimer = bs.Timer(
                                    gMythBPowerUpsWearOffTime,
                                    bs.Call(checkSpeed, False))
                                spaz._speedWearOffFlashTimer = bs.Timer(
                                    gMythBPowerUpsWearOffTime - 2000,
                                    bs.WeakCall(self._powerUpWearOffFlash, tex,
                                                spaz))
                                self.handleMessage(bs.DieMessage())
                    elif self.powerupType == 'iceCube':
                        spaz = node.getDelegate()

                        def checkFreezer(val):
                            self._powersGiven = True
                            if spaz.isAlive() and spaz.node.invincible:
                                bs.playSound(
                                    bs.Powerup.getFactory().blockSound,
                                    position=spaz.node.position)
                            if spaz.isAlive() and not spaz.node.invincible:
                                setattr(spaz, 'frozen', val)
                            if val and spaz.isAlive(
                            ) and not spaz.node.invincible:
                                spaz.node.frozen = 1
                                m = bs.newNode('math',
                                               owner=spaz,
                                               attrs={
                                                   'input1': (0, 1.3, 0),
                                                   'operation': 'add'
                                               })
                                spaz.node.connectAttr('torsoPosition', m,
                                                      'input2')
                                opsText = bsUtils.PopupText(
                                    "Oops!",
                                    color=(1, 1, 1),
                                    scale=0.9,
                                    offset=(0, -1, 0)).autoRetain()
                                m.connectAttr('output', opsText.node,
                                              'position')
                                bs.playSound(
                                    bs.Powerup.getFactory().iceCubeSound,
                                    position=spaz.node.position)
                            if not val and spaz.isAlive():
                                spaz.node.frozen = 0

                        checkFreezer(True)
                        if self._powersGiven == True:
                            spaz._iceCubeWearOffTimer = bs.Timer(
                                gMythBPowerUpsWearOffTime,
                                bs.Call(checkFreezer, False))
                            self.handleMessage(bs.DieMessage())
                    elif self.powerupType == 'surprise':
                        self._powersGiven = True
                        spaz = node.getDelegate()
                        if spaz.isAlive():
                            bs.shakeCamera(1)
                            bsUtils.PopupText(
                                "Surprise!",
                                color=(1, 1, 1),
                                scale=0.9,
                                offset=(0, -1, 0),
                                position=(spaz.node.position[0],
                                          spaz.node.position[1] - 1,
                                          spaz.node.position[2])).autoRetain()
                            bs.playSound(bs.Powerup.getFactory().surpriseSound,
                                         position=spaz.node.position)
                            bs.emitBGDynamics(position=spaz.node.position,
                                              velocity=(0, 1, 0),
                                              count=random.randrange(30, 70),
                                              scale=0.5,
                                              chunkType='spark')
                            spaz.node.handleMessage("knockout", 3000)
                            spaz.node.handleMessage(
                                "impulse", spaz.node.position[0],
                                spaz.node.position[1], spaz.node.position[2],
                                -spaz.node.velocity[0], -spaz.node.velocity[1],
                                -spaz.node.velocity[2], 400, 400, 0, 0,
                                -spaz.node.velocity[0], -spaz.node.velocity[1],
                                -spaz.node.velocity[2])
                        if self._powersGiven == True:
                            self.handleMessage(bs.DieMessage())
                    elif self.powerupType == 'martyrdom':
                        spaz = node.getDelegate()
                        tex = bs.Powerup.getFactory().texMartyrdom
                        self._flashBillboard(tex, spaz)

                        def checkDead():  #FIXME
                            if spaz.hitPoints <= 0 and (
                                (spaz.lastPlayerHeldBy is not None
                                 and spaz.lastPlayerHeldBy.exists()) or
                                (spaz.lastPlayerAttackedBy is not None
                                 and spaz.lastPlayerAttackedBy.exists()
                                 and bs.getGameTime() - spaz.lastAttackedTime <
                                 4000)):
                                try:
                                    spaz.lastDeathPos = spaz.node.position  #FIXME
                                except Exception:
                                    spaz.dropss = None
                                else:
                                    if not spaz.lastPlayerAttackedBy == spaz.getPlayer(
                                    ):
                                        dropBomb()
                                        spaz.dropss = None

                        def dropBomb():
                            bs.playSound(
                                bs.Powerup.getFactory().martyrdomSound,
                                position=spaz.lastDeathPos)
                            drop0 = bs.Bomb(
                                position=(spaz.lastDeathPos[0] + 0.43,
                                          spaz.lastDeathPos[1] + 4,
                                          spaz.lastDeathPos[2] - 0.25),
                                velocity=(0, -6, 0),
                                sourcePlayer=spaz.getPlayer(
                                ),  #some math for perfect triangle
                                bombType='sticky').autoRetain()
                            drop1 = bs.Bomb(
                                position=(spaz.lastDeathPos[0] - 0.43,
                                          spaz.lastDeathPos[1] + 4,
                                          spaz.lastDeathPos[2] - 0.25),
                                velocity=(0, -6, 0),
                                sourcePlayer=spaz.getPlayer(),
                                bombType='sticky').autoRetain()
                            drop2 = bs.Bomb(
                                position=(spaz.lastDeathPos[0],
                                          spaz.lastDeathPos[1] + 4,
                                          spaz.lastDeathPos[2] + 0.5),
                                velocity=(0, -6, 0),
                                sourcePlayer=spaz.getPlayer(),
                                bombType='sticky').autoRetain()

                        def checkVal(val):
                            self._powersGiven = True
                            if val and spaz.isAlive():
                                m = bs.newNode('math',
                                               owner=spaz,
                                               attrs={
                                                   'input1': (0, 1.3, 0),
                                                   'operation': 'add'
                                               })
                                spaz.node.connectAttr('torsoPosition', m,
                                                      'input2')
                                activatedText = bsUtils.PopupText(
                                    "ACTIVATED",
                                    color=(1, 1, 1),
                                    scale=0.7,
                                    offset=(0, -1, 0)).autoRetain()
                                m.connectAttr('output', activatedText.node,
                                              'position')
                                bs.playSound(
                                    bs.Powerup.getFactory().martyrdomPickSound,
                                    position=spaz.node.position)
                                spaz.isDropped = True
                                spaz.dropss = bs.Timer(1,
                                                       bs.Call(checkDead),
                                                       repeat=True)

                        checkVal(True)
                        if 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(150, 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)