def _result_infos_new_move(self, gained_levels: typing.Dict[int, typing.Dict], new_move: MoveModel, move_to_forget: [LearnedMoveModel]) -> None: """Ask the player to confirm he doesn't want to learn the new move. :param gained_levels: A dictionary with the gained levels as well as the stats increase for each level and the new moves. :param new_move: The new ``MoveModel`` to learn. :param move_to_forget: The ``LearnedMoveModel`` the player wants to forget or None if he doesn't want. """ if not move_to_forget: self._confirmation_not_learn_move(gained_levels, new_move) else: move = move_to_forget[0] self._dialog.set_text( I18n().get("BATTLE.FORGET_MOVE").format( move.move.name, new_move.name), callback=lambda answer: self._battle_controller.forget_move( gained_levels, new_move, move) if answer == 0 else self._show_infos_new_move( gained_levels, new_move), choices=[I18n().get("COMMON.YES"), I18n().get("COMMON.NO")])
def _new_move_to_learn( self, gained_levels: typing.Dict[int, typing.Dict]) -> None: """After leveling up, suggest the player to learn new moves. :param gained_levels: A dictionary with the gained levels as well as the stats increase for each level and the new moves. """ new_move = next(iter(gained_levels.values()))["moves"][0] del gained_levels[next(iter(gained_levels.keys()))]["moves"][0] just_learned = False for learnedMove in self._battle.players_pokemon.moves: if learnedMove.move == new_move: just_learned = True break if just_learned: self.learn_move(gained_levels, new_move) else: self._dialog.set_text( [ I18n().get("BATTLE.WANTS_NEW_MOVE").format( self._battle.players_pokemon.nickname, new_move.name), I18n().get("BATTLE.TOO_MANY_MOVES").format( self._battle.players_pokemon.nickname), I18n().get("BATTLE.SHOULD_FORGET_MOVE").format( new_move.name) ], lambda answer: self._confirmation_not_learn_move( gained_levels, new_move) if answer == 1 else self._show_infos_new_move( gained_levels, new_move), choices=[I18n().get("COMMON.YES"), I18n().get("COMMON.NO")])
def _do_action(self, action: typing.Union[FightActionModel, RunActionModel, ShiftActionModel], next_action: typing.Union[FightActionModel, RunActionModel, ShiftActionModel] = None): """Perform the specified action. :param action: The action to play. :param next_action: The next action to be played. """ callback = lambda: self._do_action( next_action) if next_action else self.show_actions() if isinstance(action, RunActionModel): if action.is_run_successful(): self._successful_run() else: self._dialog.set_text(I18n().get("BATTLE.FAILED_RUN"), callback) elif isinstance(action, ShiftActionModel): hp = action.pokemon.hp - next_action.get_effects( ).hp if isinstance(next_action, FightActionModel) else None self._actions.do(CallFunc(self._actions.toggle_apparition)) self._player.flash(True) self._dialog.set_text(I18n().get("BATTLE.COME_BACK").format( action.previous_pokemon.nickname)) self._pokemon.do(Delay(1.5) + CallFunc(self._add_pkmn, hp)) self._dialog.do( Delay(1.5) + CallFunc( self._dialog.set_text, I18n().get("BATTLE.GO_POKEMON").format( action.pokemon.nickname))) self.remove(self._moves) self._moves = MovesLayer(action.pokemon) self.add(self._moves) self.do(Delay(3) + CallFunc(callback)) elif isinstance(action, FightActionModel): self._dialog.set_text(I18n().get("BATTLE.MOVE_USED").format( action.attacker.nickname, action.move.move.name)) if action.attacker == self._battle.players_pokemon: self._pokemon.do( Delay(0.5) + MoveBy((15, 15), 0.10) + MoveBy((-15, -15), 0.10) + (CallFunc(self._opponent_hud.update_hp) | CallFunc(self._moves.update_moves))) else: self._opponent_pokemonLayer.do( Delay(0.5) + MoveBy((-15, -15), 0.10) + MoveBy((15, 15), 0.10) + CallFunc(self._hud.update_hp)) delay = 1 if action.move.move.category == MoveCategoryEnum.STATUS else 2 self._dialog.do( Delay(delay) + CallFunc(self._explain_fight_action_effects, action, callback))
def player_lost_battle(self) -> None: """The player lost the battle. Display a message.""" self._dialog.set_text([ I18n().get("BATTLE.OUT_OF_POKEMON").format( Game().game_state.player.name), I18n().get("BATTLE.WHITED_OUT").format( Game().game_state.player.name) ], self._battle_controller.lost_battle)
def ask_player_shift_pokemon(self) -> None: """The player's pokemon fainted. Ask him if he wants to shift.""" self._dialog.set_text( [I18n().get("BATTLE.USE_NEXT")], callback=lambda choice: self.show_infos_shift_pokemon_out() if choice == 0 else self._successful_run(), choices=[I18n().get("COMMON.YES"), I18n().get("COMMON.NO")])
def show_actions(self) -> None: """Ask the player to choose an action.""" self._dialog.set_text(I18n().get("BATTLE.WHAT_WILL_DO").format( self._battle.players_pokemon.nickname)) self._actions.toggle_apparition()
def name(self) -> str: """Get the translated name of the move. :return: The name of the move. """ return I18n().get("MOVE.{0}".format(self._id))
def __init__(self, selected: ActionEnum = ActionEnum.FIGHT) -> None: """Create a layer with the list of actions and manage their interaction. :param selected: The selected action. """ super().__init__() self._selected = selected self._is_visible = False self._actions = dict() for action in ActionEnum: self._actions[action.name] = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/battle/actions/action.png')) self._actions[action.name].position = 700 + self._actions[ action.name].width, 100 + 40 * action.value self._actions[action.name].scale = 1.2 selected_sprite = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/battle/actions/selected_action.png')) selected_sprite.scale = self._actions[action.name].scale selected_sprite.visible = False self._actions[action.name].add(selected_sprite, name=ActionsLayer.SELECTED_SPRITE) label = cocos.text.Label(I18n().get("BATTLE.ACTION.{0}".format( action.name)), font_size=8, anchor_x="center", anchor_y="center") self._actions[action.name].add(label) self.add(self._actions[action.name])
def __init__(self, pokemon: PokemonModel) -> None: """Show the pokemon's list of moves and ask the player to choose one. :param pokemon: The player's pokemon. """ super().__init__() self._pokemon = pokemon self._selected = 0 self._is_visible = False self._actions = dict() self.update_moves() self._actions[len(self._actions)] = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/common/buttons/small_right.png')) self._actions[len(self._actions) - 1].position = 615 + self._actions[len(self._actions) - 1].width, 90 self.add(self._actions[len(self._actions) - 1]) selected_sprite = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/common/buttons/selected_small_right.png')) selected_sprite.visible = False self._actions[len(self._actions) - 1].add( selected_sprite, name=MovesLayer.SELECTED_SPRITE) text = cocos.text.Label(I18n().get("BATTLE.MOVE_RETURN"), anchor_y="top", font_size=30) text.position = (-text.element.content_width / 2 + 3, text.element.content_height / 2 - 2) self._actions[len(self._actions) - 1].add(text)
def name(self) -> str: """Get the translated name of the species. :return: The name of the species. """ return I18n().get("POKEMON.{0}".format(self._id))
def __init__( self, pokemon: PokemonModel, gained_levels: typing.Union[None, typing.Dict[int, typing.Dict[StatEnum, int]]] ) -> None: """Create a stat layer. :param pokemon: The pokemon whose stats are displayed. :param gained_levels: The list of the levels along with, for each stat, the amount of the increase. """ super().__init__() self._background = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/common/stats.png'), anchor=(0, 0)) self.add(self._background) stats = {stat: pokemon.stats[stat] for stat in StatEnum} if gained_levels: for level in gained_levels: for stat in StatEnum: stats[stat] -= gained_levels[level][stat] i = 0 for stat in StatEnum: stat_label = cocos.text.Label( (I18n().get("STAT.{0}".format(stat.name))), bold=True, anchor_x="left", color=StatLayer.stats_color[stat]) stat_label.position = (15, 150 - i * 27) self.add(stat_label) stat_value_str = str( stats[stat] ) if gained_levels or stat != StatEnum.HP else "{0} / {1}".format( str(pokemon.hp), str(stats[stat])) stat_value = cocos.text.Label(stat_value_str, bold=True, anchor_x="center") x = 100 if gained_levels else 120 stat_value.position = (x, 150 - i * 27) self.add(stat_value) if gained_levels: gained_stat = cocos.text.Label("+ {0}".format( next(iter(gained_levels.values()))[stat]), bold=True, color=(16, 173, 231, 255)) gained_stat.position = (120, 150 - i * 27) self.add(gained_stat) i += 1
def _confirmation_not_learn_move(self, gained_levels: typing.Dict[int, typing.Dict], new_move: MoveModel) -> None: """Ask the player to confirm he doesn't want to learn the new move. :param gained_levels: A dictionary with the gained levels as well as the stats increase for each level and the new moves. :param new_move: The new ``MoveModel`` to learn. """ self._dialog.set_text( I18n().get("BATTLE.CONFIRMATION_NOT_LEARN_MOVE").format( new_move.name), lambda answer: self._didnt_learn_move(gained_levels, new_move) if answer == 0 else self._show_infos_new_move( gained_levels, new_move), choices=[I18n().get("COMMON.YES"), I18n().get("COMMON.NO")])
def message(self, text_key: str) -> None: """Show a message to the player. :param text_key: The key of the message. """ self._dialog.visible = True self.player_handles_event(False) callback = lambda: (setattr(self._dialog, "visible", False), self.player_handles_event(True)) self._dialog.set_text([I18n().get(text_key)], callback)
def _didnt_learn_move(self, gained_levels: typing.Dict[int, typing.Dict], new_move: MoveModel) -> None: """After leveling up, the player didn't want to learn the new move. :param gained_levels: A dictionary with the gained levels as well as the stats increase for each level and the new moves. :param new_move: The move the player chose not to learn. """ self._dialog.set_text( I18n().get("BATTLE.DIDNT_LEARN_MOVE").format( self._battle.players_pokemon.nickname, new_move.name), lambda: self._continue_experience_gained(gained_levels))
def player_won_fight(self, xp_points: int, gained_levels: typing.Dict[int, typing.Dict]) -> None: """The player's pokemon defeated the opponent. They gain some XP. :param xp_points: The total number of gained xp points. :param gained_levels: A dictionary with the gained levels as well as the stats increase for each level. """ self._dialog.set_text( I18n().get("BATTLE.GAINED_XP").format( self._battle.players_pokemon.nickname, xp_points), lambda: self.experience_gained(gained_levels))
def _pokemon_ko(self, pokemon: PokemonModel) -> None: """A pokemon is KO. Notify the user and the controller. :param pokemon: The pokemon who fainted. """ if pokemon == self._battle.players_pokemon: self._pokemon.do(MoveBy((-200, -200), 0.5)) else: self._opponent_pokemonLayer.do(MoveBy((200, 0), 0.5)) self._dialog.set_text( I18n().get("BATTLE.KO").format(pokemon.nickname), lambda: self._battle_controller.pokemon_ko(pokemon))
def learn_move(self, gained_levels: typing.Dict[int, typing.Dict], new_move: MoveModel, forgot_move: LearnedMoveModel = None): """The pokemon learned a new move. :param gained_levels: A dictionary with the gained levels as well as the stats increase for each level and the new moves. :param new_move: The move the player chose not to learn. :param forgot_move: The ``LearnedMoveModel`` the player decided """ if forgot_move: self._dialog.set_text( I18n().get("BATTLE.REPLACE_MOVE").format( self._battle.players_pokemon.nickname, forgot_move.move.name, new_move.name), lambda: self._continue_experience_gained(gained_levels)) else: self._dialog.set_text( I18n().get("BATTLE.MOVE_LEARNED").format( self._battle.players_pokemon.nickname, new_move.name), lambda: self._continue_experience_gained(gained_levels))
def shift_players_pokemon(self, action: ShiftActionModel) -> None: """Shift the player's pokemon :param action: The ``ShiftActionModel``. """ self._player.flash() self._pokemon.do(Delay(1.5) + CallFunc(self._add_pkmn)) self._dialog.set_text(I18n().get("BATTLE.GO_POKEMON").format( action.pokemon.nickname)) self.remove(self._moves) self._moves = MovesLayer(action.pokemon) self.add(self._moves) self.do(Delay(2) + CallFunc(self.show_actions))
def _send_pokemon(self) -> None: """Show the player's pokemon.""" self._player.animation() self._dialog.set_text("") self._dialog.do( FadeIn(0.4) | (Delay(0.2) + CallFunc( self._dialog.set_text, I18n().get("BATTLE.GO_POKEMON").format( self._battle.players_pokemon.nickname)))) self._pokemon.do(Delay(1.6) + FadeIn(0.5)) self._hud.do(Delay(2) + FadeIn(0.5)) self.do(Delay(2.2) + CallFunc(self.show_actions))
def _explain_fight_action_effects(self, action: FightActionModel, callback: typing.Callable) -> None: """Write the effects of the move to the user. :param action: The fight action being played. :param callback: The function to call after. """ text = [] effects = action.get_effects() if effects.failed: text.append(I18n().get("BATTLE.MOVE_FAILED").format( action.attacker.nickname)) else: if effects.critical_hit: text.append(I18n().get("BATTLE.CRITICAL_HIT")) if effects.effectiveness and effects.effectiveness == MoveEffectivenessEnum.NO_EFFECT: text.append(I18n().get("BATTLE.NO_EFFECT")) elif effects.effectiveness and effects.effectiveness == MoveEffectivenessEnum.NOT_EFFECTIVE or effects.effectiveness == MoveEffectivenessEnum.VERY_INEFFECTIVE: text.append(I18n().get("BATTLE.NOT_EFFECTIVE")) elif effects.effectiveness and effects.effectiveness == MoveEffectivenessEnum.SUPER_EFFECTIVE or effects.effectiveness == MoveEffectivenessEnum.EXTREMELY_EFFECTIVE: text.append(I18n().get("BATTLE.SUPER_EFFECTIVE")) if action.defender.hp > 0: for staged_stat, stage in effects.staged_stats.items(): if stage > 0 or stage < 0: if stage > 0: pokemon_name = action.attacker.nickname else: pokemon_name = action.defender.nickname text.append(I18n().get( "BATTLE.STAGED_STAT_{0}".format(stage)).format( pokemon_name, I18n().get("STAT.{0}".format( staged_stat.name)))) if action.defender.hp > 0: if text: self._dialog.set_text(text, callback) else: callback() else: if text: self._dialog.set_text( text, lambda: self._pokemon_ko(action.defender)) else: self._pokemon_ko(action.defender)
def _level_up(self, gained_levels: typing.Dict[int, typing.Dict]) -> None: """The pokemon has leveled up. Show a message to the player , the stat increase and a possible new move to learn. :param gained_levels: A dictionary with the gained levels as well as the stats increase for each level. """ self._stats = StatLayer(self._battle.players_pokemon, gained_levels) self._stats.position = (490, 70) self.add(self._stats, z=100) self._dialog.set_text( I18n().get("BATTLE.LEVEL_UP").format( self._battle.players_pokemon.nickname, next(iter(gained_levels.keys()))), lambda: self._continue_experience_gained(gained_levels))
def on_key_press(self, key, modifiers) -> bool: """Manage the key press event. Update the selected action when pressing UP or BOTTOM. Change the value of the settings with RIGHT or LEFT. :param key: The pressed key. :param modifiers: The pressed modifiers. :return Whether the event has been handled. """ event_handled = False if is_key_up(key) and self._choice > 0: self._choice -= 1 event_handled = True elif is_key_down(key) and self._choice < len(self._actions) - 1: self._choice += 1 event_handled = True elif self._actions[ActionsLayer.LANGUAGE].get( ActionsLayer.SELECTED_SPRITE).visible and (is_key_left(key) or is_key_right(key)): if is_key_left(key): self._selected_language = self._selected_language - 1 if self._selected_language > 0 else len( LanguageEnum) - 1 elif is_key_right(key): self._selected_language = self._selected_language + 1 if self._selected_language < len( LanguageEnum) - 1 else 0 self.get(str(ActionsLayer.LANGUAGE)).get( ActionsLayer.LANGUAGE_VALUE).element.text = I18n().get( "SETTINGS.LANGUAGE.{0}".format( LanguageEnum.from_index(self._selected_language).name)) event_handled = True elif (is_key_action(key) and self._actions[ActionsLayer.CANCEL].get( ActionsLayer.SELECTED_SPRITE).visible) or is_key_cancel(key): new_settings = { LanguageEnum: LanguageEnum.from_index(self._selected_language) } self.parent.cancel_settings(new_settings) event_handled = True self._update_screen() return event_handled
def _intro(self) -> None: """The "cinematic" showing the battle field and the pokemon.""" self._transition = TransitionLayer() self._transition.do( Delay(BattleScene.TRANSITION_DURATION * 2 / 3) + (ScaleTo(3.5, BattleScene.TRANSITION_DURATION * 1 / 3) | FadeOut(BattleScene.TRANSITION_DURATION * 1 / 3))) self.add(self._transition, z=100) self._background = BackgroundLayer(self._battle.place) self._background.scale = 2 self._background.position = (160, 240) self._background.do( Delay(BattleScene.TRANSITION_DURATION * 2 / 3) + MoveBy((250, 0), BattleScene.TRAVELING_DURATION) + MoveTo((160, 240), 0) + (ScaleTo(1, BattleScene.ZOOM_OUT_DURATION) | MoveTo((260, 240), BattleScene.ZOOM_OUT_DURATION))) self.add(self._background) self._dialog = Dialog() self._dialog.do( Delay(BattleScene.TRANSITION_DURATION + BattleScene.TRAVELING_DURATION / 2 + 0.2) + FadeOut(0)) self._dialog.set_text(I18n().get("BATTLE.WILD").format( self._battle.opponent_pokemon.nickname)) self.add(self._dialog, z=75) self._opponent_pokemonLayer = OpponentPokemonLayer( self._battle.opponent_pokemon) self._opponent_pokemonLayer.scale = 2 self._opponent_pokemonLayer.position = (720, 380) self._opponent_pokemonLayer.do( Delay(BattleScene.TRANSITION_DURATION * 2 / 3) + MoveBy((250, 0), BattleScene.TRAVELING_DURATION) + MoveTo((720, 380), 0) + (ScaleTo(1, BattleScene.ZOOM_OUT_DURATION) | MoveBy((-180, -70), BattleScene.ZOOM_OUT_DURATION))) self.add(self._opponent_pokemonLayer) self._fade = FadeLayer() self._fade.do( Delay(BattleScene.TRANSITION_DURATION + BattleScene.TRAVELING_DURATION / 2) + FadeIn(0.2) + FadeOut(1)) self.add(self._fade, z=100) self._opponent_hud = OpponentHUDLayer(self._battle.opponent_pokemon) self._opponent_hud.position = (350, 370) self._opponent_hud.opacity = 0 self._opponent_hud.do( Delay(BattleScene.TRANSITION_DURATION + BattleScene.TRAVELING_DURATION) + FadeIn(0.5)) self.add(self._opponent_hud, z=50) self._actions = ActionsLayer() self.add(self._actions) self._moves = MovesLayer(self._battle.players_pokemon) self.add(self._moves) self._player = PlayerLayer() self.add(self._player, z=60) self._hud = None self._pokemon = None self._add_pkmn() self._pokemon.opacity = 0 self._hud.opacity = 0 self.do( Delay(BattleScene.TRANSITION_DURATION + BattleScene.TRAVELING_DURATION) + CallFunc(self._send_pokemon))
def __init__(self, settings: SettingsModel) -> None: """Create the list of settings. :param settings: The player's settings. """ super().__init__() self._actions = dict() self._selected_language = settings.language.index language = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/main_menu/single_line_action.jpg')) language.position = (320, 445) language_selected = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/single_line_action_selected.jpg')) language.add(language_selected, name=ActionsLayer.SELECTED_SPRITE) language_text = cocos.text.Label(I18n().get("SETTINGS.LANGUAGE"), bold=True, color=(0, 0, 0, 255)) language_text.position = (-180, -5) language.add(language_text) language_value = cocos.text.Label(I18n().get( "SETTINGS.LANGUAGE.{0}".format(settings.language.name)), bold=True, color=(0, 0, 0, 255)) language_value.position = (70, -5) language.add(language_value, name=ActionsLayer.LANGUAGE_VALUE) language_left_arrow = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/common/cursor.png')) language_left_arrow.do(RotateBy(90, 0)) language_left_arrow.position = (40, 0) language.add(language_left_arrow) language_right_arrow = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/common/cursor.png')) language_right_arrow.do(RotateBy(-90, 0)) language_right_arrow.position = (170, 0) language.add(language_right_arrow) self._actions[ActionsLayer.LANGUAGE] = language self.add(language, name=str(ActionsLayer.LANGUAGE)) for index, control in enumerate(ControlsEnum): control_sprite = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/single_line_action.jpg')) control_sprite.position = (320, 445 - (control_sprite.height + 9) * (index + 1)) control_sprite_selected = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/single_line_action_selected.jpg')) control_sprite.add(control_sprite_selected, name=ActionsLayer.SELECTED_SPRITE) control_text = cocos.text.Label(I18n().get("CONTROLS.{0}".format( control.name)), bold=True, color=(0, 0, 0, 255)) control_text.position = (-180, -5) control_sprite.add(control_text) control_value = cocos.text.Label(str( keys.symbol_string(Game().settings.controls[control])), bold=True, color=(0, 0, 0, 255)) control_value.position = (70, -5) control_sprite.add(control_value, name=ActionsLayer.CONTROL_VALUE) self._actions[control.name] = control_sprite self.add(control_sprite, name=str(control)) cancel = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/single_little_line_action.jpg')) cancel.position = (320, 34) cancel_selected = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/single_little_line_action_selected.jpg') ) cancel.add(cancel_selected, name=ActionsLayer.SELECTED_SPRITE) cancel_text = cocos.text.Label(I18n().get("SETTINGS.CANCEL"), bold=True, color=(0, 0, 0, 255)) cancel_text.position = (-cancel_text.element.content_width / 2, -5) cancel.add(cancel_text) self._actions[ActionsLayer.CANCEL] = cancel self.add(cancel) self._choice = 0 self._update_screen()
def __init__(self, pkmn_infos_type: PkmnInfosTypeEnum, pokemon: PokemonModel, selected_action: ActionEnum = None, battle: BattleModel = None, new_move: MoveModel = None) -> None: """Create a layer with the list of actions and manage their interaction. :param pkmn_infos_type: The type of scene. Affects the information displayed and the interactions. :param pokemon: The pokemon whose infos is shown. :param selected_action: The selected action by default. :param battle: The battle model if it is for a shift. :param new_move: The new move to learn if any. """ super().__init__() self._pokemon = pokemon self._pkmn_infos_type = pkmn_infos_type self._new_move = new_move self._available_actions = pkmn_infos_type.actions.copy() if ActionEnum.SHIFT in self._available_actions and ( (battle is not None and battle.players_pokemon == pokemon) or pokemon.hp <= 0): self._available_actions.remove(ActionEnum.SHIFT) if ActionEnum.PREVIOUS in self._available_actions and Game( ).game_state.player.pokemons.index(pokemon) == 0: self._available_actions.remove(ActionEnum.PREVIOUS) if ActionEnum.NEXT and Game().game_state.player.pokemons.index( pokemon) == len(Game().game_state.player.pokemons) - 1: self._available_actions.remove(ActionEnum.NEXT) self._selected_action = self._available_actions.index( selected_action ) if selected_action and selected_action in self._available_actions else self._available_actions.index( pkmn_infos_type.default_action) self._actions = {} if ActionEnum.PREVIOUS in self._available_actions: previous = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/common/buttons/small_left.png'), anchor=(0, 0)) selected_previous = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/buttons/selected_small_left.png'), anchor=(0, 0)) previous.add(selected_previous, name=ActionsLayer.SELECTED_SPRITE) previous_text = cocos.text.Label( I18n().get("POKEMON_INFOS.PREVIOUS"), font_size=20) previous_text.position = ( previous.width / 2 - previous_text.element.content_width / 1.5, previous.height / 2 - previous_text.element.content_height / 4) previous.add(previous_text) self.add(previous) self._actions[ActionEnum.PREVIOUS] = previous if ActionEnum.SHIFT in self._available_actions: shift = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/buttons/small_center_red.png'), anchor=(0, 0)) shift.position = ( cocos.director.director.get_window_size()[0] / 2 - shift.width - 5, 0) selected_shift = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/buttons/selected_small_center_red.png'), anchor=(0, 0)) shift.add(selected_shift, name=ActionsLayer.SELECTED_SPRITE) shift_text = cocos.text.Label(I18n().get("POKEMON_INFOS.SHIFT"), font_size=14) shift_text.position = (shift.width / 2 - shift_text.element.content_width / 2, shift.height / 2 - shift_text.element.content_height / 4) shift.add(shift_text) self.add(shift) self._actions[ActionEnum.SHIFT] = shift if ActionEnum.CANCEL in self._available_actions: cancel = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/buttons/small_center.png'), anchor=(0, 0)) cancel_position_x = cocos.director.director.get_window_size( )[0] / 2 if ActionEnum.SHIFT not in self._available_actions: cancel_position_x -= cancel.width / 2 cancel.position = (cancel_position_x, 0) selected_cancel = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/buttons/selected_small_center.png'), anchor=(0, 0)) cancel.add(selected_cancel, name=ActionsLayer.SELECTED_SPRITE) cancel_text = cocos.text.Label(I18n().get("POKEMON_INFOS.CANCEL"), font_size=14) cancel_text.position = (cancel.width / 2 - cancel_text.element.content_width / 2, cancel.height / 2 - cancel_text.element.content_height / 4) cancel.add(cancel_text) self.add(cancel) self._actions[ActionEnum.CANCEL] = cancel if ActionEnum.NEXT in self._available_actions: next = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/buttons/small_right.png'), anchor=(0, 0)) next.position = (cocos.director.director.get_window_size()[0] - next.width, -2) selected_next = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/buttons/selected_small_right.png'), anchor=(0, 0)) next.add(selected_next, name=ActionsLayer.SELECTED_SPRITE) next_text = cocos.text.Label(I18n().get("POKEMON_INFOS.NEXT"), font_size=20) next_text.position = (next.width / 2 - next_text.element.content_width / 4, next.height / 2 - next_text.element.content_height / 4) next.add(next_text) self.add(next) self._actions[ActionEnum.NEXT] = next list_moves = pokemon.moves + [new_move] if new_move else pokemon.moves for index, move in enumerate(list_moves): name = move.name.capitalize() if isinstance( move, MoveModel) else move.move.name.capitalize() current_pp = move.default_pp if isinstance( move, MoveModel) else move.current_pp max_pp = move.default_pp if isinstance(move, MoveModel) else move.pp type = move.type.name.lower() if isinstance( move, MoveModel) else move.move.type.name.lower() y_position = 170 if isinstance(move, MoveModel) else 350 - 40 * index move_sprite = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/battle/moves/{0}.png'.format(type))) move_sprite.position = ( cocos.director.director.get_window_size()[0] - move_sprite.width / 2, y_position) selected_sprite = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/battle/moves/selected_{0}.png'.format(type))) selected_sprite.visible = False move_sprite.add(selected_sprite, name=ActionsLayer.SELECTED_SPRITE) name_label = cocos.text.Label(name, font_size=9, anchor_x="left", anchor_y="center", color=(0, 0, 0, 255), bold=True) name_label.position = (-57, 8) move_sprite.add(name_label) pp = cocos.text.Label("PP {0}/{1}".format(current_pp, max_pp), font_size=9, anchor_x="left", anchor_y="center", bold=True) pp.position = (-15, -8) move_sprite.add(pp) type = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/common/types/{0}.png'.format(type))) type.position = (-35, -8) type.scale = 0.9 move_sprite.add(type) self.add(move_sprite) if pkmn_infos_type == PkmnInfosTypeEnum.NEW_MOVE: if move == new_move: new = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/pkmn_infos/new.png'.format(type))) new.position = (-move_sprite.width / 2 + 8, -move_sprite.height / 2 + 8) move_sprite.add(new) self._actions[self._available_actions[index]] = move_sprite self._update_screen()
def _successful_run(self) -> None: """The attempt to run is successful. The battle is over.""" self._dialog.set_text(I18n().get("BATTLE.SUCCESSFUL_RUN"), lambda: self._battle_controller.run())
def save(self) -> None: """Save the model into a file.""" I18n().load_translations() super().save()
def __init__(self, pkmn_infos_controller: PkmnInfosController, pkmn_infos_type: PkmnInfosTypeEnum, pokemon: PokemonModel, selected_action: ActionEnum = None, replace: bool = False, battle: BattleModel = None, new_move: MoveModel = None, cancel_callback: typing.Callable = None) -> None: """Create a PKMN infos scene. :param pkmn_infos_controller: The controller. :param pkmn_infos_type: The type of scene. Affects the information displayed and the interactions. :param pokemon : The Pokemon the information is to be displayed. :param selected_action: The selected action by default. :param replace: Whether the scene should replace the previous one or not. :param battle: The battle model if it is for a shift. :param new_move: The new move to learn if any. :param cancel_callback: The function to call if the player chooses to cancel. """ super().__init__() self._pkmn_infos_controller = pkmn_infos_controller self._pkmn_infos_type = pkmn_infos_type self._pokemon = pokemon self._battle = battle self._cancel_callback = cancel_callback self._background = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/pkmn_infos/background.jpg'), anchor=(0, 0)) self._background.position = (0, 0) self.add(self._background) self._pokemon_name = cocos.text.Label(pokemon.nickname, bold=True, color=(0, 0, 0, 255), font_size=15) self._pokemon_name.position = ( cocos.director.director.get_window_size()[0] / 2 - self._pokemon_name.element.content_width / 2, 450) self.add(self._pokemon_name) self._pokemon_types = [] for type in pokemon.species.type: type_sprite = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/common/types/{0}.png'.format(type.name.lower())), anchor=(0, 0)) type_sprite.scale = 1.5 self._pokemon_types.append(type_sprite) self.add(type_sprite) for index, type_sprite in enumerate(self._pokemon_types): type_sprite.position = cocos.director.director.get_window_size( )[0] / 2 - len( self._pokemon_types) * (type_sprite.width + 5) / 2 + index * ( type_sprite.width + 5), 420 self._pokemon_sprite = cocos.sprite.Sprite( pyglet.image.load_animation(PATH + '/assets/img/pokemon/front/{0}.gif'. format(pokemon.species.id.lower()))) self._pokemon_sprite.scale = 1.5 self._pokemon_sprite.position = ( cocos.director.director.get_window_size()[0] / 2, cocos.director.director.get_window_size()[1] / 2) self.add(self._pokemon_sprite) self._stats = StatLayer(pokemon, None) self._stats.position = (5, 200) self.add(self._stats) self._experience_background = cocos.sprite.Sprite(pyglet.image.load( PATH + '/assets/img/pkmn_infos/experience_background.png'), anchor=(0, 0)) self._experience_background.opacity = 125 self._experience_background.position = (0, 90) self.add(self._experience_background) experience_gained_text = cocos.text.Label( I18n().get("POKEMON_INFOS.EXPERIENCE_POINTS"), anchor_x="left", anchor_y="center", bold=True) experience_gained_text.position = ( 5, self._experience_background.height / 2 + experience_gained_text.element.content_height / 2 + 2.5) self._experience_background.add(experience_gained_text) experience_gained = cocos.text.Label(str(pokemon.experience), anchor_x="center", anchor_y="center", bold=True) experience_gained.position = ( 5 + experience_gained_text.element.content_width + (self._experience_background.width - experience_gained_text.element.content_width) / 2, self._experience_background.height / 2 + experience_gained.element.content_height / 2 + 2.5) self._experience_background.add(experience_gained) experience_next_text = cocos.text.Label( I18n().get("POKEMON_INFOS.NEXT_LEVEL"), anchor_x="left", anchor_y="center", bold=True) experience_next_text.position = ( 5, self._experience_background.height / 2 - experience_next_text.element.content_height / 2 - 2.5) self._experience_background.add(experience_next_text) experience_next = cocos.text.Label( str(pokemon.experience_for_next_level - pokemon.experience), anchor_x="center", anchor_y="center", bold=True) experience_next.position = ( 5 + experience_gained_text.element.content_width + (self._experience_background.width - experience_gained_text.element.content_width) / 2, self._experience_background.height / 2 - experience_next.element.content_height / 2 - 2.5) self._experience_background.add(experience_next) self._level = Text(str(pokemon.level)) self._level.scale = 1.5 level_sprite = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/battle/hud/level.png')) level_sprite.scale = 2 level_sprite.position = ( cocos.director.director.get_window_size()[0] / 2 - level_sprite.width / 2 - self._level.width / 2, 150) self.add(level_sprite) self._level.position = ( cocos.director.director.get_window_size()[0] / 2 + level_sprite.width / 2 - self._level.width / 2, 152) self.add(self._level) self._actions = ActionsLayer(pkmn_infos_type, pokemon, selected_action, battle, new_move) self.add(self._actions) if replace: cocos.director.director.replace(FadeTransition(self)) else: cocos.director.director.push(FadeTransition(self))
def __init__(self) -> None: """Create the list of actions available in the main menu.""" super().__init__() self._game_state = None if Game().game_state.time == 0 else Game( ).game_state self._actions = [] continue_file = "multi_line_action" if self._game_state else "multi_line_action_disabled" continue_sprite = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/{0}.jpg'.format(continue_file))) continue_sprite.position = (320, 355) continue_selected = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/multi_line_action_selected.jpg')) continue_sprite.add(continue_selected, name=ActionsLayer.SELECTED_SPRITE) continue_text = cocos.text.Label(I18n().get("MAIN_MENU.CONTINUE"), bold=True, color=(0, 0, 0, 255)) continue_text.position = (-180, 60) continue_sprite.add(continue_text) if self._game_state: player = cocos.text.Label(I18n().get("MAIN_MENU.PLAYER"), bold=True, color=(16, 173, 231, 255)) player.position = (-130, 30) continue_sprite.add(player) player_name = cocos.text.Label(self._game_state.player.name, bold=True, color=(16, 173, 231, 255), anchor_x="right") player_name.position = (70, 30) continue_sprite.add(player_name) time = cocos.text.Label(I18n().get("MAIN_MENU.TIME"), bold=True, color=(16, 173, 231, 255)) time.position = (-130, 0) continue_sprite.add(time) hours = int(self._game_state.time // 3600) minutes = int((self._game_state.time - (hours * 3600)) // 60) time_value = cocos.text.Label("{:02d}:{:02d}".format( hours, minutes), bold=True, color=(16, 173, 231, 255), anchor_x="right") time_value.position = (70, 0) continue_sprite.add(time_value) for index, pokemon in enumerate(self._game_state.player.pokemons): pokemon_sprite = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/pokemon/mini/{0}.png'. format(pokemon.species.id.lower()))) pokemon_sprite.scale = 0.7 pokemon_sprite.position = (-140 + index * 60, -50) continue_sprite.add(pokemon_sprite) self.add(continue_sprite) self._actions.append(continue_sprite) new_game = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/main_menu/single_line_action.jpg')) new_game.position = (320, 188) new_game_selected = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/single_line_action_selected.jpg')) new_game.add(new_game_selected, name=ActionsLayer.SELECTED_SPRITE) new_game_text = cocos.text.Label(I18n().get("MAIN_MENU.NEW_GAME"), bold=True, color=(0, 0, 0, 255)) new_game_text.position = (-180, -5) new_game.add(new_game_text) self.add(new_game) self._actions.append(new_game) settings = cocos.sprite.Sprite( pyglet.image.load(PATH + '/assets/img/main_menu/single_line_action.jpg')) settings.position = (320, 91) settings_selected = cocos.sprite.Sprite( pyglet.image.load( PATH + '/assets/img/main_menu/single_line_action_selected.jpg')) settings.add(settings_selected, name=ActionsLayer.SELECTED_SPRITE) settings_text = cocos.text.Label(I18n().get("MAIN_MENU.SETTINGS"), bold=True, color=(0, 0, 0, 255)) settings_text.position = (-180, -5) settings.add(settings_text) self.add(settings) self._actions.append(settings) self._choice = 0 if self._game_state else 1 self._update_screen()