From 1aac583cee47d232ef22d8c5df97b888f689ab96 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 9 Oct 2024 17:20:55 +0200 Subject: intermediate commit --- Game/States/Build/BuilderElement.gd | 11 +++++++---- Game/States/Build/StateBuild.gd | 22 +++++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'Game/States/Build') 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 -- cgit v1.2.3