2 Commits

Author SHA1 Message Date
Segey Lapin
153878d792 Interior algorithm taking its shape 2020-04-19 04:20:13 +03:00
Segey Lapin
b7a9e2e0b2 Fixed bug with front door placement 2020-04-16 09:50:31 +03:00
18 changed files with 3215 additions and 162 deletions

View File

@@ -5,8 +5,7 @@ var raycasts_count = 100
var raycast_queue = []
var astar: AStar
# Need to make more generic
var exit_door: Node
var interior
func _ready():
set_save_slot(0)
@@ -35,6 +34,7 @@ func update_time(delta):
if game_hour == 24:
game_hour = 0
game_day += 1
emit_signal("new_day")
match(game_hour):
23,0,1,2,3:
day_period = periods.NIGHT

View File

@@ -159,7 +159,7 @@ class ObjectiveWalkto extends QuestObjective:
return save_data
func _ready():
pass
set_process(false)
func check_trigger(t):
@@ -201,13 +201,15 @@ func create_objective(v):
var o_title = v[1]
var o_desc = v[2]
var o_radius = v[3]
var where = global.exit_door.global_transform.origin
var where = global.interior.exit_doors[0].global_transform.origin
var obj = ObjectiveWalkto.new(o_title, o_desc, where, o_radius)
return obj
return null
var up_time = 0.0
var state: int = 0
func activate():
set_process(true)
func _process(delta):
up_time += delta
if up_time > 1000.0:

View File

