Now About Social Code
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--prefabs/bsp_level_generator.tscn5
-rw-r--r--prefabs/exit.tscn22
-rw-r--r--prefabs/test_arena.tscn7
-rw-r--r--scripts/bsp_level_generator.gd5
-rw-r--r--scripts/dungeon_manager.gd55
5 files changed, 81 insertions, 13 deletions
diff --git a/prefabs/bsp_level_generator.tscn b/prefabs/bsp_level_generator.tscn
index 6d8fa48..94a8c4c 100644
--- a/prefabs/bsp_level_generator.tscn
+++ b/prefabs/bsp_level_generator.tscn
@@ -1,9 +1,7 @@
-[gd_scene load_steps=4 format=3 uid="uid://w7hxcvuvud"]
+[gd_scene load_steps=3 format=3 uid="uid://w7hxcvuvud"]
[ext_resource type="Script" path="res://scripts/bsp_level_generator.gd" id="1_6jn1x"]
-[sub_resource type="ArrayMesh" id="ArrayMesh_xgab6"]
-
[sub_resource type="NavigationMesh" id="NavigationMesh_q1fo6"]
geometry_parsed_geometry_type = 1
geometry_collision_mask = 4294967041
@@ -14,7 +12,6 @@ region_min_size = 1.0
script = ExtResource("1_6jn1x")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
-mesh = SubResource("ArrayMesh_xgab6")
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="."]
navigation_mesh = SubResource("NavigationMesh_q1fo6")
diff --git a/prefabs/exit.tscn b/prefabs/exit.tscn
new file mode 100644
index 0000000..c6da7d7
--- /dev/null
+++ b/prefabs/exit.tscn
@@ -0,0 +1,22 @@
+[gd_scene load_steps=4 format=3 uid="uid://bby6nvx5y03x"]
+
+[sub_resource type="BoxMesh" id="BoxMesh_80n3v"]
+size = Vector3(1, 0.1, 1)
+
+[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_yj1cw"]
+albedo_color = Color(0, 0, 0.988235, 1)
+
+[sub_resource type="BoxShape3D" id="BoxShape3D_5ln3u"]
+
+[node name="Exit" type="Area3D"]
+collision_layer = 4
+collision_mask = 4
+
+[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
+mesh = SubResource("BoxMesh_80n3v")
+surface_material_override/0 = SubResource("StandardMaterial3D_yj1cw")
+
+[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
+shape = SubResource("BoxShape3D_5ln3u")
diff --git a/prefabs/test_arena.tscn b/prefabs/test_arena.tscn
index 011b517..b56da43 100644
--- a/prefabs/test_arena.tscn
+++ b/prefabs/test_arena.tscn
@@ -1,9 +1,8 @@
-[gd_scene load_steps=10 format=3 uid="uid://dlevowk0jrhlg"]
+[gd_scene load_steps=9 format=3 uid="uid://dlevowk0jrhlg"]
[ext_resource type="Script" path="res://scripts/dungeon_manager.gd" id="1_dbsm0"]
[ext_resource type="PackedScene" uid="uid://cc1m2a1obsyn4" path="res://addons/fpc/character.tscn" id="1_vc6b5"]
[ext_resource type="Script" path="res://scripts/player.gd" id="2_puqns"]
-[ext_resource type="PackedScene" uid="uid://w7hxcvuvud" path="res://prefabs/bsp_level_generator.tscn" id="4_501hd"]
[sub_resource type="Environment" id="Environment_2poci"]
background_color = Color(0.130548, 0.170599, 0.433834, 1)
@@ -111,6 +110,4 @@ libraries = {
"": SubResource("AnimationLibrary_7dyvd")
}
-[node name="BspLevelGenerator" parent="." instance=ExtResource("4_501hd")]
-
-[connection signal="grid_generated" from="BspLevelGenerator" to="." method="_grid_generated"]
+[node name="LevelContainer" type="Node3D" parent="."]
diff --git a/scripts/bsp_level_generator.gd b/scripts/bsp_level_generator.gd
index bef90be..4a1ca9b 100644
--- a/scripts/bsp_level_generator.gd
+++ b/scripts/bsp_level_generator.gd
@@ -175,7 +175,10 @@ func _ready() -> void:
grid_generated.emit(grid, grid_width, grid_height)
generate_geo(grid, surface_array)
+ mesh.mesh = ArrayMesh.new()
mesh.mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, surface_array)
var tri_mesh = mesh.mesh.create_trimesh_shape()
$NavigationRegion3D/StaticBody3D/CollisionShape3D.shape = tri_mesh
- $NavigationRegion3D.bake_navigation_mesh()
+ #$NavigationRegion3D.navigation_mesh = NavigationMesh.new()
+ #$NavigationRegion3D.navigation_mesh.radius
+ $NavigationRegion3D.bake_navigation_mesh(false)
diff --git a/scripts/dungeon_manager.gd b/scripts/dungeon_manager.gd
index ec3f5d4..12b80fa 100644
--- a/scripts/dungeon_manager.gd
+++ b/scripts/dungeon_manager.gd
@@ -5,10 +5,19 @@ var grid_width: int
var grid_height: int
var enemy_inst = preload("res://prefabs/enemy.tscn")
+var exit_inst = preload("res://prefabs/exit.tscn")
+var bsp_level_inst = preload("res://prefabs/bsp_level_generator.tscn")
+
+var level_done: bool = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
- pass # Replace with function body.
+ spawn_level()
+
+func spawn_level() -> void:
+ var bsp_level = bsp_level_inst.instantiate()
+ bsp_level.connect("grid_generated", _grid_generated)
+ $LevelContainer.add_child(bsp_level)
func create_enemies() -> void:
var num_enemies = randi_range(4, 10)
@@ -24,11 +33,49 @@ func create_enemies() -> void:
var pos = Vector2i(randi_range(0, grid_width-1), randi_range(0, grid_height-1))
if grid[pos.y * grid_width + pos.x] == Tile.Tile.FLOOR:
- enemy.position = Vector3(pos.x, 0, pos.y)
+ enemy.position = Vector3(pos.x, 0, pos.y) + Vector3(0.5, 0, 0.5)
found_pos = true
print("Placing at ", pos)
- add_child.call_deferred(enemy)
+ $LevelContainer.add_child.call_deferred(enemy)
+
+func create_exit() -> void:
+ var found_pos = false
+ var exit: Area3D = exit_inst.instantiate()
+ exit.connect("body_entered", _on_player_exit)
+ while not found_pos:
+ var pos = Vector2i(randi_range(0, grid_width-1), randi_range(0, grid_height-1))
+
+ if grid[pos.y * grid_width + pos.x] == Tile.Tile.FLOOR:
+ exit.position = Vector3(pos.x, 0, pos.y) + Vector3(0.5, 0, 0.5)
+ found_pos = true
+
+ $LevelContainer.add_child.call_deferred(exit)
+
+func place_player() -> void:
+ var found_pos = false
+ while not found_pos:
+ var pos = Vector2i(randi_range(0, grid_width-1), randi_range(0, grid_height-1))
+
+ if grid[pos.y * grid_width + pos.x] == Tile.Tile.FLOOR:
+ $Player.position = Vector3(pos.x, 0, pos.y) + Vector3(0.5, 0, 0.5)
+ found_pos = true
+
+func reset_level() -> void:
+ for child in $LevelContainer.get_children():
+ print("Child is ", child)
+ $LevelContainer.remove_child(child)
+ child.queue_free()
+
+ spawn_level()
+ level_done = false
+
+func _process(_delta: float) -> void:
+ if level_done:
+ reset_level()
+
+func _on_player_exit(_body: Node3D):
+ level_done = true
func _grid_generated(p_grid: Array[Tile.Tile], p_grid_width: int, p_grid_height: int) -> void:
grid = p_grid
@@ -36,3 +83,5 @@ func _grid_generated(p_grid: Array[Tile.Tile], p_grid_width: int, p_grid_height:
grid_height = p_grid_height
create_enemies()
+ create_exit()
+ place_player()