03 - first try of hallways - still buggy
This commit is contained in:
parent
71641a8ea7
commit
8ab65eb96a
1 changed files with 47 additions and 1 deletions
48
03_map.py
48
03_map.py
|
@ -92,11 +92,15 @@ class Room:
|
|||
for x in range(0, self.width):
|
||||
tilemap[self.x + x][self.y + self.height - 1] = Level.TILE_WALL
|
||||
|
||||
def center(self):
|
||||
return round(self.x + self.width/2), round(self.y + self.height/2)
|
||||
|
||||
|
||||
class Level:
|
||||
TILE_WALL = 0
|
||||
TILE_ROAD = 1
|
||||
TILE_GROUND = 2
|
||||
TILE_HALLWAY = 3
|
||||
|
||||
def __init__(self, sizex, sizey, tile_file=None):
|
||||
self.sizex, self.sizey = sizex, sizey
|
||||
|
@ -164,11 +168,13 @@ class Level:
|
|||
self.tree = self.generate_tree()
|
||||
|
||||
# initialize tilemap with road/ground
|
||||
self.tilemap = [[self.TILE_ROAD for y in range(0, self.sizey)] for x in range(0, self.sizex)]
|
||||
self.tilemap = [[self.TILE_GROUND for y in range(0, self.sizey)] for x in range(0, self.sizex)]
|
||||
|
||||
# create rooms from partitions
|
||||
self.rooms = self.generate_rooms(self.tree[0], self.tilemap, [])
|
||||
|
||||
self.generate_hallways()
|
||||
|
||||
def draw_map(self):
|
||||
for y in range(0, self.sizey):
|
||||
for x in range(0, self.sizex):
|
||||
|
@ -180,6 +186,46 @@ class Level:
|
|||
print(self.tilemap[x][y], end="")
|
||||
print("")
|
||||
|
||||
def generate_hallways(self):
|
||||
""" """
|
||||
if len(self.rooms) < 2:
|
||||
# out of luck ?
|
||||
return
|
||||
|
||||
room_a = self.rooms[0]
|
||||
for r in self.rooms[1:]:
|
||||
room_b = r
|
||||
self.generate_hallway(room_a, room_b)
|
||||
room_a = room_b
|
||||
|
||||
def generate_hallway(self, room_a, room_b):
|
||||
""" """
|
||||
print("hallway between room" + str(room_a.id) + " and room " + str(room_b.id))
|
||||
(xa, ya) = room_a.center()
|
||||
(xb, yb) = room_b.center()
|
||||
|
||||
# horizontal part
|
||||
if xa < xb:
|
||||
start_x = xa
|
||||
end_x = xb
|
||||
else:
|
||||
start_x = xb
|
||||
end_x = xa
|
||||
print("h_hw form " + str(start_x) + " and " + str(end_x))
|
||||
for x in range(start_x, end_x):
|
||||
self.tilemap[x][ya] = self.TILE_ROAD
|
||||
|
||||
# vertical part
|
||||
if ya < yb:
|
||||
start_y = ya
|
||||
end_y = yb
|
||||
else:
|
||||
start_y = yb
|
||||
end_y = ya
|
||||
print("v_hw form " + str(start_y) + " and " + str(end_y))
|
||||
for y in range(start_y, end_y):
|
||||
self.tilemap[end_x][y] = self.TILE_ROAD
|
||||
|
||||
|
||||
##
|
||||
# main
|
||||
|
|
Loading…
Reference in a new issue