1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-22 16:14:22 +00:00

Make it possible for MoveTowardsMouse to detach and stop moving

This commit is contained in:
Steffo 2024-04-14 05:12:10 +02:00
parent c2dab55333
commit 45512a8ba1
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 10 additions and 2 deletions

View file

@ -3,17 +3,19 @@ class_name MoveTowardsMouse
signal move(movement: Vector2) signal move(movement: Vector2)
signal detached
signal captured signal captured
@export_range(-500, 500, 1) var speed: float = 100.0 @export_range(-500, 500, 1) var speed: float = 100.0
@export var can_detach: bool = false
@onready var game := MainGame.get_ancestor(self) @onready var game := MainGame.get_ancestor(self)
enum State { STILL, CAPTURED } enum State { DETACHED, CAPTURED }
var state: State = State.STILL var state: State = State.DETACHED
func get_relative_mouse_position(): func get_relative_mouse_position():
@ -32,3 +34,8 @@ func _physics_process(delta: float) -> void:
func _on_capture_area_mouse_entered() -> void: func _on_capture_area_mouse_entered() -> void:
state = State.CAPTURED state = State.CAPTURED
captured.emit() captured.emit()
func _on_capture_area_mouse_exited() -> void:
if can_detach:
state = State.DETACHED
detached.emit()

View file

@ -9,3 +9,4 @@ script = ExtResource("1_nbja1")
[node name="CaptureArea" parent="." instance=ExtResource("2_qru2e")] [node name="CaptureArea" parent="." instance=ExtResource("2_qru2e")]
[connection signal="mouse_entered" from="CaptureArea" to="." method="_on_capture_area_mouse_entered"] [connection signal="mouse_entered" from="CaptureArea" to="." method="_on_capture_area_mouse_entered"]
[connection signal="mouse_exited" from="CaptureArea" to="." method="_on_capture_area_mouse_exited"]