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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
extends Node2D
var current_builder_element: BuilderElement
func _ready():
Game.initialize_stage($Layer0)
for tower in $Towers.get_children():
tower.selected.connect(func():
%Tower.text = "Range: %s - Power: %s - Speed: %s" % [
tower.attack_range, tower.attack_power, tower.attack_speed
]
)
#while true:
#var scene = preload("res://Mob.tscn")
#var mob = scene.instantiate()
#add_child(Game.spawn_mob(mob, $Spawn))
#await get_tree().create_timer(randi_range(1, 2)).timeout
#await get_tree().create_timer(0.01).timeout
#break
func _draw():
if Game.debug:
var area = Game.path_grid.region
var cell_size = Game.path_grid.cell_size
var offset = Game.path_grid.offset + (Game.path_grid.cell_size / 2)
for row in range(0, area.size.y + 1):
draw_line(
Vector2(offset.x, offset.y + row * cell_size.y),
Vector2(offset.x + area.size.x * cell_size.x, offset.y + row * cell_size.y),
Color(1, 1, 0, 0.25),
1.0
)
for column in range(0, area.size.x + 1):
draw_line(
Vector2(offset.x + column * cell_size.x, offset.y),
Vector2(offset.x + column * cell_size.x, offset.y + area.size.y * cell_size.y),
Color(1, 1, 0, 0.25),
1.0
)
for row in range(0, area.size.y):
for column in range(0, area.size.x):
if Game.path_grid.is_point_solid(Vector2i(column, row)):
draw_circle(
Vector2(
offset.x + column * cell_size.x + cell_size.x/2,
offset.y + row * cell_size.y + cell_size.y/2
),
1,
Color(1, 1, 0, 0.25)
)
func _input(event: InputEvent):
if event.is_action_pressed("ui_accept"):
for _i in range(0, 1):
var scene = preload("res://Mob.tscn")
var mob = scene.instantiate()
add_child(Game.spawn_mob(mob, $Spawn))
if event.is_action_pressed("spawn_box_toggle"):
%SpawnBox.visible = not %SpawnBox.visible
if Game.mode == Game.Mode.DEFAULT:
if event.is_action_pressed("build_mode_start"):
Game.start_build_mode()
if event.is_action_pressed("builder_tower_select"):
if Tower.selected_tower:
Tower.selected_tower.is_selected = false
if event.is_action_pressed("select"):
if Mob.selected_unit:
Mob.selected_unit.is_selected = false
elif Game.mode == Game.Mode.BUILD:
if event.is_action_pressed("builder_tower_select"):
get_viewport().set_input_as_handled()
if Game.current_builder_element.can_build():
var placed_tower = Game.current_builder_element.element.duplicate() as Tower
Game.place_tower(placed_tower, Game.current_builder_element.global_position)
placed_tower.selected.connect(func():
%Tower.text = "Range: %s - Power: %s - Speed: %s" % [
placed_tower.attack_range, placed_tower.attack_power, placed_tower.attack_speed
]
)
if not Input.is_action_pressed("builder_tower_place_keep"):
Game.stop_build_mode()
if event.is_action_pressed("builder_cancel") or event.is_action_pressed("build_mode_start"):
get_viewport().set_input_as_handled()
Game.stop_build_mode()
func _on_build_mode_button_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("builder_tower_select"):
Game.mode = Game.Mode.BUILD
Game.start_build_mode()
func _on_spawner_box_button_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("select"):
%SpawnBox.visible = not %SpawnBox.visible
|