diff options
Diffstat (limited to 'scripts/path_generator.gd')
-rw-r--r-- | scripts/path_generator.gd | 48 |
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 |