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

Tweak SkitterFromMouse after manual testing

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

View file

@ -7,25 +7,36 @@ signal scared
signal calmed signal calmed
@export_range(1, 500, 1) var speed: float = 200.0 @export_range(1, 500, 1) var speed: float = 300.0
@export_range(0.1, 5, 0.1) var scare_secs: float = 1.0 @export_range(0.1, 5, 0.1) var scare_secs: float = 0.2
@export var directions: Array[Vector2] = [] @export var directions: Array[Vector2] = []
@onready var calm_timer: Timer = $"CalmTimer" @onready var calm_timer: Timer = $"CalmTimer"
@onready var scare_area: HoverDetector = $"HoverDetector" @onready var scare_area: HoverDetector = $"ScareArea"
enum State { CALM, SCARED } enum State { CALM, SCARED }
var state: State = State.CALM var state := State.CALM
var direction := Vector2.ZERO
func recheck():
if scare_area.mouse_inside:
scare()
else:
calm()
func calm(): func calm():
state = State.CALM state = State.CALM
calmed.emit() calmed.emit()
func scare(): func scare():
state = State.SCARED 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) calm_timer.start(scare_secs)
scared.emit() scared.emit()
@ -38,16 +49,11 @@ func _physics_process(delta: float) -> void:
match state: match state:
State.SCARED: State.SCARED:
if len(directions) > 0: if len(directions) > 0:
var idx := Random.rng.randi_range(0, len(directions) - 1)
var direction: Vector2 = directions[idx]
var movement: Vector2 = direction * delta * speed var movement: Vector2 = direction * delta * speed
move.emit(movement) move.emit(movement)
func _on_calm_timer_timeout() -> void: func _on_calm_timer_timeout() -> void:
if scare_area.mouse_inside: recheck()
scare()
else:
calm()
func _on_hover_detector_mouse_entered() -> void: func _on_hover_detector_mouse_entered() -> void:
scare() scare()

View file

@ -9,6 +9,7 @@ script = ExtResource("1_ftcf8")
[node name="ScareArea" parent="." instance=ExtResource("2_cuaq0")] [node name="ScareArea" parent="." instance=ExtResource("2_cuaq0")]
[node name="CalmTimer" type="Timer" parent="."] [node name="CalmTimer" type="Timer" parent="."]
one_shot = true
[connection signal="calmed" from="." to="." method="_on_calmed"] [connection signal="calmed" from="." to="." method="_on_calmed"]
[connection signal="move" from="." to="." method="_on_move"] [connection signal="move" from="." to="." method="_on_move"]