From 7d47bdbf5a3e1507eae5063028124f9ce2346f0a Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 15 May 2024 14:47:28 +0100 Subject: [PATCH] Enhanced snail interaction and sleep behavior The update includes improvements to the snail's interactive behavior. Now, when the mouse hovers over a snail that is eating, it changes to a hand cursor. This change enhances user feedback during interaction. Additionally, the sleeping state of the snail has been expanded. The snail now wakes up after a random interval between 15 and 25 seconds. A timer tracks this duration and triggers a state transition to "Eating" once elapsed. A new hand cursor resource was also added to the CursorManager for use in these interactions. --- entities/scripts/snail.gd | 6 ++++-- entities/snail/states/snail_sleeping.gd | 16 ++++++++++++++-- utility/cursor_manager.gd | 6 +++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/entities/scripts/snail.gd b/entities/scripts/snail.gd index 0bb18a6..491e152 100644 --- a/entities/scripts/snail.gd +++ b/entities/scripts/snail.gd @@ -37,8 +37,10 @@ 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!") + if eating: + mouse_over = true + CursorMgr.hand() + Log.pr("Mouse entered the snail!") func on_mouse_exited() -> void: # Reset the cursor to the default diff --git a/entities/snail/states/snail_sleeping.gd b/entities/snail/states/snail_sleeping.gd index c7b52b0..f47363d 100644 --- a/entities/snail/states/snail_sleeping.gd +++ b/entities/snail/states/snail_sleeping.gd @@ -3,14 +3,26 @@ class_name SnailSleeping @onready var snail : Snail = get_parent().get_parent() as Snail # I think this is bad but I dont care it works +var wakes_up_in : float = 0 +var sleep_timer : float = 0 + func enter(_msg : Dictionary = {}) -> void: Log.pr("I am a snail asleep...") + snail.rotation = 0 + CursorMgr.reset_cursor() + + # Decide how many seconds until the snail wakes up again + wakes_up_in = randf_range(15.0, 25.0) + sleep_timer = 0 func exit() -> void: pass -func update(_delta : float) -> void: - pass +func update(delta : float) -> void: + sleep_timer += delta + + if sleep_timer > wakes_up_in: + state_transition.emit(self, "Eating") func physics_update(_delta : float) -> void: pass diff --git a/utility/cursor_manager.gd b/utility/cursor_manager.gd index 9a5bb36..38d3fe9 100644 --- a/utility/cursor_manager.gd +++ b/utility/cursor_manager.gd @@ -4,6 +4,7 @@ class_name CursorManager @onready var default_cursor : Resource = preload("res://resources/cursors/pointer_a.png") @onready var place_cursor : Resource = preload("res://resources/cursors/target_round_b.png") @onready var edit_cursor : Resource = preload("res://resources/cursors/message_dots_round.png") +@onready var hand_cursor : Resource = preload("res://resources/cursors/hand_open.png") func reset_cursor() -> void: Input.set_custom_mouse_cursor(default_cursor, Input.CURSOR_ARROW, Vector2(8, 8)) @@ -12,4 +13,7 @@ func place() -> void: Input.set_custom_mouse_cursor(place_cursor, Input.CURSOR_ARROW, Vector2(32, 32)) func edit() -> void: - Input.set_custom_mouse_cursor(edit_cursor, Input.CURSOR_ARROW, Vector2(32, 32)) \ No newline at end of file + Input.set_custom_mouse_cursor(edit_cursor, Input.CURSOR_ARROW, Vector2(32, 32)) + +func hand() -> void: + Input.set_custom_mouse_cursor(hand_cursor, Input.CURSOR_ARROW, Vector2(32, 32)) \ No newline at end of file