mirror of
https://github.com/mightypanders/GMTKJam2021.git
synced 2025-01-30 21:59:55 +01:00
Introduced max number of tries for guest spawning.
Also spawn zone now adjustable by exclusionzone size
This commit is contained in:
parent
298dd2f0ae
commit
eeda21349e
1
Guest.gd
1
Guest.gd
@ -10,6 +10,7 @@ signal dropped_off_idle
|
||||
signal dropped_off_fail
|
||||
var rng = RandomNumberGenerator.new()
|
||||
onready var sprite = $Sprite
|
||||
onready var exclusionZoneShape = $ExclusionZone/CollisionShape2D
|
||||
|
||||
var colorList = [
|
||||
Color.yellow,
|
||||
|
@ -4,7 +4,7 @@
|
||||
[ext_resource path="res://Guest.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="CircleShape2D" id=1]
|
||||
radius = 150.29
|
||||
radius = 124.702
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=2]
|
||||
radius = 6.04475
|
||||
@ -15,6 +15,9 @@ radius = 24.5545
|
||||
|
||||
[node name="Guest" type="KinematicBody2D"]
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_horizontal_guides_": [ ]
|
||||
}
|
||||
|
||||
[node name="ExclusionZone" type="Area2D" parent="."]
|
||||
|
||||
|
15
World.gd
15
World.gd
@ -8,13 +8,17 @@ var Guest = load("res://Guest.tscn")
|
||||
|
||||
var rng = RandomNumberGenerator.new()
|
||||
var spawn_tries = 0
|
||||
const MAX_SPAWN_TRIES = 50
|
||||
|
||||
onready var radius_guests = guests.get_child(0).exclusionZoneShape.shape.radius * 2
|
||||
export var max_guests = 10
|
||||
|
||||
func _on_Guest_picked_up(destinationColor,name):
|
||||
print('Picked Up %s with name %s' % [destinationColor,name])
|
||||
|
||||
func _ready():
|
||||
rng.randomize()
|
||||
pass
|
||||
print(radius_guests)
|
||||
|
||||
func _physics_process(delta):
|
||||
pass
|
||||
@ -24,22 +28,27 @@ func _on_GuestTimer_timeout():
|
||||
|
||||
|
||||
func create_new_guest():
|
||||
if guests.get_children().size() >= 7:
|
||||
if guests.get_children().size() >= max_guests:
|
||||
return
|
||||
|
||||
var position_found = false;
|
||||
var new_guest_position
|
||||
|
||||
while !position_found:
|
||||
if spawn_tries >= MAX_SPAWN_TRIES:
|
||||
print("Max spawn tries reached!")
|
||||
return
|
||||
position_found = true;
|
||||
var new_guest_cell = used_cells[rng.randi_range(0, used_cells.size()) -1]
|
||||
new_guest_position = streets.map_to_world(new_guest_cell)
|
||||
|
||||
for guest in guests.get_children():
|
||||
if (new_guest_position - guest.position).length() < 300:
|
||||
if (new_guest_position - guest.position).length() < radius_guests:
|
||||
position_found = false
|
||||
spawn_tries+=1
|
||||
break
|
||||
|
||||
var new_guest = Guest.instance()
|
||||
new_guest.position = new_guest_position;
|
||||
guests.add_child(new_guest)
|
||||
spawn_tries = 0
|
||||
|
@ -181,6 +181,7 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
|
||||
|
||||
[node name="World" type="Node2D"]
|
||||
script = ExtResource( 6 )
|
||||
max_guests = 30
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
modulate = Color( 0.0352941, 0.121569, 0, 1 )
|
||||
@ -222,7 +223,7 @@ position = Vector2( 520.662, 230.739 )
|
||||
position = Vector2( 166.312, 322.885 )
|
||||
|
||||
[node name="GuestTimer" type="Timer" parent="."]
|
||||
wait_time = 5.0
|
||||
wait_time = 1.019
|
||||
autostart = true
|
||||
|
||||
[node name="Guests" type="Node" parent="."]
|
||||
@ -230,11 +231,5 @@ autostart = true
|
||||
[node name="Guest" parent="Guests" instance=ExtResource( 5 )]
|
||||
position = Vector2( 337.119, 100.387 )
|
||||
|
||||
[node name="Guest2" parent="Guests" instance=ExtResource( 5 )]
|
||||
position = Vector2( 761.14, 102.634 )
|
||||
|
||||
[node name="Guest3" parent="Guests" instance=ExtResource( 5 )]
|
||||
position = Vector2( 777.143, 410.075 )
|
||||
|
||||
[connection signal="timeout" from="GuestTimer" to="." method="_on_GuestTimer_timeout"]
|
||||
[connection signal="picked_up" from="Guests/Guest" to="." method="_on_Guest_picked_up"]
|
||||
|
Loading…
Reference in New Issue
Block a user