Return to repo list

tzed

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

commit 8eaeb5d84aad230dbcc7dd5e9b8dcaaa093d47b1
parent 880d306185bff6e96dbc287098387a558db26800
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 10 Sep 2021 17:32:58 -0500

can now move in dungeons

Diffstat:
Mdata/dungeons/testdun1/dungeon.json | 61++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Mdata/images/dungeon1_fc.png | 0
Mdata/images/dungeon1_h.png | 0
Msrc/board.py | 2+-
Msrc/dungeon.py | 14++++++++++++--
Msrc/game.py | 10+++++++---
Msrc/gamelib.py | 3++-
7 files changed, 72 insertions(+), 18 deletions(-)

diff --git a/data/dungeons/testdun1/dungeon.json b/data/dungeons/testdun1/dungeon.json @@ -4,20 +4,39 @@ "height" : 4, "sheet" : "dungeon1", "entrance" : [0, 0], + "direction" : 1, "layout" : [ [ [ { "North" : { + "ceiling" : [0, 2], + "floor" : [0, 2], + "l_wall" : [4, 0], + "r_wall" : [4, 0], + "horizon" : [2, 4], + "pass" : false, + "data" : {} + }, + "South" : { + "ceiling" : [0, 2], + "floor" : [0, 2], + "l_wall" : [4, 0], + "r_wall" : [4, 0], + "horizon" : [2, 4], + "pass" : false, + "data" : {} + }, + "East" : { "ceiling" : [0, 0], "floor" : [0, 1], "l_wall" : [0, 0], "r_wall" : [2, 0], - "horizon" : [0, 0], + "horizon" : [2, 1], "pass" : true, "data" : {} }, - "South" : { + "West" : { "ceiling" : [0, 0], "floor" : [0, 1], "l_wall" : [0, 0], @@ -25,8 +44,10 @@ "horizon" : [3, 0], "pass" : false, "data" : {} - }, - "East" : { + } + }, + { + "North" : { "ceiling" : [0, 2], "floor" : [0, 2], "l_wall" : [4, 0], @@ -35,17 +56,35 @@ "pass" : false, "data" : {} }, - "West" : { - "ceiling" : [0, 2], - "floor" : [0, 2], - "l_wall" : [4, 0], - "r_wall" : [4, 0], - "horizon" : [2, 4], + "South" : { + "ceiling" : [0, 0], + "floor" : [0, 1], + "l_wall" : [0, 0], + "r_wall" : [2, 0], + "horizon" : [2, 3], "pass" : false, "data" : {} + }, + "East" : { + "ceiling" : [2, 0], + "floor" : [2, 1], + "l_wall" : [0, 0], + "r_wall" : [3, 0], + "horizon" : [0, 4], + "pass" : false, + "data" : {} + }, + "West" : { + "ceiling" : [0, 0], + "floor" : [0, 1], + "l_wall" : [0, 0], + "r_wall" : [2, 0], + "horizon" : [2, 0], + "pass" : true, + "data" : {} } }, - null, null, null], + null, null], [null, null, null, null], [null, null, null, null], [null, null, null, null] diff --git a/data/images/dungeon1_fc.png b/data/images/dungeon1_fc.png Binary files differ. diff --git a/data/images/dungeon1_h.png b/data/images/dungeon1_h.png Binary files differ. diff --git a/src/board.py b/src/board.py @@ -220,7 +220,7 @@ class Board(object): self.game.spawn_player(self.game.party[self.game.player_name], tuple(event["cell"]), tuple(event["tile"])) elif event["type"] == "enterdungeon": self.game.switch_mode(STATE_MODES.Dungeon_Mode) - self.game.switch_dungeon(event["dungeon"], event["direction"], event["floor"], tuple(event["cell"])) + self.game.switch_dungeon(event["dungeon"], True, event["direction"], event["floor"], tuple(event["cell"])) def execute_npc_turns(self, time): """ 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, disp_str, width, height, sheetname, entrance, layout): + def __init__(self, game, name, disp_str, width, height, sheetname, enter_dir, entrance, layout): # Saved vals self.game = game @@ -28,7 +28,8 @@ class Dungeon(object): self.maze_width = width self.maze_height = height self.sheetname = sheetname - self.entrance = entrance + self.entrance_direction = enter_dir + self.entrance_cell = entrance self.layout_definition = layout # Other vals @@ -54,6 +55,15 @@ class Dungeon(object): """ Move to the forward cell if possible. """ + # Setup + workcell = self.layout_definition[self.current_floor][self.current_cell[1]][self.current_cell[0]][DIRECTIONS[self.direction]] + newcell = (self.current_cell[0] + DIRMOVE[self.direction][0], self.current_cell[1] + DIRMOVE[self.direction][1]) + + # Check if we can go there and if it exists, and if so, change cell + if workcell["pass"] and newcell[1] >= 0 and newcell[1] < self.maze_height and newcell[0] >= 0 and newcell[0] < self.maze_width: + self.current_cell = newcell + + # Refresh the view self.construct_dungeon_view() def rotate_direction(self, mod = 1): diff --git a/src/game.py b/src/game.py @@ -136,7 +136,7 @@ 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["display_name"], dungeondef["width"], dungeondef["height"], dungeondef["sheet"], tuple(dungeondef["entrance"]), dungeondef["layout"]) + nd = dungeon.Dungeon(self, d, dungeondef["display_name"], dungeondef["width"], dungeondef["height"], dungeondef["sheet"], dungeondef["direction"], tuple(dungeondef["entrance"]), dungeondef["layout"]) self.loaded_dungeons[d] = nd def build_ui(self): @@ -164,13 +164,17 @@ class Game(object): else: return 1 - def switch_dungeon(self, dungeonname, direction = 0, floor = 0, cell = (0, 0)): + def switch_dungeon(self, dungeonname, enter = False, direction = 0, floor = 0, cell = (0, 0)): """ Switch to the given dungeon and go to the given floor, facing the given direction, and in the given cell. """ if dungeonname in self.loaded_dungeons.keys(): + if enter: + direction = self.loaded_dungeons[dungeonname].entrance_direction + floor = 0 + cell = self.loaded_dungeons[dungeonname].entrance_cell self.current_dungeon = self.loaded_dungeons[dungeonname] self.current_dungeon.enter_dungeon(direction, floor, cell) self.collect_game_data() @@ -462,7 +466,7 @@ class Game(object): # Load a dungeon elif saveraw["at"]["type"] == "dungeon": - self.switch_dungeon(saveraw["at"]["data"]["dungeon"], saveraw["at"]["data"]["direction"], saveraw["at"]["data"]["floor"], tuple(saveraw["at"]["data"]["cell"])) + self.switch_dungeon(saveraw["at"]["data"]["dungeon"], False, saveraw["at"]["data"]["direction"], saveraw["at"]["data"]["floor"], tuple(saveraw["at"]["data"]["cell"])) # Pass time up self.pass_time(saveraw["gametime"], False) diff --git a/src/gamelib.py b/src/gamelib.py @@ -63,7 +63,8 @@ OVERHEAD_MODES = [STATE_MODES.Location_Mode, STATE_MODES.Overworld_Mode] BOARD_TYPES = enum.Enum("BOARD_TYPES", "Location Overworld") # Other series -DIRECTIONS = ["North", "East", "South", "West"] +DIRECTIONS = ("North", "East", "South", "West") +DIRMOVE = ((0, -1), (1, 0), (0, 1), (-1, 0)) ####################### # Section 2 - Classes #