From f844cd02d22abdd8d1ce89eb86c75d7c2c1a5f34 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 1 Oct 2023 01:33:54 +0200 Subject: [PATCH] Configure spawners --- entity/coin_copper.tscn | 2 +- root.tscn | 20 ++++++++------------ spawner/spawner.gd | 18 ++++++++++++------ spawner/spawner.tscn | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/entity/coin_copper.tscn b/entity/coin_copper.tscn index 034efc9..a788a5f 100644 --- a/entity/coin_copper.tscn +++ b/entity/coin_copper.tscn @@ -5,7 +5,7 @@ [ext_resource type="Texture2D" uid="uid://2vtvoj6ua3cb" path="res://entity/coin_copper_outline_2.png" id="2_2ifq3"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"] -size = Vector2(14, 3) +size = Vector2(16, 5) [node name="CoinCopper" type="RigidBody2D"] collision_layer = 5 diff --git a/root.tscn b/root.tscn index 3be6353..19e6525 100644 --- a/root.tscn +++ b/root.tscn @@ -1,10 +1,9 @@ -[gd_scene load_steps=6 format=3 uid="uid://cbccs6kwwf265"] +[gd_scene load_steps=5 format=3 uid="uid://cbccs6kwwf265"] [ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_4fmd3"] [ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper.tscn" id="2_dv01l"] [ext_resource type="PackedScene" uid="uid://d05b8jy3xmpcb" path="res://bottle/gravity_from_gyro.tscn" id="2_m7p4p"] [ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="3_pubxn"] -[ext_resource type="PackedScene" path="res://convertitore.tscn" id="5_6hpcd"] [node name="Root" type="Node"] @@ -79,21 +78,18 @@ texture_filter = 1 [node name="GravityFromGyro" parent="UI/GameContainer/Game/Bottle" instance=ExtResource("2_m7p4p")] -[node name="Spawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] -position = Vector2(-24, -407) +[node name="TimeSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] +position = Vector2(-24, -490) scene = ExtResource("2_dv01l") target_parent = NodePath("..") -[node name="Timer2" type="Timer" parent="UI/GameContainer/Game/Spawner"] +[node name="Timer" type="Timer" parent="UI/GameContainer/Game/TimeSpawner"] autostart = true -[node name="TouchSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] -position = Vector2(23, -424) +[node name="ButtonSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] +position = Vector2(24, -490) scene = ExtResource("2_dv01l") target_parent = NodePath("..") -[node name="Convertitore" parent="UI/GameContainer/Game" instance=ExtResource("5_6hpcd")] -position = Vector2(-110, -257) - -[connection signal="pressed" from="UI/Rows/UpperButtons/SpawnButton" to="UI/GameContainer/Game/TouchSpawner" method="spawn"] -[connection signal="timeout" from="UI/GameContainer/Game/Spawner/Timer2" to="UI/GameContainer/Game/Spawner" method="spawn"] +[connection signal="pressed" from="UI/Rows/UpperButtons/SpawnButton" to="UI/GameContainer/Game/ButtonSpawner" method="spawn"] +[connection signal="timeout" from="UI/GameContainer/Game/TimeSpawner/Timer" to="UI/GameContainer/Game/TimeSpawner" method="spawn"] diff --git a/spawner/spawner.gd b/spawner/spawner.gd index de26e49..f749c76 100644 --- a/spawner/spawner.gd +++ b/spawner/spawner.gd @@ -1,12 +1,18 @@ extends Node2D class_name Spawner + + @export var scene: PackedScene -@export var target_parent: NodePath + func spawn(): - if len($Area.get_overlapping_bodies()) > 0: - return - var scene_instant = scene.instantiate() - scene_instant.position=Vector2.ZERO - add_child(scene_instant) + var overlapping_bodies = $Area.get_overlapping_bodies() + for overlapping_body in overlapping_bodies: + if overlapping_body.collision_layer && 0b100: + print("[Spawner] Not spawning, overlapping with: ", overlapping_body) + return + var scene_instant = scene.instantiate() + scene_instant.position = Vector2.ZERO + print("[Spawner] Created: ", scene_instant) + add_child(scene_instant) diff --git a/spawner/spawner.tscn b/spawner/spawner.tscn index fd59048..0a69c47 100644 --- a/spawner/spawner.tscn +++ b/spawner/spawner.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://spawner/spawner.gd" id="1_xqfmg"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_p13i4"] -size = Vector2(16, 5) +size = Vector2(14, 3) [node name="Spawner" type="Node2D"] script = ExtResource("1_xqfmg")