From 4b3e05b74fec984fdb09aab0acf8295458ec6bca Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 19 Apr 2024 03:39:07 +0200 Subject: [PATCH] Tweak a few more things --- behaviours/eater.gd | 7 +++---- behaviours/eater.tscn | 1 - behaviours/timer_stddev.gd | 4 ---- entities/imp.gd | 5 ++++- entities/imp.tscn | 18 +++++++++++++--- entities/sheep.tscn | 43 +++++++++++++++++++------------------- 6 files changed, 43 insertions(+), 35 deletions(-) diff --git a/behaviours/eater.gd b/behaviours/eater.gd index 4bd5392..2a0c563 100644 --- a/behaviours/eater.gd +++ b/behaviours/eater.gd @@ -11,6 +11,9 @@ signal eaten(edible: Edible) @export var acceptable_diets: Array[StringName] = [] +func log_eaten(edible: Edible) -> void: + Log.p(self, "Eaten: %s" % edible) + func _on_body_entered(body: Node2D) -> void: var edibles: Array = body.find_children("Edible", "Edible", false, false) @@ -18,7 +21,3 @@ func _on_body_entered(body: Node2D) -> void: if edible.diet in acceptable_diets: eaten.emit(edible) edible.eat() - - -func _on_eaten(edible: Edible) -> void: - Log.p(self, "Eaten: %s" % edible) diff --git a/behaviours/eater.tscn b/behaviours/eater.tscn index d1f79ab..765b510 100644 --- a/behaviours/eater.tscn +++ b/behaviours/eater.tscn @@ -9,4 +9,3 @@ monitorable = false script = ExtResource("1_urx5y") [connection signal="body_entered" from="." to="." method="_on_body_entered"] -[connection signal="eaten" from="." to="." method="_on_eaten"] diff --git a/behaviours/timer_stddev.gd b/behaviours/timer_stddev.gd index ef3418a..6a05b64 100644 --- a/behaviours/timer_stddev.gd +++ b/behaviours/timer_stddev.gd @@ -17,7 +17,3 @@ func randomize_wait_time() -> void: Random.rng.randfn(mean_secs, deviation), max_secs ) - - -func _ready() -> void: - randomize_wait_time() diff --git a/entities/imp.gd b/entities/imp.gd index e87d76e..57ffea1 100644 --- a/entities/imp.gd +++ b/entities/imp.gd @@ -5,6 +5,9 @@ class_name Imp @onready var sprite: SpriteLeftRight = $"Sprite" -func _on_move(movement:Vector2): +func _on_move(movement: Vector2): move_and_collide(movement) sprite.handle_move(movement) + +func _on_eater_eaten(edible: Edible) -> void: + edible.get_parent().queue_free() diff --git a/entities/imp.tscn b/entities/imp.tscn index dc0c5ac..a083533 100644 --- a/entities/imp.tscn +++ b/entities/imp.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=16 format=3 uid="uid://4d3ksr3171x4"] +[gd_scene load_steps=18 format=3 uid="uid://4d3ksr3171x4"] [ext_resource type="Script" path="res://entities/imp.gd" id="1_dixpc"] [ext_resource type="PackedScene" uid="uid://bxbjfev0lhwws" path="res://behaviours/sprite_left_right.tscn" id="2_eqcdi"] @@ -13,6 +13,7 @@ [ext_resource type="PackedScene" uid="uid://cml7rqvyfuagx" path="res://behaviours/move_towards.tscn" id="11_4ra22"] [ext_resource type="PackedScene" uid="uid://ctpn4hvkhxoi3" path="res://behaviours/tracker_edible.tscn" id="12_dr2oe"] [ext_resource type="PackedScene" uid="uid://dti7l0d40hhgt" path="res://behaviours/target_picker.tscn" id="13_mwxuf"] +[ext_resource type="PackedScene" uid="uid://jg7qkbswgqjc" path="res://behaviours/eater.tscn" id="14_w2h8x"] [sub_resource type="CircleShape2D" id="CircleShape2D_ide4n"] radius = 8.0 @@ -20,6 +21,9 @@ radius = 8.0 [sub_resource type="CircleShape2D" id="CircleShape2D_1bmhf"] radius = 256.0 +[sub_resource type="CircleShape2D" id="CircleShape2D_qhk1q"] +radius = 40.0 + [node name="Imp" type="CharacterBody2D"] collision_layer = 8 collision_mask = 14 @@ -54,6 +58,7 @@ default_priority = 10 alternative_priority = 10 [node name="ChangeDirectionTimer" parent="MovementWander" instance=ExtResource("10_phvea")] +wait_time = 0.001 autostart = true mean_secs = 2.0 deviation = 2.0 @@ -61,6 +66,7 @@ min_secs = 0.6 max_secs = 3.0 [node name="MovementHunt" parent="." instance=ExtResource("11_4ra22")] +speed = 140.0 enabled = false [node name="HuntPriority" parent="MovementHunt" instance=ExtResource("9_2wb1b")] @@ -76,12 +82,17 @@ debug_color = Color(1, 0.498039, 0, 0) [node name="TargetPicker" parent="MovementHunt/TrackerMeat" node_paths=PackedStringArray("tracker") instance=ExtResource("13_mwxuf")] tracker = NodePath("..") +[node name="Eater" parent="." instance=ExtResource("14_w2h8x")] +acceptable_diets = Array[StringName]([&"Meat"]) + +[node name="Shape" type="CollisionShape2D" parent="Eater"] +shape = SubResource("CircleShape2D_qhk1q") +debug_color = Color(1, 0, 0, 0) + [connection signal="timeout" from="CoinSpawner/Timer" to="CoinSpawner" method="spawn"] [connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"] [connection signal="changed_direction" from="MovementWander" to="MovementWander/WanderPriority" method="priority_conditional"] [connection signal="move" from="MovementWander" to="." method="_on_move"] -[connection signal="move_disabled" from="MovementWander" to="MovementWander/ChangeDirectionTimer" method="stop"] -[connection signal="move_enabled" from="MovementWander" to="MovementWander/ChangeDirectionTimer" method="start"] [connection signal="priority_changed_no_args" from="MovementWander/WanderPriority" to="MovementSampler" method="enable"] [connection signal="timeout" from="MovementWander/ChangeDirectionTimer" to="MovementWander" method="randomize_direction"] [connection signal="changed_target" from="MovementHunt" to="MovementHunt/HuntPriority" method="priority_conditional"] @@ -90,3 +101,4 @@ tracker = NodePath("..") [connection signal="tracked" from="MovementHunt/TrackerMeat" to="MovementHunt/TrackerMeat/TargetPicker" method="sample_target_if_null" unbinds=1] [connection signal="untracked" from="MovementHunt/TrackerMeat" to="MovementHunt/TrackerMeat/TargetPicker" method="clear_if_target"] [connection signal="target_changed" from="MovementHunt/TrackerMeat/TargetPicker" to="MovementHunt" method="set_target" unbinds=1] +[connection signal="eaten" from="Eater" to="." method="_on_eater_eaten"] diff --git a/entities/sheep.tscn b/entities/sheep.tscn index aca8877..7f76420 100644 --- a/entities/sheep.tscn +++ b/entities/sheep.tscn @@ -131,30 +131,30 @@ one_shot = true min_secs = 0.3 max_secs = 1.5 -[node name="MovementRunFromHunter" parent="." instance=ExtResource("12_x2g3x")] -speed = -66.0 -enabled = false - -[node name="RunFromHunterPriority" parent="MovementRunFromHunter" instance=ExtResource("11_0jlmk")] -alternative_priority = 30 - -[node name="HunterSense" parent="MovementRunFromHunter" instance=ExtResource("14_eqowb")] - -[node name="TargetPicker" parent="MovementRunFromHunter/HunterSense" node_paths=PackedStringArray("tracker") instance=ExtResource("13_jf6em")] -tracker = NodePath("..") - [node name="MovementRunFromMouse" parent="." instance=ExtResource("12_x2g3x")] speed = -66.0 enabled = false [node name="RunFromMousePriority" parent="MovementRunFromMouse" instance=ExtResource("11_0jlmk")] -alternative_priority = 40 +alternative_priority = 30 [node name="CursorSense" parent="MovementRunFromMouse" instance=ExtResource("13_5fkdr")] [node name="Shape" type="CollisionShape2D" parent="MovementRunFromMouse/CursorSense"] shape = SubResource("CircleShape2D_etpf6") -debug_color = Color(1, 0, 0, 0.0470588) +debug_color = Color(1, 1, 0, 0) + +[node name="MovementRunFromHunter" parent="." instance=ExtResource("12_x2g3x")] +speed = -66.0 +enabled = false + +[node name="RunFromHunterPriority" parent="MovementRunFromHunter" instance=ExtResource("11_0jlmk")] +alternative_priority = 40 + +[node name="HunterSense" parent="MovementRunFromHunter" instance=ExtResource("14_eqowb")] + +[node name="TargetPicker" parent="MovementRunFromHunter/HunterSense" node_paths=PackedStringArray("tracker") instance=ExtResource("13_jf6em")] +tracker = NodePath("..") [connection signal="ready" from="MovementSampler" to="MovementSampler" method="enable"] [connection signal="move" from="MovementIdle" to="." method="_on_move"] @@ -168,17 +168,16 @@ debug_color = Color(1, 0, 0, 0.0470588) [connection signal="move_enabled" from="MovementWander" to="MovementWander/TiredTimer" method="start"] [connection signal="priority_changed_no_args" from="MovementWander/WanderPriority" to="MovementSampler" method="enable"] [connection signal="timeout" from="MovementWander/TiredTimer" to="MovementWander" method="clear_direction"] -[connection signal="changed_target" from="MovementRunFromHunter" to="MovementRunFromHunter/RunFromHunterPriority" method="priority_conditional"] -[connection signal="changed_target" from="MovementRunFromHunter" to="MovementRunFromHunter" method="log_target" unbinds=1] -[connection signal="move" from="MovementRunFromHunter" to="." method="_on_move"] -[connection signal="move_disabled" from="MovementRunFromHunter" to="MovementWander" method="clear_direction"] -[connection signal="priority_changed_no_args" from="MovementRunFromHunter/RunFromHunterPriority" to="MovementSampler" method="enable"] -[connection signal="tracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="set_target_if_null"] -[connection signal="untracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="clear_if_target"] -[connection signal="target_changed" from="MovementRunFromHunter/HunterSense/TargetPicker" to="MovementRunFromHunter" method="set_target" unbinds=1] [connection signal="changed_target" from="MovementRunFromMouse" to="MovementRunFromMouse/RunFromMousePriority" method="priority_conditional"] [connection signal="move" from="MovementRunFromMouse" to="." method="_on_move"] [connection signal="move_enabled" from="MovementRunFromMouse" to="MovementWander" method="clear_direction"] [connection signal="priority_changed_no_args" from="MovementRunFromMouse/RunFromMousePriority" to="MovementSampler" method="enable"] [connection signal="cursor_entered" from="MovementRunFromMouse/CursorSense" to="MovementRunFromMouse" method="set_target"] [connection signal="cursor_exited" from="MovementRunFromMouse/CursorSense" to="MovementRunFromMouse" method="clear_target" unbinds=1] +[connection signal="changed_target" from="MovementRunFromHunter" to="MovementRunFromHunter/RunFromHunterPriority" method="priority_conditional"] +[connection signal="move" from="MovementRunFromHunter" to="." method="_on_move"] +[connection signal="move_disabled" from="MovementRunFromHunter" to="MovementWander" method="clear_direction"] +[connection signal="priority_changed_no_args" from="MovementRunFromHunter/RunFromHunterPriority" to="MovementSampler" method="enable"] +[connection signal="tracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="set_target_if_null"] +[connection signal="untracked" from="MovementRunFromHunter/HunterSense" to="MovementRunFromHunter/HunterSense/TargetPicker" method="clear_if_target"] +[connection signal="target_changed" from="MovementRunFromHunter/HunterSense/TargetPicker" to="MovementRunFromHunter" method="set_target" unbinds=1]