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 +++++++++++++++------- Game/States/Default/StateDefault.gd | 10 ++++++---- Game/States/StateManager.gd | 4 ++++ 4 files changed, 32 insertions(+), 15 deletions(-) (limited to 'Game/States') 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 diff --git a/Game/States/Default/StateDefault.gd b/Game/States/Default/StateDefault.gd index 1d2dd9f..b7b630c 100644 --- a/Game/States/Default/StateDefault.gd +++ b/Game/States/Default/StateDefault.gd @@ -6,6 +6,12 @@ func _state_input(event: InputEvent) -> void: if event.is_action_pressed("build_mode_start"): set_state("StateBuild") + if event.is_action_pressed("select"): + if Unit.selected_unit: + Unit.selected_unit.is_selected = false + + +func _state_unhandled_input(event: InputEvent) -> void: # deselect if event.is_action_pressed("select"): # if not multi selecting @@ -13,7 +19,3 @@ func _state_input(event: InputEvent) -> void: if Tower.selected_towers: for tower in Tower.selected_towers.duplicate(): tower.is_selected = false - - if event.is_action_pressed("select"): - if Unit.selected_unit: - Unit.selected_unit.is_selected = false diff --git a/Game/States/StateManager.gd b/Game/States/StateManager.gd index e62cdb4..5a176e2 100644 --- a/Game/States/StateManager.gd +++ b/Game/States/StateManager.gd @@ -10,6 +10,10 @@ func _input(event: InputEvent) -> void: Client.state._state_input(event) +func _unhandled_input(event: InputEvent) -> void: + Client.state._state_unhandled_input(event) + + func set_state(state: Variant): if state is not State: state = get_node(state) -- cgit v1.2.3