def hurt(self, dhp, hurter=None):
     if hurter:
         self.reel(hurter.x, hurter.y)
     self.hp = max(self.hp - dhp, 0)
     if self.hp <= 0:
         self.die()
     else:
         if self.hurtsound:
             jukebox.play_sound(self.hurtsound)
 def shoot(self):
     if self.weapont < self.weaponchargetime:
         return None
     jukebox.play_sound("raygun")
     shot = Ray(self.x, self.y, self.z + 3)
     shot.x, shot.y = self.x, self.y  # it's 1am, i'm doing this the sloppy way
     shot.move(*directions[self.last_direction])
     self.weapont = 0
     return shot
	def shoot(self):
		if self.weapont < self.weaponchargetime:
			return None
		jukebox.play_sound("raygun")
		shot = Ray(self.x, self.y, self.z + 3)
		shot.x, shot.y = self.x, self.y   # it's 1am, i'm doing this the sloppy way
		shot.move(*directions[self.last_direction])
		self.weapont = 0
		return shot
	def hurt(self, dhp, hurter=None):
		if hurter:
			self.reel(hurter.x, hurter.y)
		self.hp = max(self.hp - dhp, 0)
		if self.hp <= 0:
			self.die()
		else:
			if self.hurtsound:
				jukebox.play_sound(self.hurtsound)
	def update(self):
		self.playscene.update(False)
		if not self.deployed: return
		deploying = self.playscene.potato.deploy_success(True)
		
		if deploying != None and deploying != 'deploying':
			a = deploying[0]
			b = deploying[1]
			c = deploying[2]
			
			if a > 0 or b > 0 or c > 0:
				self.deploy(a, b, c)
				jukebox.play_sound("bot")
			else:
				jukebox.play_sound("wrong")
 def die(self):
     self.alive = False
     if self.diesound:
         jukebox.play_sound(self.diesound)
	def die(self):
		self.alive = False
		if self.diesound:
			jukebox.play_sound(self.diesound)
 def destroy(self):
     if self.destroyed: return
     jukebox.play_sound("destroyed")
     effects.add(effects.SmokeCloud(self.x, self.y, self.z))
     self.destroyed = True
def add(e):
	if e.sound: jukebox.play_sound(e.sound)
	effects.append(e)
	def destroy(self):
		if self.destroyed: return
		jukebox.play_sound("destroyed")
		effects.add(effects.SmokeCloud(self.x, self.y, self.z))
		self.destroyed = True
	def update(self, bdsoverride=True):
		
		bot_deploy_success = self.potato.deploy_success(bdsoverride)
		if bot_deploy_success != None:
			b = bot_deploy_success
			self.next = DeployBotsScene(self, b[0], b[1], b[2])
		
		if self.curiosity != None:
			self.curiosity.update()
			if self.curiosity.is_done():
				self.curiosity = None
		
		self.potato.update()
		self.poll_countdown -= 1
		if self.poll_countdown < 0 and len(self.poll) == 0:
			self.poll.append(network.send_poll(
				self.user_id, self.password,
				self.get_current_sector(),
				self.potato.last_id_by_sector))
		
		i = 0
		while i < len(self.poll):
			if self.poll[i].has_response():
				if not self.poll[i].is_error():
					self.potato.apply_poll_data(self.poll[i].get_response(), self.user_id)
				self.poll = self.poll[:i] + self.poll[i + 1:]
			else:
				i += 1

		if self.potato.queue_epic_battle and not self.potato.epic_battle_won and self.pendingbattle == None and self.battle == None:
		
			buildings = self.potato.get_all_buildings_of_player_SLOW(self.user_id)
			if not any(b.btype == "launchsite" for b in buildings):
				self.potato.queue_epic_battle = False
			else:
				bord = self.potato.borders_by_user[self.user_id]
				self.pendingbattle = battle.Battle(self.user_id, buildings, bord, None, nbytes=10000)
			
		
		if len(self.poll) == 0 and self.poll_countdown < 0:
			self.poll_countdown = 10 * settings.fps
		if self.battle is None:
			worldmap.killtime(0.01)  # Helps remove jitter when exploring

		# TODO: this could just as easily be called once every 100 frames or so.
		# Populate nearby sectors with aliens
		self.exploret += 1
		if not self.battle and self.exploret >= 10:
			self.explore()
		
		if self.battle != None:
			self.battle.update(self)
			if self.battle.is_complete(self):
				self.pendingbattle = 17  # dummy number
		
		px, py = self.player.getModelXY()
		bords = self.potato.get_borders_near_sector(int(px // 60), int(py // 60))
		t0 = time.time()
		for s in self.sprites:
			# HACK
			if (s.x - self.player.x) ** 2 + (s.y - self.player.y) ** 2 > 80 ** 2:
				continue
			s.update(self)
			if s.freerange:
				if any(border.iswithin(s.x, s.y) for border in bords):
					s.die()
#		print len(self.sprites), time.time() - t0
		self.player.update(self)
		for s in self.shots:
			s.update(self)
			s.handlealiens(self.sprites)
			if self.battle:
				s.handlealiens(self.battle.attackers)
		for s in self.sprites:
			if not s.alive and s.awardnumber is not None:
				network.send_alien_award(self.user_id, self.password, s.awardnumber)
		self.sprites = [s for s in self.sprites if s.alive]
		self.shots = [s for s in self.shots if s.alive]
		
		if not self.player.alive:
			self.player.x, self.player.y = terrain.toCenterRender(self.cx, self.cy + 1)
			self.player.healall()
			self.sprites.append(self.player)
			self.player.alive = True
		effects.update()
		
		if self.pendingbattle:
			self.blinkt += 1
			if self.blinkt >= 10:
				if self.pendingbattle == 17:   # ending a battle
					if self.battle:
						for building in self.battle.buildings:
							if building.destroyed:
								self.blow_stuff_up(*building.getModelXY())
							if building.btype == "fireturret":
								building.cleartargets()
						if self.battle.nbytes >= 10000:
							if self.battle.hq.hp == 0:
								self.blow_stuff_up(*self.battle.hq.getModelXY())
								jukebox.play_voice("research_failed")
							for building in self.battle.buildings:
								if building.hp > 0:
									building.healfull()
						elif self.battle.is_computer_attacking():
							for building in self.battle.buildings:
								if building.hp > 0:
									building.healfull()
							if self.battle.hq.hp > 0:
								jukebox.play_voice("research_successful")
							else:
								jukebox.play_voice("research_failed")
						else:
							if self.battle.hq.hp > 0:
								jukebox.play_voice("infiltration_failed")
							else:
								jukebox.play_voice("infiltration_successful")
							for building in self.battle.buildings:
								building.healfull()
						self.battle.hq.healfull()   # Repair the HQ after the battle
						self.battle = None
						self.pendingbattle = None
					self.explored = set()
				else:   # starting a battle
					jukebox.play_sound("klaxon")
					self.battle = self.pendingbattle
					if self.battle.is_computer_attacking():
						jukebox.play_voice("incoming_attack")
					self.sprites = [self.player]  # get rid of all the free range aliens
					self.pendingbattle = None
		elif self.blinkt:
			self.blinkt -= 1
Exemple #12
0
def add(e):
    if e.sound: jukebox.play_sound(e.sound)
    effects.append(e)