From 49cc6ef696c101825121381f05dcdee8b9d6565c Mon Sep 17 00:00:00 2001 From: Francois Belair Date: Mon, 28 Dec 2020 12:09:56 -0500 Subject: [PATCH] Clean spawner code --- godot/Demos/GroupBehaviors/Spawner.gd | 31 +++++++++++++++++---------- godot/project.godot | 5 +++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/godot/Demos/GroupBehaviors/Spawner.gd b/godot/Demos/GroupBehaviors/Spawner.gd index 75bd1ae..7706015 100644 --- a/godot/Demos/GroupBehaviors/Spawner.gd +++ b/godot/Demos/GroupBehaviors/Spawner.gd @@ -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) diff --git a/godot/project.godot b/godot/project.godot index b33b93c..5352085 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -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]