@@ -0,0 +1,459 @@
extends Spatial
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var wall = preload("res://scenes/maps/wall.escn")
var window = preload("res://scenes/maps/window.tscn")
var door = preload("res://scenes/maps/door.tscn")
var entry = preload("res://scenes/maps/door-outside.tscn")
var fl = preload("res://scenes/maps/floor.escn")
const FLAG_WALL_LEFT = (1 << 0)
const FLAG_WALL_UP = (1 << 1)
const FLAG_WALL_RIGHT = (1 << 2)
const FLAG_WALL_DOWN = (1 << 3)
const FLAG_FLOOR = (1 << 4)
const FLAG_ENTRY_LEFT = (1 << 5)
const FLAG_ENTRY_UP = (1 << 6)
const FLAG_ENTRY_RIGHT = (1 << 7)
const FLAG_ENTRY_DOWN = (1 << 8)
const FLAG_WINDOW_LEFT = (1 << 9)
const FLAG_WINDOW_UP = (1 << 10)
const FLAG_WINDOW_RIGHT = (1 << 11)
const FLAG_WINDOW_DOWN = (1 << 12)
const FLAG_DOOR_LEFT = (1 << 13)
const FLAG_DOOR_UP = (1 << 14)
const FLAG_DOOR_RIGHT = (1 << 15)
const FLAG_DOOR_DOWN = (1 << 16)
const FLAG_WALL_MASK = (FLAG_WALL_LEFT | FLAG_WALL_UP | FLAG_WALL_RIGHT | FLAG_WALL_DOWN)
const FLAG_ENTRY_MASK = (FLAG_ENTRY_LEFT | FLAG_ENTRY_UP | FLAG_ENTRY_RIGHT | FLAG_ENTRY_DOWN)
const FLAG_WINDOW_MASK = (FLAG_WINDOW_LEFT | FLAG_WINDOW_UP | FLAG_WINDOW_RIGHT | FLAG_WINDOW_DOWN)
const FLAG_DOOR_MASK = (FLAG_DOOR_LEFT | FLAG_DOOR_UP | FLAG_DOOR_RIGHT | FLAG_DOOR_DOWN)
const FLAG_LEFT_MASK = (FLAG_WALL_LEFT | FLAG_ENTRY_LEFT | FLAG_WINDOW_LEFT | FLAG_DOOR_LEFT)
const FLAG_UP_MASK = (FLAG_WALL_UP | FLAG_ENTRY_UP | FLAG_WINDOW_UP | FLAG_DOOR_UP)
const FLAG_RIGHT_MASK = (FLAG_WALL_RIGHT | FLAG_ENTRY_RIGHT | FLAG_WINDOW_RIGHT | FLAG_DOOR_RIGHT)
const FLAG_DOWN_MASK = (FLAG_WALL_DOWN | FLAG_ENTRY_DOWN | FLAG_WINDOW_DOWN | FLAG_DOOR_DOWN)
# Called when the node enters the scene tree for the first time.
var rnd: RandomNumberGenerator
var contour = [
Vector2(-10, -10), Vector2(-8, -10), Vector2(-8, -8), Vector2(-6, -8), Vector2(-6, -10),
Vector2(10, -10), Vector2(10, -8), Vector2(8, -8), Vector2(8, -6), Vector2(10, -6),
Vector2(10, 10), Vector2(8, 10), Vector2(8, 8), Vector2(6, 8), Vector2(6, 10),
Vector2(-10, 10), Vector2(-10, 8), Vector2(-8, 8), Vector2(-8, 6), Vector2(-10, 6), Vector2(-15, 2),
]
var wall_length = 2.0
var grid_areas = []
var grid_walls = []
var grid_rect: = Rect2()
var grid_size = 2.0
var size_x:int = 0
var size_y:int = 0
var windows = []
var enterance
var spaces = [
"entry",
"window",
"corridoor"
]
var walls_tiles = []
#var adj = {
# "entry": ["hall"],
# "hall": ["hall1", "kitchen", "toilet1", "bathroom1", "hall2"],
#}
func init_grid():
$debug.begin(Mesh.PRIMITIVE_LINES)
for k in range(contour.size()):
var p1 = contour[k]
var p2 = contour[(k + 1) % contour.size()]
$debug.add_vertex(Vector3(p1.x, 3.0, p1.y))
$debug.add_vertex(Vector3(p2.x, 3.0, p2.y))
$debug.end()
for x in contour:
grid_rect = grid_rect.expand(x)
size_x = grid_rect.size.x / grid_size + 2
size_y = grid_rect.size.y / grid_size + 2
grid_areas.resize(size_x * size_y)
grid_walls.resize(size_x * size_y)
for t in range(size_x * size_y):
grid_areas[t] = 0
grid_walls[t] = 0
# for e in adj.keys():
# if !e in spaces:
# spaces.push_back(e)
var cur_pos: = Vector2()
func init_walls():
for y in range(size_y):
for x in range(size_x):
var point_flags = 0
var px = float(x) * grid_size + grid_rect.position.x - grid_size
var py = float(y) * grid_size + grid_rect.position.y - grid_size
var p0 = Vector2(px - 0.1, py - 0.1)
var p1 = Vector2(px - 0.1 + grid_size + 0.1, py)
var p2 = Vector2(px + grid_size + 0.1, py + grid_size + 0.1)
var p3 = Vector2(px - 0.1, py + grid_size + 0.1)
var p4 = p0 + Vector2(grid_size * 0.5, grid_size * 0.5) + Vector2(0.1, 0.1)
var p01 = p0.linear_interpolate(p1, 0.5)
var p12 = p1.linear_interpolate(p2, 0.5)
var p23 = p2.linear_interpolate(p3, 0.5)
var p30 = p3.linear_interpolate(p0, 0.5)
if Geometry.is_point_in_polygon(p0, PoolVector2Array(contour)):
point_flags |= 1
if Geometry.is_point_in_polygon(p1, PoolVector2Array(contour)):
point_flags |= 2
if Geometry.is_point_in_polygon(p2, PoolVector2Array(contour)):
point_flags |= 4
if Geometry.is_point_in_polygon(p3, PoolVector2Array(contour)):
point_flags |= 8
if Geometry.is_point_in_polygon(p4, PoolVector2Array(contour)):
point_flags |= 16
if Geometry.is_point_in_polygon(p01, PoolVector2Array(contour)):
point_flags |= 32
if Geometry.is_point_in_polygon(p12, PoolVector2Array(contour)):
point_flags |= 64
if Geometry.is_point_in_polygon(p23, PoolVector2Array(contour)):
point_flags |= 128
if Geometry.is_point_in_polygon(p30, PoolVector2Array(contour)):
point_flags |= 256
if point_flags == 0:
grid_areas[y * size_x + x] = 0xffff
else:
grid_areas[y * size_x + x] = 0
grid_walls[y * size_x + x] = point_flags
func convert_walls():
$debug.begin(Mesh.PRIMITIVE_LINES)
for y in range(size_y):
for x in range(size_x):
var left = false
var right = false
var up = false
var down = false
var f = false
var point_flags = grid_walls[y * size_x + x]
var px = float(x) * grid_size + grid_rect.position.x - grid_size
var py = float(y) * grid_size + grid_rect.position.y - grid_size
var p0 = Vector2(px, py)
var p1 = Vector2(px + grid_size, py)
var p2 = Vector2(px + grid_size, py + grid_size)
var p3 = Vector2(px, py + grid_size)
$debug.add_vertex(Vector3(p0.x, 0.1, p0.y))
$debug.add_vertex(Vector3(p1.x, 0.1, p1.y))
$debug.add_vertex(Vector3(p1.x, 0.1, p1.y))
$debug.add_vertex(Vector3(p2.x, 0.1, p2.y))
$debug.add_vertex(Vector3(p2.x, 0.1, p2.y))
$debug.add_vertex(Vector3(p3.x, 0.1, p3.y))
$debug.add_vertex(Vector3(p3.x, 0.1, p3.y))
$debug.add_vertex(Vector3(p0.x, 0.1, p0.y))
match(point_flags):
0x1ff:
f = true
0x01, 0x02, 0x4, 0x08, 0x108, 0x84, 0x8c, 0x88, 0x0, 0x22, 0x23, 0x21, 0x046:
f = false
0x109, 0x101, 0x12b, 0x18d, 0x042, 0x06, 0xe4, 0x67, 0x40, 0x64, 0xc6:
f = false
0x80, 0xc, 0x1ce, 0x100, 0x1a9, 0x9, 0x161, 0x3, 0x20:
f = false
0xd6, 0xde:
f = true
up = true
left = true
0x19c, 0x1de, 0x1df, 0x1da:
f = true
up = true
0x19a, 0x19b, 0x198:
f = true
up = true
right = true
0xf4, 0xf6, 0xf7, 0xff, 0xfe, 0x1fe:
f = true
left = true
0x1b3, 0x1bb, 0x1bf, 0x199, 0x1bd, 0x1b9:
f = true
right = true
0x1fd, 0x1fb, 0x1f7, 0x1f6:
f = true
0x72, 0x76:
f = true
left = true
down = true
0x73, 0x152, 0x173, 0x17b, 0x177, 0x172, 0x17f:
f = true
down = true
0x131, 0x133, 0x139:
f = true
right = true
down = true
0x52, 0x56:
f = true
down = true
up = true
left = true
0x96:
f = true
left = true
right = true
up = true
0x11a, 0x110:
f = true
up = true
right = true
down = true
0x33:
f = true
left = true
right = true
down = true
_:
if point_flags & 0x10 != 0:
print("%03x" % (point_flags))
else:
print("skip %03x" % (point_flags))
if up:
if y > 0:
if grid_walls[(y - 1) * size_x + x] & 16 != 0:
up = false
if down:
if y < size_y - 1:
if grid_walls[(y + 1) * size_x + x] & 16 != 0:
down = false
if left:
if x > 0:
if grid_walls[y * size_x + x - 1] & 16 != 0:
left = false
if right:
if x < size_x - 1:
if grid_walls[y * size_x + x + 1] & 16 != 0:
right = false
if !up && f:
if y > 0:
if grid_walls[(y - 1) * size_x + x] & 16 == 0:
up = true
if !down && f:
if y < size_y - 1:
if grid_walls[(y + 1) * size_x + x] & 16 == 0:
down = true
if !left && f:
if x > 0:
if grid_walls[y * size_x + x - 1] & 16 == 0:
left = true
if !right && f:
if x < size_x - 1:
if grid_walls[y * size_x + x + 1] & 16 == 0:
right = true
point_flags = 0
if left:
point_flags |= 1
if up:
point_flags |= 2
if right:
point_flags |= 4
if down:
point_flags |= 8
if f:
point_flags |= 16
grid_walls[y * size_x + x] = point_flags
if point_flags & 0xf != 0:
walls_tiles.push_back(y * size_x + x)
$debug.end()
func create_entry_door():
var tile = walls_tiles[rnd.randi() % walls_tiles.size()]
var point_flags = grid_walls[tile]
var flags = [
[1, 32],
[2, 64],
[4, 128],
[8, 256]
]
var rflags = []
for p in flags:
if point_flags & p[0] != 0:
rflags.push_back(p)
var f = rflags[rnd.randi() % rflags.size()]
point_flags &= ~f[0]
point_flags |= f[1]
grid_walls[tile] = point_flags
func create_windows(pwindow: float):
for tile in walls_tiles:
var point_flags = grid_walls[tile]
var flags = [
[1, 512],
[2, 1024],
[4, 2048],
[8, 4096]
]
var rflags = []
for p in flags:
if point_flags & p[0] != 0:
if rnd.randf() > pwindow:
rflags.push_back(p)
for f in rflags:
point_flags &= ~f[0]
point_flags |= f[1]
grid_walls[tile] = point_flags
func tile_distance(tile1: int, tile2: int):
var last_x = tile1 % size_x
var last_y = int(tile1 / size_x)
var cur_x = tile2 % size_x
var cur_y = int(tile2 / size_x)
var dst = Vector2(cur_x - last_x, cur_y - last_y).length()
return int(dst)
func create_areas(min_d: int = 4):
var created_roots = []
for t in range(grid_walls.size()):
if grid_walls[t] & FLAG_FLOOR:
grid_areas[t] = 0x0
else:
grid_areas[t] = 0xffff
var p = walls_tiles.duplicate()
var area_code: int = 1
while p.size() > 0:
var tile = p.pop_front()
print("tile ", tile)
var point_flags = grid_walls[tile]
for t in [FLAG_ENTRY_MASK, FLAG_WINDOW_MASK]:
if (point_flags & t != 0):
if created_roots.empty():
print("p")
grid_areas[tile] = area_code
area_code += 1
created_roots.push_back(tile)
else:
print("pp")
var mdst = 1000000000
for e in created_roots:
var dst = tile_distance(e, tile)
if mdst > dst:
mdst = dst
print(mdst)
if mdst >= min_d:
grid_areas[tile] = area_code
area_code += 1
created_roots.push_back(tile)
func grow_areas_left():
for k in range(grid_areas.size()):
pass
print(grid_areas)
print(grid_walls)
func build_area_walls():
for tile in range(grid_areas.size()):
var code = grid_areas[tile]
var point_flags = grid_walls[tile]
var old_point_flags = point_flags
if code == 0xffff:
continue
if (point_flags & FLAG_FLOOR) == 0:
continue
var x = tile % size_x
var y = int(tile / size_x)
var leftm = point_flags & FLAG_LEFT_MASK
var rightm = point_flags & FLAG_RIGHT_MASK
var upm = point_flags & FLAG_UP_MASK
var downm = point_flags & FLAG_DOWN_MASK
if (leftm == 0) && x > 0:
var left_code = grid_areas[tile - 1]
if code != left_code:
var left_flags = grid_walls[tile - 1]
if (point_flags & FLAG_LEFT_MASK == 0) && (left_flags & FLAG_RIGHT_MASK == 0):
point_flags |= FLAG_WALL_LEFT
print("left ", leftm)
if (rightm == 0) && x < size_x - 1:
var right_code = grid_areas[tile + 1]
if code != right_code:
var right_flags = grid_walls[tile + 1]
if (point_flags & FLAG_RIGHT_MASK == 0) && (right_flags & FLAG_LEFT_MASK == 0):
point_flags |= FLAG_WALL_RIGHT
print("right ", rightm)
if upm == 0 && y > 0:
var up_code = grid_areas[tile - size_x]
if code != up_code:
var up_flags = grid_walls[tile - size_x]
if (point_flags & FLAG_UP_MASK == 0) && (up_flags & FLAG_DOWN_MASK == 0):
point_flags |= FLAG_WALL_UP
print("up ", upm)
if downm == 0 && y < size_y - 1:
var down_code = grid_areas[tile + size_x]
if code != down_code:
var down_flags = grid_walls[tile + size_x]
if (point_flags & FLAG_DOWN_MASK == 0) && (down_flags & FLAG_UP_MASK == 0):
point_flags |= FLAG_WALL_DOWN
print("down ", downm)
if old_point_flags != point_flags:
print("point flags %04x" % (old_point_flags), " after %04x" % (point_flags))
grid_walls[tile] = point_flags
func instance_wall(what, p0, p1):
var obj = what.instance()
add_child(obj)
var v = p1 - p0
var xform = Transform().rotated(Vector3(0, 1, 0), -v.angle())
var p = p0 + v * 0.5
xform.origin = Vector3(p.x, 0, p.y)
obj.transform = xform
func display_walls():
for y in range(size_y):
for x in range(size_x):
var point_flags = grid_walls[y * size_x + x]
var px = float(x) * grid_size + grid_rect.position.x - grid_size
var py = float(y) * grid_size + grid_rect.position.y - grid_size
var p0 = Vector2(px, py)
var p1 = Vector2(px + grid_size, py)
var p2 = Vector2(px + grid_size, py + grid_size)
var p3 = Vector2(px, py + grid_size)
var obje
var objects = {
FLAG_WALL_MASK: wall,
FLAG_ENTRY_MASK: entry,
FLAG_WINDOW_MASK: window,
FLAG_DOOR_MASK: door
}
for k in objects.keys():
if point_flags & k != 0:
obje = objects[k]
if point_flags & (k & FLAG_LEFT_MASK) != 0:
instance_wall(obje, p3, p0)
if point_flags & (k & FLAG_UP_MASK) != 0:
instance_wall(obje, p0, p1)
if point_flags & (k & FLAG_RIGHT_MASK) != 0:
instance_wall(obje, p1, p2)
if point_flags & (k & FLAG_DOWN_MASK) != 0:
instance_wall(obje, p2, p3)
if point_flags & FLAG_FLOOR != 0:
var fd = fl.instance()
add_child(fd)
var xform = Transform()
var p = p0
xform.origin = Vector3(p.x, 0, p.y)
fd.transform = xform
func _ready():
rnd = RandomNumberGenerator.new()
rnd.seed = OS.get_unix_time()
var state = 0
func _process(delta):
match(state):
0:
init_grid()
init_walls()
convert_walls()
create_entry_door()
create_windows(0.0)
create_areas(4)
build_area_walls()
display_walls()
# place_flats()
# grow_flats()
# draw_grid()
# draw_walls()
# print(grid)
# for k in range(150):
# build_corridor()
state = 1

