summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/cursor.gd70
-rw-r--r--scripts/cursor.gd.uid1
-rw-r--r--scripts/game_stats_config.gd6
-rw-r--r--scripts/ui_panel.gd9
4 files changed, 7 insertions, 79 deletions
diff --git a/scripts/cursor.gd b/scripts/cursor.gd
deleted file mode 100644
index 22c1da1..0000000
--- a/scripts/cursor.gd
+++ /dev/null
@@ -1,70 +0,0 @@
-extends Node2D
-
-@onready var tilemap = get_node("../Map/TileMapLayer")
-var game_stats_config = preload("res://resources/game_stats_config.tres")
-@onready var map_config = preload("res://resources/map_generator_resource.tres")
-
-var occupied_tiles = {}
-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"]
- }
-}
-
-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):
- handle_tower(towers[tower])
- return
-
-func handle_tower(tower):
- 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
- occupy_tile(position)
- GameData.subtract_life(tower_cost)
-
-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))
-
-func is_valid_placement_tile():
- var tile_coords = tilemap.get_cell_atlas_coords(tilemap.local_to_map(global_position))
- return (tile_coords == (Vector2i(-1, -1))) && (!is_tile_occupied(position))
-
-func is_tile_occupied(tile_position):
- return occupied_tiles.has(tile_position)
-
-func occupy_tile(tile_position):
- occupied_tiles[tile_position] = true
-
-func free_tile(tile_position):
- occupied_tiles.erase(tile_position)
diff --git a/scripts/cursor.gd.uid b/scripts/cursor.gd.uid
deleted file mode 100644
index 015cefa..0000000
--- a/scripts/cursor.gd.uid
+++ /dev/null
@@ -1 +0,0 @@
-uid://bwiimenoyb5og
diff --git a/scripts/game_stats_config.gd b/scripts/game_stats_config.gd
index 1710dbc..4e0a3e6 100644
--- a/scripts/game_stats_config.gd
+++ b/scripts/game_stats_config.gd
@@ -18,16 +18,16 @@ class_name GameStatsConfig
"damage" : 4.0,
"fire_rate" : 1.2,
"range": 75.0,
- "sprite_panel": Vector2i(30, 1),
+ "sprite_panel": Vector2i(32, 4),
"sprite_attacking": Vector2i(31, 2),
"sprite_idle": Vector2i(31, 1),
"cost": 10
},
"wyvern": {
- "damage" : 2.0,
+ "damage" : 1.0,
"fire_rate" : 1.0,
"range": 35.0,
- "sprite_panel": Vector2i(24, 10),
+ "sprite_panel": Vector2i(28, 11),
"sprite_attacking": Vector2i(25, 10),
"sprite_idle": Vector2i(24, 10),
"cost": 15,
diff --git a/scripts/ui_panel.gd b/scripts/ui_panel.gd
index 31275c6..7d3cd7a 100644
--- a/scripts/ui_panel.gd
+++ b/scripts/ui_panel.gd
@@ -1,16 +1,15 @@
extends Panel
var tile_set : TileSet = preload("res://resources/tiles.tres")
+var game_stats_config = preload("res://resources/game_stats_config.tres")
+@onready var util = preload("res://scripts/util.gd")
-@export var texture_atlas_coords: Vector2
@export var object_name: String
@export var cost: String
func _ready():
- var source : TileSetAtlasSource = tile_set.get_source(0)
- var texture_region : Rect2i = source.get_tile_texture_region(texture_atlas_coords)
- var tile_image : Image = source.texture.get_image().get_region(texture_region)
- $HBoxContainer/Texture.texture = ImageTexture.create_from_image(tile_image)
+ var texture = util.get_tile_texture(game_stats_config.defenders[object_name.to_lower()]["sprite_panel"])
+ $HBoxContainer/Texture.texture = texture
$HBoxContainer/Texture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
$HBoxContainer/VBoxContainer/Label.text = object_name
$HBoxContainer/VBoxContainer/Label2.text = cost