commit ba95489ce4eef6483c5f387bead479ba91dfb00b
parent 8eaeb5d84aad230dbcc7dd5e9b8dcaaa093d47b1
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Sat, 11 Sep 2021 15:02:51 -0500
can now move in reverse in dungeons
Diffstat:
5 files changed, 106 insertions(+), 16 deletions(-)
diff --git a/data/dungeons/testdun1/dungeon.json b/data/dungeons/testdun1/dungeon.json
@@ -12,9 +12,9 @@
"North" : {
"ceiling" : [0, 2],
"floor" : [0, 2],
- "l_wall" : [4, 0],
+ "l_wall" : [0, 0],
"r_wall" : [4, 0],
- "horizon" : [2, 4],
+ "horizon" : [0, 4],
"pass" : false,
"data" : {}
},
@@ -22,8 +22,8 @@
"ceiling" : [0, 2],
"floor" : [0, 2],
"l_wall" : [4, 0],
- "r_wall" : [4, 0],
- "horizon" : [2, 4],
+ "r_wall" : [2, 0],
+ "horizon" : [1, 4],
"pass" : false,
"data" : {}
},
@@ -32,7 +32,7 @@
"floor" : [0, 1],
"l_wall" : [0, 0],
"r_wall" : [2, 0],
- "horizon" : [2, 1],
+ "horizon" : [3, 1],
"pass" : true,
"data" : {}
},
@@ -51,8 +51,8 @@
"ceiling" : [0, 2],
"floor" : [0, 2],
"l_wall" : [4, 0],
- "r_wall" : [4, 0],
- "horizon" : [2, 4],
+ "r_wall" : [2, 0],
+ "horizon" : [1, 4],
"pass" : false,
"data" : {}
},
@@ -62,7 +62,7 @@
"l_wall" : [0, 0],
"r_wall" : [2, 0],
"horizon" : [2, 3],
- "pass" : false,
+ "pass" : true,
"data" : {}
},
"East" : {
@@ -75,17 +75,97 @@
"data" : {}
},
"West" : {
+ "ceiling" : [1, 0],
+ "floor" : [1, 1],
+ "l_wall" : [1, 0],
+ "r_wall" : [2, 0],
+ "horizon" : [2, 0],
+ "pass" : true,
+ "data" : {}
+ }
+ },
+ null,
+ {
+ "North" : {
+ "ceiling" : [0, 2],
+ "floor" : [0, 2],
+ "l_wall" : [4, 0],
+ "r_wall" : [4, 0],
+ "horizon" : [2, 4],
+ "pass" : false,
+ "data" : {}
+ },
+ "South" : {
"ceiling" : [0, 0],
"floor" : [0, 1],
"l_wall" : [0, 0],
"r_wall" : [2, 0],
- "horizon" : [2, 0],
+ "horizon" : [1, 1],
"pass" : true,
"data" : {}
+ },
+ "East" : {
+ "ceiling" : [0, 0],
+ "floor" : [0, 1],
+ "l_wall" : [0, 0],
+ "r_wall" : [2, 0],
+ "horizon" : [3, 0],
+ "pass" : false,
+ "data" : {}
+ },
+ "West" : {
+ "ceiling" : [1, 0],
+ "floor" : [1, 1],
+ "l_wall" : [1, 0],
+ "r_wall" : [2, 0],
+ "horizon" : [1, 4],
+ "pass" : false,
+ "data" : {}
+ }
+ }
+ ],
+ [
+ null,
+ {
+ "North" : {
+ "ceiling" : [0, 0],
+ "floor" : [0, 1],
+ "l_wall" : [0, 0],
+ "r_wall" : [2, 0],
+ "horizon" : [1, 1],
+ "pass" : true,
+ "data" : {}
+ },
+ "South" : {
+ "ceiling" : [0, 0],
+ "floor" : [0, 1],
+ "l_wall" : [0, 0],
+ "r_wall" : [2, 0],
+ "horizon" : [3, 6],
+ "pass" : false,
+ "data" : {}
+ },
+ "East" : {
+ "ceiling" : [0, 2],
+ "floor" : [0, 2],
+ "l_wall" : [4, 0],
+ "r_wall" : [4, 0],
+ "horizon" : [2, 4],
+ "pass" : false,
+ "data" : {}
+ },
+ "West" : {
+ "ceiling" : [0, 2],
+ "floor" : [0, 2],
+ "l_wall" : [4, 0],
+ "r_wall" : [4, 0],
+ "horizon" : [2, 4],
+ "pass" : false,
+ "data" : {}
}
},
- null, null],
- [null, null, null, null],
+ null,
+ null],
[null, null, null, null],
[null, null, null, null]
]
diff --git a/data/images/dungeon1_h.png b/data/images/dungeon1_h.png
Binary files differ.
diff --git a/src/dungeon.py b/src/dungeon.py
@@ -51,16 +51,20 @@ class Dungeon(object):
self.current_cell = cell
self.construct_dungeon_view()
- def move_forward(self):
+ def move_forward(self, reverse = False):
"""
Move to the forward cell if possible.
"""
# Setup
+ d = DIRMOVE
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])
+ if reverse:
+ d = REVMOVE
+ workcell = self.layout_definition[self.current_floor][self.current_cell[1]][self.current_cell[0]][REVERSES[self.direction]]
+ newcell = (self.current_cell[0] + d[self.direction][0], self.current_cell[1] + d[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:
+ if workcell["pass"] and newcell[1] >= 0 and newcell[1] < self.maze_height and newcell[0] >= 0 and newcell[0] < self.maze_width and self.layout_definition[self.current_floor][newcell[1]][newcell[0]] != None:
self.current_cell = newcell
# Refresh the view
@@ -91,10 +95,10 @@ class Dungeon(object):
workcell = self.layout_definition[self.current_floor][self.current_cell[1]][self.current_cell[0]][DIRECTIONS[self.direction]]
# Add the individual components
- self.dungeon_view.add(DungeonSprite(self.game.sheets[self.sheetname + "_w"].sprites[tuple(workcell["l_wall"])], self.game.viewport_rect.topleft))
- self.dungeon_view.add(DungeonSprite(self.game.sheets[self.sheetname + "_w"].sprites[tuple(workcell["r_wall"])], (self.game.viewport_rect.topleft[0] + 462, self.game.viewport_rect.topleft[1])))
self.dungeon_view.add(DungeonSprite(self.game.sheets[self.sheetname + "_fc"].sprites[tuple(workcell["ceiling"])], self.game.viewport_rect.topleft))
self.dungeon_view.add(DungeonSprite(self.game.sheets[self.sheetname + "_fc"].sprites[tuple(workcell["floor"])], (self.game.viewport_rect.topleft[0], self.game.viewport_rect.topleft[1] + 347)))
+ self.dungeon_view.add(DungeonSprite(self.game.sheets[self.sheetname + "_w"].sprites[tuple(workcell["l_wall"])], self.game.viewport_rect.topleft))
+ self.dungeon_view.add(DungeonSprite(self.game.sheets[self.sheetname + "_w"].sprites[tuple(workcell["r_wall"])], (self.game.viewport_rect.topleft[0] + 462, self.game.viewport_rect.topleft[1])))
self.dungeon_view.add(DungeonSprite(self.game.sheets[self.sheetname + "_h"].sprites[tuple(workcell["horizon"])], (self.game.viewport_rect.center[0] - 121, self.game.viewport_rect.center[1] - 91)))
def update_dungeon(self, surface = None):
diff --git a/src/gamelib.py b/src/gamelib.py
@@ -64,7 +64,9 @@ BOARD_TYPES = enum.Enum("BOARD_TYPES", "Location Overworld")
# Other series
DIRECTIONS = ("North", "East", "South", "West")
+REVERSES = ("South", "West", "North", "East")
DIRMOVE = ((0, -1), (1, 0), (0, 1), (-1, 0))
+REVMOVE = ((0, 1), (-1, 0), (0, -1), (1, 0))
#######################
# Section 2 - Classes #
diff --git a/src/interface.py b/src/interface.py
@@ -90,6 +90,10 @@ class Interface(object):
elif k in CONTROLS["down"]:
if self.game.state_mode in OVERHEAD_MODES:
self.game.move_player_on_board((0, 1))
+ 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()
for j in CONTROLS["down"]:
self.key_bools[j] = False
return