summaryrefslogtreecommitdiff
path: root/scenes/UI/cursor.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scenes/UI/cursor.gd')
-rw-r--r--scenes/UI/cursor.gd24
1 files changed, 16 insertions, 8 deletions
diff --git a/scenes/UI/cursor.gd b/scenes/UI/cursor.gd
index cb0d0b4..c71eaa2 100644
--- a/scenes/UI/cursor.gd
+++ b/scenes/UI/cursor.gd
@@ -11,17 +11,23 @@ var dirs = {"move_right": Vector2.RIGHT,
"move_left": Vector2.LEFT,
"move_up": Vector2.UP,
"move_down": Vector2.DOWN}
-var towers : Dictionary
+var towers : Dictionary = {
+ "place_warlock": {
+ "scene": preload("res://scenes/defenders/warlock.tscn"),
+ "cost": 10
+ },
+ "place_wyvern": {
+ "scene": preload("res://scenes/defenders/wyvern.tscn"),
+ "cost": 15
+ }
+}
func _ready():
tile_size = grid_manager.tile_size
max_x = 20 * tile_size
max_y = 15 * tile_size
-
- towers["place_warlock"] = preload("res://scenes/defenders/warlock.tscn")
- towers["place_wyvern"] = preload("res://scenes/defenders/wyvern.tscn")
position = position.snapped(Vector2.ONE * tile_size)
- position += Vector2.ONE * tile_size / 2
+ position += Vector2(max_x / 2, max_y / 2) + Vector2(1, 0) * tile_size / 2
func _unhandled_input(event):
for dir in dirs.keys():
@@ -34,17 +40,19 @@ func _unhandled_input(event):
return
func handle_tower(tower):
- if is_valid_placement_tile():
- var tmp = tower.instantiate()
+ var tower_cost = tower["cost"]
+ if is_valid_placement_tile() && GameData.get_life() >= tower_cost:
+ var tmp = tower["scene"].instantiate()
var path = get_tree().get_root().get_node("Main/Defenders")
path.add_child(tmp)
tmp.global_position = position
grid_manager.occupy_tile(position)
+ GameData.subtract_life(tower_cost)
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.y = max(position.y, tile_size + tile_size / 2)
position.x = min(position.x, max_x - (tile_size / 2))
position.y = min(position.y, max_y - (tile_size / 2))