Return to repo list

tzed

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

commit 38b0cee05e7c23d8b44cf60f0943b6a5a8e9b938
parent 137c7e3e820a033c767549caf928bfea3e9dd3f2
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat,  2 Oct 2021 21:33:00 -0500

loading from encount file

Diffstat:
Mdata/dungeons/testdun1/dungeon.json | 1+
Mdata/dungeons/testdun1/encounters.json | 72++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Msrc/dungeon.py | 20+++++++++++++++++++-
Msrc/game.py | 4+++-
Msrc/interface.py | 16++++++++--------
5 files changed, 81 insertions(+), 32 deletions(-)

diff --git a/data/dungeons/testdun1/dungeon.json b/data/dungeons/testdun1/dungeon.json @@ -6,6 +6,7 @@ "entrance" : [0, 0], "direction" : 1, "north_color" : 7, + "floor_names" : ["B1", "B2"], "layout" : [ [ [ diff --git a/data/dungeons/testdun1/encounters.json b/data/dungeons/testdun1/encounters.json @@ -1,24 +1,52 @@ { - "factor" : 10, - "rate" : 12, - "parties" : { - "party1" : [ - "Rat1" : { - "name" : "Big Rat", - "sheet" : "enemies_battle1", - "sprite" : [0, 0], - "color" : 9, - "level" : 1, - "xp" : 0, - "hp" : 100, - "mp" : 100, - "sp" : 100, - "phs" : 3, - "mag" : 9, - "agi" : 2, - "chr" : 2, - "luk" : 1 - } - ] - } + "floors" : [ + { + "factor" : 10, + "rate" : 12, + "parties" : { + "party1" : [ + { + "name" : "Big Rat", + "sheet" : "enemies_battle1", + "sprite" : [0, 0], + "color" : 9, + "level" : 1, + "xp" : 0, + "hp" : 100, + "mp" : 100, + "sp" : 100, + "phs" : 3, + "mag" : 9, + "agi" : 2, + "chr" : 2, + "luk" : 1 + } + ] + } + }, + { + "factor" : 10, + "rate" : 1, + "parties" : { + "party1" : [ + { + "name" : "Big Rat", + "sheet" : "enemies_battle1", + "sprite" : [0, 0], + "color" : 9, + "level" : 1, + "xp" : 0, + "hp" : 100, + "mp" : 100, + "sp" : 100, + "phs" : 3, + "mag" : 9, + "agi" : 2, + "chr" : 2, + "luk" : 1 + } + ] + } + } + ] } diff --git a/src/dungeon.py b/src/dungeon.py @@ -19,7 +19,7 @@ class Dungeon(object): for the dungeon-crawling sections of the game. """ - def __init__(self, game, name, definition): + def __init__(self, game, name, definition, encounters): # Saved vals self.game = game @@ -36,6 +36,9 @@ class Dungeon(object): self.north_color = definition["north_color"] self.layout_definition = definition["layout"] + # Encounter-file derived vals + self.encounter_definition = encounters + # Other vals self.direction = 0 self.current_floor = 0 @@ -109,6 +112,21 @@ class Dungeon(object): self.dungeon_view.add(entity.CustomSprite(self.game.sheets["compass"].sprites[(0, 0)], (self.game.viewport_rect.center[0] - 96, self.game.viewport_rect.top + 3))) self.dungeon_view.add(entity.CustomSprite(self.game.sheets[self.sheetname + "_cd"].sprites[(self.direction, 0)], (self.game.viewport_rect.center[0] - 16, self.game.viewport_rect.top + 12), self.north_color if self.direction == 0 else None)) + def take_dungeon_turn(self): + """ + This method executes all the logic that + must happen each dungeon turn. Note that + things like moving and rotating are not + handled here. This method should only + be called by the Interface or perhaps by + the Game object. + """ + # Post-refresh game method calls + self.game.pass_time() + self.game.generate_party_graphics() + + # Check for random dungeon encounters + def update_dungeon(self, surface = None): """ Update the dungeon logic and visuals. diff --git a/src/game.py b/src/game.py @@ -137,7 +137,9 @@ class Game(object): for d in dungeonlist["dungeons"]: with open(os.path.join(DUNGEON_PATH, d, "dungeon.json")) as dj: dungeondef = json.load(dj) - nd = dungeon.Dungeon(self, d, dungeondef) + with open(os.path.join(DUNGEON_PATH, d, "encounters.json")) as ej: + encountdef = json.load(ej) + nd = dungeon.Dungeon(self, d, dungeondef, encountdef) self.loaded_dungeons[d] = nd def build_ui(self): diff --git a/src/interface.py b/src/interface.py @@ -83,8 +83,7 @@ class Interface(object): elif self.game.state_mode == STATE_MODES.Dungeon_Mode: if self.game.current_dungeon != None: self.game.current_dungeon.move_forward() - self.game.pass_time() - self.game.generate_party_graphics() + self.game.current_dungeon.take_dungeon_turn() for j in CONTROLS["up"]: self.key_bools[j] = False return @@ -94,8 +93,7 @@ class Interface(object): elif self.game.state_mode == STATE_MODES.Dungeon_Mode: if self.game.current_dungeon != None: self.game.current_dungeon.move_forward(True) - self.game.pass_time() - self.game.generate_party_graphics() + self.game.current_dungeon.take_dungeon_turn() for j in CONTROLS["down"]: self.key_bools[j] = False return @@ -105,8 +103,7 @@ class Interface(object): elif self.game.state_mode == STATE_MODES.Dungeon_Mode: if self.game.current_dungeon != None: self.game.current_dungeon.rotate_direction(-1) - self.game.pass_time() - self.game.generate_party_graphics() + self.game.current_dungeon.take_dungeon_turn() for j in CONTROLS["left"]: self.key_bools[j] = False return @@ -116,8 +113,7 @@ class Interface(object): elif self.game.state_mode == STATE_MODES.Dungeon_Mode: if self.game.current_dungeon != None: self.game.current_dungeon.rotate_direction() - self.game.pass_time() - self.game.generate_party_graphics() + self.game.current_dungeon.take_dungeon_turn() for j in CONTROLS["right"]: self.key_bools[j] = False return @@ -125,6 +121,10 @@ class Interface(object): if self.game.state_mode in OVERHEAD_MODES: self.game.post_message("$PLAYERNAME waits.") self.game.pass_time() + elif self.game.state_mode == STATE_MODES.Dungeon_Mode: + if self.game.current_dungeon != None: + self.game.post_message("$PLAYERNAME waits.") + self.game.current_dungeon.take_dungeon_turn() for j in CONTROLS["wait"]: self.key_bools[j] = False return