Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit 2402721f2d6423e48de05b807df68f758bb06841
parent 0a17ef0dfb48b663fb7fdf0bb7f0c302bb09feda
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Tue, 27 Apr 2021 19:58:16 -0500

imperfect switch to keys for scrolling

Diffstat:
Msrc/constants.py | 6++++++
Msrc/interface.py | 47+++++++++++++++++++++++++++++++++--------------
2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/src/constants.py b/src/constants.py @@ -106,6 +106,12 @@ EXITABLE_TURN_MODES = [ CTRL_MODES.Turn_Choose_Skill, CTRL_MODES.Turn_Choose_Item ] +SCROLLABLE_TURN_MODES = [ + CTRL_MODES.Turn_Normal, + CTRL_MODES.Turn_Select_Move, + CTRL_MODES.Turn_Select_Attack, + CTRL_MODES.Turn_Select_Push +] # Save environment SAVE_ENV = { diff --git a/src/interface.py b/src/interface.py @@ -37,6 +37,7 @@ class GameInterface(subsystem.GameSubsystem): self.double_click_timer = 0 self.double_click_mousepos = None self.old_mousepos = None + self.camera_motions = [0, 0] def handle_events(self, events): """ @@ -60,23 +61,40 @@ class GameInterface(subsystem.GameSubsystem): """ # TODO: This is irregular compared to mouseclick. Desireable??? if self.game.control_mode == CTRL_MODES.Turn_Normal: - if event.key == pygame.K_s: + if event.key == pygame.K_i: self.bus.perform_turn_manager_display_stats(self.bus.fetch("turn_manager", "active_piece")) self.game.control_mode = CTRL_MODES.Turn_Display_Stats elif self.game.control_mode == CTRL_MODES.Turn_Display_Stats: - if event.key == pygame.K_s or event.key == pygame.K_q: + if event.key == pygame.K_i or event.key == pygame.K_q: self.bus.perform_turn_manager_display_stats(None) self.game.control_mode = CTRL_MODES.Turn_Normal - elif self.game.control_mode in EXITABLE_TURN_MODES: + if self.game.control_mode in EXITABLE_TURN_MODES: if event.key == pygame.K_q: self.game.control_mode = CTRL_MODES.Turn_Normal self.bus.perform_load_board_overlay() + if self.game.control_mode in SCROLLABLE_TURN_MODES: + if event.key == pygame.K_w or event.key == pygame.K_UP and self.camera_motions[1] < 1: + self.camera_motions[1] += 1 + elif event.key == pygame.K_s or event.key == pygame.K_DOWN and self.camera_motions[1] > -1: + self.camera_motions[1] -= 1 + elif event.key == pygame.K_a or event.key == pygame.K_LEFT and self.camera_motions[0] < 1: + self.camera_motions[0] += 1 + elif event.key == pygame.K_d or event.key == pygame.K_RIGHT and self.camera_motions[0] > -1: + self.camera_motions[0] -= 1 def handle_key_release(self, event): """ React to a key being released. """ - pass + if self.game.control_mode in SCROLLABLE_TURN_MODES: + if event.key == pygame.K_w or event.key == pygame.K_UP and self.camera_motions[1] > 0: + self.camera_motions[1] -= 1 + elif event.key == pygame.K_s or event.key == pygame.K_DOWN and self.camera_motions[1] < 0: + self.camera_motions[1] += 1 + elif event.key == pygame.K_a or event.key == pygame.K_LEFT and self.camera_motions[0] > 0: + self.camera_motions[0] -= 1 + elif event.key == pygame.K_d or event.key == pygame.K_RIGHT and self.camera_motions[0] < 0: + self.camera_motions[0] += 1 def handle_mouse_click(self, event): """ @@ -244,16 +262,17 @@ class GameInterface(subsystem.GameSubsystem): ap.facing = FACE_DIR.D ap.set_animation(ap.sheet.animations["stand_" + ap.facing.name], True) - # Scroll camera - if self.game.control_mode in (CTRL_MODES.Turn_Normal, CTRL_MODES.Turn_Select_Move, CTRL_MODES.Turn_Select_Attack): - for r in self.camera.scroll_rects: - if self.camera.scroll_rects[r].collidepoint(mouseraw) and pygame.mouse.get_focused(): - self.camera.move_offset(r, SCROLL_SPEED) - - # Position cursor - if tilepos != None: - self.bus.perform_piece_manager_position_tile_cursor((tilepos[0], tilepos[1])) - + # Position cursor in scrollable modes and/or scroll + if self.game.control_mode in SCROLLABLE_TURN_MODES and tilepos != None: + self.bus.perform_piece_manager_position_tile_cursor((tilepos[0], tilepos[1])) + + if self.camera_motions != (0, 0): + if self.camera_motions[0] > 1 or self.camera_motions[0] < -1: + self.camera_motions[0] = 0 + if self.camera_motions[1] > 1 or self.camera_motions[1] < -1: + self.camera_motions[1] = 0 + self.camera.move_offset(self.camera_motions, SCROLL_SPEED) + # Watching a move complete elif self.game.control_mode == CTRL_MODES.Turn_Watch_Move: ap = self.bus.fetch("turn_manager", "active_piece")