feat: Proper exit onning algo

This commit is contained in:
Dendy 2026-03-02 20:36:20 +01:00
parent 54d1a90e3e
commit 7c36377c25
4 changed files with 28 additions and 47 deletions

View File

@ -1,7 +1,7 @@
extends Node3D
var exits: Array = [false, true, true, false]
var exits: Array = [false, false, false, false]
func _ready() -> void:
@ -17,7 +17,6 @@ func _ready() -> void:
func update() -> void:
var i = 0
exits = [true, false, true, false]
for exit in exits:
if not exit:
i += 1

View File

@ -26,20 +26,13 @@ func vector_to_dir(vec: Vector2i) -> int:
return -1
func _ready() -> void:
randomize()
var chunks: Array
# Populate the array with [dimension(x)][dimension(y)]bool
for x in range(dimension):
var row: Array
for y in range(dimension):
row.append(false)
chunks.append(row)
# Decide position of station & spawn
var station = Vector2i(randi() % dimension, 0)
var spawn = Vector2i(dimension - station.x - 1, dimension - 1)
$Player.position.x = station.x * 100
$Player.position.z = station.y * 100
var paths: Array = []
for path_idx in range(path_count):
var path: Array[Vector2i] = [
@ -64,41 +57,30 @@ func _ready() -> void:
paths.append(path)
for path in paths:
for cell in path:
chunks[cell.x][cell.y] = true
var chunk_scn = preload("res://chunk.tscn")
for rowi in range(dimension):
for coli in range(dimension):
var chunk_inst = chunk_scn.instantiate()
chunk_inst.position = Vector3(
# TODO: Don't set the size by hand, get it from chunk
rowi * 101,
0,
coli * 101,
)
var chunks: Array
# Populate the array with [dimension(x)][dimension(y)]instance
for x in range(dimension):
var row: Array
for y in range(dimension):
var new_chunk = chunk_scn.instantiate()
new_chunk.position = Vector3(x * 101, 0, y * 101)
row.append(new_chunk)
add_child(new_chunk)
chunks.append(row)
#chunk_inst.get_node("n").position.y = -10
#chunk_inst.get_node("s").position.y = -10
#chunk_inst.get_node("w").position.y = -10
#chunk_inst.get_node("e").position.y = -10
for path in paths:
for i in range(path.size()):
var curr = path[i]
var next = path.get(i+1)
for path in paths:
for i in range(path.size()):
var curr = path[i]
var next = path[i+1] if i+1 < path.size() else null
if rowi != curr.x or coli != curr.y or not next:
continue
var dir = vector_to_dir(next - curr)
print(next-curr, dir)
chunk_inst.exits[dir] = true
chunk_inst.update()
add_child(chunk_inst)
if next:
var revdir = vector_to_dir(curr - next)
chunks[next.x][next.y].exits[revdir] = true
chunks[next.x][next.y].update()
var dir = vector_to_dir(next - curr)
chunks[curr.x][curr.y].exits[dir] = true
chunks[curr.x][curr.y].update()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:

View File

@ -36,7 +36,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.874296, 3.5, -11.78)
mesh = SubResource("BoxMesh_oi3di")
[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, 24.337463, 0)
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 440.23715, 0)
current = true
fov = 55.0
script = ExtResource("2_vonw3")

View File

@ -1,6 +1,6 @@
extends CharacterBody3D
const BASE_STAMINA = 50
const BASE_SPEED = 10
const BASE_SPEED = 100
const SPRINT_MULT = 1.6
const STAMINA_COST = 15
const STAMINA_RECOVER = 10