From c9c57a1ff97bf590bb9c0082fb068fd76055b3df Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 1 Oct 2023 02:27:49 +0200 Subject: [PATCH] Add spawn randomization --- export_presets.cfg | 4 ++-- root.tscn | 8 ++++++-- spawner/spawner.gd | 13 ++++++++----- spawner/spawner.tscn | 5 ++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/export_presets.cfg b/export_presets.cfg index e66f044..20ed2b4 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -28,8 +28,8 @@ architectures/x86=false architectures/x86_64=false version/code=1 version/name="1.0" -package/unique_name="eu.steffo.ld54s" -package/name="Garasautos" +package/unique_name="org.godotengine.$genname" +package/name="" package/signed=true package/app_category=2 package/retain_data_on_uninstall=false diff --git a/root.tscn b/root.tscn index dfbeef2..026284d 100644 --- a/root.tscn +++ b/root.tscn @@ -79,17 +79,21 @@ texture_filter = 1 [node name="GravityFromGyro" parent="UI/GameContainer/Game/Bottle" instance=ExtResource("2_m7p4p")] [node name="TimeSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] -position = Vector2(0, -490) +position = Vector2(0, -480) scene = ExtResource("2_dv01l") buffer_cap = 1 +spawn_position_range_x = 32.0 +spawn_rotation_range = 15.0 [node name="Timer" type="Timer" parent="UI/GameContainer/Game/TimeSpawner"] autostart = true [node name="ButtonSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] -position = Vector2(0, -490) +position = Vector2(0, -480) scene = ExtResource("2_dv01l") buffer_cap = 50 +spawn_position_range_x = 32.0 +spawn_rotation_range = 15.0 [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 3bd99bc..9764dd0 100644 --- a/spawner/spawner.gd +++ b/spawner/spawner.gd @@ -8,8 +8,9 @@ var buffer: int = 0 @export var buffer_cap: int @onready var area: Area2D = $Area -@onready var shape: CollisionShape2D = $Area/Shape +@export var spawn_position_range_x: float +@export_range(0, 90) var spawn_rotation_range: float @onready var rng: RandomNumberGenerator = RandomNumberGenerator.new() @@ -21,9 +22,10 @@ func spawn(): func _select_spawn_position() -> Vector2: - var variance = shape.shape.size.x / 2 - var x = rng.randf_range(-variance, +variance) - return Vector2(x, 0) + return Vector2(rng.randf_range(-spawn_position_range_x, +spawn_position_range_x), 0) + +func _select_spawn_rotation() -> float: + return rng.randf_range(-spawn_rotation_range, spawn_rotation_range) func _do_spawn(): var overlapping_bodies = area.get_overlapping_bodies() @@ -31,7 +33,8 @@ func _do_spawn(): if overlapping_body.collision_layer && 0b100: return var scene_instant = scene.instantiate() - scene_instant.position = _select_spawn_location() + scene_instant.position = _select_spawn_position() + scene_instant.rotation_degrees = _select_spawn_rotation() add_child(scene_instant) buffer -= 1 diff --git a/spawner/spawner.tscn b/spawner/spawner.tscn index 56a8b1d..788a581 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(32, 2) +size = Vector2(96, 32) [node name="Spawner" type="Node2D"] script = ExtResource("1_xqfmg") @@ -12,6 +12,5 @@ script = ExtResource("1_xqfmg") collision_mask = 4 [node name="Shape" type="CollisionShape2D" parent="Area"] -position = Vector2(0, -3) -scale = Vector2(3, 3) +position = Vector2(0, -16) shape = SubResource("RectangleShape2D_p13i4")