19
proto3/godot/city/cam.gd Normal file
View File

@@ -0,0 +1,19 @@
extends Camera
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_pressed("walk_forward"):
global_translate(Vector3(0, 0, -1) * 10.0 * delta)
if Input.is_action_pressed("walk_back"):
global_translate(Vector3(0, 0, 1) * 10.0 * delta)

View File

@@ -0,0 +1,38 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://city/building.gd" type="Script" id=1]
[ext_resource path="res://city/cam.gd" type="Script" id=2]
[sub_resource type="SpatialMaterial" id=1]
albedo_color = Color( 0.180392, 0.737255, 0.490196, 1 )
[sub_resource type="PlaneMesh" id=2]
material = SubResource( 1 )
size = Vector2( 200, 200 )
[sub_resource type="SpatialMaterial" id=3]
flags_unshaded = true
flags_vertex_lighting = true
vertex_color_use_as_albedo = true
params_line_width = 3.0
params_point_size = 3.0
[node name="contour_building_gen" type="Spatial"]
[node name="cam" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 10, 10 )
script = ExtResource( 2 )
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.843487, 0 )
mesh = SubResource( 2 )
material/0 = null
[node name="building" type="Spatial" parent="."]
script = ExtResource( 1 )
[node name="debug" type="ImmediateGeometry" parent="building"]
material_override = SubResource( 3 )
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0, 20, 0 )

View File

@@ -0,0 +1,21 @@
extends Spatial
var graph = {
"entry": ["corridoor", "stairs"],
"corridoor": ["corridoor", "flat-door"]
}
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://city/spaces_building_gen.gd" type="Script" id=1]
[node name="spaces_building_gen" type="Spatial"]
script = ExtResource( 1 )

