summaryrefslogtreecommitdiff
path: root/scripts/path_tester.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/path_tester.gd')
-rw-r--r--scripts/path_tester.gd55
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/path_tester.gd b/scripts/path_tester.gd
new file mode 100644
index 0000000..5add640
--- /dev/null
+++ b/scripts/path_tester.gd
@@ -0,0 +1,55 @@
+extends Node2D
+
+@export var grid_width : int = 20
+@export var grid_height : int = 14
+@export var tile_size : int = 16
+
+var _pg : PathGenerator
+var path_straight_atlas_coords : Vector2i = Vector2i(8, 1)
+var path_corner_atlas_coords : Vector2i = Vector2i(9, 1)
+var path_empty_atlas_coords : Vector2i = Vector2i(0, 0)
+
+# Called when the node enters the scene tree for the first time.
+func _ready() -> void:
+ _pg = PathGenerator.new(grid_width, grid_height)
+ _display_path()
+
+func _display_path():
+ var _path : Array[Vector2i] = []
+ while _path.size() < 35:
+ _path = _pg.generate_path()
+
+ for i in _path:
+ var score : int = _pg.get_tile_score(i)
+
+ var atlas_coords : Vector2i = path_empty_atlas_coords
+ var rotation : float = 0.0
+
+ match score:
+ 2, 8, 10:
+ atlas_coords = path_straight_atlas_coords
+ rotation = 90.0
+ 1, 4, 5:
+ atlas_coords = path_straight_atlas_coords
+ 3:
+ atlas_coords = path_corner_atlas_coords
+ rotation = -90.0
+ 6:
+ atlas_coords = path_corner_atlas_coords
+ 12:
+ atlas_coords = path_corner_atlas_coords
+ rotation = 90
+ 9:
+ atlas_coords = path_corner_atlas_coords
+ rotation = 180
+
+ var tile : Sprite2D = Sprite2D.new()
+ tile.texture = TileManager.get_tile_texture(atlas_coords)
+ tile.global_rotation_degrees = rotation
+ _display_tile(tile, i)
+
+func _display_tile(tile : Sprite2D, pos : Vector2i):
+ tile.global_position = (pos * tile_size) + (Vector2i.ONE * tile_size / 2)
+ add_child(tile)
+
+