summaryrefslogtreecommitdiff
path: root/scenes/UI/cursor.gd
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-05-20 17:09:58 -0400
committerbd <bdunahu@operationnull.com>2025-05-20 17:09:58 -0400
commit2e1a04a94ee7e132ac2b4334e37978bb2a271c21 (patch)
tree2866fc9dcccf0dcc0ba22aaa2c5062ac0ca74850 /scenes/UI/cursor.gd
parent5daf4cc09c6fb40729607138260cc10acb422477 (diff)
Add cursor scene, ability to place Warlock tower anywhere
Diffstat (limited to 'scenes/UI/cursor.gd')
-rw-r--r--scenes/UI/cursor.gd39
1 files changed, 39 insertions, 0 deletions
diff --git a/scenes/UI/cursor.gd b/scenes/UI/cursor.gd
new file mode 100644
index 0000000..158a2a4
--- /dev/null
+++ b/scenes/UI/cursor.gd
@@ -0,0 +1,39 @@
+extends Node2D
+
+var tile_size = 16.0
+var max_x = 20 * tile_size
+var max_y = 15 * tile_size
+
+var dirs = {"move_right": Vector2.RIGHT,
+ "move_left": Vector2.LEFT,
+ "move_up": Vector2.UP,
+ "move_down": Vector2.DOWN}
+var towers : Dictionary
+
+func _ready():
+ towers["place_warlock"] = preload("res://scenes/defenders/warlock.tscn")
+ position = position.snapped(Vector2.ONE * tile_size)
+ position += Vector2.ONE * tile_size/2
+
+func _unhandled_input(event):
+ for dir in dirs.keys():
+ if event.is_action_pressed(dir):
+ handle_move(dirs[dir])
+ return
+ for tower in towers.keys():
+ if event.is_action_pressed(tower):
+ handle_tower(towers[tower])
+ return
+
+func handle_tower(tower):
+ var tmp = tower.instantiate()
+ var path = get_tree().get_root().get_node("Main/Defenders")
+ path.add_child(tmp)
+ tmp.global_position = position
+
+func handle_move(dir):
+ position += dir * tile_size
+ position.x = max(position.x, tile_size / 2)
+ position.y = max(position.y, tile_size / 2)
+ position.x = min(position.x, max_x - (tile_size / 2))
+ position.y = min(position.y, max_y - (tile_size / 2))