feat: Initial WIP implementation of the path deciding algo
It doesn't really work but oh well
This commit is contained in:
parent
fa15bbf1a8
commit
29308d78c2
28
chunk.gd
28
chunk.gd
|
|
@ -5,27 +5,33 @@ var exits: Array = [false, false, false, false]
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
exits = [
|
pass
|
||||||
randi() % 2 == 0,
|
#exits = [
|
||||||
randi() % 2 == 0,
|
#randi() % 2 == 0,
|
||||||
randi() % 2 == 0,
|
#randi() % 2 == 0,
|
||||||
randi() % 2 == 0,
|
#randi() % 2 == 0,
|
||||||
]
|
#randi() % 2 == 0,
|
||||||
|
#]
|
||||||
|
|
||||||
update()
|
#update()
|
||||||
|
|
||||||
func update() -> void:
|
func update() -> void:
|
||||||
var i = 0
|
var i = 0
|
||||||
for exit in exits:
|
for exit in exits:
|
||||||
if not exit:
|
if not exit:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if i == 0: #n
|
if i == 0: #n
|
||||||
$n.get_surface_override_material(0).albedo_color = Color.GREEN
|
$n.position.y = 1
|
||||||
|
#$n.get_surface_override_material(0).albedo_color = Color.GREEN
|
||||||
if i == 1: #s
|
if i == 1: #s
|
||||||
$s.get_surface_override_material(0).albedo_color = Color.GREEN
|
$s.position.y = 1
|
||||||
|
#$s.get_surface_override_material(0).albedo_color = Color.GREEN
|
||||||
if i == 2: #w
|
if i == 2: #w
|
||||||
$w.get_surface_override_material(0).albedo_color = Color.GREEN
|
$w.position.y = 1
|
||||||
|
#$w.get_surface_override_material(0).albedo_color = Color.GREEN
|
||||||
if i == 3: #e
|
if i == 3: #e
|
||||||
$e.get_surface_override_material(0).albedo_color = Color.GREEN
|
$e.position.y = 1
|
||||||
|
#$e.get_surface_override_material(0).albedo_color = Color.GREEN
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
||||||
|
|
@ -31,21 +31,21 @@ script = ExtResource("1_kdh3y")
|
||||||
mesh = SubResource("PlaneMesh_kdh3y")
|
mesh = SubResource("PlaneMesh_kdh3y")
|
||||||
|
|
||||||
[node name="n" type="MeshInstance3D" parent="." unique_id=1732708017]
|
[node name="n" type="MeshInstance3D" parent="." unique_id=1732708017]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2531815, -50.90088)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, -45.583553)
|
||||||
mesh = SubResource("PlaneMesh_eat54")
|
mesh = SubResource("PlaneMesh_eat54")
|
||||||
surface_material_override/0 = SubResource("StandardMaterial3D_eat54")
|
surface_material_override/0 = SubResource("StandardMaterial3D_eat54")
|
||||||
|
|
||||||
[node name="s" type="MeshInstance3D" parent="." unique_id=2083422071]
|
[node name="s" type="MeshInstance3D" parent="." unique_id=2083422071]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2531815, 50.541702)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 45.142174)
|
||||||
mesh = SubResource("PlaneMesh_eat54")
|
mesh = SubResource("PlaneMesh_eat54")
|
||||||
surface_material_override/0 = SubResource("StandardMaterial3D_a0kup")
|
surface_material_override/0 = SubResource("StandardMaterial3D_a0kup")
|
||||||
|
|
||||||
[node name="w" type="MeshInstance3D" parent="." unique_id=518228778]
|
[node name="w" type="MeshInstance3D" parent="." unique_id=518228778]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -50.98094, 1.2531815, -0.19546509)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -44.286728, -1, -0.19546509)
|
||||||
mesh = SubResource("PlaneMesh_eat54")
|
mesh = SubResource("PlaneMesh_eat54")
|
||||||
surface_material_override/0 = SubResource("StandardMaterial3D_7yqgf")
|
surface_material_override/0 = SubResource("StandardMaterial3D_7yqgf")
|
||||||
|
|
||||||
[node name="e" type="MeshInstance3D" parent="." unique_id=1202960026]
|
[node name="e" type="MeshInstance3D" parent="." unique_id=1202960026]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 49.071243, 1.2531815, -0.17337036)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 45.81064, -1, -0.17337036)
|
||||||
mesh = SubResource("PlaneMesh_eat54")
|
mesh = SubResource("PlaneMesh_eat54")
|
||||||
surface_material_override/0 = SubResource("StandardMaterial3D_381vs")
|
surface_material_override/0 = SubResource("StandardMaterial3D_381vs")
|
||||||
|
|
|
||||||
132
level.gd
132
level.gd
|
|
@ -1,68 +1,104 @@
|
||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
@export var dimension: int = 10
|
@export var dimension: int = 10
|
||||||
|
@export var path_count: int = 2
|
||||||
|
|
||||||
|
func dir_to_vector(dir: int) -> Vector2i:
|
||||||
|
assert(dir >= 0 and dir <= 3)
|
||||||
|
var polarity = dir % 2 # 0: negative, 1: positive
|
||||||
|
var axis = floor(dir / 2) # 0: vertical, 1: horizontal
|
||||||
|
return Vector2i(
|
||||||
|
axis * (polarity * 2 - 1),
|
||||||
|
(1 - axis) * (polarity * 2 -1),
|
||||||
|
)
|
||||||
|
|
||||||
|
func vector_to_dir(vec: Vector2i) -> int:
|
||||||
|
assert(vec.length() == 1)
|
||||||
|
if vec == Vector2i(0, -1):
|
||||||
|
return 0
|
||||||
|
elif vec == Vector2i(0, 1):
|
||||||
|
return 1
|
||||||
|
elif vec == Vector2i(-1, 0):
|
||||||
|
return 2
|
||||||
|
elif vec == Vector2i(1, 0):
|
||||||
|
return 3
|
||||||
|
assert(false)
|
||||||
|
return -1
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
var chunks: Array
|
var chunks: Array
|
||||||
# Populate the array with [dimension(x)][dimension(y)][4]bool
|
# Populate the array with [dimension(x)][dimension(y)]bool
|
||||||
for x in range(dimension):
|
for x in range(dimension):
|
||||||
|
var row: Array
|
||||||
for y in range(dimension):
|
for y in range(dimension):
|
||||||
chunks.append([
|
row.append(false)
|
||||||
randi() % 2 == 0,
|
chunks.append(row)
|
||||||
randi() % 2 == 0,
|
|
||||||
randi() % 2 == 0,
|
|
||||||
randi() % 2 == 0,
|
|
||||||
])
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
|
var paths: Array = []
|
||||||
|
for path_idx in range(path_count):
|
||||||
|
var path: Array[Vector2i] = [
|
||||||
|
station,
|
||||||
|
Vector2i(station.x, station.y + 1),
|
||||||
|
]
|
||||||
|
|
||||||
#for pathNum in range(2): # Create paths
|
while true: # Decide each of the steps
|
||||||
#var iPosition = station
|
var last_pos = path.slice(-1)[0]
|
||||||
#iPosition.y += 1 # Station always is entered from below
|
var next_dir = dir_to_vector(randi() % 3 + 1) # cannot go up
|
||||||
#var i = 1
|
var next_pos = (last_pos + next_dir).clampi(0,dimension-1)
|
||||||
#while true:
|
|
||||||
#var path = [false, true, false, false]
|
|
||||||
#
|
|
||||||
#while true: # select a random neighbour until it's a new one
|
|
||||||
#var nextDir = randi() % 4
|
|
||||||
#var nextPosition = iPosition
|
|
||||||
#
|
|
||||||
#if nextDir > 1:
|
|
||||||
#nextPosition.x += (nextDir % 2) * 2 - 1
|
|
||||||
#else:
|
|
||||||
#nextPosition.y += (nextDir % 2) * 2 - 1
|
|
||||||
#
|
|
||||||
#var passedPrevPath = false
|
|
||||||
#for prevPos in path:
|
|
||||||
#if prevPos == nextPosition:
|
|
||||||
#true
|
|
||||||
#
|
|
||||||
#if not passedPrevPath:
|
|
||||||
#break
|
|
||||||
#
|
|
||||||
#if iPosition.x == spawn.x and iPosition.y == spawn.y:
|
|
||||||
#break # Path finished
|
|
||||||
#
|
|
||||||
#i += 1
|
|
||||||
#
|
|
||||||
#while true:
|
|
||||||
#chunks[iPosition.x][iPosition.y] = [
|
|
||||||
#randi() % 2 == 0,
|
|
||||||
#randi() % 2 == 0,
|
|
||||||
#randi() % 2 == 0,
|
|
||||||
#randi() % 2 == 0,
|
|
||||||
#]
|
|
||||||
#
|
|
||||||
#var openDoorCount = chunks[iPosition.x][iPosition.y].filter(func(isOpen): return isOpen).size()
|
|
||||||
#if openDoorCount == 2:
|
|
||||||
#break
|
|
||||||
|
|
||||||
#print(chunks)
|
if next_pos in path:
|
||||||
|
# Invalid path, try again
|
||||||
|
continue
|
||||||
|
|
||||||
|
path.append(next_pos)
|
||||||
|
|
||||||
|
if next_pos == spawn or next_pos.y == dimension-1:
|
||||||
|
# End of path
|
||||||
|
break
|
||||||
|
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
# 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:
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ environment = SubResource("Environment_vonw3")
|
||||||
[node name="Player" parent="." unique_id=1536233267 instance=ExtResource("1_u52ul")]
|
[node name="Player" parent="." unique_id=1536233267 instance=ExtResource("1_u52ul")]
|
||||||
|
|
||||||
[node name="Chunk" parent="." unique_id=731620195 instance=ExtResource("3_f2txt")]
|
[node name="Chunk" parent="." unique_id=731620195 instance=ExtResource("3_f2txt")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.08452606, -3.8146973e-06, 0.120262146)
|
||||||
|
|
||||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="." unique_id=306152407]
|
[node name="MeshInstance3D2" type="MeshInstance3D" parent="." unique_id=306152407]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.031, 7.5, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.031, 7.5, 0)
|
||||||
|
|
@ -34,7 +35,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.031, 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, 25.705143, 0)
|
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 551.1044, 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
|
||||||
|
|
@ -22,6 +22,5 @@ func _process(delta: float) -> void:
|
||||||
stamina += STAMINA_RECOVER * delta
|
stamina += STAMINA_RECOVER * delta
|
||||||
|
|
||||||
self.velocity = Vector3(dir.x * speed, 0, dir.y * speed)
|
self.velocity = Vector3(dir.x * speed, 0, dir.y * speed)
|
||||||
print(str(self.velocity))
|
|
||||||
|
|
||||||
self.move_and_slide()
|
self.move_and_slide()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue