diff options
author | bd <bdunahu@operationnull.com> | 2025-05-24 18:50:01 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-05-24 18:50:01 -0400 |
commit | 2190d18d8d58f867927126829e7c0d7ef6fac372 (patch) | |
tree | 1dd88af4374a9105ef2c723c43a68a0fd67e390f /scripts/player.gd | |
parent | c38a303aad3c3c0d8114524e664da6ad721e21c4 (diff) |
Add UI panel which displays actions/upgrades
Diffstat (limited to 'scripts/player.gd')
-rw-r--r-- | scripts/player.gd | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/scripts/player.gd b/scripts/player.gd index 45b2b61..d9ee0bd 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -1,16 +1,27 @@ extends Node2D +var game_stats_config = preload("res://resources/game_stats_config.tres") @onready var map_config = preload("res://resources/map_generator_resource.tres") @onready var _tm = get_node("../Defenders") var _max_x : int var _max_y : int -var dirs = {"move_right": Vector2.RIGHT, - "move_left": Vector2.LEFT, - "move_up": Vector2.UP, - "move_down": Vector2.DOWN - } +var dirs = { + "move_right": Vector2.RIGHT, + "move_left": Vector2.LEFT, + "move_up": Vector2.UP, + "move_down": Vector2.DOWN +} + +var tower_ids = { + "tower_action_one": 0, + "tower_action_two": 1, + "tower_action_three": 2, + "tower_action_four": 3, +} + +signal curr_tile(tile_state) func _ready(): _max_x = map_config.grid_width * map_config.tile_size @@ -23,7 +34,10 @@ func _unhandled_input(event): if event.is_action_pressed(dir): handle_move(dirs[dir]) return - _tm.handle_tower_key(event, position) + for id in tower_ids.keys(): + if event.is_action_pressed(id): + _tm.handle_tower_key(tower_ids[id], global_position) + emit_signal("curr_tile", _get_tile_state()) func handle_move(dir): position += dir * map_config.tile_size @@ -31,3 +45,14 @@ func handle_move(dir): position.y = max(position.y, map_config.tile_size / 2) position.x = min(position.x, _max_x - (map_config.tile_size / 2)) position.y = min(position.y, _max_y - (map_config.tile_size / 2)) + +# this method of getting uniform menu for the panel +# was specifically designed that way in game stats config +# it may be inefficient and is somewhat messy +func _get_tile_state(): + var tile_info = null + if _tm.is_tile_occupied(position): + tile_info = _tm.get_upgrades_at(position) + elif _tm.is_valid_placement_tile(position): + tile_info = game_stats_config.defenders + return tile_info |