Fixed bug with front door placement
This commit is contained in:
@@ -13,25 +13,30 @@ var room = preload("res://scenes/maps/interior2.tscn")
|
||||
var bed = preload("res://scenes/furniture/bed.tscn")
|
||||
var table_chairs = preload("res://scenes/furniture/table_chairs.tscn")
|
||||
var closet = preload("res://scenes/furniture/closet.tscn")
|
||||
var size_x = 3
|
||||
var size_y = 3
|
||||
var floors = 6
|
||||
var size_x = 2
|
||||
var size_y = 2
|
||||
var floors = 2
|
||||
var w = 10
|
||||
var h = 8
|
||||
var dungeon = []
|
||||
var dungeon_save = {}
|
||||
var spawn_save = {}
|
||||
var prepared = false
|
||||
var map = []
|
||||
var exit_doors = []
|
||||
var stairs_x = 0
|
||||
var stairs_y = 0
|
||||
func save():
|
||||
for k in range(dungeon.size()):
|
||||
dungeon[k].save()
|
||||
dungeon_save[str(k)] = dungeon[k].save_data
|
||||
global.save_data.dungeon = dungeon_save
|
||||
var window_rooms = []
|
||||
var doors = {}
|
||||
func build_rooms():
|
||||
print("build_rooms")
|
||||
var stairs_x = randi() % size_x
|
||||
var stairs_y = randi() % size_y
|
||||
stairs_x = randi() % size_x
|
||||
stairs_y = randi() % size_y
|
||||
|
||||
for k in range(floors):
|
||||
var cur_x = stairs_x
|
||||
@@ -41,38 +46,23 @@ func build_rooms():
|
||||
var visited = []
|
||||
while cur_room:
|
||||
var choice = randi() % 4
|
||||
match(choice):
|
||||
0:
|
||||
if cur_x > 0:
|
||||
cur_room.open_path(cur_room.OPEN_LEFT)
|
||||
cur_x -= 1
|
||||
1:
|
||||
if cur_x < size_x - 1:
|
||||
cur_room.open_path(cur_room.OPEN_RIGHT)
|
||||
cur_x += 1
|
||||
2:
|
||||
if cur_y > 0:
|
||||
cur_room.open_path(cur_room.OPEN_UP)
|
||||
cur_y -= 1
|
||||
3:
|
||||
if cur_y < size_y - 1:
|
||||
cur_room.open_path(cur_room.OPEN_DOWN)
|
||||
cur_y += 1
|
||||
if !cur_room in visited:
|
||||
visited.push_back(cur_room)
|
||||
cur_room = dungeon[k * size_x * size_y + cur_y * size_x + cur_x]
|
||||
match(choice):
|
||||
0:
|
||||
cur_room.open_path(cur_room.OPEN_RIGHT)
|
||||
1:
|
||||
cur_room.open_path(cur_room.OPEN_LEFT)
|
||||
2:
|
||||
cur_room.open_path(cur_room.OPEN_DOWN)
|
||||
3:
|
||||
cur_room.open_path(cur_room.OPEN_UP)
|
||||
# print(cur_x, " ", cur_y)
|
||||
if visited.size() == size_x * size_y:
|
||||
break
|
||||
var sel = [cur_room.OPEN_LEFT, cur_room.OPEN_RIGHT, cur_room.OPEN_UP, cur_room.OPEN_DOWN]
|
||||
var rsel = [cur_room.OPEN_RIGHT, cur_room.OPEN_LEFT, cur_room.OPEN_DOWN, cur_room.OPEN_UP]
|
||||
var selx = [-1, 1, 0, 0]
|
||||
var sely = [0, 0, -1, 1]
|
||||
var nx = cur_x + selx[choice]
|
||||
var ny = cur_y + sely[choice]
|
||||
if nx >= 0 && nx < size_x && ny >= 0 && ny < size_y:
|
||||
cur_room.open_path(sel[choice])
|
||||
if !cur_room in visited:
|
||||
visited.push_back(cur_room)
|
||||
var old_room = cur_room
|
||||
cur_x = nx
|
||||
cur_y = ny
|
||||
cur_room = dungeon[k * size_x * size_y + cur_y * size_x + cur_x]
|
||||
cur_room.open_path(rsel[choice])
|
||||
if visited.size() == size_x * size_y:
|
||||
break
|
||||
print("base rooms done")
|
||||
for fl in range(floors):
|
||||
for k in range(size_x):
|
||||
@@ -89,11 +79,41 @@ func build_rooms():
|
||||
dungeon[right].open_window(dungeon[right].OPEN_RIGHT)
|
||||
window_rooms.push_back(left)
|
||||
window_rooms.push_back(right)
|
||||
|
||||
func build_exits():
|
||||
var street_exits = []
|
||||
while street_exits.size() == 0:
|
||||
var fl = 0
|
||||
for k in range(size_x):
|
||||
var up = fl * size_x * size_y + k
|
||||
var down = fl * size_x * size_y + (size_y - 1) * size_x + k
|
||||
for h in [up, down]:
|
||||
print(h)
|
||||
if street_exits.size() < 1:
|
||||
if dungeon[h].has_meta("master_room"):
|
||||
continue
|
||||
if randf() > 0.7:
|
||||
var d = dungeon[h].OPEN_UP if h == up else dungeon[h].OPEN_DOWN
|
||||
dungeon[h].outside_doors.push_back(d)
|
||||
dungeon[h].set_meta("exit_room", true)
|
||||
print("exit room: ", h)
|
||||
street_exits.push_back(h)
|
||||
for k in range(size_y):
|
||||
var left = fl * size_x * size_y + k * size_x
|
||||
var right = fl * size_x * size_y + k * size_x + size_x - 1
|
||||
for h in [left, right]:
|
||||
print(h)
|
||||
if street_exits.size() < 1:
|
||||
if dungeon[h].has_meta("master_room"):
|
||||
continue
|
||||
if randf() > 0.7:
|
||||
var d = dungeon[h].OPEN_LEFT if h == left else dungeon[h].OPEN_RIGHT
|
||||
dungeon[h].outside_doors.push_back(d)
|
||||
dungeon[h].set_meta("exit_room", true)
|
||||
print("exit room: ", h)
|
||||
street_exits.push_back(h)
|
||||
print("rooms build complete")
|
||||
var special_rooms = {
|
||||
"exit_room": {
|
||||
"alloc": size_x * size_y
|
||||
},
|
||||
"master_room": {
|
||||
"alloc": floors * size_x * size_y
|
||||
},
|
||||
@@ -106,6 +126,10 @@ var special_rooms = {
|
||||
}
|
||||
func alloc_special_rooms():
|
||||
var allocated = []
|
||||
for e in range(floors):
|
||||
var id = e * size_x * size_y + stairs_y * size_x + stairs_x
|
||||
allocated.push_back(id)
|
||||
dungeon[id].set_meta("stairs", e)
|
||||
for k in special_rooms.keys():
|
||||
if special_rooms[k].has("id"):
|
||||
allocated.push_back(special_rooms[k].id)
|
||||
@@ -126,8 +150,6 @@ func alloc_special_rooms():
|
||||
dungeon[room_id].add_child(player_spawn)
|
||||
player_spawn.name = "player-spawn"
|
||||
player_spawn.add_to_group("spawn")
|
||||
if k == "exit_room":
|
||||
print("exit room: ", room_id)
|
||||
|
||||
func build_special_rooms():
|
||||
print("build_special_rooms")
|
||||
@@ -163,22 +185,30 @@ func _process(_delta):
|
||||
if dungeon_save.empty():
|
||||
state = 20
|
||||
else:
|
||||
state = 30
|
||||
state = 40
|
||||
20:
|
||||
print("build rooms")
|
||||
build_rooms()
|
||||
state = 21
|
||||
21:
|
||||
print("build special rooms")
|
||||
build_special_rooms()
|
||||
state = 22
|
||||
22:
|
||||
state = 31
|
||||
31:
|
||||
print("build exits")
|
||||
build_exits()
|
||||
state = 32
|
||||
32:
|
||||
print("build room nodes")
|
||||
for r in dungeon:
|
||||
r.create_rooms()
|
||||
assert(global.exit_door)
|
||||
state = 23
|
||||
23:
|
||||
exit_doors = get_tree().get_nodes_in_group("exit_door")
|
||||
state = 33
|
||||
33:
|
||||
print("spawn furniture")
|
||||
furniture_nodes = get_tree().get_nodes_in_group("furniture")
|
||||
state = 24
|
||||
24:
|
||||
state = 34
|
||||
34:
|
||||
if furniture_nodes.size() > 0:
|
||||
var k = furniture_nodes.pop_front()
|
||||
if k.name.begins_with("fc"):
|
||||
@@ -200,19 +230,19 @@ func _process(_delta):
|
||||
k.rotate_y(randf() * PI / 24.0)
|
||||
else:
|
||||
save()
|
||||
state = 40
|
||||
30:
|
||||
state = 50
|
||||
40:
|
||||
dungeon_ids = range(dungeon.size())
|
||||
state = 31
|
||||
31:
|
||||
state = 41
|
||||
41:
|
||||
if dungeon_ids.size() > 0:
|
||||
var k = dungeon_ids.pop_front()
|
||||
dungeon[k].save_data = dungeon_save[str(k)]
|
||||
dungeon[k].restore()
|
||||
else:
|
||||
state = 40
|
||||
40:
|
||||
state = 50
|
||||
50:
|
||||
print("loaded")
|
||||
state = 50
|
||||
state = 60
|
||||
prepared = true
|
||||
emit_signal("prepared")
|
||||
|
||||
Reference in New Issue
Block a user