Return to repo list

heart-of-gold

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

commit 10b25a2a80e8357d207196724328b2ee2d02e117
parent 4f40b7b1961982873d79828661d34a58725b17b5
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 16 Oct 2020 16:09:25 -0500

Sprites passed to vgos on init + scene loading work

Diffstat:
Mdata/json/ents/testmap1.json | 1+
Msrc/board.py | 3+--
Msrc/menu.py | 6++----
Msrc/scene.py | 26++++++++++++++++++--------
Msrc/vgo.py | 25++++++++++++-------------
5 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/data/json/ents/testmap1.json b/data/json/ents/testmap1.json @@ -3,6 +3,7 @@ "name" : "Jisella", "type" : "Piece", "sheet" : "jisella_1", + "sprite" : [0, 0], "visible" : true, "animation" : "stand_L", "animated" : true, diff --git a/src/board.py b/src/board.py @@ -112,9 +112,8 @@ class BoardManager(manager.Manager): for x, y, gid in layer: for p in tile_pos_list: if p == (x, y) and self.current_board.tmx_data.get_tile_properties_by_gid(gid)["Passable"] == 1 and self.game.entity_manager.selected_entity.tile_pos != (x, y): - v = vgo.VisibleGameObject(self.game.sheet_manager.loaded_sheets["board_overlays_1"]) + v = vgo.VisibleGameObject(self.game.sheet_manager.loaded_sheets["board_overlays_1"], (1, 0)) v.set_position((x * self.current_board.tmx_data.tilewidth, y * self.current_board.tmx_data.tileheight)) - v.set_sprite((1, 0)) v.custom_flags = ("OverlayMove", (x, y)) self.board_overlay.add(v) diff --git a/src/menu.py b/src/menu.py @@ -117,16 +117,14 @@ class Menu(object): # as e.g. being animated are hardcoded here. self.background = vgo.Entity(self.definition["bg_sheet"] + " _ent", self.contained_entities, self.manager.game.sheet_manager.loaded_sheets[self.definition["bg_sheet"]], - None, False, True, None) - self.background.set_sprite(tuple(self.definition["bg_sprite"])) + tuple(self.definition["bg_sprite"]), None, False, True, None) self.contained_entities += 1 # Load buttons, if any for b in self.definition["buttons"]: nmb = vgo.MenuButton(b, self.contained_entities, self.manager.game.sheet_manager.loaded_sheets[self.definition["buttons"][b]["sheet"]], - None, False, True, None, self.definition["buttons"][b]["effects"]) - nmb.set_sprite(tuple(self.definition["buttons"][b]["sprite"])) + tuple(self.definition["buttons"][b]["sprite"]), None, False, True, None, self.definition["buttons"][b]["effects"]) nmb.rect.topleft = tuple(self.definition["buttons"][b]["pos"]) self.button_group.add(nmb) diff --git a/src/scene.py b/src/scene.py @@ -1,5 +1,5 @@ import py, os, json -from . import manager +from . import manager, vgo from .constants import SCENE_JSON_PATH ############ @@ -59,10 +59,17 @@ class StillScene(object): self.manager = manager # Important values - self.characters = [] - self.current_text = "" - self.text_speed = 1 - self.font = None + self.script = [] + self.fonts = [] + self.characters = {} + self.text_speed = 10 + self.text_write_timer = 0 + + # Swap-in values + self.displayed_characters = pygame.sprite.LayeredDirty() + self.current_text_string = "" + self.displayed_string = "" + self.current_font = None # An index of the 'fonts' value self.current_text_voice = None # Load the scene @@ -74,6 +81,9 @@ class StillScene(object): """ scenedef = json.load(open(os.path.join(SCENE_JSON_PATH, scenefile))) - #TODO!!!!!!! - for i in scenedef: - + self.script = scenedef["script"]: + self.fonts = scenedef["fonts"] + for c in scendef["characters"]: + nc = vgo.VGO(self.game.sheet_manager.loaded_sheets[scenedef["characters"][c]["sheet"]], scenedef["characters"][c]["sprite"]) + nc.set_position(scenedef["characters"][c]["pos"]) + self.characters[scenedef["characters"][c]["name"]] = nc diff --git a/src/vgo.py b/src/vgo.py @@ -26,14 +26,14 @@ class VisibleGameObject(pygame.sprite.DirtySprite): object. """ - def __init__(self, sheet, animation = None, animated = False): + def __init__(self, sheet, sprite = (0, 0), animation = None, animated = False): # Parent initialization super().__init__() # Saved values self.sheet = sheet - self.image = sheet.sprites[(0, 0)] # TODO: Should this be assigned?? + self.image = sheet.sprites[sprite] # TODO: Should this be assigned?? self.rect = self.image.get_rect() self.rect.topleft = (0, 0) self.custom_flags = None # Used to pass special info to VGOs @@ -163,10 +163,10 @@ class Entity(VisibleGameObject): their statistics in gameplay. """ - def __init__(self, name, ent_id, sheet, animation = None, animated = False, passable = False, unit = None): + def __init__(self, name, ent_id, sheet, sprite = (0, 0), animation = None, animated = False, passable = False, unit = None): # Parent initialization - super().__init__(sheet, animation, animated) + super().__init__(sheet, sprite, animation, animated) # Saved values self.name = name @@ -204,10 +204,10 @@ class MenuButton(Entity): """ # TODO: MenuButton should probably eventually be passed info on its draw layer. - def __init__(self, name, ent_id, sheet, animation = None, animated = False, passable = True, unit = None, effects = []): + def __init__(self, name, ent_id, sheet, sprite = (0, 0), animation = None, animated = False, passable = True, unit = None, effects = []): # Parent initialization - super().__init__(name, ent_id, sheet, animation, animated, passable, unit) + super().__init__(name, ent_id, sheet, sprite, animation, animated, passable, unit) # Saved values self.effects = effects # A list of effects. Each effect goes with a method in MenuManager, and each one is triggered on a press. @@ -224,10 +224,10 @@ class TileCursor(Entity): tiles. """ - def __init__(self, name, ent_id, sheet, animation = None, animated = False, passable = True, unit = None): + def __init__(self, name, ent_id, sheet, sprite = (0, 0), animation = None, animated = False, passable = True, unit = None): # Parent initialization - super().__init__(name, ent_id, sheet, animation, animated, passable, unit) + super().__init__(name, ent_id, sheet, sprite, animation, animated, passable, unit) # VGO settings self.custom_flags = "TileCursor" @@ -243,10 +243,10 @@ class Piece(Entity): sligthly modified move_motion and set_motion methods. """ - def __init__(self, name, ent_id, sheet, animation = None, animated = False, passable = False, unit = None, team = None): + def __init__(self, name, ent_id, sheet, sprite = (0, 0), animation = None, animated = False, passable = False, unit = None, team = None): # Parent initialization - super().__init__(name, ent_id, sheet, animation, animated, passable, unit) + super().__init__(name, ent_id, sheet, sprite, animation, animated, passable, unit) # Face settings self.facing = FACE_DIR.L @@ -334,12 +334,12 @@ class EntityManager(manager.Manager): # TODO: type should be enum if j[e]["type"] == "Entity": ne = Entity(j[e]["name"], self.total_entities, - self.game.sheet_manager.loaded_sheets[j[e]["sheet"]], + self.game.sheet_manager.loaded_sheets[j[e]["sheet"]], tuple(j[e]["sprite"]), self.game.sheet_manager.animations[j[e]["sheet"]][j[e]["animation"]], j[e]["animated"], j[e]["passable"], unit.Unit(self, self.game.unit_manager.get_stats(j[e]["name"]))) elif j[e]["type"] == "Piece": ne = Piece(j[e]["name"], self.total_entities, - self.game.sheet_manager.loaded_sheets[j[e]["sheet"]], + self.game.sheet_manager.loaded_sheets[j[e]["sheet"]], tuple(j[e]["sprite"]), self.game.sheet_manager.animations[j[e]["sheet"]][j[e]["animation"]], j[e]["animated"], j[e]["passable"], unit.Unit(self, self.game.unit_manager.get_stats(j[e]["name"])), j[e]["team"]) @@ -368,7 +368,6 @@ class EntityManager(manager.Manager): Find if there are any loaded entities at the provided tile definition. """ - # TODO: Should not just check for TileCursor name, should be something more concrete found_ents = [] for e in self.loaded_entities: if e.tile_pos == (tile_def[0], tile_def[1]) and e.custom_flags != "TileCursor":