World gen doors and walls
authorStan_Lewry <stanley.jml@gmail.com>
Tue, 20 Jul 2021 17:01:39 +0000 (18:01 +0100)
committerStan_Lewry <stanley.jml@gmail.com>
Tue, 20 Jul 2021 17:01:39 +0000 (18:01 +0100)
Algorithm.py
InputHandler.py
Main.py
World.py
WorldGen.py
Writeup/worldgen_doors_and_walls.png [new file with mode: 0644]
Writeup/worldgen_walls.png [new file with mode: 0644]

index 627f22a..d47216f 100644 (file)
@@ -75,8 +75,8 @@ def line(x0, y0, x1, y1):
     if dx > dy:
         err = dx / 2.0
         while x != x1:
-            if x in range(0, World.worldWidth - 1) and y in range (0, World.worldHeight - 1) and not World.world[y][x].containsSolid():
-                World.world[y][x].visible = True
+            if x in range(0, World.worldWidth - 1) and y in range (0, World.worldHeight - 1) and not World.world[int(y)][int(x)].containsSolid():
+                World.world[int(y)][int(x)].visible = True
                 Debug.debugRects.append((x, y, (255, 0, 0)))
                 err -= dy
                 if err < 0:
@@ -88,8 +88,8 @@ def line(x0, y0, x1, y1):
     else:
         err = dy / 2.0
         while y != y1:
-            if x in range(0, World.worldWidth - 1) and y in range (0, World.worldHeight - 1) and not World.world[y][x].containsSolid():
-                World.world[y][x].visible = True
+            if x in range(0, World.worldWidth - 1) and y in range (0, World.worldHeight - 1) and not World.world[int(y)][int(x)].containsSolid():
+                World.world[int(y)][int(x)].visible = True
                 Debug.debugRects.append((x, y, (255, 0, 0)))
                 err -= dx
                 if err < 0:
@@ -98,5 +98,5 @@ def line(x0, y0, x1, y1):
                 y += sy        
             else:
                 break
-    World.world[y][x].visible = True
+    World.world[int(y)][int(x)].visible = True
     Debug.debugRects.append((x, y, (255, 0, 0)))
index 9a4340a..5d51aff 100644 (file)
@@ -13,7 +13,7 @@ class InputState:
     debugRegenWorld: bool = False
 
 maxZoom = 3.0
-minZoom = 1.0
+minZoom = 0.125
 maxDebugLevel = 2
 globalInputState = InputState()
 
@@ -38,9 +38,9 @@ def handleInputs():
             elif event.key in (pygame.K_d, pygame.K_RIGHT):
                 newInputState.xy = (1, 0)
             elif event.key == pygame.K_RIGHTBRACKET and newInputState.zoomLevel <= maxZoom:
-                newInputState.zoomLevel += 0.5
+                newInputState.zoomLevel += 0.125
             elif event.key == pygame.K_LEFTBRACKET and newInputState.zoomLevel >= minZoom:
-                newInputState.zoomLevel -= 0.5
+                newInputState.zoomLevel -= 0.125
             elif event.key == pygame.K_F3:
                 if newInputState.debugLevel < maxDebugLevel:
                     newInputState.debugLevel += 1
diff --git a/Main.py b/Main.py
index 9eaf236..8e7cf2e 100644 (file)
--- a/Main.py
+++ b/Main.py
@@ -34,7 +34,7 @@ def main():
 
         player.update()
         
-        #Algorithm.computeVisibility(player)
+        Algorithm.computeVisibility(player)
                 
         cam = (player.worldX, player.worldY)
         
index 39e45da..eac01ba 100644 (file)
--- a/World.py
+++ b/World.py
@@ -1,4 +1,4 @@
 
-worldWidth = 40
-worldHeight = 40
+worldWidth : int = 40
+worldHeight : int  = 40
 world = [[]]
\ No newline at end of file
index d685d52..3e77396 100644 (file)
@@ -34,7 +34,7 @@ def generateWorldGrowingRectangles(minMaxRooms, iterations):
         row = []
         for x in range(World.worldWidth):
             cell = GameObject.WorldCell()
-            cell.objects.append(GameObject.GameObject(x, y, "wall_side", False))
+            cell.objects.append(GameObject.GameObject(x, y, "wall_side", True))
             row.append(cell)
         outputWorld.insert(y, row)
 
@@ -154,6 +154,7 @@ def generateWorldGrowingRectangles(minMaxRooms, iterations):
     # paint generated rooms to output
     for r in rooms:
         debugCol = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
+        # draw the floor
         for y in range(len(r.cells)):
             for _, x in enumerate(r.cells[y]):
                 cell = GameObject.WorldCell()
