Return to repo list

heart-of-gold

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

commit c85951c3a8f1dc000ea637f53613ee7dd5a54854
parent ed06aa1ed331f3170d917ef88c244d6d5012a54e
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Thu,  5 Nov 2020 15:00:19 -0600

Refactor checkpoint again

Diffstat:
Adata/board/testmap1/testmap1.json | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rdata/map/testmap1.tmx -> data/board/testmap1/testmap1.tmx | 0
Ddata/json/ents/testmap1.json | 26--------------------------
Ddata/json/stats/jisella_1.json | 33---------------------------------
Rdata/map/tsx/testtiles1.tsx -> data/tsx/testtiles1.tsx | 0
Msrc/board.py | 13++++++-------
Msrc/constants.py | 4++--
Msrc/game.py | 11++++-------
Msrc/piece.py | 20+++++++++++++++++---
9 files changed, 145 insertions(+), 78 deletions(-)

diff --git a/data/board/testmap1/testmap1.json b/data/board/testmap1/testmap1.json @@ -0,0 +1,116 @@ +{ + "testent1" : { + "name" : "Jisella", + "type" : "Piece", + "sheet" : "jisella_1", + "sprite" : [0, 0], + "visible" : true, + "animation" : "stand_L", + "animated" : true, + "passable" : false, + "tile" : [5, 4], + "team" : "Player", + "normal_stats" : { + "LVL" : 1, + "HP" : 100, + "ATK" : 10, + "DEF" : 6, + "SPD" : 9, + "ACC" : 7, + "INT" : 5, + "WIS" : 6, + "LUK" : 8, + "INIT" : 2, + "CNTR" : 2, + "GARD" : 1, + "PUSH" : 2, + "MOVE" : 6, + "SKIL" : 3, + "PASS" : 3, + "AFFINITY" : "Fire" + }, + "active_stats" : { + "LVL" : 1, + "HP" : 100, + "ATK" : 10, + "DEF" : 6, + "SPD" : 9, + "ACC" : 7, + "INT" : 5, + "WIS" : 6, + "LUK" : 8, + "INIT" : 2, + "CNTR" : 2, + "GARD" : 1, + "PUSH" : 2, + "MOVE" : 6, + "SKIL" : 3, + "PASS" : 3, + "AFFINITY" : "Fire" + }, + "equipment" : { + "weapon" : "Basic_Sword_1", + "armor" : "Basic_Armor_1", + "acc1" : null, + "acc2" : null, + "acc3" : null + } + }, + "testent2" : { + "name" : "Fakella", + "type" : "Piece", + "sheet" : "jisella_1", + "sprite" : [0, 0], + "visible" : true, + "animation" : "stand_R", + "animated" : true, + "passable" : false, + "tile" : [0, 2], + "team" : "Player", + "normal_stats" : { + "LVL" : 1, + "HP" : 100, + "ATK" : 10, + "DEF" : 6, + "SPD" : 9, + "ACC" : 7, + "INT" : 5, + "WIS" : 6, + "LUK" : 8, + "INIT" : 2, + "CNTR" : 2, + "GARD" : 1, + "PUSH" : 2, + "MOVE" : 6, + "SKIL" : 3, + "PASS" : 3, + "AFFINITY" : "Water" + }, + "active_stats" : { + "LVL" : 1, + "HP" : 100, + "ATK" : 10, + "DEF" : 6, + "SPD" : 9, + "ACC" : 7, + "INT" : 5, + "WIS" : 6, + "LUK" : 8, + "INIT" : 2, + "CNTR" : 2, + "GARD" : 1, + "PUSH" : 2, + "MOVE" : 6, + "SKIL" : 3, + "PASS" : 3, + "AFFINITY" : "Water" + }, + "equipment" : { + "weapon" : "Basic_Sword_1", + "armor" : "Basic_Armor_1", + "acc1" : null, + "acc2" : null, + "acc3" : null + } + } +} diff --git a/data/map/testmap1.tmx b/data/board/testmap1/testmap1.tmx diff --git a/data/json/ents/testmap1.json b/data/json/ents/testmap1.json @@ -1,26 +0,0 @@ -{ - "testent1" : { - "name" : "Jisella", - "type" : "Piece", - "sheet" : "jisella_1", - "sprite" : [0, 0], - "visible" : true, - "animation" : "stand_L", - "animated" : true, - "passable" : false, - "tile" : [5, 4], - "team" : "Player" - }, - "testent2" : { - "name" : "Fakella", - "type" : "Piece", - "sheet" : "jisella_1", - "sprite" : [0, 0], - "visible" : true, - "animation" : "stand_R", - "animated" : true, - "passable" : false, - "tile" : [0, 2], - "team" : "Player" - } -} diff --git a/data/json/stats/jisella_1.json b/data/json/stats/jisella_1.json @@ -1,33 +0,0 @@ -{ - "name" : "Jisella", - "LVL" : 1, - "HP" : 100, - "ATK" : 135, - "DEF" : 45, - "SPD" : 100, - "ACC" : 60, - "INT" : 50, - "WIS" : 30, - "MOVE" : 8, - "CRIT" : 10, - "SKIL" : 4, - "RANK" : 1, - "LEAD" : 4, - "INIT" : 5, - "MORL" : 70, - "AFFINITY" : "Fire", - "WEAPON" : "Sword", - "POWERS" : [ - "Courage" - ], - "KNOWN_SKILLS" : [ - "Charge", - "Drive" - ], - "EQ_SKILLS" : [ - "Charge", - "Drive", - false, - false - ] -} diff --git a/data/map/tsx/testtiles1.tsx b/data/tsx/testtiles1.tsx diff --git a/src/board.py b/src/board.py @@ -34,18 +34,17 @@ class BoardManager(manager.Manager): # Board values self.current_board = None self.board_overlay = pygame.sprite.LayeredDirty() - self.current_board_dimensions = (0, 0) # Move values self.move_targets = {} # Keys = (x, y) of tiles, vals are a list of (x, y) tuples representing the path to be taken self.previous_moves = {} # Keys = (x, y) of tiles, vals are the (x, y) of the previous node - def load_board_from_file(self, boardfile): + def load_board(self, boardname): """ - Load a board from a given tmx file. + Load a given board. """ - self.current_board = Board(self, boardfile) - self.current_board_dimensions = (self.current_board.tmx_data.width * self.current_board.tmx_data.tilewidth, self.current_board.tmx_data.height * self.current_board.tmx_data.tileheight) + boardtmx = boardname + ".tmx" + self.current_board = Board(self, boardtmx) self.load_overlay() def load_overlay(self): @@ -264,8 +263,8 @@ class Board(object): # Pytmx values self.tmx_data = pytmx.load_pygame(os.path.join(BOARD_PATH, self.filename)) - self.grid_width = self.tmx_data.width * self.tmx_data.tilewidth - self.grid_height = self.tmx_data.height * self.tmx_data.tileheight + self.tile_dimensions = (self.tmx_data.width, self.tmx_data.height) + self.grid_dimensions = (self.tmx_data.width * self.tmx_data.tilewidth, self.tmx_data.height * self.tmx_data.tileheight) def draw_board(self, surface = None): """ diff --git a/src/constants.py b/src/constants.py @@ -33,9 +33,9 @@ DATA_PATH = os.path.join(os.getcwd(), "data") IMAGE_PATH = os.path.join(DATA_PATH, "img") SOUND_PATH = os.path.join(DATA_PATH, "snd") FONT_PATH = os.path.join(DATA_PATH, "font") -BOARD_PATH = os.path.join(DATA_PATH, "map") +BOARD_PATH = os.path.join(DATA_PATH, "board") +TILE_PATH = os.path.join(DATA_PATH, "tsx") JSON_PATH = os.path.join(DATA_PATH, "json") -ENTITY_JSON_PATH = os.path.join(JSON_PATH, "ents") MENU_JSON_PATH = os.path.join(JSON_PATH, "menus") SCENE_JSON_PATH = os.path.join(JSON_PATH, "scenes") diff --git a/src/game.py b/src/game.py @@ -83,16 +83,13 @@ class Game(object): self.camera.load_camera_surface((SCREEN_WIDTH, SCREEN_HEIGHT)) elif new_mode == STATE_MODES.Battle_Mode: self.control_mode = CTRL_MODES.Turn_Normal - # TODO: Obv this must be made more generic. Currently only - # sources from the one map file. - #self.board_manager.load_board_from_file("testmap1.tmx") - #self.entity_manager.load_entities_from_json("testmap1.json") + self.board_manager.load_board(data) + self.piece_manager.load_pieces_from_file(data) self.piece_manager.load_tile_cursor("cursor1") - self.camera.load_camera_surface(self.board_manager.current_board_dimensions) + self.camera.load_camera_surface(self.board_manager.current_board.grid_dimensions) elif new_mode == STATE_MODES.Still_Scene_Mode: self.control_mode = CTRL_MODES.Still_Scene_Normal - # TODO: Generic-ify - #self.scene_manager.load_still_scene_from_file("testscene.json") + self.scene_manager.load_still_scene_from_file(data) self.camera.load_camera_surface((SCREEN_WIDTH, SCREEN_HEIGHT)) def lose_control(self, time = -1, followup_mode = None): diff --git a/src/piece.py b/src/piece.py @@ -61,8 +61,21 @@ class PieceManager(manager.Manager): n_nstats = definition[p]["normal_stats"] n_astats = definition[p]["active_stats"] n_team = definition[p]["team"] - # TODO: ID needs fixing - self.add_piece(Piece(n_sheet, n_sprite, n_anim, n_animated, n_name, n_passable, n_nstats, n_astats, n_team)) + n_equip = definition[p]["equipment"] + self.add_piece(Piece(n_sheet, n_sprite, n_anim, n_animated, n_name, n_passable, n_nstats, n_astats, n_team, n_equip)) + + def load_pieces_from_file(self, filename): + """ + Load pieces from a given file. Checks to see if + the provided filename is a JSON (or rather, has a + .json extension) and tries to correct it if not. + This method is called to load the pre-defined pieces + that spawn in pre-made boards. + """ + if filename[::-4] != ".json": + filename = filename + ".json" + jsondef = json.load(open(os.path.join(BOARD_PATH, filename))) + self.load_pieces_from_def(jsondef) def load_tile_cursor(self, sheet): """ @@ -222,7 +235,7 @@ class Piece(entity.Entity): """ def __init__(self, sheet, sprite = (0, 0), animation = None, animated = False, - name = None, passable = False, normal_stats = None, active_stats = None, team = None): + name = None, passable = False, normal_stats = None, active_stats = None, team = None, equipment = None): # Parent initialization super().__init__(sheet, sprite, animation, animated) @@ -236,6 +249,7 @@ class Piece(entity.Entity): self.normal_stats = normal_stats self.active_stats = active_stats self.team = team + self.equipment = equipment self.back_to_stand = False # TODO: This may not be the best way self.current_tile_path = [] self.current_tile_path_index = 0