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:
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:
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)))
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)
# 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()
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