fixing comments in code
This commit is contained in:
parent
7ea2915f5d
commit
4d48ced249
8 changed files with 92 additions and 91 deletions
8
finish.gd
Normal file
8
finish.gd
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
extends Sprite2D
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||||
|
if body.name == "Player":
|
||||||
|
get_tree().change_scene_to_file("res://end.tscn")
|
25
generator.gd
25
generator.gd
|
@ -1,41 +1,42 @@
|
||||||
extends Sprite2D
|
extends Sprite2D
|
||||||
|
|
||||||
var maze_pos = Vector2i(0, 0)
|
var maze_pos = Vector2i(0, 0) # start position for the generator
|
||||||
var dir_history = []
|
var dir_history = []
|
||||||
var directions = [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]
|
var directions = [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]
|
||||||
var tile_b = Vector2i(1, 0) # border # black
|
|
||||||
var tile_n = Vector2i(0, 0) # no visited # grey
|
var tile_n = Vector2i(0, 0) # no visited # dark blue
|
||||||
var tile_v = Vector2i(0, 1) # visited # blue
|
var tile_v = Vector2i(0, 1) # visited # light blue
|
||||||
var tile_s = Vector2i(1, 1) # visited and stuck # green
|
var tile_s = Vector2i(1, 1) # visited and stuck # blue
|
||||||
|
|
||||||
signal done
|
signal done
|
||||||
|
|
||||||
@onready var Maze = $"../maze"
|
@onready var Maze = $"../maze"
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Maze.set_cell(maze_pos,0,tile_v)
|
Maze.set_cell(maze_pos,0,tile_v) # set first cell as visited
|
||||||
|
|
||||||
|
|
||||||
func get_neighbors():
|
func get_neighbors():
|
||||||
|
"get surrounding not visited neighbors"
|
||||||
var dlist = []
|
var dlist = []
|
||||||
for dir in directions:
|
for dir in directions:
|
||||||
var next_pos = maze_pos + dir * 2
|
var next_pos = maze_pos + dir * 2
|
||||||
if $"../maze".get_cell_atlas_coords(next_pos) == tile_n:
|
if $"../maze".get_cell_atlas_coords(next_pos) == tile_n:
|
||||||
#$"../maze".set_cell(next_pos,0,tile_v)
|
|
||||||
#print(next_pos)
|
|
||||||
dlist.append(dir)
|
dlist.append(dir)
|
||||||
print(dlist)
|
print(dlist)
|
||||||
|
|
||||||
return dlist
|
return dlist
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
var dlist = get_neighbors()
|
var dlist = get_neighbors() # possible directions list
|
||||||
if dlist.is_empty():
|
if dlist.is_empty():
|
||||||
if dir_history.is_empty():
|
if dir_history.is_empty():
|
||||||
print("Maze generation completed")
|
print("Maze generation completed")
|
||||||
done.emit()
|
done.emit()
|
||||||
set_process(false)
|
set_process(false)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# remove current cell in history if stuck and go back
|
||||||
var removed_item = dir_history.pop_back()
|
var removed_item = dir_history.pop_back()
|
||||||
$"../maze".set_cell(maze_pos-removed_item, 0, tile_s)
|
$"../maze".set_cell(maze_pos-removed_item, 0, tile_s)
|
||||||
$"../maze".set_cell(maze_pos, 0, tile_s)
|
$"../maze".set_cell(maze_pos, 0, tile_s)
|
||||||
|
@ -44,12 +45,12 @@ func _process(delta: float) -> void:
|
||||||
else:
|
else:
|
||||||
# 2.1 pick random neighbar
|
# 2.1 pick random neighbar
|
||||||
var dir = dlist.pick_random()
|
var dir = dlist.pick_random()
|
||||||
# Wand zwischen Zellen entfernen
|
# remove walls between the cells
|
||||||
$"../maze".set_cell(maze_pos + dir, 0, tile_v)
|
$"../maze".set_cell(maze_pos + dir, 0, tile_v)
|
||||||
# add to stack
|
# add direction to history
|
||||||
dir_history.append(dir)
|
dir_history.append(dir)
|
||||||
# set new cell
|
# set new cell
|
||||||
maze_pos += dir * 2
|
maze_pos += dir * 2
|
||||||
$"../maze".set_cell(maze_pos, 0, tile_v)
|
$"../maze".set_cell(maze_pos, 0, tile_v)
|
||||||
|
|
||||||
position = 16 * maze_pos+Vector2i(1, 1)
|
position = 16 * maze_pos+Vector2i(1, 1) # just set sprite position
|
||||||
|
|
10
main.tscn
10
main.tscn
|
@ -5,7 +5,7 @@
|
||||||
[ext_resource type="Texture2D" uid="uid://d11d3alxengr0" path="res://assets/maze_tileset.png" id="3_2kohv"]
|
[ext_resource type="Texture2D" uid="uid://d11d3alxengr0" path="res://assets/maze_tileset.png" id="3_2kohv"]
|
||||||
[ext_resource type="Script" path="res://player.gd" id="4_8cre8"]
|
[ext_resource type="Script" path="res://player.gd" id="4_8cre8"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b27nu8tq38o1h" path="res://assets/blo.png" id="5_ikxa5"]
|
[ext_resource type="Texture2D" uid="uid://b27nu8tq38o1h" path="res://assets/blo.png" id="5_ikxa5"]
|
||||||
[ext_resource type="Script" path="res://ziel.gd" id="6_0cii3"]
|
[ext_resource type="Script" path="res://finish.gd" id="6_0cii3"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dm6q0abakck7u" path="res://stick/joystick.tscn" id="6_fsx4f"]
|
[ext_resource type="PackedScene" uid="uid://dm6q0abakck7u" path="res://stick/joystick.tscn" id="6_fsx4f"]
|
||||||
[ext_resource type="Texture2D" uid="uid://c8shyusyohh1u" path="res://assets/button.png" id="7_bd03u"]
|
[ext_resource type="Texture2D" uid="uid://c8shyusyohh1u" path="res://assets/button.png" id="7_bd03u"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cwuboikffi42n" path="res://assets/butto_toggledn.png" id="8_p48aj"]
|
[ext_resource type="Texture2D" uid="uid://cwuboikffi42n" path="res://assets/butto_toggledn.png" id="8_p48aj"]
|
||||||
|
@ -80,14 +80,14 @@ position = Vector2(-1, -1)
|
||||||
scale = Vector2(0.1, 0.1)
|
scale = Vector2(0.1, 0.1)
|
||||||
texture = ExtResource("1_w8mkk")
|
texture = ExtResource("1_w8mkk")
|
||||||
|
|
||||||
[node name="Ziel" type="Sprite2D" parent="."]
|
[node name="FInish" type="Sprite2D" parent="."]
|
||||||
position = Vector2(1136, 624)
|
position = Vector2(1136, 624)
|
||||||
texture = ExtResource("5_ikxa5")
|
texture = ExtResource("5_ikxa5")
|
||||||
script = ExtResource("6_0cii3")
|
script = ExtResource("6_0cii3")
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="Ziel"]
|
[node name="Area2D" type="Area2D" parent="FInish"]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Ziel/Area2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="FInish/Area2D"]
|
||||||
shape = SubResource("RectangleShape2D_is8wb")
|
shape = SubResource("RectangleShape2D_is8wb")
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
@ -116,5 +116,5 @@ texture_pressed = ExtResource("8_p48aj")
|
||||||
stretch_mode = 5
|
stretch_mode = 5
|
||||||
|
|
||||||
[connection signal="done" from="generator" to="Player" method="_on_generator_done"]
|
[connection signal="done" from="generator" to="Player" method="_on_generator_done"]
|
||||||
[connection signal="body_entered" from="Ziel/Area2D" to="Ziel" method="_on_area_2d_body_entered"]
|
[connection signal="body_entered" from="FInish/Area2D" to="FInish" method="_on_area_2d_body_entered"]
|
||||||
[connection signal="toggled" from="CanvasLayer/stick/Button" to="Player" method="_on_button_toggled"]
|
[connection signal="toggled" from="CanvasLayer/stick/Button" to="Player" method="_on_button_toggled"]
|
||||||
|
|
8
ziel.gd
8
ziel.gd
|
@ -1,8 +0,0 @@
|
||||||
extends Sprite2D
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
|
||||||
if body.name == "Player":
|
|
||||||
get_tree().change_scene_to_file("res://end.tscn")
|
|
Loading…
Add table
Reference in a new issue