def _handle_score(self) -> None: """A point has been scored.""" assert self._puck is not None assert self._score_regions is not None # Our puck might stick around for a second or two # we don't want it to be able to score again. if self._puck.scored: return region = ba.get_collision_info("source_node") index = 0 for index in range(len(self._score_regions)): if region == self._score_regions[index].node: break for team in self.teams: if team.get_id() == index: scoring_team = team team.gamedata['score'] += 1 # Tell all players to celebrate. for player in team.players: if player.actor: player.actor.handlemessage(ba.CelebrateMessage(2.0)) # If we've got the player from the scoring team that last # touched us, give them points. if (scoring_team.get_id() in self._puck.last_players_to_touch and self._puck.last_players_to_touch[ scoring_team.get_id()]): self.stats.player_scored(self._puck.last_players_to_touch[ scoring_team.get_id()], 100, big_message=True) # End game if we won. if team.gamedata['score'] >= self.settings['Score to Win']: self.end_game() ba.playsound(self._foghorn_sound) ba.playsound(self._cheer_sound) self._puck.scored = True # Kill the puck (it'll respawn itself shortly). ba.timer(1.0, self._kill_puck) light = ba.newnode('light', attrs={ 'position': ba.get_collision_info('position'), 'height_attenuated': False, 'color': (1, 0, 0) }) ba.animate(light, 'intensity', {0: 0, 0.5: 1, 1.0: 0}, loop=True) ba.timer(1.0, light.delete) ba.cameraflash(duration=10.0) self._update_scoreboard()
def end_game(self) -> None: # Stop our on-screen timer so players can see what they got. assert self._timer is not None self._timer.stop() results = ba.TeamGameResults() # If we won, set our score to the elapsed time # (there should just be 1 team here since this is co-op). # ..if we didn't win, leave scores as default (None) which means # we lost. if self._won: curtime = ba.time(timeformat=ba.TimeFormat.MILLISECONDS) assert isinstance(curtime, int) starttime = self._timer.getstarttime( timeformat=ba.TimeFormat.MILLISECONDS) assert isinstance(starttime, int) elapsed_time_ms = curtime - starttime ba.cameraflash() ba.playsound(self._winsound) for team in self.teams: for player in team.players: if player.actor: player.actor.handlemessage(ba.CelebrateMessage()) results.set_team_score(team, elapsed_time_ms) # Ends the activity. self.end(results)
def _handle_score(self) -> None: """A point has been scored.""" # Our flag might stick around for a second or two # make sure it doesn't score again. assert self._flag is not None if self._flag.scored: return region = ba.getcollision().sourcenode i = None for i in range(len(self._score_regions)): if region == self._score_regions[i].node: break for team in self.teams: if team.id == i: team.score += 7 # Tell all players to celebrate. for player in team.players: if player.actor: player.actor.handlemessage(ba.CelebrateMessage(2.0)) # If someone on this team was last to touch it, # give them points. assert self._flag is not None if (self._flag.last_holding_player and team == self._flag.last_holding_player.team): self.stats.player_scored(self._flag.last_holding_player, 50, big_message=True) # End the game if we won. if team.score >= self._score_to_win: self.end_game() ba.playsound(self._score_sound) ba.playsound(self._cheer_sound) assert self._flag self._flag.scored = True # Kill the flag (it'll respawn shortly). ba.timer(1.0, self._kill_flag) light = ba.newnode('light', attrs={ 'position': ba.getcollision().position, 'height_attenuated': False, 'color': (1, 0, 0) }) ba.animate(light, 'intensity', {0.0: 0, 0.5: 1, 1.0: 0}, loop=True) ba.timer(1.0, light.delete) ba.cameraflash(duration=10.0) self._update_scoreboard()
def end_game(self) -> None: # Stop our on-screen timer so players can see what they got. assert self._timer is not None self._timer.stop() results = ba.TeamGameResults() # If we won, set our score to the elapsed time in milliseconds. # (there should just be 1 team here since this is co-op). # ..if we didn't win, leave scores as default (None) which means # we lost. if self._won: elapsed_time_ms = int((ba.time() - self._timer.starttime) * 1000.0) ba.cameraflash() ba.playsound(self._winsound) for team in self.teams: for player in team.players: if player.actor: player.actor.handlemessage(ba.CelebrateMessage()) results.set_team_score(team, elapsed_time_ms) # Ends the activity. self.end(results)
def _update_waves(self) -> None: # pylint: disable=too-many-branches # If we have no living bots, go to the next wave. if (self._can_end_wave and not self._bots.have_living_bots() and not self._game_over and self._lives > 0): self._can_end_wave = False self._time_bonus_timer = None self._time_bonus_text = None if self._preset in {Preset.ENDLESS, Preset.ENDLESS_TOURNAMENT}: won = False else: assert self._waves is not None won = (self._wavenum == len(self._waves)) # Reward time bonus. base_delay = 4.0 if won else 0 if self._time_bonus > 0: ba.timer(0, ba.Call(ba.playsound, self._cashregistersound)) ba.timer(base_delay, ba.Call(self._award_time_bonus, self._time_bonus)) base_delay += 1.0 # Reward flawless bonus. if self._wavenum > 0 and self._flawless: ba.timer(base_delay, self._award_flawless_bonus) base_delay += 1.0 self._flawless = True # reset if won: # Completion achievements: if self._preset in {Preset.PRO, Preset.PRO_EASY}: self._award_achievement('Pro Runaround Victory', sound=False) if self._lives == self._start_lives: self._award_achievement('The Wall', sound=False) if not self._player_has_picked_up_powerup: self._award_achievement('Precision Bombing', sound=False) elif self._preset in {Preset.UBER, Preset.UBER_EASY}: self._award_achievement('Uber Runaround Victory', sound=False) if self._lives == self._start_lives: self._award_achievement('The Great Wall', sound=False) if not self._a_player_has_been_killed: self._award_achievement('Stayin\' Alive', sound=False) # Give remaining players some points and have them celebrate. self.show_zoom_message(ba.Lstr(resource='victoryText'), scale=1.0, duration=4.0) self.celebrate(10.0) ba.timer(base_delay, self._award_lives_bonus) base_delay += 1.0 ba.timer(base_delay, self._award_completion_bonus) base_delay += 0.85 ba.playsound(self._winsound) ba.cameraflash() ba.setmusic(ba.MusicType.VICTORY) self._game_over = True ba.timer(base_delay, ba.Call(self.do_end, 'victory')) return self._wavenum += 1 # Short celebration after waves. if self._wavenum > 1: self.celebrate(0.5) ba.timer(base_delay, self._start_next_wave)
def _handle_score(self) -> None: """ a point has been scored """ # FIXME tidy this up # pylint: disable=too-many-branches # Our flag might stick around for a second or two; # we don't want it to be able to score again. assert self._flag is not None if self._flag.scored: return # See which score region it was. region = ba.getcollision().sourcenode i = None for i in range(len(self._score_regions)): if region == self._score_regions[i].node: break for team in [self.teams[0], self._bot_team]: assert team is not None if team.id == i: team.score += 7 # Tell all players (or bots) to celebrate. if i == 0: for player in team.players: if player.actor: player.actor.handlemessage( ba.CelebrateMessage(2.0)) else: self._bots.celebrate(2.0) # If the good guys scored, add more enemies. if i == 0: if self.teams[0].score == 7: assert self._bot_types_7 is not None for bottype in self._bot_types_7: self._spawn_bot(bottype) elif self.teams[0].score == 14: assert self._bot_types_14 is not None for bottype in self._bot_types_14: self._spawn_bot(bottype) ba.playsound(self._score_sound) if i == 0: ba.playsound(self._cheer_sound) else: ba.playsound(self._boo_sound) # Kill the flag (it'll respawn shortly). self._flag.scored = True ba.timer(0.2, self._kill_flag) self.update_scores() light = ba.newnode('light', attrs={ 'position': ba.getcollision().position, 'height_attenuated': False, 'color': (1, 0, 0) }) ba.animate(light, 'intensity', {0: 0, 0.5: 1, 1.0: 0}, loop=True) ba.timer(1.0, light.delete) if i == 0: ba.cameraflash(duration=10.0)