Return to repo list

heart-of-gold

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

commit 12bfb2530a8065f51befa03d09b5a5b90267e770
parent bc7653ca250f3027fa5bef31cbedf5d9ce0e4b40
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat,  7 Nov 2020 22:48:54 -0600

Restored significant functionality

Diffstat:
Mdata/board/testmap1/testmap1.tmx | 2+-
Mdata/json/menus/mainmenu.json | 4++--
Mdata/json/scenes/testscene.json | 2+-
Mdata/tsx/testtiles1.tsx | 4++--
Msrc/board.py | 10+++++-----
Msrc/game.py | 6+-----
Msrc/manager.py | 4+++-
Msrc/piece.py | 12+++++++++---
Msrc/subsystem.py | 16++++++++--------
9 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/data/board/testmap1/testmap1.tmx b/data/board/testmap1/testmap1.tmx @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="18" height="18" tilewidth="64" tileheight="64" infinite="0" nextlayerid="3" nextobjectid="1"> - <tileset firstgid="1" source="tsx/testtiles1.tsx"/> + <tileset firstgid="1" source="../../tsx/testtiles1.tsx"/> <layer id="1" name="BaseTileLayer" width="18" height="18"> <data encoding="csv"> 1,1,1,1,1,1,2,2,3,4,4,4,4,4,4,4,4,4, diff --git a/data/json/menus/mainmenu.json b/data/json/menus/mainmenu.json @@ -11,7 +11,7 @@ "effects" : [ { "call" : "ef_game_switch_mode", - "data" : "Battle_Mode" + "data" : ["Battle_Mode", "testmap1"] } ] }, @@ -23,7 +23,7 @@ "effects" : [ { "call" : "ef_game_switch_mode", - "data" : "Still_Scene_Mode" + "data" : ["Still_Scene_Mode", "testscene.json"] } ] }, diff --git a/data/json/scenes/testscene.json b/data/json/scenes/testscene.json @@ -42,7 +42,7 @@ "effects" : [ { "call" : "ef_game_switch_mode", - "data" : "Battle_Mode" + "data" : ["Battle_Mode", "testmap1"] } ] } diff --git a/data/tsx/testtiles1.tsx b/data/tsx/testtiles1.tsx @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<tileset version="1.4" tiledversion="1.4.1" name="testtiles1" tilewidth="64" tileheight="64" tilecount="4" columns="2"> - <image source="../../img/testtiles1.png" trans="ff00ff" width="128" height="128"/> +<tileset version="1.2" tiledversion="1.3.2" name="testtiles1" tilewidth="64" tileheight="64" tilecount="4" columns="2"> + <image source="../img/testtiles1.png" trans="ff00ff" width="128" height="128"/> <tile id="0"> <properties> <property name="Passable" type="int" value="1"/> diff --git a/src/board.py b/src/board.py @@ -43,8 +43,7 @@ class BoardManager(manager.Manager): """ Load a given board. """ - boardtmx = boardname + ".tmx" - self.current_board = Board(self, boardtmx) + self.current_board = Board(self, boardname) self.load_overlay() def load_overlay(self): @@ -254,14 +253,15 @@ class Board(object): BoardManager object. """ - def __init__(self, manager, filename): + def __init__(self, manager, boardname): # Saved values self.manager = manager - self.filename = filename + self.boardname = boardname + self.filename = boardname + ".tmx" # Pytmx values - self.tmx_data = pytmx.load_pygame(os.path.join(BOARD_PATH, self.filename)) + self.tmx_data = pytmx.load_pygame(os.path.join(BOARD_PATH, self.boardname, self.filename)) 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) diff --git a/src/game.py b/src/game.py @@ -133,12 +133,8 @@ class Game(object): self.menu_manager.update_current_menu(self.camera.camera_surface) elif self.state_mode == STATE_MODES.Battle_Mode: self.board_manager.update_board(self.camera.camera_surface) - self.piece_manager.update_entities(self.camera.camera_surface) + self.piece_manager.update_pieces(self.camera.camera_surface) self.piece_manager.update_tile_cursor(self.camera.camera_surface) - # NOTE: MenuManager should not be an overlay for the - # battle mode. In-battle menus should be handled - # by EntityManager most likely - #self.menu_manager.update_current_menu(self.screen) elif self.state_mode == STATE_MODES.Still_Scene_Mode: self.scene_manager.update_scene(self.camera.camera_surface) diff --git a/src/manager.py b/src/manager.py @@ -68,8 +68,10 @@ class Manager(subsystem.GameSubsystem): for ef in effect_list: if ef["call"] == GAME_EFFECTS.ef_game_quit.name: self.game.quit_game() + # Switch mode ALWAYS has a two-part list for its data, with the second part being able to + # be whatever game needs for that particular mode (even compound data types such as list/dict) elif ef["call"] == GAME_EFFECTS.ef_game_switch_mode.name: - self.game.switch_mode(STATE_MODES[ef["data"]]) + self.game.switch_mode(STATE_MODES[ef["data"][0]], ef["data"][1]) def update_managed(self, surface): """ diff --git a/src/piece.py b/src/piece.py @@ -54,7 +54,7 @@ class PieceManager(manager.Manager): for p in definition: n_sheet = self.bus.fetch_sheet(definition[p]["sheet"]) n_sprite = tuple(definition[p]["sprite"]) - n_anim = self.bus.fetch_animation(n_sheet, definition[p]["animation"]) + n_anim = self.bus.fetch_animation(definition[p]["sheet"], definition[p]["animation"]) n_animated = definition[p]["animated"] n_name = definition[p]["name"] n_passable = definition[p]["passable"] @@ -62,7 +62,10 @@ class PieceManager(manager.Manager): n_astats = definition[p]["active_stats"] n_team = definition[p]["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)) + np = Piece(n_sheet, n_sprite, n_anim, n_animated, n_name, n_passable, n_nstats, n_astats, n_team, n_equip) + np.assign_tile(self.bus.fetch_tile_by_tile_pos(tuple(definition[p]["tile"]))) + np.snap_to_tile() + self.add_piece(np) def load_pieces_from_file(self, filename): """ @@ -73,8 +76,11 @@ class PieceManager(manager.Manager): that spawn in pre-made boards. """ if filename[::-4] != ".json": + foldname = filename filename = filename + ".json" - jsondef = json.load(open(os.path.join(BOARD_PATH, filename))) + else: + foldname = filename[::-4] + jsondef = json.load(open(os.path.join(BOARD_PATH, foldname, filename))) self.load_pieces_from_def(jsondef) def load_tile_cursor(self, sheet): diff --git a/src/subsystem.py b/src/subsystem.py @@ -101,7 +101,7 @@ class GameInterface(GameSubsystem): # Normal main menu control if self.game.control_mode == CTRL_MODES.Main_Menu_Normal: - self.bus.perform_trigger_button_at_pos(mousepos) + self.bus.perform_trigger_menu_button_at_pos(mousepos) # Battle mode behavior elif self.game.state_mode == STATE_MODES.Battle_Mode: @@ -114,7 +114,7 @@ class GameInterface(GameSubsystem): # Selecting a move for the active piece control elif self.game.control_mode == CTRL_MODES.Turn_Select_Move: - to_path = self.bus.fetch_piece_path_by_previous_moves(self.bus.fetch_selected_entity_tile_pos(), + to_path = self.bus.fetch_piece_path_by_previous_moves(self.bus.fetch_selected_piece_tile_pos(), self.bus.fetch_tile_pos_by_screen_pos(mousepos)) if to_path != None: self.bus.perform_set_piece_move_along_tile_path(self.bus.fetch_selected_piece(), to_path) @@ -145,7 +145,7 @@ class GameInterface(GameSubsystem): if self.game.state_mode == STATE_MODES.Battle_Mode: mouseraw = pygame.mouse.get_pos() mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) - tilepos = self.bus.fetch_tile_at_screen_pos(mousepos) + tilepos = self.bus.fetch_tile_by_screen_pos(mousepos) if tilepos != None: self.bus.perform_position_tile_cursor(tilepos) @@ -191,9 +191,9 @@ class ManagerBus(GameSubsystem): def fetch_selected_piece_tile_pos(self): return self.game.piece_manager.selected_piece.tile_pos def fetch_tile_by_screen_pos(self, position): - return self.game.board_manager.get_tile_by_position(position) + return self.game.board_manager.get_tile_at_position(position) def fetch_tile_by_tile_pos(self, tile_pos): - return self.game.board_manager.get_tile_by_tile_pos(tile_pos) + return self.game.board_manager.get_tile_at_tile_pos(tile_pos) def fetch_tile_pos_by_screen_pos(self, position): return self.game.board_manager.get_tile_pos_at_position(position) def fetch_piece_path_by_previous_moves(self, start_tile, target_tile): @@ -207,11 +207,11 @@ class ManagerBus(GameSubsystem): self.game.menu_manager.trigger_button_at_pos(pos) def perform_select_piece_with_tile_cursor(self): self.game.piece_manager.select_piece_with_tile_cursor() - def perform_position_tile_cursor(tile_pos): - self.game.entity_manager.position_tile_cursor(tile_pos) + def perform_position_tile_cursor(self, tile_pos): + self.game.piece_manager.position_tile_cursor(tile_pos) def perform_set_piece_move_along_tile_path(self, piece, path): self.game.piece_manager.set_piece_move_to_tile_path(piece, path) - def perform_continue_current_scene_script(): + def perform_continue_current_scene_script(self): self.game.scene_manager.current_scene.continue_script() ####################################