blob: 5add6405d6b7fb4eda37acd6911c2cd1fbb63db1 (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)
|