Return to repo list

heart-of-gold

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

commit 41f5941cac8778446f86584a516ef6d2f4f3da3e
parent 60afb2f819a4c89a57a51b276354a4520c1505f1
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Tue, 17 Nov 2020 21:57:37 -0600

Added ability to drag unit to face

Diffstat:
Msrc/interface.py | 43+++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/interface.py b/src/interface.py @@ -31,6 +31,8 @@ class GameInterface(subsystem.GameSubsystem): # Others self.bus = bus self.camera = camera + self.drag_piece = False + self.old_mouseraw = (0, 0) def handle_events(self, events): """ @@ -90,6 +92,11 @@ class GameInterface(subsystem.GameSubsystem): # See if we clicked a UI button if self.game.control_mode == CTRL_MODES.Turn_Normal: self.bus.perform_trigger_turn_manager_buttons_at_pos(mouseraw) + self.bus.perform_select_piece_with_tile_cursor() + sp = self.bus.fetch("piece_manager", "selected_piece") + if sp != None and self.bus.fetch("turn_manager", "active_piece") == sp: + self.drag_piece = True + self.old_mouseraw = mouseraw # Selecting a move for the active piece control elif self.game.control_mode == CTRL_MODES.Turn_Select_Move: @@ -124,7 +131,16 @@ class GameInterface(subsystem.GameSubsystem): """ React to a mousebutton being released. """ - pass + # If we released the left mouse button... + if event.button == 1: + + # First, get important mouse positional info, namely unoffset mouse position and camera-offset mouse position + mouseraw = pygame.mouse.get_pos() + mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) + + if self.game.state_mode == STATE_MODES.Battle_Mode: + if self.drag_piece: + self.drag_piece = False def update_interface(self): """ @@ -137,6 +153,30 @@ class GameInterface(subsystem.GameSubsystem): mouseraw = pygame.mouse.get_pos() mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) tilepos = self.bus.check_for_tile_by_screen_pos(mousepos) + + # Drag facing + if self.drag_piece: + diff = (self.old_mouseraw[0] - mouseraw[0], self.old_mouseraw[1] - mouseraw[1]) + if diff != (0, 0): + ap = self.bus.fetch("turn_manager", "active_piece") + if diff[0] < 0: + if diff[0] >= diff[1]: + ap.facing = FACE_DIR.D + else: + ap.facing = FACE_DIR.R + elif diff[0] > 0: + if diff[0] <= diff[1]: + ap.facing = FACE_DIR.U + else: + ap.facing = FACE_DIR.L + else: + if diff[1] > 0: + ap.facing = FACE_DIR.U + else: + ap.facing = FACE_DIR.D + ap.set_animation(self.bus.fetch("sheet_manager", "animations")[ap.sheet.name]["stand_" + ap.facing.name], True) + + # Position cursor if tilepos != None: self.bus.perform_position_tile_cursor((tilepos[0], tilepos[1])) @@ -156,4 +196,3 @@ class GameInterface(subsystem.GameSubsystem): ap = self.bus.fetch("turn_manager", "active_piece") if not ap.attacking: self.game.control_mode = CTRL_MODES.Turn_Normal -