Return to repo list

heart-of-gold

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

commit 751f0a80f19f223d1e45acb6d401936f149b9fac
parent 8253e780aedff645944162fd244b50a163453e55
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun, 13 Dec 2020 01:10:31 -0600

Added bg, added sword to jisella sprite, and added dodging

Diffstat:
Mdata/board/testmap1/testmap1.json | 2+-
Adata/img/bg/crystal_mountains_1.png | 0
Mdata/img/jisella_1.png | 0
Mdata/json/anims.json | 30+++++++++++++++++++++++++++++-
Mdata/json/scenes/testscene.json | 9++++-----
Mdata/json/sheets.json | 9++++++++-
Msrc/piece.py | 57+++++++++++++++++++++++++++++++++++++++++++++------------
7 files changed, 87 insertions(+), 20 deletions(-)

diff --git a/data/board/testmap1/testmap1.json b/data/board/testmap1/testmap1.json @@ -18,7 +18,7 @@ "acc2" : null, "acc3" : null }, - "stat_mod" : { }, + "stat_mod" : { "LUK" : 100}, "stat_dist" : { }, "replace" : { } }, diff --git a/data/img/bg/crystal_mountains_1.png b/data/img/bg/crystal_mountains_1.png Binary files differ. diff --git a/data/img/jisella_1.png b/data/img/jisella_1.png Binary files differ. diff --git a/data/json/anims.json b/data/json/anims.json @@ -187,7 +187,35 @@ { "sprite" : [3, 5], "timer" : 2 }, { "sprite" : [7, 1], "timer" : 2 }, { "sprite" : [3, 5], "timer" : 2 } - ] + ], + "dodge_L" : [ + { "sprite" : [1, 5], "timer" : 4 }, + { "sprite" : [2, 5], "timer" : 4 } + ], + "dodge_R" : [ + { "sprite" : [5, 5], "timer" : 4 }, + { "sprite" : [6, 5], "timer" : 4 } + ], + "dodge_U" : [ + { "sprite" : [9, 5], "timer" : 4 }, + { "sprite" : [10, 5], "timer" : 4 } + ], + "dodge_D" : [ + { "sprite" : [5, 5], "timer" : 4 }, + { "sprite" : [6, 5], "timer" : 4 } + ], + "block_L" : [ + { "sprite" : [0, 5], "timer" : 100 } + ], + "block_R" : [ + { "sprite" : [4, 5], "timer" : 100 } + ], + "block_U" : [ + { "sprite" : [8, 5], "timer" : 100 } + ], + "block_D" : [ + { "sprite" : [4, 5], "timer" : 100 } + ] }, "Board_Cursor_1" : { "pulse" : [ diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -3,7 +3,7 @@ "fonts" : { "A" : ["ArchivoNarrow-Regular.otf", 28] }, - "bg_sheet" : "test_scene_bg_1", + "bg_sheet" : "bg_crystal_mountains_1", "bg_sprite" : [0, 0], "script" : [ { @@ -16,14 +16,13 @@ "characters" : [ { "name" : "jisella", - "flipped" : false, + "flipped" : true, "pos" : [70, 118], "actor" : [ { "sheet" : "base", "sprite" : [0, 0] }, - { "sheet" : "eyes", "sprite" : [1, 0] }, + { "sheet" : "eyes", "sprite" : [1, 2] }, { "sheet" : "mouth", "sprite" : [1, 0] }, - { "sheet" : "brows", "sprite" : [0, 0] }, - { "sheet" : "details", "sprite" : [0, 0] } + { "sheet" : "brows", "sprite" : [0, 0] } ] } ], diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -257,5 +257,12 @@ "total_sprites" : 6, "anim_class" : "Plumb_Bob_1", "alpha" : false - } + }, + "bg_crystal_mountains_1" : { + "filename" : "bg/crystal_mountains_1.png", + "dimensions" : [1024, 768], + "total_sprites" : 1, + "anim_class" : null, + "alpha" : false + } } diff --git a/src/piece.py b/src/piece.py @@ -329,6 +329,7 @@ class Piece(entity.Entity): self.attack_target = None self.attack_anim_timer = 0 self.being_damaged = False + self.dodging = False self.damage_timer = 0 self.damage_to_receive = 0 self.damage_number_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), self.rect.height // 2) @@ -420,15 +421,21 @@ class Piece(entity.Entity): self.normal_stats[s] += self.growth[g][s] self.normal_stats["HP"] += self.normal_stats["DEF"] // 3 - def render_damage_number(self): + def render_damage_number(self, is_hit = True): """ Render the name font image for display. Also renders damage notations. """ - self.damage_number_surface = self.damage_number_font.render(str(self.damage_to_receive), False, (255, 255, 255)).convert() - self.damage_number_outline = self.damage_number_outline_font.render(str(self.damage_to_receive), False, (0, 0, 0)).convert() - self.damage_number_rect = self.damage_number_surface.get_rect() - self.damage_number_outline_rect = self.damage_number_outline.get_rect() + if is_hit: + self.damage_number_surface = self.damage_number_font.render(str(self.damage_to_receive), False, (255, 255, 255)).convert() + self.damage_number_outline = self.damage_number_outline_font.render(str(self.damage_to_receive), False, (0, 0, 0)).convert() + self.damage_number_rect = self.damage_number_surface.get_rect() + self.damage_number_outline_rect = self.damage_number_outline.get_rect() + else: + self.damage_number_surface = None + self.damage_number_outline = None + self.damage_number_rect = None + self.damage_number_outline_rect = None for n in self.damage_notations: ns = self.damage_notation_font.render(n[0], False, n[1]).convert() nr = ns.get_rect() @@ -502,9 +509,9 @@ class Piece(entity.Entity): raw_dam += round((self.active_stats[bon] + random.randint(0, self.active_stats["LUK"] // 2)) * 0.2) elif raw_dam < 0: raw_dam = 0 - self.attack_target.set_be_damaged_action(round(raw_dam * ca), aff, notelist) + self.attack_target.set_be_damaged_action(round(raw_dam * ca), aff, self.active_stats["ACC"] + (self.active_stats["LUK"] // 2), notelist) - def set_be_damaged_action(self, raw_damage, affinity, notations): + def set_be_damaged_action(self, raw_damage, affinity, accuracy, notations): """ Setup the action of being damaged. 'affinity' is the elemental affinity of the attack. It is @@ -529,6 +536,15 @@ class Piece(entity.Entity): affmod = 0.5 notations.append(ATTACK_NOTATIONS.resist) + # Next, see if we are hit at all + cth = min(((round(accuracy * 1.5) / ((self.active_stats["SPD"] * 2) + self.active_stats["LUK"])) * 100), 95) + hit = True + #print(cth) + if not (True if random.randint(0, 100) <= cth else False): + notations = [ATTACK_NOTATIONS.miss] + raw_damage = 0 + hit = False + # Next, notation handling for n in notations: if n == ATTACK_NOTATIONS.backattack: @@ -541,16 +557,20 @@ class Piece(entity.Entity): self.damage_notations.append(("Weak!", (200, 0, 240))) elif n == ATTACK_NOTATIONS.resist: self.damage_notations.append(("Resist!", (50, 50, 50))) + elif n == ATTACK_NOTATIONS.miss: + self.damage_notations.append(("Miss!", (255, 255, 255))) # Lastly, go through with the damage if raw_damage <= 0: self.damage_to_receive = 0 else: - self.damage_to_receive = max(0, - round(((raw_damage - (self.active_stats["DEF"] * 1.4)) + random.randint(-(self.active_stats["LUK"] // 2), self.active_stats["LUK"])) * affmod)) + self.damage_to_receive = max(0, round(((raw_damage - (self.active_stats["DEF"] * 1.4)) + random.randint(-(self.active_stats["LUK"] // 2), self.active_stats["LUK"])) * affmod)) self.damage_timer = 100 - self.being_damaged = True - self.render_damage_number() + if hit: + self.being_damaged = True + else: + self.dodging = True + self.render_damage_number(hit) def get_full_stat_def(self): """ @@ -686,6 +706,19 @@ class Piece(entity.Entity): else: self.set_animation(self.sheet.animations["stand_" + self.facing.name], True) self.manager.bus.perform_turn_manager_refresh_state() + elif self.dodging: + if self.damage_timer > 0: + self.damage_timer -= 1 + if self.damage_timer == 68: + self.set_animation(self.sheet.animations["dodge_" + self.facing.name], True) + elif self.damage_timer == 60: + self.set_animation(self.sheet.animations["stand_" + self.facing.name], True) + else: + self.dodging = False + self.damage_notations = [] + self.damage_notation_surfaces = [] + self.damage_notation_rects = [] + self.manager.bus.perform_turn_manager_refresh_state() def modulate_stats(self): """ @@ -738,7 +771,7 @@ class Piece(entity.Entity): surface.blit(self.health_bar_fill, self.health_bar_fill_rect) if self.facing_arrow != None: self.facing_arrow.update(surface) - if self.damage_timer > 0 and self.damage_timer < 55: + if self.damage_timer > 0 and self.damage_timer < 55 and self.damage_number_surface != None: self.damage_number_rect.center = (self.rect.center[0], self.rect.center[1] + (self.damage_timer // 10)) self.damage_number_outline_rect.center = self.damage_number_rect.center surface.blit(self.damage_number_outline, self.damage_number_outline_rect)