feat: Proper exit onning algo
This commit is contained in:
parent
54d1a90e3e
commit
7c36377c25
3
chunk.gd
3
chunk.gd
|
|
@ -1,7 +1,7 @@
|
||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
|
|
||||||
var exits: Array = [false, true, true, false]
|
var exits: Array = [false, false, false, false]
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|
@ -17,7 +17,6 @@ func _ready() -> void:
|
||||||
|
|
||||||
func update() -> void:
|
func update() -> void:
|
||||||
var i = 0
|
var i = 0
|
||||||
exits = [true, false, true, false]
|
|
||||||
for exit in exits:
|
for exit in exits:
|
||||||
if not exit:
|
if not exit:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
||||||
66
level.gd
66
level.gd
|
|
@ -26,20 +26,13 @@ func vector_to_dir(vec: Vector2i) -> int:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
func _ready() -> void:
|
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
|
# Decide position of station & spawn
|
||||||
var station = Vector2i(randi() % dimension, 0)
|
var station = Vector2i(randi() % dimension, 0)
|
||||||
var spawn = Vector2i(dimension - station.x - 1, dimension - 1)
|
var spawn = Vector2i(dimension - station.x - 1, dimension - 1)
|
||||||
|
|
||||||
|
$Player.position.x = station.x * 100
|
||||||
|
$Player.position.z = station.y * 100
|
||||||
|
|
||||||
var paths: Array = []
|
var paths: Array = []
|
||||||
for path_idx in range(path_count):
|
for path_idx in range(path_count):
|
||||||
var path: Array[Vector2i] = [
|
var path: Array[Vector2i] = [
|
||||||
|
|
@ -64,41 +57,30 @@ func _ready() -> void:
|
||||||
|
|
||||||
paths.append(path)
|
paths.append(path)
|
||||||
|
|
||||||
for path in paths:
|
|
||||||
for cell in path:
|
|
||||||
chunks[cell.x][cell.y] = true
|
|
||||||
|
|
||||||
|
|
||||||
var chunk_scn = preload("res://chunk.tscn")
|
var chunk_scn = preload("res://chunk.tscn")
|
||||||
for rowi in range(dimension):
|
var chunks: Array
|
||||||
for coli in range(dimension):
|
# Populate the array with [dimension(x)][dimension(y)]instance
|
||||||
var chunk_inst = chunk_scn.instantiate()
|
for x in range(dimension):
|
||||||
chunk_inst.position = Vector3(
|
var row: Array
|
||||||
# TODO: Don't set the size by hand, get it from chunk
|
for y in range(dimension):
|
||||||
rowi * 101,
|
var new_chunk = chunk_scn.instantiate()
|
||||||
0,
|
new_chunk.position = Vector3(x * 101, 0, y * 101)
|
||||||
coli * 101,
|
row.append(new_chunk)
|
||||||
)
|
add_child(new_chunk)
|
||||||
|
chunks.append(row)
|
||||||
|
|
||||||
#chunk_inst.get_node("n").position.y = -10
|
for path in paths:
|
||||||
#chunk_inst.get_node("s").position.y = -10
|
for i in range(path.size()):
|
||||||
#chunk_inst.get_node("w").position.y = -10
|
var curr = path[i]
|
||||||
#chunk_inst.get_node("e").position.y = -10
|
var next = path[i+1] if i+1 < path.size() else null
|
||||||
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:
|
if next:
|
||||||
continue
|
var revdir = vector_to_dir(curr - next)
|
||||||
|
chunks[next.x][next.y].exits[revdir] = true
|
||||||
var dir = vector_to_dir(next - curr)
|
chunks[next.x][next.y].update()
|
||||||
print(next-curr, dir)
|
var dir = vector_to_dir(next - curr)
|
||||||
chunk_inst.exits[dir] = true
|
chunks[curr.x][curr.y].exits[dir] = true
|
||||||
|
chunks[curr.x][curr.y].update()
|
||||||
chunk_inst.update()
|
|
||||||
|
|
||||||
add_child(chunk_inst)
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
|
|
||||||
|
|
@ -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")
|
mesh = SubResource("BoxMesh_oi3di")
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="." unique_id=2083164402]
|
[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
|
current = true
|
||||||
fov = 55.0
|
fov = 55.0
|
||||||
script = ExtResource("2_vonw3")
|
script = ExtResource("2_vonw3")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
extends CharacterBody3D
|
extends CharacterBody3D
|
||||||
const BASE_STAMINA = 50
|
const BASE_STAMINA = 50
|
||||||
const BASE_SPEED = 10
|
const BASE_SPEED = 100
|
||||||
const SPRINT_MULT = 1.6
|
const SPRINT_MULT = 1.6
|
||||||
const STAMINA_COST = 15
|
const STAMINA_COST = 15
|
||||||
const STAMINA_RECOVER = 10
|
const STAMINA_RECOVER = 10
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue