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,6 @@
|
|||
class_name DirectorDrone extends Drone
|
||||
|
||||
@onready var edit_cursor : Resource = preload("res://resources/cursors/message_dots_round.png")
|
||||
|
||||
@onready var label : Label = get_node("Label")
|
||||
|
||||
@export var visit_order : int = 0 :
|
||||
|
|
@ -17,21 +17,19 @@ func _on_click_detection_mouse_entered() -> void:
|
|||
if GameState.placing_drone == false:
|
||||
Log.pr("Mouse entered the director drone!")
|
||||
label.visible = true
|
||||
Input.set_custom_mouse_cursor(edit_cursor, Input.CURSOR_ARROW, Vector2(32, 32))
|
||||
CursorMgr.edit()
|
||||
|
||||
func _on_click_detection_mouse_exited() -> void:
|
||||
if GameState.placing_drone == false:
|
||||
Log.pr("Mouse exited the director drone!")
|
||||
label.visible = false
|
||||
#Input.set_custom_mouse_cursor(null)
|
||||
GameState.reset_cursor()
|
||||
CursorMgr.reset_cursor()
|
||||
|
||||
|
||||
func _on_click_detection_input_event(_viewport:Node, event:InputEvent, _shape_idx:int) -> void:
|
||||
if GameState.placing_drone == false:
|
||||
if (event is InputEventMouseButton && event.button_index == MOUSE_BUTTON_RIGHT && event.pressed):
|
||||
#Input.set_custom_mouse_cursor(null)
|
||||
GameState.reset_cursor()
|
||||
CursorMgr.reset_cursor()
|
||||
queue_free()
|
||||
get_parent().get_parent().update_director_drone_list()
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ func _physics_process(delta : float) -> void:
|
|||
if current_state:
|
||||
current_state.physics_update(delta)
|
||||
|
||||
func get_current_state_name() -> String:
|
||||
if current_state:
|
||||
return current_state.name.to_lower()
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Use force_change_state cautiously, it immediately switches to a state regardless of any transitions.
|
||||
# This is used to force us into a 'death state' when killed
|
||||
func force_change_state(new_state : String) -> void:
|
||||
|
|
|
|||
|
|
@ -10,17 +10,25 @@ var spawn_snails : bool = false
|
|||
@onready var spawn_area : CollisionShape2D = $FlowerCollectionArea/CollisionShape2D
|
||||
@onready var snail : Snail = $Snail
|
||||
|
||||
var last_health_check : float = 0
|
||||
var health_check_timer : float = 0.5
|
||||
|
||||
@onready var health_bar : ProgressBar = $HealthBar
|
||||
|
||||
func _ready() -> void:
|
||||
hide_outline()
|
||||
setup_healthbar()
|
||||
|
||||
## Check if this level is spawning snails or not
|
||||
if GameState.spawn_snails:
|
||||
Log.pr("Going to be spawning snails!")
|
||||
spawn_snails = true
|
||||
|
||||
Log.pr(get_random_snail_spawn())
|
||||
snail.global_position = get_random_snail_spawn()
|
||||
Log.pr(get_random_circumference_points())
|
||||
snail.global_position = get_random_circumference_points()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
update_healthbar(delta)
|
||||
|
||||
func show_outline() -> void:
|
||||
outline.visible = true
|
||||
|
|
@ -29,7 +37,7 @@ func hide_outline() -> void:
|
|||
outline.visible = false
|
||||
|
||||
|
||||
func get_random_snail_spawn() -> Vector2:
|
||||
func get_random_circumference_points() -> Vector2:
|
||||
var circle_radius : float = spawn_area.shape.radius
|
||||
var random_angle : float = randf_range(0, TAU)
|
||||
|
||||
|
|
@ -39,4 +47,24 @@ func get_random_snail_spawn() -> Vector2:
|
|||
var circle_center : Vector2 = spawn_area.global_position
|
||||
var random_point : Vector2 = circle_center + Vector2(x, y)
|
||||
|
||||
return random_point
|
||||
return random_point
|
||||
|
||||
## Initial setup of the health bar - updating the values
|
||||
# and hiding it from view.
|
||||
func setup_healthbar() -> void:
|
||||
health_bar.max_value = GameState.max_flower_nectar_level
|
||||
health_bar.value = GameState.flower_nectar_level
|
||||
health_bar.visible = false
|
||||
|
||||
## Update the health bar based on the current GameState values
|
||||
# and display it if required. Conversely, hide it if the flower is at max powah.
|
||||
func update_healthbar(delta : float) -> void:
|
||||
last_health_check += delta
|
||||
if last_health_check >= health_check_timer:
|
||||
last_health_check = 0
|
||||
if GameState.flower_nectar_level < GameState.max_flower_nectar_level:
|
||||
health_bar.value = GameState.flower_nectar_level
|
||||
health_bar.visible = true
|
||||
else:
|
||||
health_bar.value = GameState.max_flower_nectar_level
|
||||
health_bar.visible = false
|
||||
|
|
@ -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