@@ -161,4 +162,66 @@ def generateWorldGrowingRectangles(minMaxRooms, iterations):
                 outputWorld[x[1]][x[0]] = cell
                 Debug.worldGenDebugRects.append((x[0], x[1], debugCol))
 
+        # draw walls
+        #for i in r.cells[0]:
+        #    cell = GameObject.WorldCell()
+        #    cell.objects.append(GameObject.GameObject(i[0], i[1] - 1, "wall_vent", True))
+        #    outputWorld[i[1] - 1][i[0]] = cell
+
+        # generate doors
+        # NOTE this approach is BAD and LAZY and provides ABSOLOUTLY NO gaurentee that the map will be traversible :)
+        doorCount = random.randint(1, 6)
+        doors = []
+        for _ in range(doorCount):
+            doorDir = random.randint(0, 3)
+            if doorDir == 0:
+                # north
+                doorPos = random.randint(0, len(r.cells[0]) - 1)
+                doorCoords = (r.cells[0][doorPos][0], r.cells[0][doorPos][1] - 1)
+                if (doorCoords[0] < World.worldWidth - 1 and doorCoords[1] < World.worldHeight -1 and
+                    doorCoords[0] > 0 and doorCoords[1] > 0 and
+                    outputWorld[doorCoords[1] + 1][doorCoords[0]].objects[0].solid == False and
+                    outputWorld[doorCoords[1] - 1][doorCoords[0]].objects[0].solid == False):
+                    doors.append((r.cells[0][doorPos][0], r.cells[0][doorPos][1] - 1))
+            elif doorDir == 1:
+                # east
+                doorPos = random.randint(0, len(r.cells) - 1)
+                doorCoords = (r.cells[doorPos][-1][0] + 1, r.cells[doorPos][-1][1])
+                if (doorCoords[0] < World.worldWidth - 1 and doorCoords[1] < World.worldHeight -1 and
+                    doorCoords[0] > 0 and doorCoords[1] > 0 and
+                    outputWorld[doorCoords[1]][doorCoords[0] + 1].objects[0].solid == False and
+                    outputWorld[doorCoords[1]][doorCoords[0] - 1].objects[0].solid == False):
+                    doors.append((r.cells[doorPos][-1][0] + 1, r.cells[doorPos][-1][1]))
+            elif doorDir == 2:
+                # south
+                doorPos = random.randint(0, len(r.cells[-1]) - 1)
+                doorCoords = (r.cells[0][doorPos][0], r.cells[0][doorPos][1] + 1)
+                if (doorCoords[0] < World.worldWidth - 1 and doorCoords[1] < World.worldHeight -1 and
+                    doorCoords[0] > 0 and doorCoords[1] > 0 and
+                    outputWorld[doorCoords[1] + 1][doorCoords[0]].objects[0].solid == False and
+                    outputWorld[doorCoords[1] - 1][doorCoords[0]].objects[0].solid == False):
+                    doors.append((r.cells[0][doorPos][0], r.cells[0][doorPos][1] + 1))
+            elif doorDir == 3:
+                # west
+                doorPos = random.randint(0, len(r.cells) - 1)
+                doorCoords = (r.cells[doorPos][0][0] - 1, r.cells[doorPos][0][1])
+                if (doorCoords[0] < World.worldWidth - 1 and doorCoords[1] < World.worldHeight -1 and
+                    doorCoords[0] > 0 and doorCoords[1] > 0 and
+                    outputWorld[doorCoords[1]][doorCoords[0] + 1].objects[0].solid == False and
+                    outputWorld[doorCoords[1]][doorCoords[0] - 1].objects[0].solid == False):
+                    doors.append((r.cells[doorPos][0][0] - 1, r.cells[doorPos][0][1]))
+        
+        for door in doors:
+            cell = GameObject.WorldCell()
+            cell.objects.append(GameObject.GameObject(door[0], door[1], "floor_tile", False))
+            outputWorld[door[1]][door[0]] = cell
+
+        for y,_ in enumerate(outputWorld):
+            if 1 < y < World.worldHeight - 1:
+                for x,_ in enumerate(outputWorld[y]):
+                    if outputWorld[y][x].objects[0].solid == True and outputWorld[y + 1][x].objects[0].solid == False:
+                        cell = GameObject.WorldCell()
+                        cell.objects.append(GameObject.GameObject(x, y, "wall_vent", True))
+                        outputWorld[y][x] = cell
+
     return outputWorld
diff --git a/Writeup/worldgen_doors_and_walls.png b/Writeup/worldgen_doors_and_walls.png
new file mode 100644 (file)
index 0000000..0ad9701
Binary files /dev/null and b/Writeup/worldgen_doors_and_walls.png differ
diff --git a/Writeup/worldgen_walls.png b/Writeup/worldgen_walls.png
new file mode 100644 (file)
index 0000000..128c680
Binary files /dev/null and b/Writeup/worldgen_walls.png differ