pollen-not-included/entities/scripts/snail.gd
Dan 84f07fde20 Updated entity interaction and game state
Significant changes include:
- Disabled input pickability for DeathBox in Dog entity
- Simplified mouse click detection logic in Snail script
- Removed unnecessary conditions and actions from snail eating state
- Adjusted cursor hotspot position for hand cursor in Cursor Manager
- Reset flower nectar level upon game reset
2024-05-16 12:33:24 +01:00

59 lines
No EOL
1.7 KiB
GDScript

extends CharacterBody2D
class_name Snail
@onready var fsm : FiniteStateMachine = $StateMachine as FiniteStateMachine
@onready var flowers : Flowers = get_parent()
@onready var sprite : Sprite2D = $Sprite
@onready var animation : AnimationPlayer = $AnimationPlayer
var enabled : bool = false
var eating : bool = false
var speed : float = 20.0
var mouse_over : bool = false
func _ready() -> void:
connect("mouse_entered", Callable(self, "on_mouse_entered"))
connect("mouse_exited", Callable(self, "on_mouse_exited"))
animation.connect("animation_finished", Callable(self, "on_animation_finished"))
# Detect mouse left click and trigger function
func _input(event : InputEvent) -> void:
if mouse_over:
if event is InputEventMouseButton:
if (event is InputEventMouseButton && event.button_index == MOUSE_BUTTON_LEFT && event.pressed):
maybe_sleep()
func eat() -> void:
# Play the munch animation and noise
# Reduce the GameState flower_nectar_level
GameState.flower_nectar_level -= 1
func hide_zeds() -> void:
$Z.hide()
$Z2.hide()
$Z3.hide()
$Sprite/ShadowShell.hide()
func maybe_sleep() -> void:
# If the snail is still eating, then we want a 30% chance of switching it it to the sleeping state
if eating:
if randf() < 0.3:
if fsm.get_current_state_name() == "eating":
fsm.change_state(fsm.current_state, "sleeping")
func get_random_target() -> Vector2:
return flowers.get_random_circumference_points()
func on_mouse_entered() -> void:
CursorMgr.hand()
mouse_over = true
func on_mouse_exited() -> void:
# Reset the cursor to the default
mouse_over = false
CursorMgr.reset_cursor()
func on_animation_finished(anim_name : StringName) -> void:
if anim_name == "GoingToSleep":
animation.play("Sleep")