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 towers : Dictionary[String, Dictionary] = { "place_warlock": { "scene": preload("res://scenes/warlock.tscn"), "cost": game_stats_config.defenders["warlock"]["cost"], }, "place_wyvern": { "scene": preload("res://scenes/wyvern.tscn"), "cost": game_stats_config.defenders["wyvern"]["cost"], }, #"place_werewolf": { #"scene": preload("res://scenes/werewolf.tscn"), #"cost": game_stats_config.defenders["werewolf"]["cost"], #}, #"place_wellspring": { #"scene": preload("res://scenes/wellspring.tscn"), #"cost": game_stats_config.defenders["werewolf"]["cost"], #}, } func _ready(): _max_x = map_config.grid_width * map_config.tile_size _max_y = map_config.grid_height * map_config.tile_size position = position.snapped(Vector2.ONE * map_config.tile_size) position += Vector2.ONE * map_config.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): _tm.place_tower(towers[tower], position) return func handle_move(dir): position += dir * map_config.tile_size position.x = max(position.x, map_config.tile_size / 2) 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))