Return to repo list

tzed

Simple story-driven open world 2D CRPG.
Return to HMagellan.com

commit 533606707a318a0dcca77011e09a51868c045fb5
parent fd47eaf0ff7a1951f98449d0e63b31c44b7bde5b
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed,  9 Jun 2021 22:36:08 -0500

skel of entity manager

Diffstat:
Adata/boards/test_town/entities.json | 0
Msrc/entity.py | 50++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/game.py | 3++-
3 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/data/boards/test_town/entities.json b/data/boards/test_town/entities.json diff --git a/src/entity.py b/src/entity.py @@ -7,13 +7,55 @@ from .envvars import * ############# # This file contains: -# 1. The Entity class that is the extension of pygame.Sprite used throughout the game -# 2. Various kinds of specialized entity classes that don't fit in other source files +# 1. The EntityManager class for managing gameplay acting entities in most modes +# 2. The Entity class that is the extension of pygame.Sprite used throughout the game +# 3. Various kinds of specialized entity classes that don't fit in other source files # TODO: This should eventually use LayeredDirty sprites for performance reasons +####################################### +# Section 1 - The EntityManager class # +####################################### + +class EntityManager(manager.Manager): + """ + Manager for the player entity and for all acting entities + that appear in Overworld, Location, Dungeon, and Battle + modes. + """ + + def __init__(self, game, name, bus, system_bus): + + super().__init__(game, name, bus, system_bus) + + # Groups + self.draw_group = pygame.sprite.LayeredDirty() + + # Other values + self.player = None + + def load_board_entities_from_file(self, current_board_name): + """ + Load entities up for the current board from the + entities.json in that board's dir. + """ + # First, clear the draw group + self.draw_group.empty() + + # Next, get the JSON as a dict + with open(os.path.join(BOARD_PATH, current_board_name, "entities.json")) as f: ent_def = json.load(f) + + # Then, load the entities + + def update_managed(self, surface = None): + """ + Update currently managed entities. + """ + if surface != None: + self.draw_group.update(surface) + ############################ -# Section 1 - Entity class # +# Section 2 - Entity class # ############################ class Entity(pygame.sprite.DirtySprite): @@ -201,7 +243,7 @@ class Entity(pygame.sprite.DirtySprite): surface.blit(pygame.transform.flip(self.image, self.flipped[0], self.flipped[1]), self.rect) ######################################### -# Section 2 - Various Entity subclasses # +# Section 3 - Various Entity subclasses # ######################################### # TODO: diff --git a/src/game.py b/src/game.py @@ -1,5 +1,5 @@ import pygame -from . import interface, bus, camera, sound, images, board, menu +from . import interface, bus, camera, sound, images, board, menu, entity from .envvars import * ########### @@ -41,6 +41,7 @@ class Game(object): # Managers self.board_manager = board.BoardManager(self, "board_manager", self.manager_bus, self.subsystem_bus) self.menu_manager = menu.MenuManager(self, "menu_manager", self.manager_bus, self.subsystem_bus) + self.entity_manager = entity.EntityManager(self, "entity_manager", self.manager_bus, self.subsystem_bus) # Setup (This is WIP) #self.sheet_system.load_animations_from_json("anims.json")