feat: Add arriving at the station and level regeneration mechanics

This commit is contained in:
Dendy 2026-03-04 22:55:07 +01:00
parent 164ddbf0ee
commit f72746c8e8
5 changed files with 33 additions and 6 deletions

View File

@ -33,6 +33,9 @@ func vector_to_dir(vec: Vector2i) -> int:
return -1
func _ready() -> void:
initialize_world()
func initialize_world() -> void:
# ---- Decide position of Spawn & Station ----
var station = Vector2i(randi() % dimension, 0)
var spawn = Vector2i(dimension - station.x - 1, dimension - 1)
@ -78,7 +81,7 @@ func _ready() -> void:
new_chunk = chunk_scn.instantiate()
new_chunk.position = Vector3(x * Global.chunk_size+1, 0, y * Global.chunk_size+1)
row.append(new_chunk)
add_child(new_chunk)
$ChunkContainer.add_child(new_chunk)
chunks.append(row)
# ---- Set exits based on paths ----
@ -114,7 +117,7 @@ func _ready() -> void:
chunk.update()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var spawn_radius = $Player/SpawnArea/Collision.shape.radius + randf_range(-5, 5)
var rand_unit_vec = Vector3.RIGHT.rotated(Vector3.UP, randf() * TAU)
@ -124,3 +127,10 @@ func _process(delta: float) -> void:
var new_ped = pedestrian_scn.instantiate()
add_child(new_ped)
new_ped.position = ped_pos
func _on_player_station_reached():
for n in $ChunkContainer.get_children():
$ChunkContainer.remove_child(n)
n.queue_free()
initialize_world()

View File

@ -18,7 +18,7 @@ environment = SubResource("Environment_vonw3")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8361101, 0)
[node name="Camera3D" type="Camera3D" parent="." unique_id=2083164402]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 33, 0)
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 332.1546, 0)
current = true
fov = 55.0
script = ExtResource("2_vonw3")
@ -26,3 +26,7 @@ script = ExtResource("2_vonw3")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="." unique_id=1835820889]
transform = Transform3D(0.8695725, -0.45099428, 0.20111632, 0, 0.4072787, 0.91330403, -0.49380532, -0.7941841, 0.35415834, 5.7922945, 3.8191757, 14.293542)
shadow_enabled = true
[node name="ChunkContainer" type="Node3D" parent="." unique_id=166513533]
[connection signal="station_reached" from="Player" to="." method="_on_player_station_reached"]

View File

@ -1,4 +1,7 @@
extends CharacterBody3D
signal station_reached
const BASE_STAMINA = 50
const BASE_SPEED = 20
const SPRINT_MULT = 1.6
@ -7,8 +10,6 @@ const STAMINA_COST = 15
const STAMINA_RECOVER = 10
var pedestrian_area_count = 0
var stamina: float = BASE_STAMINA
func _process(delta: float) -> void:
@ -36,10 +37,12 @@ func _on_area_area_entered(area: Area3D) -> void:
if area.name == "PedestrianArea":
pedestrian_area_count += 1
print(pedestrian_area_count)
if area.name == "StationArea":
station_reached.emit()
func _on_area_area_exited(area: Area3D) -> void:
if area.name == "PedestrianArea":
pedestrian_area_count -= 1
print(pedestrian_area_count)

View File

@ -3,3 +3,5 @@ extends Node3D
func _ready() -> void:
$Mesh.mesh.size.x = Global.chunk_size
$Mesh.mesh.size.y = Global.chunk_size
$StationArea/CollisionShape3D.shape.size.x = Global.chunk_size * 0.80
$StationArea/CollisionShape3D.shape.size.z = Global.chunk_size * 0.80

View File

@ -12,6 +12,9 @@ albedo_color = Color(0.29986, 0.58, 0.2146, 1)
radius = 24.892
height = 134.805
[sub_resource type="BoxShape3D" id="BoxShape3D_lu35c"]
size = Vector3(120, 20, 120)
[node name="Station" type="Node3D" unique_id=1195945545]
script = ExtResource("1_lu35c")
@ -22,3 +25,8 @@ surface_material_override/0 = SubResource("StandardMaterial3D_eoxb4")
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=833530865]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 0, 0)
mesh = SubResource("CapsuleMesh_lu35c")
[node name="StationArea" type="Area3D" parent="." unique_id=206017994]
[node name="CollisionShape3D" type="CollisionShape3D" parent="StationArea" unique_id=793426973]
shape = SubResource("BoxShape3D_lu35c")