View File

@@ -0,0 +1,35 @@
extends Node2D
var graph = {
"entry": ["corridoor", "stairs"],
"corridoor": ["corridoor", "flat-door"]
}
var grid = []
var spaces = []
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
var space_color = []
var xdim = 10
var ydim = 10
func _ready():
$Camera2D.current = true
grid.resize(10 * 10)
for e in graph.keys():
for k in [e] + graph[e]:
if !k in spaces:
spaces.push_back(k)
space_color.push_back(Color(randf(), randf(), randf(), 1))
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _draw():
draw_rect(Rect2(-10, -10, 20, 20), Color(1, 0, 0, 1))

View File

@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://city/spaces_building_gen_2d.gd" type="Script" id=1]
[node name="spaces_building_gen_2d" type="Node2D"]
script = ExtResource( 1 )
[node name="Camera2D" type="Camera2D" parent="."]

View File

@@ -217,7 +217,6 @@ grabbing="*res://autoloads/grabbing.gd"
global="*res://autoloads/global.gd"
rpg="*res://autoloads/rpg.gd"
combat="*res://autoloads/combat.gd"
phy_bones="*res://autoloads/phy_bones.gd"
quests="*res://autoloads/quests.gd"
[input]

View File

@@ -20,6 +20,7 @@ func _ready():
assert(e == OK)
e = quests.connect("new_quest", self, "new_quest")
assert(e == OK)
global.interior = $dungeon
var default_meta = {
"grabbing": false,
@@ -39,6 +40,8 @@ var player_meta = {
func start_ai():
print("prepared")
$"meta-ai".start()
global.interior = $dungeon
quests.activate()
func save():
global.save_characters()

View File

@@ -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")

View File

@@ -0,0 +1,140 @@
[gd_scene load_steps=1 format=2]
[sub_resource id=1 type="Shader"]
resource_name = "Shader Nodetree"
code = "shader_type spatial;
render_mode blend_mix, depth_draw_always, cull_back, diffuse_burley, specular_schlick_ggx;
void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
float metallic, float specular, float roughness, float clearcoat,
float clearcoat_roughness, float anisotropy, float transmission,
float IOR, out vec3 albedo, out float sss_strength_out,
out float metallic_out, out float specular_out,
out float roughness_out, out float clearcoat_out,
out float clearcoat_gloss_out, out float anisotropy_out,
out float transmission_out, out float ior) {
metallic = clamp(metallic, 0.0, 1.0);
transmission = clamp(transmission, 0.0, 1.0);
subsurface = subsurface * (1.0 - metallic);
albedo = mix(color.rgb, subsurface_color.rgb, subsurface);
sss_strength_out = subsurface;
metallic_out = metallic;
specular_out = pow((IOR - 1.0)/(IOR + 1.0), 2)/0.08;
roughness_out = roughness;
clearcoat_out = clearcoat * (1.0 - transmission);
clearcoat_gloss_out = 1.0 - clearcoat_roughness;
anisotropy_out = clamp(anisotropy, 0.0, 1.0);
transmission_out = (1.0 - transmission) * (1.0 - metallic);
ior = IOR;
}
void vertex () {
}
void fragment () {
// node: 'Principled BSDF'
// type: 'ShaderNodeBsdfPrincipled'
// input sockets handling
vec4 node0_in0_basecolor = vec4(0.06881529837846756, 0.005524288397282362,
0.003115540137514472, 1.0);
float node0_in1_subsurface = float(0.0);
vec3 node0_in2_subsurfaceradius = vec3(1.0, 0.20000000298023224,
0.10000000149011612);
vec4 node0_in3_subsurfacecolor = vec4(0.800000011920929, 0.800000011920929,
0.800000011920929, 1.0);
float node0_in4_metallic = float(0.0);
float node0_in5_specular = float(0.5);
float node0_in6_speculartint = float(0.0);
float node0_in7_roughness = float(0.4000000059604645);
float node0_in8_anisotropic = float(0.0);
float node0_in9_anisotropicrotation = float(0.0);
float node0_in10_sheen = float(0.0);
float node0_in11_sheentint = float(0.5);
float node0_in12_clearcoat = float(0.0);
float node0_in13_clearcoatroughness = float(0.029999999329447746);
float node0_in14_ior = float(1.4500000476837158);
float node0_in15_transmission = float(0.0);
float node0_in16_transmissionroughness = float(0.0);
vec4 node0_in17_emission = vec4(0.0, 0.0, 0.0, 1.0);
float node0_in18_alpha = float(1.0);
vec3 node0_in19_normal = NORMAL;
vec3 node0_in20_clearcoatnormal = vec3(0.0, 0.0, 0.0);
vec3 node0_in21_tangent = TANGENT;
// output sockets definitions
vec3 node0_bsdf_out0_albedo;
float node0_bsdf_out1_sss_strength;
float node0_bsdf_out3_specular;
float node0_bsdf_out2_metallic;
float node0_bsdf_out4_roughness;
float node0_bsdf_out5_clearcoat;
float node0_bsdf_out6_clearcoat_gloss;
float node0_bsdf_out7_anisotropy;
float node0_bsdf_out8_transmission;
float node0_bsdf_out9_ior;
node_bsdf_principled(node0_in0_basecolor, node0_in1_subsurface,
node0_in3_subsurfacecolor, node0_in4_metallic, node0_in5_specular,
node0_in7_roughness, node0_in12_clearcoat, node0_in13_clearcoatroughness,
node0_in8_anisotropic, node0_in15_transmission, node0_in14_ior,
node0_bsdf_out0_albedo, node0_bsdf_out1_sss_strength, node0_bsdf_out2_metallic,
node0_bsdf_out3_specular, node0_bsdf_out4_roughness, node0_bsdf_out5_clearcoat,
node0_bsdf_out6_clearcoat_gloss, node0_bsdf_out7_anisotropy,
node0_bsdf_out8_transmission, node0_bsdf_out9_ior);
ALBEDO = node0_bsdf_out0_albedo;
SSS_STRENGTH = node0_bsdf_out1_sss_strength;
SPECULAR = node0_bsdf_out3_specular;
METALLIC = node0_bsdf_out2_metallic;
ROUGHNESS = node0_bsdf_out4_roughness;
CLEARCOAT = node0_bsdf_out5_clearcoat;
CLEARCOAT_GLOSS = node0_bsdf_out6_clearcoat_gloss;
NORMAL = node0_in19_normal;
// uncomment it when you need it
// TRANSMISSION = vec3(1.0, 1.0, 1.0) * node0_bsdf_out8_transmission;
// uncomment it when you are modifing TANGENT
// TANGENT = normalize(cross(cross(node0_in21_tangent, NORMAL), NORMAL));
// BINORMAL = cross(TANGENT, NORMAL);
// uncomment it when you have tangent(UV) set
// ANISOTROPY = node0_bsdf_out7_anisotropy;
}
"
[sub_resource id=2 type="ShaderMaterial"]
resource_name = ""
shader = SubResource(1)
[sub_resource id=3 type="ArrayMesh"]
resource_name = "floor"
surfaces/0 = {
"material":SubResource(2),
"primitive":4,
"arrays":[
Vector3Array(1.99, 2.23517e-08, 0.01, 0.01, 2.23517e-08, 1.99, 0.01, 2.23517e-08, 0.01, 0.0, -0.19, 1.99, 0.0, -0.00999998, 0.01, 0.0, -0.00999998, 1.99, 1.99, -0.19, 2.0, 0.01, -0.00999998, 2.0, 1.99, -0.00999998, 2.0, 0.01, -0.2, 0.01, 1.99, -0.2, 1.99, 1.99, -0.2, 0.01, 2.0, -0.19, 0.01, 2.0, -0.00999998, 1.99, 2.0, -0.00999998, 0.01, 1.99, -0.19, 0.0, 1.99, -0.2, 0.01, 2.0, -0.19, 0.01, 1.99, 2.23517e-08, 0.01, 1.99, -0.00999998, 0.0, 2.0, -0.00999998, 0.01, 2.0, -0.19, 1.99, 1.99, -0.2, 1.99, 1.99, -0.19, 2.0, 2.0, -0.00999998, 1.99, 1.99, -0.00999998, 2.0, 1.99, 2.23517e-08, 1.99, 0.01, -0.19, 0.0, 0.0, -0.19, 0.01, 0.01, -0.2, 0.01, 0.0, -0.00999998, 0.01, 0.01, -0.00999998, 0.0, 0.01, 2.23517e-08, 0.01, 0.0, -0.19, 1.99, 0.01, -0.19, 2.0, 0.01, -0.2, 1.99, 0.01, 2.23517e-08, 1.99, 0.01, -0.00999998, 2.0, 0.0, -0.00999998, 1.99, 0.01, 2.23517e-08, 1.99, 0.0, -0.00999998, 0.01, 0.01, 2.23517e-08, 0.01, 0.01, 2.23517e-08, 0.01, 1.99, -0.00999998, 0.0, 1.99, 2.23517e-08, 0.01, 2.0, -0.00999998, 0.01, 1.99, -0.19, 0.0, 2.0, -0.19, 0.01, 0.01, -0.19, 2.0, 0.0, -0.00999998, 1.99, 0.01, -0.00999998, 2.0, 1.99, -0.00999998, 2.0, 2.0, -0.19, 1.99, 1.99, -0.19, 2.0, 0.01, -0.00999998, 0.0, 0.0, -0.19, 0.01, 0.01, -0.19, 0.0, 0.01, -0.2, 1.99, 1.99, -0.19, 2.0, 1.99, -0.2, 1.99, 1.99, -0.2, 1.99, 2.0, -0.19, 0.01, 1.99, -0.2, 0.01, 1.99, 2.23517e-08, 1.99, 0.01, -0.00999998, 2.0, 0.01, 2.23517e-08, 1.99, 0.01, -0.2, 0.01, 0.0, -0.19, 1.99, 0.01, -0.2, 1.99, 1.99, -0.2, 0.01, 0.01, -0.19, 0.0, 0.01, -0.2, 0.01, 1.99, 2.23517e-08, 0.01, 2.0, -0.00999998, 1.99, 1.99, 2.23517e-08, 1.99, 0.01, -0.19, 0.0, 1.99, -0.00999998, 0.0, 0.01, -0.00999998, 0.0, 1.99, 2.23517e-08, 1.99, 0.0, -0.19, 0.01, 0.01, -0.19, 2.0, 0.01, -0.2, 1.99, 2.0, -0.19, 1.99, 0.0, -0.00999998, 1.99, 0.01, -0.00999998, 0.0, 2.0, -0.00999998, 0.01, 1.99, -0.00999998, 0.0, 1.99, -0.19, 0.0, 0.01, -0.19, 2.0, 0.0, -0.19, 1.99, 0.0, -0.00999998, 1.99, 1.99, -0.00999998, 2.0, 2.0, -0.00999998, 1.99, 2.0, -0.19, 1.99, 0.01, -0.00999998, 0.0, 0.0, -0.00999998, 0.01, 0.0, -0.19, 0.01, 0.01, -0.2, 1.99, 0.01, -0.19, 2.0, 1.99, -0.19, 2.0, 1.99, -0.2, 1.99, 2.0, -0.19, 1.99, 2.0, -0.19, 0.01, 1.99, 2.23517e-08, 1.99, 1.99, -0.00999998, 2.0, 0.01, -0.00999998, 2.0, 0.01, -0.2, 0.01, 0.0, -0.19, 0.01, 0.0, -0.19, 1.99, 1.99, -0.19, 0.0, 2.0, -0.00999998, 0.01, 1.99, -0.19, 0.0),
Vector3Array(0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -0.577356, 0.577353, 0.577342, -0.577356, 0.577353, 0.577342, -0.577356, 0.577353, 0.577342, -0.577354, -0.577354, 0.577343, -0.577354, -0.577354, 0.577343, -0.577354, -0.577354, 0.577343, -0.577351, 0.577361, -0.577339, -0.577351, 0.577361, -0.577339, -0.577351, 0.577361, -0.577339, -0.577351, -0.577361, -0.577339, -0.577351, -0.577361, -0.577339, -0.577351, -0.577361, -0.577339, 0.577351, 0.57735, 0.57735, 0.577351, 0.57735, 0.57735, 0.577351, 0.57735, 0.57735, 0.57735, -0.57735, 0.57735, 0.57735, -0.57735, 0.57735, 0.57735, -0.57735, 0.57735, 0.577354, 0.577342, -0.577354, 0.577354, 0.577342, -0.577354, 0.577354, 0.577342, -0.577354, 0.577354, -0.577343, -0.577354, 0.577354, -0.577343, -0.577354, 0.577354, -0.577343, -0.577354, 0.707107, -0.707107, 0.0, 0.707107, -0.707107, 0.0, 0.707107, -0.707107, 0.0, 0.0, -0.707107, 0.707107, 0.0, -0.707107, 0.707107, 0.0, -0.707107, 0.707107, -0.707107, 0.0, 0.707107, -0.707107, 0.0, 0.707107, -0.707107, 0.0, 0.707107, 0.707106, 0.0, -0.707107, 0.707106, 0.0, -0.707107, 0.707106, 0.0, -0.707107, -0.707106, 0.0, -0.707107, -0.707106, 0.0, -0.707107, -0.707106, 0.0, -0.707107, 0.707107, 0.0, 0.707107, 0.707107, 0.0, 0.707107, 0.707107, 0.0, 0.707107, 0.0, 0.707101, -0.707112, 0.0, 0.707101, -0.707112, 0.0, 0.707101, -0.707112, -0.707106, 0.707107, 0.0, -0.707106, 0.707107, 0.0, -0.707106, 0.707107, 0.0, 0.0, -0.707102, -0.707112, 0.0, -0.707102, -0.707112, 0.0, -0.707102, -0.707112, 0.707106, 0.707108, 0.0, 0.707106, 0.707108, 0.0, 0.707106, 0.707108, 0.0, 0.0, 0.707107, 0.707107, 0.0, 0.707107, 0.707107, 0.0, 0.707107, 0.707107, -0.707107, -0.707106, 0.0, -0.707107, -0.707106, 0.0, -0.707107, -0.707106, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.707107, -0.707107, 0.0, 0.0, -0.707107, 0.707107, -0.707107, 0.0, 0.707107, -0.707107, 0.0, 0.707107, -0.707107, 0.0, 0.707107, 0.707106, 0.0, -0.707107, 0.707106, 0.0, -0.707107, 0.707106, 0.0, -0.707107, -0.707106, 0.0, -0.707107, -0.707106, 0.0, -0.707107, -0.707106, 0.0, -0.707107, 0.707107, 0.0, 0.707107, 0.707107, 0.0, 0.707107, 0.707107, 0.0, 0.707107, 0.0, 0.70711, -0.707104, 0.0, 0.70711, -0.707104, 0.0, 0.70711, -0.707104, -0.707108, 0.707105, 0.0, -0.707108, 0.707105, 0.0, -0.707108, 0.707105, 0.0, 0.0, -0.70711, -0.707103, 0.0, -0.70711, -0.707103, 0.0, -0.70711, -0.707103, 0.707108, 0.707106, 0.0, 0.707108, 0.707106, 0.0, 0.707108, 0.707106, 0.0, 0.0, 0.707107, 0.707107, -0.707107, -0.707106, 0.0, 0.0, 0.0, 1.0),
FloatArray(-1.49949e-07, 0.0, 1.0, 1.0, -1.49949e-07, 0.0, 1.0, 1.0, -1.2163e-07, 0.0, 1.0, 1.0, 0.0, -1.0, -2.82773e-07, 1.0, 0.0, -1.0, -1.73203e-08, 1.0, 0.0, -1.0, -3.00093e-07, 1.0, 4.87539e-09, -1.0, 0.0, 1.0, 2.98626e-10, -1.0, 0.0, 1.0, 5.17401e-09, -1.0, 0.0, 1.0, -6.08149e-08, 0.0, -1.0, 1.0, -6.08149e-08, 0.0, -1.0, 1.0, -1.2163e-07, 0.0, -1.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 4.59712e-06, 0.707102, -0.707111, 1.0, 4.59712e-06, 0.707102, -0.707111, 1.0, 4.59712e-06, 0.707102, -0.707111, 1.0, -4.60837e-06, 0.707102, 0.707111, 1.0, -4.60837e-06, 0.707102, 0.707111, 1.0, -4.60837e-06, 0.707102, 0.707111, 1.0, -0.70711, -0.707103, -4.21548e-06, 1.0, -0.70711, -0.707103, -4.21548e-06, 1.0, -0.70711, -0.707103, -4.21548e-06, 1.0, 0.707111, -0.707103, 4.43916e-06, 1.0, 0.707111, -0.707103, 4.43916e-06, 1.0, 0.707111, -0.707103, 4.43916e-06, 1.0, -8.44653e-06, 0.707111, -0.707102, 1.0, -8.44653e-06, 0.707111, -0.707102, 1.0, -8.44653e-06, 0.707111, -0.707102, 1.0, -0.707103, -0.707111, -8.42933e-06, 1.0, -0.707103, -0.707111, -8.42933e-06, 1.0, -0.707103, -0.707111, -8.42933e-06, 1.0, 0.707102, -0.707112, 4.68611e-06, 1.0, 0.707102, -0.707112, 4.68611e-06, 1.0, 0.707102, -0.707112, 4.68611e-06, 1.0, -3.90413e-06, -0.707116, 0.707098, 1.0, -3.90413e-06, -0.707116, 0.707098, 1.0, -3.90413e-06, -0.707116, 0.707098, 1.0, -1.20532e-07, -1.20532e-07, 1.0, 1.0, -1.20416e-07, -1.20416e-07, 1.0, 1.0, -1.20415e-07, -1.20415e-07, 1.0, 1.0, 8.39109e-06, 0.707107, 0.707107, 1.0, 3.82867e-08, 0.707107, 0.707107, 1.0, 0.0, 0.707107, 0.707107, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 5.17402e-09, -1.0, -5.17401e-09, 1.0, 5.17402e-09, -1.0, -5.17401e-09, 1.0, 5.17402e-09, -1.0, -5.17401e-09, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, -0.707112, -0.707101, 1.0, 0.0, -0.707112, -0.707101, 1.0, 0.0, -0.707112, -0.707101, 1.0, -1.20414e-07, -1.20413e-07, -1.0, 1.0, -1.20414e-07, -1.20413e-07, -1.0, 1.0, -1.20414e-07, -1.20413e-07, -1.0, 1.0, -8.51452e-06, -0.707112, 0.707102, 1.0, -8.51452e-06, -0.707112, 0.707102, 1.0, -8.51452e-06, -0.707112, 0.707102, 1.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0, -1.0, 1.0, -7.73467e-08, 0.707107, -0.707107, 1.0, -1.69517e-05, 0.707107, -0.707107, 1.0, -1.7029e-05, 0.707107, -0.707107, 1.0, -1.7859e-07, 1.7859e-07, 1.0, 1.0, -1.7827e-07, 1.7827e-07, 1.0, 1.0, -1.78268e-07, 1.78268e-07, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, -1.78268e-07, 0.0, 1.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, -1.0, 1.0, 0.0, -1.0, 0.0, 1.0, -1.20533e-07, -1.20533e-07, 1.0, 1.0, 8.42937e-06, 0.707107, 0.707107, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, -0.707104, -0.70711, 1.0, 0.0, -0.707104, -0.70711, 1.0, 0.0, -0.707104, -0.70711, 1.0, -1.20347e-07, -1.20348e-07, -1.0, 1.0, -1.20347e-07, -1.20348e-07, -1.0, 1.0, -1.20347e-07, -1.20348e-07, -1.0, 1.0, -1.97563e-07, -0.707103, 0.70711, 1.0, -1.97563e-07, -0.707103, 0.70711, 1.0, -1.97563e-07, -0.707103, 0.70711, 1.0, -1.20534e-07, 1.20534e-07, -1.0, 1.0, -1.20534e-07, 1.20534e-07, -1.0, 1.0, -1.20534e-07, 1.20534e-07, -1.0, 1.0, 0.0, 0.707107, -0.707107, 1.0, -1.78592e-07, 1.78592e-07, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0),
null, ; no Vertex Colors,
Vector2Array(0.00357143, 0.9975, 0.710714, 0.5025, 0.00357151, 0.5025, 0.782143, 0.9975, 0.717857, 0.5025, 0.717857, 0.9975, 0.853571, 0.9975, 0.789286, 0.5025, 0.789286, 0.9975, 0.710714, 0.0025, 0.00357142, 0.4975, 0.710714, 0.4975, 0.996429, 0.9975, 0.932143, 0.5025, 0.932143, 0.9975, 0.860714, 0.9975, 0.857143, 0.9975, 0.860714, 1.0, 0.00357143, 0.9975, 4.25747e-10, 0.9975, 0.00357142, 1.0, 0.996429, 0.5025, 1.0, 0.5025, 0.996429, 0.5, 0.932143, 0.5025, 0.932143, 0.5, 0.928572, 0.5025, 0.860714, 0.5025, 0.860714, 0.5, 0.857143, 0.5025, 0.717857, 0.5025, 0.717857, 0.5, 0.714286, 0.5025, 0.782143, 0.9975, 0.782143, 1.0, 0.785714, 0.9975, 0.710714, 0.5025, 0.714285, 0.5025, 0.710714, 0.5, 0.710714, 0.5025, 0.00357151, 0.5, 0.00357151, 0.5025, 0.00357151, 0.5025, 4.25747e-10, 0.9975, 0.00357143, 0.9975, 0.932143, 0.9975, 0.996429, 1.0, 0.996429, 0.9975, 0.853571, 0.5025, 0.789286, 0.5, 0.789286, 0.5025, 0.789286, 0.9975, 0.853571, 1.0, 0.853571, 0.9975, 0.925, 0.5025, 0.860714, 0.5, 0.860714, 0.5025, 0.00357154, 0.0025, 5.81859e-10, 0.4975, 0.00357142, 0.4975, 0.00357142, 0.4975, 0.710714, 0.5, 0.710714, 0.4975, 0.710714, 0.9975, 0.714285, 0.5025, 0.710714, 0.5025, 0.710714, 0.0025, 0.00357154, 0.0, 0.00357154, 0.0025, 0.710714, 0.4975, 0.714285, 0.00250006, 0.710714, 0.0025, 0.00357143, 0.9975, 0.710714, 1.0, 0.710714, 0.9975, 0.860714, 0.5025, 0.925, 0.9975, 0.925, 0.5025, 0.710714, 0.9975, 0.782143, 0.5025, 0.853571, 0.5025, 0.00357154, 0.0025, 0.996429, 0.5025, 0.710714, 0.5, 8.47237e-08, 0.5025, 0.932143, 0.9975, 0.932143, 1.0, 0.996429, 1.0, 0.853571, 0.5025, 0.853571, 0.5, 0.789286, 0.5, 0.789286, 0.9975, 0.789286, 1.0, 0.853571, 1.0, 0.925, 0.5025, 0.925, 0.5, 0.860714, 0.5, 0.00357154, 0.0025, 1.1579e-07, 0.0025, 5.81859e-10, 0.4975, 0.00357142, 0.4975, 0.00357142, 0.5, 0.710714, 0.5, 0.710714, 0.9975, 0.714285, 0.9975, 0.714285, 0.5025, 0.710714, 0.0025, 0.710714, 5.96046e-08, 0.00357154, 0.0, 0.714285, 0.4975, 0.00357142, 1.0, 0.860714, 0.9975),
null, ; No UV2,
null, ; No Bones,
null, ; No Weights,
IntArray(0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10, 12, 14, 13, 15, 17, 16, 18, 20, 19, 21, 23, 22, 24, 26, 25, 27, 29, 28, 30, 32, 31, 33, 35, 34, 36, 38, 37, 39, 41, 40, 42, 44, 43, 45, 47, 46, 48, 50, 49, 51, 53, 52, 54, 56, 55, 57, 59, 58, 60, 62, 61, 63, 65, 64, 66, 68, 67, 69, 71, 70, 72, 74, 73, 75, 77, 76, 0, 1, 78, 3, 4, 79, 6, 7, 80, 9, 10, 81, 12, 13, 82, 39, 40, 83, 42, 43, 84, 85, 87, 86, 88, 90, 89, 91, 93, 92, 94, 96, 95, 97, 99, 98, 100, 102, 101, 103, 105, 104, 106, 108, 107, 69, 70, 109, 72, 73, 110, 75, 76, 111)
],
"morph_arrays":[]
}
[node type="Spatial" name="Scene"]
[node name="floor" type="MeshInstance" parent="."]
mesh = SubResource(3)
visible = true
transform = Transform(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)

File diff suppressed because it is too large Load Diff

View File

@@ -9,11 +9,12 @@ const BITLEFT = (1 << 2)
const BITRIGHT = (1 << 3)
var exits = []
var windows = []
var outside_doors = []
var door = preload("res://scenes/maps/door.tscn")
var jail_door = preload("res://scenes/maps/jail-door.tscn")
var window = preload("res://scenes/maps/window.tscn")
var outside_door = preload("res://scenes/maps/window.tscn")
var outside_door = preload("res://scenes/maps/door-outside.tscn")
var stairs = preload("res://scenes/maps/stairs.tscn")
var outside_door_placed = false
var tw2d
@@ -127,31 +128,46 @@ func _ready():
te2d = $c_modular/e2d.transform
tn2d = $c_modular/n2d.transform
ts2d = $c_modular/s2d.transform
var open_paths = {
OPEN_UP: {
"rm_walls": ["n2d", "iw4d"],
"rm": ["fc4"],
"bit": BITUP
},
OPEN_DOWN: {
"rm_walls": ["s2d", "iw11d"],
"rm": ["fc5"],
"bit": BITDOWN
},
OPEN_LEFT: {
"rm_walls": ["w2d", "iw17d"],
"rm": ["fc2"],
"bit": BITLEFT
},
OPEN_RIGHT: {
"rm_walls": ["e2d", "iw22d"],
"rm": ["fc3"],
"bit": BITRIGHT
},
}
func open_path(flag):
if flag == OPEN_UP:
$c_modular/n2d.queue_free()
$c_modular/iw4d.queue_free()
$fc4.queue_free()
bitflags |= BITUP
elif flag == OPEN_DOWN:
$c_modular/s2d.queue_free()
$c_modular/iw11d.queue_free()
$fc5.queue_free()
bitflags |= BITDOWN
elif flag == OPEN_LEFT:
$c_modular/w2d.queue_free()
$c_modular/iw17d.queue_free()
$fc2.queue_free()
bitflags |= BITLEFT
elif flag == OPEN_RIGHT:
$c_modular/e2d.queue_free()
$c_modular/iw22d.queue_free()
$fc3.queue_free()
bitflags |= BITRIGHT
if !flag in exits:
if exits.size() == 1 && !has_meta("master_room"):
$fc1.queue_free()
var kf = open_paths[flag]
bitflags |= kf.bit
exits.push_back(flag)
for e in kf.rm:
if get_node(e):
get_node(e).queue_free()
func create_paths():
for flag in exits:
var kf = open_paths[flag]
for e in kf.rm_walls:
$c_modular.get_node(e).queue_free()
for e in kf.rm:
if get_node(e):
get_node(e).queue_free()
if exits.size() == 1 && !has_meta("master_room"):
$fc1.queue_free()
func open_window(flag):
if !flag in windows:
windows.push_back(flag)
@@ -202,51 +218,85 @@ func master_room():
func wall2door(n):
var door_xform = n.transform
var door_i
for e in get_tree().get_nodes_in_group("door"):
var xpos = e.global_transform.origin
var ypos = n.global_transform.origin
if xpos.distance_to(ypos) < 1.3:
n.queue_free()
return
if has_meta("jail_room"):
door_i = jail_door.instance()
else:
door_i = door.instance()
add_child(door_i)
door_i.transform = door_xform
door_i.add_to_group("door")
n.queue_free()
func exit_door(n):
var xn = n.name
var exit_door_xform = n.transform
var xdoor_i = outside_door.instance()
add_child(xdoor_i)
xdoor_i.transform = exit_door_xform
xdoor_i.name = xn
n.queue_free()
xdoor_i.add_to_group("exit_door")
func wall2window(n):
var window_xform = n.transform
var xn = n.name
var window_i
# if has_meta("jail_room"):
# window_i = jail_window.instance()
# else:
# window_i = door.instance()
if has_meta("exit_room") && !outside_door_placed:
print("exit room place door")
window_i = outside_door.instance()
outside_door_placed = true
global.exit_door = window_i
else:
window_i = window.instance()
window_i = window.instance()
add_child(window_i)
window_i.name = xn
window_i.transform = window_xform
n.queue_free()
var bitdata = {
BITLEFT: {
"doors": ["iw17d"],
"path_remove": ["path_west"],
"nodes_remove": ["iw1", "iw2d", "iw3", "iw8", "iw9d", "iw10"]
},
BITRIGHT: {
"doors": ["iw22d"],
"path_remove": ["path_east"],
"nodes_remove": ["iw5", "iw6d", "iw7", "iw12", "iw13d", "iw14"]
},
BITUP: {
"doors": [],
"path_remove": ["path_north"],
"nodes_remove": ["iw15", "iw16d", "iw23d", "iw24"]
},
BITDOWN: {
"doors": [],
"path_remove": ["path_south"],
"nodes_remove": ["iw18d", "iw19", "iw20", "iw21d"]
}
}
var master_metas = ["master_room", "kitchen_room", "exit_room", "stairs"]
func create_rooms():
assert(exits.size() > 0)
if has_meta("master_room"):
create_paths()
var is_master_room = false
for m in master_metas:
if has_meta(m):
is_master_room = true
if is_master_room:
master_room()
elif has_meta("kitchen_room"):
master_room()
elif has_meta("exit_room"):
assert(windows.size() > 0)
master_room()
for e in get_children():
if e.is_in_group("furniture"):
e.queue_free()
elif has_meta("stairs"):
master_room()
var stairs_i = stairs.instance()
add_child(stairs_i)
for e in get_children():
if e.is_in_group("furniture"):
e.queue_free()
if get_meta("stairs") > 0:
$c_modular/floor.queue_free()
if has_meta("exit_room"):
assert(windows.size() > 0)
for e in get_children():
if e.is_in_group("furniture"):
e.queue_free()
if has_meta("stairs"):
var stairs_i = stairs.instance()
add_child(stairs_i)
for e in get_children():
if e.is_in_group("furniture"):
e.queue_free()
if get_meta("stairs") > 0:
$c_modular/floor.queue_free()
elif exits.size() == 1:
personal_room()
elif exits.size() == 4:
@@ -255,49 +305,26 @@ func create_rooms():
wall2door($c_modular/iw9d)
wall2door($c_modular/iw13d)
else:
if bitflags & BITLEFT == 0:
$c_modular/iw1.queue_free()
$c_modular/iw2d.queue_free()
$c_modular/iw3.queue_free()
$c_modular/iw8.queue_free()
$c_modular/iw9d.queue_free()
$c_modular/iw10.queue_free()
wall2door($c_modular/iw17d)
$path_west.queue_free()
if bitflags & BITRIGHT == 0:
$c_modular/iw5.queue_free()
$c_modular/iw6d.queue_free()
$c_modular/iw7.queue_free()
$c_modular/iw12.queue_free()
$c_modular/iw13d.queue_free()
$c_modular/iw14.queue_free()
wall2door($c_modular/iw22d)
$path_east.queue_free()
if bitflags & BITUP == 0:
$c_modular/iw15.queue_free()
$c_modular/iw16d.queue_free()
$c_modular/iw23d.queue_free()
$c_modular/iw24.queue_free()
$path_north.queue_free()
if bitflags & BITDOWN == 0:
$c_modular/iw18d.queue_free()
$c_modular/iw19.queue_free()
$c_modular/iw20.queue_free()
$c_modular/iw21d.queue_free()
$path_south.queue_free()
if OPEN_LEFT in windows:
wall2window($c_modular/w1)
wall2window($c_modular/w2d)
wall2window($c_modular/w3)
if OPEN_DOWN in windows:
wall2window($c_modular/s1)
wall2window($c_modular/s2d)
wall2window($c_modular/s3)
if OPEN_RIGHT in windows:
wall2window($c_modular/e1)
wall2window($c_modular/e2d)
wall2window($c_modular/e3)
if OPEN_UP in windows:
wall2window($c_modular/n1)
wall2window($c_modular/n2d)
wall2window($c_modular/n3)
for e in [BITLEFT, BITRIGHT, BITUP, BITDOWN]:
if bitflags & e == 0:
for g in bitdata[e].doors:
wall2door($c_modular.get_node(g))
for g in bitdata[e].path_remove:
get_node(g).queue_free()
for g in bitdata[e].nodes_remove:
$c_modular.get_node(g).queue_free()
var external = {
OPEN_LEFT: ["w1", "w2d", "w3"],
OPEN_DOWN: ["s1", "s2d", "s3"],
OPEN_RIGHT: ["e1", "e2d", "e3"],
OPEN_UP: ["n1", "n2d", "n3"]
}
for p in windows:
for q in external[p]:
var n = $c_modular.get_node(q)
if !p in outside_doors:
wall2window(n)
for p in outside_doors:
var q = external[p][1]
var n = $c_modular.get_node(q)
exit_door(n)

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -10,14 +10,14 @@ extends Node2D
var target: = Vector3()
var rect: = Rect2()
func _ready():
var pos = get_viewport().get_camera().unproject_position(target)
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var pos = get_viewport().get_camera().unproject_position(target)
rect = get_viewport_rect()
rect.grow(-8.0)
rect = rect.grow(-8.0)
if get_viewport().get_camera().is_position_behind(target):
if visible:
hide()