1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-21 23:54:23 +00:00

Delete SkitterFromMouse

This commit is contained in:
Steffo 2024-04-17 01:54:12 +02:00
parent 382fe80266
commit 44f5556e74
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 0 additions and 86 deletions

View file

@ -1,68 +0,0 @@
extends Node2D
class_name SkitterFromMouse
signal move(movement: Vector2)
signal scared
signal calmed
@export_range(1, 500, 1) var speed: float = 300.0
@export_range(0.1, 5, 0.1) var scare_secs: float = 0.2
@export var directions: Array[Vector2] = []
@onready var calm_timer: Timer = $"CalmTimer"
@onready var scare_area: HoverDetector = $"ScareArea"
enum State { CALM, SCARED }
var state := State.CALM
var direction := Vector2.ZERO
func recheck():
if scare_area.mouse_inside:
scare()
else:
calm()
func calm():
state = State.CALM
calmed.emit()
func scare():
state = State.SCARED
# Pick a direction
var idx := Random.rng.randi_range(0, len(directions) - 1)
direction = directions[idx]
# Start the timeout for calming down
calm_timer.start(scare_secs)
scared.emit()
func _ready():
if not directions:
Log.w(self, "No directions defined, object won't skitter.")
func _physics_process(delta: float) -> void:
match state:
State.SCARED:
if len(directions) > 0:
var movement: Vector2 = direction * delta * speed
move.emit(movement)
func _on_calm_timer_timeout() -> void:
recheck()
func _on_hover_detector_mouse_entered() -> void:
scare()
func _on_move(movement: Vector2) -> void:
Log.p(self, "Moving by: %s" % movement)
func _on_scared() -> void:
Log.p(self, "Scared!")
func _on_calmed() -> void:
Log.p(self, "Calmed down.")

View file

@ -1,18 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://c1wqgyakaultt"]
[ext_resource type="Script" path="res://behaviours/skitter_from_mouse.gd" id="1_ftcf8"]
[ext_resource type="PackedScene" uid="uid://cbg5kgwxusvxf" path="res://behaviours/cursor_detector.tscn" id="2_cuaq0"]
[node name="SkitterFromMouse" type="Node2D"]
script = ExtResource("1_ftcf8")
[node name="ScareArea" parent="." instance=ExtResource("2_cuaq0")]
[node name="CalmTimer" type="Timer" parent="."]
one_shot = true
[connection signal="calmed" from="." to="." method="_on_calmed"]
[connection signal="move" from="." to="." method="_on_move"]
[connection signal="scared" from="." to="." method="_on_scared"]
[connection signal="mouse_entered" from="ScareArea" to="." method="_on_hover_detector_mouse_entered"]
[connection signal="timeout" from="CalmTimer" to="." method="_on_calm_timer_timeout"]