Return to repo list

heart-of-gold

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

commit 069f24d7ec6f02ed2527d3b654a1b4607964319b
parent 992e3860c25482a0b65e23b97dfc78f1dc7cdf24
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Tue, 13 Oct 2020 18:31:40 -0500

Menu implemented in first functioning state

Diffstat:
Rdata/img/menubuttons_1.png -> data/img/mainmenu_buttons_1.png | 0
Adata/img/mainmenubg.png | 0
Mdata/json/ents/testmap1.json | 1+
Mdata/json/menus/mainmenu.json | 8++++----
Mdata/json/sheets.json | 10++++++++++
Msrc/game.py | 38+++++++++++++++++++++++++++++++++-----
Msrc/menu.py | 18++++++++++++++----
Msrc/vgo.py | 6+++++-
8 files changed, 67 insertions(+), 14 deletions(-)

diff --git a/data/img/menubuttons_1.png b/data/img/mainmenu_buttons_1.png Binary files differ. diff --git a/data/img/mainmenubg.png b/data/img/mainmenubg.png Binary files differ. diff --git a/data/json/ents/testmap1.json b/data/json/ents/testmap1.json @@ -2,6 +2,7 @@ "testent1" : { "name" : "Jisella", "type" : "Piece", + "unit" : "jisella_1.json", "sheet" : "jisella_1", "visible" : true, "animation" : "stand_L", diff --git a/data/json/menus/mainmenu.json b/data/json/menus/mainmenu.json @@ -1,24 +1,24 @@ { "name" : "MainMenu", - "bg_sheet" : "mainmenubg.png", + "bg_sheet" : "mainmenubg", "bg_sprite" : [0, 0], "buttons" : { "NewGame" : { - "sheet" : "mainmenu_buttons_1.png", + "sheet" : "mainmenu_buttons_1", "sprite" : [0, 0], "pos" : [100, 100], "intlayer" : 0, "effect" : ["me_quit"] }, "LoadGame" : { - "sheet" : "mainmenu_buttons_1.png", + "sheet" : "mainmenu_buttons_1", "sprite" : [0, 1], "pos" : [100, 200], "intlayer" : 0, "effect" : ["me_quit"] }, "Options" : { - "sheet" : "mainmenu_buttons_1.png", + "sheet" : "mainmenu_buttons_1", "sprite" : [0, 2], "pos" : [100, 300], "intlayer" : 0, diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -1,4 +1,14 @@ { + "mainmenubg" : { + "filename" : "mainmenubg.png", + "dimensions" : [1024, 768], + "total_sprites" : 1 + }, + "mainmenu_buttons_1" : { + "filename" : "mainmenu_buttons_1.png", + "dimensions" : [100, 50], + "total_sprites" : 16 + }, "jisella_1" : { "filename" : "jisella_1.png", "dimensions" : [64, 64], diff --git a/src/game.py b/src/game.py @@ -1,5 +1,5 @@ import pygame -from . import images, board, vgo, unit +from . import images, board, vgo, unit, menu from .constants import SCREEN_WIDTH, SCREEN_HEIGHT, FRAMERATE, TILE_WIDTH, TILE_HEIGHT ########### @@ -35,25 +35,48 @@ class Game(object): self.screen = pygame.display.set_mode(self.screen_dimensions) self.frame_clock = pygame.time.Clock() + # Mode management values + # TODO: enum + self.state_mode = "Main_Menu_Mode" + self.control_mode = None + # Subsystems self.interface = GameInterface(self) # Managers self.sheet_manager = images.SheetManager(self) + self.menu_manager = menu.MenuManager(self) self.board_manager = board.BoardManager(self) self.entity_manager = vgo.EntityManager(self) self.unit_manager = unit.UnitManager(self) # Setup (This is WIP) - # TODO: Fix this up, will see lots of revision self.sheet_manager.load_sheets_from_json("sheets.json") self.sheet_manager.load_animations_from_json("anims.json") + self.entity_manager.load_tile_cursor("cursor1") + + # TODO: Fix this up, will see lots of revision + self.menu_manager.load_menu_from_file("mainmenu.json") + self.menu_manager.switch_to_menu("mainmenu.json") self.board_manager.load_board_from_file("testmap1.tmx") self.board_manager.switch_to_board("testmap1.tmx") self.unit_manager.load_stats_from_json("jisella_1.json") - self.entity_manager.load_tile_cursor("cursor1") self.entity_manager.load_entities_from_json("testmap1.json") + def switch_mode(self, new_mode_def): + """ + Change the current state_mode, as well as load up + the elements of the new mode. + """ + self.state_mode = new_mode_def["new_mode"] + self.control_mode = new_mode_def["control_mode"] + for action in new_mode_def: + if action == "switch_to_board": + self.board_manager.load_board_from_file(new_mode_def[action]["name"] + ".tmx") + self.board_manager.switch_to_board(new_mode_def[action]["name"] + ".tmx") + self.entity_manager.load_entities_from_json(new_mode_def[action]["name"] + ".json") + # TODO: entity loading should be able to assign units. entity jsons should have units listed then + def shift_frames(self): """ Shift to the next frame using the PyGame Clock object. @@ -72,8 +95,13 @@ class Game(object): # Next, update all the subsurfaces/game objects and draw them # TODO: This is WIP and will change self.interface.update_interface() - self.board_manager.update_board(self.screen) - self.entity_manager.update_entities(self.screen) + + if self.state_mode == "Main_Menu_Mode": + self.menu_manager.update_current_menu(self.screen) + elif self.state_mode == "Battle_Mode": + self.board_manager.update_board(self.screen) + self.entity_manager.update_entities(self.screen) + self.menu_manager.update_current_menu(self.screen) # Last, update the screen pygame.display.update() diff --git a/src/menu.py b/src/menu.py @@ -1,6 +1,6 @@ import pygame, json, os from . import images, vgo, manager -from .constants import MENU_JSON_PATH +from .constants import IMAGE_PATH, MENU_JSON_PATH # TODO: EntityManager should be used to manage menu entities as well, eventually. @@ -52,7 +52,7 @@ class MenuManager(manager.Manager): sub-entities. """ if surface != None and self.current_menu != None: - surface.blit(self.current_menu.background, (0, 0)) + surface.blit(self.current_menu.background.image, (0, 0)) self.current_menu.update_menu(surface) ########################### @@ -102,9 +102,19 @@ class Menu(object): # Load buttons, if any for b in self.definition["buttons"]: nmb = vgo.MenuButton(b, self.contained_entities, - self.definitions["buttons"][b]["sheet"], None, False, True, None, - self.definitions["buttons"][b]["effect"]) + self.manager.game.sheet_manager.loaded_sheets[self.definition["buttons"][b]["sheet"]], + None, False, True, None, self.definition["buttons"][b]["effect"]) nmb.set_sprite(tuple(self.definition["buttons"][b]["sprite"])) + nmb.rect.topleft = tuple(self.definition["buttons"][b]["pos"]) self.button_group.add(nmb) # TODO: add generic ent loader and some way to enumerate sublayouts. + + def update_menu(self, surface = None): + """ + Draw and update menu elements. + """ + + if surface != None: + # TODO: Add the other groups when they get made + self.button_group.update(surface) diff --git a/src/vgo.py b/src/vgo.py @@ -1,6 +1,6 @@ import pygame, json, os, math from . import manager, unit -from .constants import ENTITY_JSON_PATH, TILE_WIDTH, TILE_HEIGHT +from .constants import ENTITY_JSON_PATH, STATUS_JSON_PATH, TILE_WIDTH, TILE_HEIGHT ########## # vgo.py # @@ -343,6 +343,10 @@ class EntityManager(manager.Manager): 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"]) + # TODO: This whole thing is a mess. It is time to simplify what + # values get passed to new ents + if "unit" in j[e].keys(): + ne.unit = json.load(open(os.path.join(STATUS_JSON_PATH, j[e]["unit"]))) ne.assign_tile(self.game.board_manager.get_tile_at_tile_pos(tuple(j[e]["tile"]))) ne.snap_to_tile() self.add_entity(ne)