Guests now spawn up to a fixed count and space between them
This commit is contained in:
parent
04b594137b
commit
298dd2f0ae
|
@ -4,7 +4,7 @@
|
|||
[ext_resource path="res://Guest.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="CircleShape2D" id=1]
|
||||
radius = 112.271
|
||||
radius = 150.29
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=2]
|
||||
radius = 6.04475
|
||||
|
|
36
World.gd
36
World.gd
|
@ -1,11 +1,13 @@
|
|||
extends Node2D
|
||||
|
||||
onready var streets = $Streets
|
||||
onready var used_cells = streets.get_used_cells()
|
||||
onready var guests = $Guests
|
||||
|
||||
var Guest = load("res://Guest.tscn")
|
||||
|
||||
var rng = RandomNumberGenerator.new()
|
||||
var spawn_tries = 0
|
||||
|
||||
func _on_Guest_picked_up(destinationColor,name):
|
||||
print('Picked Up %s with name %s' % [destinationColor,name])
|
||||
|
@ -14,14 +16,30 @@ func _ready():
|
|||
rng.randomize()
|
||||
pass
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
pass
|
||||
|
||||
func _on_GuestTimer_timeout():
|
||||
var used_cells = streets.get_used_cells()
|
||||
var new_guest_cell = used_cells[rng.randi_range(0, used_cells.size())]
|
||||
var guest_position = streets.map_to_world(new_guest_cell)
|
||||
print('new guest at: %s' % [guest_position])
|
||||
var guest = Guest.instance();
|
||||
guest.position = guest_position;
|
||||
guests.add_child(guest)
|
||||
print('Guest count: %s' % [guests.get_child_count()])
|
||||
create_new_guest()
|
||||
|
||||
|
||||
func create_new_guest():
|
||||
if guests.get_children().size() >= 7:
|
||||
return
|
||||
|
||||
var position_found = false;
|
||||
var new_guest_position
|
||||
|
||||
while !position_found:
|
||||
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:
|
||||
position_found = false
|
||||
break
|
||||
|
||||
var new_guest = Guest.instance()
|
||||
new_guest.position = new_guest_position;
|
||||
guests.add_child(new_guest)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=23 format=2]
|
||||
[gd_scene load_steps=22 format=2]
|
||||
|
||||
[ext_resource path="res://assets/city_tiles/Street.png" type="Texture" id=1]
|
||||
[ext_resource path="res://assets/city_tiles/Buildings.png" type="Texture" id=2]
|
||||
|
@ -7,7 +7,6 @@
|
|||
[ext_resource path="res://Guest.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://World.gd" type="Script" id=6]
|
||||
[ext_resource path="res://assets/placeholder_white.png" type="Texture" id=7]
|
||||
[ext_resource path="res://GuestTimer.gd" type="Script" id=8]
|
||||
|
||||
[sub_resource type="TileSet" id=1]
|
||||
0/name = "Street.png 0"
|
||||
|
@ -225,7 +224,6 @@ position = Vector2( 166.312, 322.885 )
|
|||
[node name="GuestTimer" type="Timer" parent="."]
|
||||
wait_time = 5.0
|
||||
autostart = true
|
||||
script = ExtResource( 8 )
|
||||
|
||||
[node name="Guests" type="Node" parent="."]
|
||||
|
||||
|
@ -236,7 +234,7 @@ position = Vector2( 337.119, 100.387 )
|
|||
position = Vector2( 761.14, 102.634 )
|
||||
|
||||
[node name="Guest3" parent="Guests" instance=ExtResource( 5 )]
|
||||
position = Vector2( 758.143, 376.075 )
|
||||
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