def __init__(self, user_id, x, y, z=None): self.user_id = user_id self.landing_hack = False self.selected = False if self.btype == 'launchsite': self.rocket_y_offset = 0 self.last_render_y = None self.x, self.y = terrain.toCenterRender(x, y) if self.size == 2: self.y -= 1 if z is None: self.setheight(0) else: self.z = z self.hp = self.hp0
def __init__(self, x, y, z=None): self.vx, self.vy = 0, 0 self.x, self.y = terrain.toCenterRender(x, y) self.z = terrain.height(self.x, self.y) if z is None else z self.alive = True self.hp = self.hp0
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