summaryrefslogtreecommitdiff
path: root/scripts/path_generator.gd
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-05-22 17:50:54 -0400
committerbd <bdunahu@operationnull.com>2025-05-22 17:50:54 -0400
commitf9d7b55634049e0ae6533fb94e058c2a368cd49b (patch)
treeaf980b24c517af4ba11bd5b1b72d728a679d533d /scripts/path_generator.gd
parent8c5c4863aeacb4afcf70f339df6d601e2df1a7a6 (diff)
Experiment with path generation
Diffstat (limited to 'scripts/path_generator.gd')
-rw-r--r--scripts/path_generator.gd48
1 files changed, 41 insertions, 7 deletions
diff --git a/scripts/path_generator.gd b/scripts/path_generator.gd
index fae2c76..e87a8f4 100644
--- a/scripts/path_generator.gd
+++ b/scripts/path_generator.gd
@@ -1,11 +1,45 @@
-extends Node
+extends Object
+class_name PathGenerator
-# Called when the node enters the scene tree for the first time.
-func _ready() -> void:
- pass # Replace with function body.
+var _grid_width : int
+var _grid_height : int
+var _path : Array[Vector2i]
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-func _process(delta: float) -> void:
- pass
+func _init(width:int, height:int):
+ _grid_width = width
+ _grid_height = height
+
+func generate_path():
+ _path.clear()
+
+ var x : int = 0
+ var y : int = randi_range(1, _grid_height-2)
+
+ while x < _grid_width:
+ if not _path.has(Vector2i(x,y)):
+ _path.append(Vector2i(x, y))
+
+ var choice : int = randi_range(0,2)
+
+ # every even tile goes right to leave room for towers
+ if choice == 0 || x % 2 == 0 || x == _grid_width - 1:
+ x += 1
+ elif choice == 1 && y < _grid_height - 2 && !_path.has(Vector2i(x, y + 1)):
+ y += 1
+ elif choice == 2 && y > 1 && !_path.has(Vector2i(x, y - 1)):
+ y -= 1
+ return _path
+
+func get_tile_score(tile : Vector2i) -> int:
+ var score : int = 0
+ var x : int = tile.x
+ var y : int = tile.y
+
+ score += 1 if _path.has(Vector2i(x, y - 1)) else 0
+ score += 2 if _path.has(Vector2i(x + 1, y)) else 0
+ score += 4 if _path.has(Vector2i(x, y + 1)) else 0
+ score += 8 if _path.has(Vector2i(x - 1, y)) else 0
+
+ return score