From 95fe9c334fc44180aea4cad6af2f413e0f33ad3c Mon Sep 17 00:00:00 2001 From: dusk Date: Sun, 1 Mar 2026 20:40:29 +0100 Subject: [PATCH] feat: WIP level generation --- level.gd | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++--- level.tscn | 3 +-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/level.gd b/level.gd index 345205f..3f162d1 100644 --- a/level.gd +++ b/level.gd @@ -3,11 +3,61 @@ extends Node3D @export var dimension: int = 10 func _ready() -> void: - var chunks = Array[Array[Array[bool]]] + randomize() - seed( + var chunks: Array + # Populate the array with [dimension(x)][dimension(y)][4]bool + for x in range(dimension): + for y in range(dimension): + chunks.append([[], [], [], []]) + + # Decide position of station & spawn + var station = Vector2i(randi() % dimension, 0) + var spawn = Vector2i(dimension - station.x - 1, dimension - 1) + + + #for pathNum in range(2): # Create paths + #var iPosition = station + #iPosition.y += 1 # Station always is entered from below + #var i = 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) # 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 0524810..0ccd438 100644 --- a/level.tscn +++ b/level.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" uid="uid://dj0cgqed5n3ys" path="res://level.gd" id="1_0b4ue"] [ext_resource type="PackedScene" uid="uid://cmb3b7xrlboy3" path="res://player.tscn" id="1_u52ul"] [ext_resource type="Script" uid="uid://b5ebibi08tjvd" path="res://camera_3d.gd" id="2_vonw3"] -[ext_resource type="PackedScene" uid="uid://x0nufa1wdu4j" path="res://chunk.tscn" id="3_f2txt"] +[ext_resource type="PackedScene" path="res://chunk.tscn" id="3_f2txt"] [sub_resource type="Environment" id="Environment_vonw3"] ambient_light_source = 2 @@ -17,7 +17,6 @@ size = Vector3(10, 7.5, 10) [node name="Level" type="Node3D" unique_id=1248504413] script = ExtResource("1_0b4ue") -dimension = null [node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=2012504496] environment = SubResource("Environment_vonw3")