summaryrefslogtreecommitdiff
path: root/Game/States/Build
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-10-09 17:20:55 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-10-09 17:20:55 +0200
commit1aac583cee47d232ef22d8c5df97b888f689ab96 (patch)
tree7ef0796e4f01272fc68d199e1b0dc1812aaad1e0 /Game/States/Build
parentb96e384d8299473b14edcbf885fa914a9308d18f (diff)
intermediate commit
Diffstat (limited to 'Game/States/Build')
-rw-r--r--Game/States/Build/BuilderElement.gd11
-rw-r--r--Game/States/Build/StateBuild.gd22
2 files changed, 22 insertions, 11 deletions
diff --git a/Game/States/Build/BuilderElement.gd b/Game/States/Build/BuilderElement.gd
index bb10b06..c698f07 100644
--- a/Game/States/Build/BuilderElement.gd
+++ b/Game/States/Build/BuilderElement.gd
@@ -2,7 +2,8 @@ class_name BuilderElement
extends Node2D
-@export var element: Node2D
+@export var element: Resource
+var instance: Tower
var collision_shape: Shape2D
@@ -12,14 +13,16 @@ var collision_areas: Array[Area2D] = []
func _ready():
- var element_sprite: Sprite2D = element.get_node("Sprite2D")
+ instance = element.instantiate()
+
+ var element_sprite: Sprite2D = instance.get_node("Sprite2D")
$Sprite2D.texture = element_sprite.texture
$Sprite2D.region_enabled = element_sprite.region_enabled
$Sprite2D.region_rect = element_sprite.region_rect
$Sprite2D.scale = element_sprite.scale
$Sprite2D.position = element_sprite.position
- var element_collision_shape = element.get_node("CollisionShape2D").duplicate() as CollisionShape2D
+ var element_collision_shape = instance.get_node("CollisionShape2D").duplicate() as CollisionShape2D
collision_shape = element_collision_shape.shape
var tile_size = Client.stage.map.tile_set.tile_size
@@ -54,7 +57,7 @@ func _ready():
func _draw():
draw_circle(
Client.stage.map.tile_set.tile_size,
- 8 + element.attack_range,
+ 8 + instance.attack_range,
Color(1, 1, 1, 0.75),
false,
1.0
diff --git a/Game/States/Build/StateBuild.gd b/Game/States/Build/StateBuild.gd
index d2fb39d..f16ee3d 100644
--- a/Game/States/Build/StateBuild.gd
+++ b/Game/States/Build/StateBuild.gd
@@ -17,14 +17,14 @@ func _state_input(event: InputEvent):
if event.is_action_pressed("builder_tower_select"):
if current_builder_element and current_builder_element.can_build():
- var placed_tower = current_builder_element.element.duplicate() as Tower
- Client.place_tower(placed_tower, current_builder_element.global_position)
+ var placed_tower = current_builder_element.element.instantiate() as Tower
+ placed_tower.attack_range = [
+ Client.stage.map.tile_set.tile_size.x * 2,
+ Client.stage.map.tile_set.tile_size.x * 3,
+ Client.stage.map.tile_set.tile_size.x * 4,
+ ].pick_random()
- placed_tower.selected.connect(func():
- Client.stage.hud.tower.text = "Range: %s - Power: %s - Speed: %s" % [
- placed_tower.attack_range, placed_tower.attack_power, placed_tower.attack_speed
- ]
- )
+ Client.place_tower(placed_tower, current_builder_element.global_position)
if not Input.is_action_pressed("builder_tower_place_keep"):
current_builder_element.queue_free()
@@ -38,3 +38,11 @@ func _state_input(event: InputEvent):
current_builder_element = null
set_state("StateDefault")
+
+ if event.is_action_pressed("builder_cancel") and current_builder_element:
+ current_builder_element.queue_free()
+ current_builder_element = null
+
+
+func _state_unhandled_input(_event: InputEvent) -> void:
+ pass