diff options
author | bd <bdunahu@operationnull.com> | 2025-05-22 17:50:54 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-05-22 17:50:54 -0400 |
commit | f9d7b55634049e0ae6533fb94e058c2a368cd49b (patch) | |
tree | af980b24c517af4ba11bd5b1b72d728a679d533d /scripts/path_tester.gd | |
parent | 8c5c4863aeacb4afcf70f339df6d601e2df1a7a6 (diff) |
Experiment with path generation
Diffstat (limited to 'scripts/path_tester.gd')
-rw-r--r-- | scripts/path_tester.gd | 55 |
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) + + |