Return to repo list

tzed

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

commit 5ed26a68fb81feb7fe33ad9881a11ef67d43c316
parent 585e05ac6c88003ca0f8ad3bdbf9e8ac226fa55a
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat,  2 Oct 2021 22:23:05 -0500

encounter triggering

Diffstat:
Mdata/dungeons/testdun1/encounters.json | 3++-
Msrc/dungeon.py | 26++++++++++++++++++++++++--
Msrc/game.py | 4++++
3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/data/dungeons/testdun1/encounters.json b/data/dungeons/testdun1/encounters.json @@ -1,8 +1,9 @@ { + "safe" : false, "floors" : [ { "factor" : 10, - "rate" : 12, + "rate" : 17, "parties" : { "party1" : [ { diff --git a/src/dungeon.py b/src/dungeon.py @@ -1,4 +1,4 @@ -import pygame +import pygame, random from . import entity from .gamelib import * @@ -37,16 +37,27 @@ class Dungeon(object): self.layout_definition = definition["layout"] # Encounter-file derived vals - self.encounter_definition = encounters + self.safe = encounters["safe"] + self.floor_encounters = encounters["floors"] # Other vals self.direction = 0 self.current_floor = 0 self.current_cell = (0, 0) + self.floor_factor_counters = None + self.dungeon_flags = None # Graphics self.dungeon_view = pygame.sprite.Group() + def load_from_savedata(self, savedata): + """ + Get info from save data at save game load + time. + """ + self.floor_factor_counters = savedata["floor_factors"] + self.dungeon_flags = savedata["dungeon_flags"] + def enter_dungeon(self, direction, floor, cell): """ Start off the dungeon in a particular place, @@ -107,6 +118,16 @@ 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 roll_for_encounter(self): + """ + Check to see if an random enemy encounter + should happen. + """ + if not self.safe and self.floor_factor_counters[self.current_floor] < self.floor_encounters[self.current_floor]["factor"]: + randchance = random.randint(1, 20) + if randchance >= self.floor_encounters[self.current_floor]["rate"]: + print("trigger encounter") + def take_dungeon_turn(self): """ This method executes all the logic that @@ -124,6 +145,7 @@ class Dungeon(object): self.game.generate_party_graphics() # Check for random dungeon encounters + self.roll_for_encounter() def update_dungeon(self, surface = None): """ diff --git a/src/game.py b/src/game.py @@ -471,6 +471,10 @@ class Game(object): self.player_name = saveraw["player"] self.party = saveraw["party"] + # Load savedata values into already-loaded resources + for dun in self.loaded_dungeons: + self.loaded_dungeons[dun].load_from_savedata(saveraw["dungeons"][dun]) + # Load a board if saveraw["at"]["type"] == "location": self.switch_board(saveraw["at"]["data"]["board"], tuple(saveraw["at"]["data"]["cell"]))