From 84f07fde204cc9b6ac481c42f1a78cadf78818fe Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 16 May 2024 12:33:24 +0100 Subject: [PATCH] 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 --- entities/Dog.tscn | 1 + entities/scripts/snail.gd | 8 +++--- entities/snail/states/snail_eating.gd | 36 +++++++-------------------- levels/level_5.tscn | 1 - utility/cursor_manager.gd | 2 +- utility/game_state.gd | 1 + 6 files changed, 15 insertions(+), 34 deletions(-) diff --git a/entities/Dog.tscn b/entities/Dog.tscn index b57a8e4..c2621a5 100644 --- a/entities/Dog.tscn +++ b/entities/Dog.tscn @@ -117,6 +117,7 @@ libraries = { autoplay = "Highlight" [node name="DeathBox" type="Area2D" parent="."] +input_pickable = false [node name="CollisionShape2D" type="CollisionShape2D" parent="DeathBox"] shape = SubResource("CircleShape2D_eyufl") diff --git a/entities/scripts/snail.gd b/entities/scripts/snail.gd index 72ead40..db51db0 100644 --- a/entities/scripts/snail.gd +++ b/entities/scripts/snail.gd @@ -18,7 +18,7 @@ func _ready() -> void: # Detect mouse left click and trigger function func _input(event : InputEvent) -> void: - if mouse_over and eating: + if mouse_over: if event is InputEventMouseButton: if (event is InputEventMouseButton && event.button_index == MOUSE_BUTTON_LEFT && event.pressed): maybe_sleep() @@ -46,10 +46,8 @@ func get_random_target() -> Vector2: return flowers.get_random_circumference_points() func on_mouse_entered() -> void: - if eating: - mouse_over = true - CursorMgr.hand() - Log.pr("Mouse entered the snail!") + CursorMgr.hand() + mouse_over = true func on_mouse_exited() -> void: # Reset the cursor to the default diff --git a/entities/snail/states/snail_eating.gd b/entities/snail/states/snail_eating.gd index 1efbe33..e97003f 100644 --- a/entities/snail/states/snail_eating.gd +++ b/entities/snail/states/snail_eating.gd @@ -7,45 +7,27 @@ var eat_interval : float = 3.0 var eat_timer : float = 0.0 var move_to : Vector2 = Vector2.ZERO - -var original_snail_scale : float = 0.1 +var speed : float = 20.0 func enter(_msg : Dictionary = {}) -> void: Log.pr("I am a snail and I will eat!") snail.eating = true - if snail.animation: - snail.animation.play("Move") - - snail.hide_zeds() func exit() -> void: snail.eating = false - snail.sprite.flip_h = false -func update(delta : float) -> void: - eat_timer += delta +func update(_delta : float) -> void: + eat_timer += _delta + + if move_to == Vector2.ZERO: + move_to = snail.get_random_target() + snail.look_at(move_to) + snail.move_to(move_to, speed) if eat_timer >= eat_interval: snail.eat() eat_timer = 0.0 func physics_update(_delta : float) -> void: - - if move_to == Vector2.ZERO: - move_to = snail.get_random_target() - - if snail.global_position.distance_to(move_to) > 3: - - snail.velocity = snail.global_position.direction_to(move_to) * snail.speed - - if move_to.x > snail.global_position.x: - snail.sprite.scale.x = original_snail_scale - else: - snail.sprite.scale.x = -original_snail_scale - - snail.move_and_slide() - else: - move_to = Vector2.ZERO - - + pass diff --git a/levels/level_5.tscn b/levels/level_5.tscn index d59b044..80f2ad1 100644 --- a/levels/level_5.tscn +++ b/levels/level_5.tscn @@ -130,7 +130,6 @@ scale = Vector2(0.6, 0.6) [node name="Mushrooms" type="Node2D" parent="LevelDecor"] position = Vector2(42, 290) rotation = 0.563741 -scale = Vector2(1, 1) [node name="Mushroom" parent="LevelDecor/Mushrooms" instance=ExtResource("8_dtrxx")] position = Vector2(232, 250) diff --git a/utility/cursor_manager.gd b/utility/cursor_manager.gd index 38d3fe9..e07edf5 100644 --- a/utility/cursor_manager.gd +++ b/utility/cursor_manager.gd @@ -16,4 +16,4 @@ func edit() -> void: 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 + Input.set_custom_mouse_cursor(hand_cursor, Input.CURSOR_ARROW, Vector2(8, 8)) \ No newline at end of file diff --git a/utility/game_state.gd b/utility/game_state.gd index 89325e1..7338b61 100644 --- a/utility/game_state.gd +++ b/utility/game_state.gd @@ -118,3 +118,4 @@ func reset() -> void: drones_used = 0 dead_bees = 0 spawn_snails = false + flower_nectar_level = max_flower_nectar_level