From 2fc4f9e91afa60716e128ef4493cf4963d953e24 Mon Sep 17 00:00:00 2001 From: Lorenzo Rossi Date: Sun, 14 Apr 2024 19:48:13 +0200 Subject: [PATCH 01/10] Add spawner and SpawnedEntities --- behaviours/spawner.gd | 18 ++++++++++++++++++ behaviours/spawner.tscn | 6 ++++++ scenes/game/main_game.tscn | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 behaviours/spawner.gd create mode 100644 behaviours/spawner.tscn diff --git a/behaviours/spawner.gd b/behaviours/spawner.gd new file mode 100644 index 0000000..13a0411 --- /dev/null +++ b/behaviours/spawner.gd @@ -0,0 +1,18 @@ +extends Node2D +class_name Spawner + +signal spawned(entity: Node2D) + +@export var scene: PackedScene +@export var parent: Node2D + +func spawn(): + var entity = scene.instantiate() + entity.global_scale = global_scale + entity.global_position = global_position + entity.global_rotation = global_rotation + parent.add_child(entity) + +func _ready(): + if parent == null: + parent = MainGame.get_ancestor(self).get_node("SpawnedEntities") diff --git a/behaviours/spawner.tscn b/behaviours/spawner.tscn new file mode 100644 index 0000000..2154f4a --- /dev/null +++ b/behaviours/spawner.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://cyrg770fsetyu"] + +[ext_resource type="Script" path="res://behaviours/spawner.gd" id="1_b4uk0"] + +[node name="Spawner" type="Node2D"] +script = ExtResource("1_b4uk0") diff --git a/scenes/game/main_game.tscn b/scenes/game/main_game.tscn index 543c167..7ee58c3 100644 --- a/scenes/game/main_game.tscn +++ b/scenes/game/main_game.tscn @@ -66,3 +66,5 @@ position = Vector2(-135, -134) [node name="Sheep2" parent="." instance=ExtResource("5_63bwb")] position = Vector2(-462, -77) + +[node name="SpawnedEntities" type="Node2D" parent="."] From 93f947aa1af15b789425a4d09959494513ae7a2a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 20:51:57 +0200 Subject: [PATCH 02/10] Name collision layers --- project.godot | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/project.godot b/project.godot index 804c00b..35cfb04 100644 --- a/project.godot +++ b/project.godot @@ -33,6 +33,15 @@ main_menu={ ] } +[layer_names] + +2d_physics/layer_1="Unset" +2d_physics/layer_2="Tiles" +2d_physics/layer_3="Trees" +2d_physics/layer_4="Entities (grounded)" +2d_physics/layer_5="Entities (air)" +2d_physics/layer_6="Pickups" + [physics] common/physics_ticks_per_second=100 From aa69648a592ba2cc0e1500a0ddee61d6a98f5e07 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 20:53:45 +0200 Subject: [PATCH 03/10] Setup collision layers on `Sheep` --- entities/sheep.tscn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entities/sheep.tscn b/entities/sheep.tscn index bca940d..56d1ffe 100644 --- a/entities/sheep.tscn +++ b/entities/sheep.tscn @@ -10,6 +10,8 @@ radius = 16.0 [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_08frh"] [node name="Sheep" type="CharacterBody2D"] +collision_layer = 8 +collision_mask = 14 script = ExtResource("1_4dmll") [node name="Shape" type="CollisionShape2D" parent="."] From 42661f8efc98ca791f5292361154fa9613b2984b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 20:55:25 +0200 Subject: [PATCH 04/10] Remove collision layers from `Collectable` --- behaviours/collectable.tscn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/behaviours/collectable.tscn b/behaviours/collectable.tscn index d9cfe9b..82d564c 100644 --- a/behaviours/collectable.tscn +++ b/behaviours/collectable.tscn @@ -9,6 +9,8 @@ radius = 16.0 script = ExtResource("1_p0pc3") [node name="MouseArea" type="Area2D" parent="."] +collision_layer = 0 +collision_mask = 0 monitorable = false [node name="Shape" type="CollisionShape2D" parent="MouseArea"] From b0908e4e29f5b7a82aac4e60a4254ab97e5573a0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 20:56:18 +0200 Subject: [PATCH 05/10] Remove collision layers from `Draggable` --- behaviours/draggable.tscn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/behaviours/draggable.tscn b/behaviours/draggable.tscn index 6750bf5..24c8ffc 100644 --- a/behaviours/draggable.tscn +++ b/behaviours/draggable.tscn @@ -7,6 +7,8 @@ radius = 8.0 [node name="Draggable" type="Area2D"] +collision_layer = 0 +collision_mask = 0 script = ExtResource("1_hdedq") [node name="Shape" type="CollisionShape2D" parent="."] From ba99709a55ab1cdcd6038bb0593f31bf0bca1832 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 20:56:44 +0200 Subject: [PATCH 06/10] Remove collision layers from `HoverDetector` --- behaviours/hover_detector.tscn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/behaviours/hover_detector.tscn b/behaviours/hover_detector.tscn index 04097d6..d79fa3e 100644 --- a/behaviours/hover_detector.tscn +++ b/behaviours/hover_detector.tscn @@ -6,6 +6,8 @@ radius = 8.0 [node name="HoverDetector" type="Area2D"] +collision_layer = 0 +collision_mask = 0 monitorable = false script = ExtResource("1_51m5p") From 9fda8cc86f5f0c28acf11f71c6adf8552cf47d24 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 20:57:25 +0200 Subject: [PATCH 07/10] Configure `Hunter`'s `CollisionArea` layer and mask --- behaviours/hunter.tscn | 3 +++ 1 file changed, 3 insertions(+) diff --git a/behaviours/hunter.tscn b/behaviours/hunter.tscn index f206d8c..42fcfc7 100644 --- a/behaviours/hunter.tscn +++ b/behaviours/hunter.tscn @@ -9,6 +9,9 @@ radius = 100.0 script = ExtResource("1_3bmd5") [node name="DetectionArea" type="Area2D" parent="."] +collision_layer = 0 +collision_mask = 24 +monitorable = false [node name="Shape" type="CollisionShape2D" parent="DetectionArea"] shape = SubResource("CircleShape2D_kxb8e") From 00fbc2f6492cfc03051a6e60ca22186b7d7410f3 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 20:59:19 +0200 Subject: [PATCH 08/10] Configure `MoveTowardsTarget`'s `CaptureArea` collision mask --- behaviours/move_towards_target.tscn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/behaviours/move_towards_target.tscn b/behaviours/move_towards_target.tscn index 0a18f6e..433b6e8 100644 --- a/behaviours/move_towards_target.tscn +++ b/behaviours/move_towards_target.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=3 format=3 uid="uid://c7b4v6h7a3dy6"] +[gd_scene load_steps=3 format=3 uid="uid://kceb2v2dm0qn"] [ext_resource type="Script" path="res://behaviours/move_towards_target.gd" id="1_703gy"] [ext_resource type="PackedScene" uid="uid://cbg5kgwxusvxf" path="res://behaviours/hover_detector.tscn" id="2_nq6qb"] @@ -7,6 +7,7 @@ script = ExtResource("1_703gy") [node name="CaptureArea" parent="." instance=ExtResource("2_nq6qb")] +collision_mask = 24 [connection signal="mouse_entered" from="CaptureArea" to="." method="_on_capture_area_mouse_entered"] [connection signal="mouse_exited" from="CaptureArea" to="." method="_on_capture_area_mouse_exited"] From 8b392b4e46583a63aee27e7f36ff1710ef136a4d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 21:01:30 +0200 Subject: [PATCH 09/10] Name collision layer 7 "System" --- project.godot | 1 + 1 file changed, 1 insertion(+) diff --git a/project.godot b/project.godot index 35cfb04..4d6dda9 100644 --- a/project.godot +++ b/project.godot @@ -41,6 +41,7 @@ main_menu={ 2d_physics/layer_4="Entities (grounded)" 2d_physics/layer_5="Entities (air)" 2d_physics/layer_6="Pickups" +2d_physics/layer_7="System" [physics] From 4f18cdaa65049b3d8078bb1a568f3ce7d488ba28 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 14 Apr 2024 21:02:08 +0200 Subject: [PATCH 10/10] Configure `CursorMagnet` layer and mask --- scenes/game/cursor_magnet.tscn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scenes/game/cursor_magnet.tscn b/scenes/game/cursor_magnet.tscn index c262ae5..05866a1 100644 --- a/scenes/game/cursor_magnet.tscn +++ b/scenes/game/cursor_magnet.tscn @@ -7,6 +7,8 @@ radius = 16.0 [node name="CursorMagnet" type="Area2D"] +collision_layer = 64 +collision_mask = 8 script = ExtResource("1_xk040") [node name="Shape" type="CollisionShape2D" parent="."]