def handle_event(self, event): from game import Overworld State.handle_event(self, event) if event.type == pygame.KEYDOWN: old_cur_x_index, old_cur_y_index = Overworld.cur_x_index, Overworld.cur_y_index if event.key == pygame.K_UP: Overworld.cur_y_index -= 1 self.refresh_screen = True elif event.key == pygame.K_DOWN: Overworld.cur_y_index += 1 self.refresh_screen = True elif event.key == pygame.K_LEFT: Overworld.cur_x_index -= 1 self.refresh_screen = True elif event.key == pygame.K_RIGHT: Overworld.cur_x_index += 1 self.refresh_screen = True if self._level.isWall(Overworld.center_x_index(), Overworld.center_y_index()): Overworld.cur_x_index = old_cur_x_index Overworld.cur_y_index = old_cur_y_index elif self._level.isLadder(Overworld.center_x_index(), Overworld.center_y_index()): self._level = self._level.load_level(Overworld.center_x_index(), Overworld.center_y_index()) self.refresh_screen = True elif self._level.isMonster(Overworld.center_x_index(), Overworld.center_y_index()): from game import set_state from battle_state import BattleState from battle import Skeleton new_state = BattleState(Skeleton()) set_state(new_state) new_state.play_music() return
def handle_event(self, event): State.handle_event(self, event) if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: if self._current_choice < self._number_of_choices - 1: self._current_choice += 1 self.refresh_screen = True elif event.key == pygame.K_UP: if self._current_choice > 0: self._current_choice -= 1 self.refresh_screen = True elif event.key == pygame.K_RETURN: if self._current_choice == 0: from level_state import LevelState from game import set_state state = LevelState("tower_entrance.txt") set_state(state) state.play_music() return
def handle_event(self, event): State.handle_event(self, event) if self.child_state: self.child_state.handle_event(event) return
def handle_event(self, event): State.handle_event(self, event) return