1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-21 23:34:18 +00:00

Add spawn randomization

This commit is contained in:
Steffo 2023-10-01 02:27:49 +02:00
parent a10335c0b9
commit c9c57a1ff9
Signed by: steffo
GPG key ID: 2A24051445686895
4 changed files with 18 additions and 12 deletions

View file

@ -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

View file

@ -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"]

View file

@ -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

View file

@ -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")