Return to repo list

heart-of-gold

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

commit dc28af9a5facc964f82e2564b10b89526d262a7d
parent 41f5941cac8778446f86584a516ef6d2f4f3da3e
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed, 18 Nov 2020 12:12:49 -0600

Fixed facing calc

Diffstat:
Mdata/json/items.json | 2+-
Msrc/interface.py | 21++++++++-------------
Msrc/piece.py | 17++++++-----------
3 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/data/json/items.json b/data/json/items.json @@ -6,7 +6,7 @@ "slot" : "weapon", "value" : 100, "rarity" : 1, - "range" : 5, + "range" : 1, "stats" : { "HP" : 0, "ATK" : 3, diff --git a/src/interface.py b/src/interface.py @@ -32,7 +32,7 @@ class GameInterface(subsystem.GameSubsystem): self.bus = bus self.camera = camera self.drag_piece = False - self.old_mouseraw = (0, 0) + self.drag_from_pos = (0, 0) def handle_events(self, events): """ @@ -96,7 +96,7 @@ class GameInterface(subsystem.GameSubsystem): 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 + self.drag_from_pos = mouseraw # Selecting a move for the active piece control elif self.game.control_mode == CTRL_MODES.Turn_Select_Move: @@ -156,21 +156,16 @@ class GameInterface(subsystem.GameSubsystem): # Drag facing if self.drag_piece: - diff = (self.old_mouseraw[0] - mouseraw[0], self.old_mouseraw[1] - mouseraw[1]) + diff = (self.drag_from_pos[0] - mouseraw[0], self.drag_from_pos[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 + if abs(diff[0]) > abs(diff[1]): + if diff[0] >= 0: + ap.facing = FACE_DIR.L 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: + elif abs(diff[1]) >= abs(diff[0]): + if diff[1] >= 0: ap.facing = FACE_DIR.U else: ap.facing = FACE_DIR.D diff --git a/src/piece.py b/src/piece.py @@ -336,19 +336,14 @@ class Piece(entity.Entity): corresponding damage calculations. """ # Set facing - face_diff = (self.tile_pos[0] - target.tile_pos[0], self.tile_pos[1] - target.tile_pos[1]) - if face_diff[0] < 0: - if face_diff[0] >= face_diff[1]: - self.facing = FACE_DIR.D + diff = (self.tile_pos[0] - target.tile_pos[0], self.tile_pos[1] - target.tile_pos[1]) + if abs(diff[0]) > abs(diff[1]): + if diff[0] >= 0: + self.facing = FACE_DIR.L else: self.facing = FACE_DIR.R - elif face_diff[0] > 0: - if face_diff[0] <= face_diff[1]: - self.facing = FACE_DIR.U - else: - self.facing = FACE_DIR.L - else: - if face_diff[1] > 0: + elif abs(diff[1]) >= abs(diff[0]): + if diff[1] >= 0: self.facing = FACE_DIR.U else: self.facing = FACE_DIR.D