extends KinematicBody2D onready var color_component = $Color onready var tinted_sprite_component = $TintedSprite onready var clickable_component = $Clickable onready var movable_component = $Movable onready var collision_component = $Collision onready var is_active = false func _ready(): if color_component and tinted_sprite_component: print ("Connecting signals") color_component.connect("color_changed", tinted_sprite_component, "set_color_tint") if clickable_component: clickable_component.connect("clicked", self, "_on_entity_clicked") if movable_component: movable_component.connect("position_updated", self, "_on_position_updated") movable_component.target = self.transform.origin movable_component.pos = self.transform.origin func _process(delta): if is_active and color_component: var color = Color( (sin(float(OS.get_system_time_msecs()) / 1000.0) + 1.0) / 2.0, (sin(float(OS.get_system_time_msecs()) / 300.0) + 1.0) / 2.0, (sin(float(OS.get_system_time_msecs()) / 100.0) + 1.0) / 2.0 ) color_component.set_color(color) pass func _physics_process(delta): if not collision_component: return if movable_component and collision_component: if movable_component.vel.length_squared() < 0.001: return var physics_velocity = move_and_slide(movable_component.vel) movable_component.pos = self.position movable_component.vel = physics_velocity func _on_entity_clicked(): is_active = not is_active func _on_position_updated(new_position): if not collision_component: transform.origin = new_position update() func _unhandled_input(event): if event is InputEventMouseButton and event.pressed: assert(movable_component) movable_component.target = event.position