blob: cf48175bc47167cd90639dbd62434bdb6f33b00b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
extends Object
class_name PathGenerator
var map_config : MapGeneratorResource = preload("res://resources/map_generator_resource.tres")
func generate_path() -> Array[Vector2i]:
var path : Array[Vector2i]
var x : int = 0
var y : int = randi_range(1, map_config.grid_height - 3)
while x < map_config.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 == map_config.grid_width - 1:
x += 1
elif choice == 1 && y < map_config.grid_height - 3 && !path.has(Vector2i(x, y + 1)):
y += 1
elif choice == 2 && y > 1 && !path.has(Vector2i(x, y - 1)):
y -= 1
return path
|