Placement and platforms
This commit is contained in:
parent
a2164dca72
commit
d37c4ec858
31 changed files with 351 additions and 11 deletions
42
scripts/construction_placer.gd
Normal file
42
scripts/construction_placer.gd
Normal file
|
@ -0,0 +1,42 @@
|
|||
extends Node2D
|
||||
|
||||
var held_construction : Construction
|
||||
|
||||
func _ready() -> void:
|
||||
GuiEventBus.construction_selected.connect(on_construction_selected)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if held_construction == null:
|
||||
return
|
||||
if event.is_action_pressed("plc_place"):
|
||||
var zone = try_get_zone(held_construction.global_position)
|
||||
if zone == null:
|
||||
held_construction.queue_free()
|
||||
else:
|
||||
if zone.get_parent().get_node("EntityHolder").add_construction(held_construction):
|
||||
held_construction = null
|
||||
|
||||
if event.is_action_pressed("plc_cancel"):
|
||||
held_construction.queue_free()
|
||||
|
||||
func on_construction_selected(constructible : Constructible):
|
||||
if held_construction:
|
||||
held_construction.queue_free()
|
||||
held_construction = constructible.scene.instantiate()
|
||||
add_child(held_construction)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if held_construction != null:
|
||||
var mouse_pos = get_global_mouse_position()
|
||||
var zone = try_get_zone(mouse_pos)
|
||||
if zone:
|
||||
global_position = zone.get_placement_position(mouse_pos)
|
||||
else:
|
||||
global_position = mouse_pos
|
||||
|
||||
func try_get_zone(point : Vector2) -> BuildZone:
|
||||
for zone in Registry.build_zones:
|
||||
if zone.is_global_point_in_zone(point):
|
||||
return zone
|
||||
return null
|
Loading…
Add table
Add a link
Reference in a new issue