Return to repo list

heart-of-gold

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

commit 315e986fde23e175fc4a04e5c2d4aa36b444511b
parent aca7d428901de8ca938e8650b2007378e18770c8
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri,  4 Dec 2020 22:06:38 -0600

Added improved actor functionality in scenes

Diffstat:
Adata/img/actors/jisella/brows.png | 0
Adata/img/actors/jisella/details.png | 0
Adata/img/actors/jisella/eyes.png | 0
Adata/img/actors/jisella/orientation.json | 7+++++++
Mdata/json/scenes/testscene.json | 8++++++--
Mdata/json/sheets.json | 21+++++++++++++++++++++
Msrc/constants.py | 1+
Msrc/entity.py | 15++++++++++++++-
Msrc/scene.py | 6+++++-
9 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/data/img/actors/jisella/brows.png b/data/img/actors/jisella/brows.png Binary files differ. diff --git a/data/img/actors/jisella/details.png b/data/img/actors/jisella/details.png Binary files differ. diff --git a/data/img/actors/jisella/eyes.png b/data/img/actors/jisella/eyes.png Binary files differ. diff --git a/data/img/actors/jisella/orientation.json b/data/img/actors/jisella/orientation.json @@ -0,0 +1,7 @@ +{ + "base" : [0, 0], + "eyes" : [191, 77], + "brows" : [190, 66], + "mouth" : [204, 115], + "details" : [188, 73] +} diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -16,9 +16,13 @@ "characters" : [ { "name" : "jisella", + "flipped" : true, + "pos" : [100, 118], "actor" : [ - { "sheet" : "base", "sprite" : [0, 0], "pos" : [100, 300] }, - { "sheet" : "mouth", "sprite" : [0, 0], "pos" : [100, 300] } + { "sheet" : "base", "sprite" : [0, 0] }, + { "sheet" : "eyes", "sprite" : [0, 3] }, + { "sheet" : "mouth", "sprite" : [0, 0] }, + { "sheet" : "brows", "sprite" : [0, 0] } ] } ], diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -62,6 +62,27 @@ "anim_class" : null, "alpha" : true }, + "jisella_actor_brows" : { + "filename" : "actors/jisella/brows.png", + "dimensions" : [64, 32], + "total_sprites" : 6, + "anim_class" : null, + "alpha" : true + }, + "jisella_actor_eyes" : { + "filename" : "actors/jisella/eyes.png", + "dimensions" : [64, 32], + "total_sprites" : 8, + "anim_class" : null, + "alpha" : true + }, + "jisella_actor_details" : { + "filename" : "actors/jisella/details.png", + "dimensions" : [64, 64], + "total_sprites" : 2, + "anim_class" : null, + "alpha" : true + }, "jisella_1" : { "filename" : "jisella_1.png", "dimensions" : [64, 64], diff --git a/src/constants.py b/src/constants.py @@ -39,6 +39,7 @@ TILE_PATH = os.path.join(DATA_PATH, "tsx") JSON_PATH = os.path.join(DATA_PATH, "json") MENU_JSON_PATH = os.path.join(JSON_PATH, "menus") SCENE_JSON_PATH = os.path.join(JSON_PATH, "scenes") +ACTORS_PATH = os.path.join(IMAGE_PATH, "actors") # Piece constants CHARBASE = json.load(open(os.path.join(JSON_PATH, "pieces.json"))) diff --git a/src/entity.py b/src/entity.py @@ -35,6 +35,7 @@ class Entity(pygame.sprite.DirtySprite): self.image = sheet.sprites[sprite] self.rect = self.image.get_rect() self.rect.topleft = (0, 0) + self.flipped = (False, False) self.custom_flags = None # Used to pass special info to Entities # DirtySprite class defaults @@ -118,6 +119,18 @@ class Entity(pygame.sprite.DirtySprite): """ self.rect.center = pos + def set_flip(self, hz = None, vt = None): + """ + Set the flip tuple valse to True or False. hz is for horizontal + flipping and vt is vertical. If either is None, that value will + not be changed. + """ + if hz == None: + hz = self.flipped[0] + if vt == None: + vt = self.flipped[1] + self.flipped = (hz, vt) + def animate(self): """ Play the current animation. This method is called as part of @@ -185,7 +198,7 @@ class Entity(pygame.sprite.DirtySprite): self.motion_move() if self.animated: self.animate() - surface.blit(self.image, self.rect) + surface.blit(pygame.transform.flip(self.image, self.flipped[0], self.flipped[1]), self.rect) ######################################### # Section 2 - Various Entity subclasses # diff --git a/src/scene.py b/src/scene.py @@ -167,10 +167,14 @@ class StillScene(object): self.current_text_string = self.script[self.script_index]["line"] for c in self.script[self.script_index]["characters"]: nc_name = c["name"] + nc_flip = c["flipped"] + with open(os.path.join(ACTORS_PATH, nc_name, "orientation.json")) as o: orient = json.load(o) nel = [] for a in c["actor"]: ne = entity.Entity(sh[nc_name + "_actor_" + a["sheet"]], tuple(a["sprite"])) - ne.set_position(tuple(a["pos"])) + pos = (c["pos"][0] + orient[a["sheet"]][0], c["pos"][1] + orient[a["sheet"]][1]) + ne.set_position(pos) + ne.set_flip(nc_flip) nel.append(ne) self.displayed_characters.append(nel) if self.script[self.script_index]["speaker"] != None: