Added health bar and snail behavior enhancements
- Introduced a health bar for flowers, which updates based on the current GameState values. - Enhanced snail behavior with eating and sleeping states. Snails now have a chance to switch to the sleeping state while eating. - Improved mouse interaction with snails, allowing them to potentially switch to sleep mode when clicked. - Refactored cursor management into its own class for better code organization and readability. - Updated drone placement logic to use the new CursorManager class. - Added functionality for bees to replenish flower nectar levels after a certain number of deposits.
This commit is contained in:
parent
2a9e78b52e
commit
f0a7c5ca05
12 changed files with 167 additions and 33 deletions
|
|
@ -1,6 +1,46 @@
|
|||
extends Sprite2D
|
||||
extends CharacterBody2D
|
||||
class_name Snail
|
||||
|
||||
@onready var fsm : FiniteStateMachine = $StateMachine as FiniteStateMachine
|
||||
@onready var flowers : Flowers = get_parent()
|
||||
|
||||
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"))
|
||||
|
||||
# Detect mouse left click and trigger function
|
||||
func _input(event : InputEvent) -> void:
|
||||
if mouse_over and eating:
|
||||
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 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:
|
||||
mouse_over = true
|
||||
Log.pr("Mouse entered the snail!")
|
||||
|
||||
func on_mouse_exited() -> void:
|
||||
# Reset the cursor to the default
|
||||
mouse_over = false
|
||||
CursorMgr.reset_cursor()
|
||||
Loading…
Add table
Add a link
Reference in a new issue