From 7c36377c25e1081b58d166da7eba8fa1d171ecd1 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Mon, 2 Mar 2026 20:36:20 +0100 Subject: [PATCH] feat: Proper exit onning algo --- chunk.gd | 3 +-- level.gd | 68 ++++++++++++++++++++---------------------------------- level.tscn | 2 +- player.gd | 2 +- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/chunk.gd b/chunk.gd index a7ae689..0734abc 100644 --- a/chunk.gd +++ b/chunk.gd @@ -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 diff --git a/level.gd b/level.gd index 9b17658..d6d4e8f 100644 --- a/level.gd +++ b/level.gd @@ -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) + + 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 - #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) - - 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: diff --git a/level.tscn b/level.tscn index b475031..977ca0c 100644 --- a/level.tscn +++ b/level.tscn @@ -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") diff --git a/player.gd b/player.gd index 5f2dbc5..a41df9a 100644 --- a/player.gd +++ b/player.gd @@ -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