Clean spawner code

This commit is contained in:
Francois Belair 2020-12-28 12:09:56 -05:00
parent d1c87d96b3
commit 49cc6ef696
2 changed files with 25 additions and 11 deletions

View File

@ -2,16 +2,23 @@ extends Node2D
export var member: PackedScene
func follower_input_event(viewport: Node, event: InputEvent, shape_idx: int, follower:KinematicBody2D):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
for other in get_children():
if other.draw_proximity:
other.draw_proximity = false
other.update()
follower.draw_proximity = true
follower.update()
move_child(follower,get_children().size())
func follower_input_event(
viewport: Node,
event: InputEvent,
shape_idx: int,
follower: KinematicBody2D
) -> void:
if event.is_action_pressed("click"):
for other in get_children():
if other.draw_proximity:
other.draw_proximity = false
other.update()
follower.draw_proximity = true
follower.update()
move_child(follower, get_child_count())
func setup(
linear_speed_max: float,
linear_accel_max: float,
@ -35,10 +42,12 @@ func setup(
cohesion_strength,
separation_strength
)
if i == 0 and show_proximity_radius:
follower.draw_proximity = true
follower.update()
follower.connect("input_event",self,"follower_input_event",[follower])
follower.connect("input_event", self, "follower_input_event", [follower])
var agents := []
for i in followers:
agents.append(i.agent)

View File

@ -239,6 +239,11 @@ toggle_fullscreen={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777254,"unicode":0,"echo":false,"script":null)
]
}
click={
"deadzone": 0.5,
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
]
}
[rendering]