summaryrefslogtreecommitdiff
path: root/scripts/path_generator.gd
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-05-22 20:24:01 -0400
committerbd <bdunahu@operationnull.com>2025-05-22 20:24:01 -0400
commita95e2ead7e3ade3c13e4e9f6e68c24df4430097a (patch)
tree49913b6b0081ec7d51a9c672437597b9cc1b6b7b /scripts/path_generator.gd
parentb318529cf9c01fca4ac2e1b7c7f7fccd0be4589a (diff)
Make WaveSpawner, Cursor, use generated paths
Diffstat (limited to 'scripts/path_generator.gd')
-rw-r--r--scripts/path_generator.gd16
1 files changed, 7 insertions, 9 deletions
diff --git a/scripts/path_generator.gd b/scripts/path_generator.gd
index 0e9719a..87fedc3 100644
--- a/scripts/path_generator.gd
+++ b/scripts/path_generator.gd
@@ -5,29 +5,27 @@ class_name PathGenerator
var _grid_width : int
var _grid_height : int
-var _path : Array[Vector2i]
-
func _init(width:int, height:int):
_grid_width = width
_grid_height = height
-func generate_path():
- _path.clear()
+func generate_path() -> Array[Vector2i]:
+ var path : Array[Vector2i]
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))
+ 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)):
+ 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)):
+ elif choice == 2 && y > 1 && !path.has(Vector2i(x, y - 1)):
y -= 1
- return _path
+ return path