commit 60afb2f819a4c89a57a51b276354a4520c1505f1
parent 315ef36927a204412e3c058dcf28a51f1d23d75a
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Tue, 17 Nov 2020 21:32:16 -0600
Facing arrows added and fixed attack face
Diffstat:
4 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/data/img/facing_arrows_1.png b/data/img/facing_arrows_1.png
Binary files differ.
diff --git a/data/json/items.json b/data/json/items.json
@@ -6,7 +6,7 @@
"slot" : "weapon",
"value" : 100,
"rarity" : 1,
- "range" : 1,
+ "range" : 5,
"stats" : {
"HP" : 0,
"ATK" : 3,
diff --git a/data/json/sheets.json b/data/json/sheets.json
@@ -113,5 +113,10 @@
"filename" : "team_indicator_small_1.png",
"dimensions" : [12, 12],
"total_sprites" : 2
+ },
+ "facing_arrows_1" : {
+ "filename" : "facing_arrows_1.png",
+ "dimensions" : [64, 64],
+ "total_sprites" : 4
}
}
diff --git a/src/piece.py b/src/piece.py
@@ -251,12 +251,15 @@ class Piece(entity.Entity):
self.health_bar_fill = None
self.health_bar_rect = None
self.health_bar_fill_rect = None
+ self.facing_arrow = None
self.create_health_bar()
# Turn order values
self.readiness = self.active_stats["INIT"] + self.active_stats["SPD"]
self.taking_turn = False
self.haste_mod = 3 # 3 - normal, 1 - minimum (slow 2), 5 - maximum (haste 2)
+
+ self.set_animation(self.manager.bus.fetch("sheet_manager", "animations")[self.sheet.name]["stand_" + self.facing.name], True)
def load_pictures(self, pictures):
"""
@@ -333,16 +336,22 @@ class Piece(entity.Entity):
corresponding damage calculations.
"""
# Set facing
- # TODO: Fails if range beyond 1, need to deal with relative vals in (x, y)
face_diff = (self.tile_pos[0] - target.tile_pos[0], self.tile_pos[1] - target.tile_pos[1])
- if face_diff == (1, 0):
- self.facing = FACE_DIR.L
- elif face_diff == (-1, 0):
- self.facing = FACE_DIR.R
- elif face_diff == (0, 1):
- self.facing = FACE_DIR.U
- elif face_diff == (0, -1):
- self.facing = FACE_DIR.D
+ if face_diff[0] < 0:
+ if face_diff[0] >= face_diff[1]:
+ self.facing = FACE_DIR.D
+ 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:
+ self.facing = FACE_DIR.U
+ else:
+ self.facing = FACE_DIR.D
# Setup the animation
self.set_animation(self.manager.bus.fetch("sheet_manager", "animations")[self.sheet.name]["attack_" + self.facing.name], True)
@@ -366,6 +375,22 @@ class Piece(entity.Entity):
self.health_bar.fill((45, 45, 45))
self.health_bar_fill.fill((0, 200, 0))
+ def create_facing_arrow(self):
+ """
+ Create a facing arrow direction indicator
+ for the piece's sprite.
+ """
+ sheet = self.manager.bus.fetch("sheet_manager", "sheets")["facing_arrows_1"]
+ if self.facing == FACE_DIR.L:
+ self.facing_arrow = entity.Entity(sheet, (0, 0))
+ elif self.facing == FACE_DIR.R:
+ self.facing_arrow = entity.Entity(sheet, (0, 1))
+ elif self.facing == FACE_DIR.U:
+ self.facing_arrow = entity.Entity(sheet, (1, 0))
+ elif self.facing == FACE_DIR.D:
+ self.facing_arrow = entity.Entity(sheet, (1, 1))
+ self.facing_arrow.rect.topleft = self.rect.topleft
+
def execute_tile_path_move(self):
"""
Execute a move along a tile path.
@@ -444,11 +469,14 @@ class Piece(entity.Entity):
Overwrite to account for health bars.
"""
super().update(surface)
+ self.create_facing_arrow()
if self.health_bar != None and self.health_bar_fill != None:
self.health_bar_rect.center = (self.rect.center[0], self.rect.center[1] + (TILE_HEIGHT // 5))
self.health_bar_fill_rect.topleft = (self.health_bar_rect.topleft[0] + 1, self.health_bar_rect.topleft[1] + 1)
surface.blit(self.health_bar, self.health_bar_rect)
surface.blit(self.health_bar_fill, self.health_bar_fill_rect)
+ if self.facing_arrow != None:
+ self.facing_arrow.update(surface)
##########################
# Section 3 - TileCursor #