From 0697f674ec33f8381ba68cf064732ee40e6e584f Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 12 Oct 2024 23:09:56 +0200 Subject: next commit --- Game/States/Build/BuilderElement.gd | 16 +++++++++++++--- Game/States/Build/StateBuild.gd | 10 ++++++---- Game/States/Build/build_grid.gd | 14 +++++++------- 3 files changed, 26 insertions(+), 14 deletions(-) (limited to 'Game/States/Build') diff --git a/Game/States/Build/BuilderElement.gd b/Game/States/Build/BuilderElement.gd index c698f07..eb5ae12 100644 --- a/Game/States/Build/BuilderElement.gd +++ b/Game/States/Build/BuilderElement.gd @@ -25,7 +25,7 @@ func _ready(): 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 + var tile_size = Client.current_stage.map.tile_set.tile_size var snapped_size = collision_shape.size.snapped(tile_size) for x in (snapped_size.x / tile_size.x): for y in (snapped_size.y / tile_size.y): @@ -39,9 +39,15 @@ func _ready(): collision_visibility_area.set_collision_mask_value(1, true) collision_visibility_area.set_collision_mask_value(2, true) collision_visibility_area.set_collision_mask_value(3, true) + collision_visibility_area.set_collision_mask_value(4, true) + collision_visibility_area.set_collision_mask_value(8, true) collision_visibility_area.colliding_color = Color(1, 0, 0, 0.5) collision_visibility_area.not_colliding_color = Color(0, 1, 0, 0.25) + if Client.current_stage.has_method("get_builder_collision_masks"): + for idx in Client.current_stage.get_builder_collision_masks(): + collision_visibility_area.set_collision_mask_value(idx, true) + var shape = RectangleShape2D.new() shape.size = Vector2(tile_size - Vector2i(1, 1)) var cshape = CollisionShape2D.new() @@ -56,7 +62,7 @@ func _ready(): func _draw(): draw_circle( - Client.stage.map.tile_set.tile_size, + Client.current_stage.map.tile_set.tile_size, 8 + instance.attack_range, Color(1, 1, 1, 0.75), false, @@ -66,7 +72,7 @@ func _draw(): func _process(_delta): previous_position = global_position - global_position = get_global_mouse_position().snapped(Client.stage.map.tile_set.tile_size) - Vector2(16,16) + global_position = get_global_mouse_position().snapped(Client.current_stage.map.tile_set.tile_size) - Vector2(16,16) if global_position != previous_position: queue_redraw() @@ -82,6 +88,10 @@ func can_build(): if area.get_overlapping_bodies().size() > 0: return false + + + if Client.current_stage.has_method("can_build"): + return Client.current_stage.can_build() return true diff --git a/Game/States/Build/StateBuild.gd b/Game/States/Build/StateBuild.gd index f16ee3d..dee5084 100644 --- a/Game/States/Build/StateBuild.gd +++ b/Game/States/Build/StateBuild.gd @@ -18,13 +18,15 @@ func _state_input(event: InputEvent): if current_builder_element and current_builder_element.can_build(): var placed_tower = current_builder_element.element.instantiate() as Tower + + placed_tower.global_position = current_builder_element.global_position 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, + Client.current_stage.map.tile_set.tile_size.x * 2, + Client.current_stage.map.tile_set.tile_size.x * 3, + Client.current_stage.map.tile_set.tile_size.x * 4, ].pick_random() - Client.place_tower(placed_tower, current_builder_element.global_position) + Client.place_tower(placed_tower) if not Input.is_action_pressed("builder_tower_place_keep"): current_builder_element.queue_free() diff --git a/Game/States/Build/build_grid.gd b/Game/States/Build/build_grid.gd index 6fd93aa..766c79b 100644 --- a/Game/States/Build/build_grid.gd +++ b/Game/States/Build/build_grid.gd @@ -2,20 +2,20 @@ extends Node2D func _draw(): - var area = Client.stage.map.get_used_rect() - var cell_size = Client.stage.map.tile_set.tile_size - var offset = Client.stage.map.position + var area = Client.current_stage.map.get_used_rect() + var cell_size = Client.current_stage.map.tile_set.tile_size + var offset = area.position for row in range(0, area.size.y + 1): draw_line( - Vector2(offset.x, offset.y + row * cell_size.y), - Vector2(offset.x + area.size.x * cell_size.x, offset.y + row * cell_size.y), + Vector2(offset.x * cell_size.x, offset.y + row * cell_size.y), + Vector2(offset.x * cell_size.x + area.size.x * cell_size.x, offset.y + row * cell_size.y), Color(1, 1, 1, 0.25), 1.0 ) for column in range(0, area.size.x + 1): draw_line( - Vector2(offset.x + column * cell_size.x, offset.y), - Vector2(offset.x + column * cell_size.x, offset.y + area.size.y * cell_size.y), + Vector2(offset.x * cell_size.x + column * cell_size.x, offset.y), + Vector2(offset.x * cell_size.x + column * cell_size.x, offset.y + area.size.y * cell_size.y), Color(1, 1, 1, 0.25), 1.0 ) -- cgit v1.2.3