Random spawning Guests
A guest timer counts down and emits a signal to the world. The world uses the street map to determine a new random guest position and spawns it
This commit is contained in:
parent
1001ada545
commit
7ef67351fb
|
@ -0,0 +1,16 @@
|
|||
extends Timer
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
23
World.gd
23
World.gd
|
@ -1,18 +1,25 @@
|
|||
extends Node2D
|
||||
|
||||
onready var streets = $Streets
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
var Guest = load("res://Guest.tscn")
|
||||
|
||||
var rng = RandomNumberGenerator.new()
|
||||
|
||||
func _on_Guest_picked_up(destinationColor,name):
|
||||
print('Picked Up %s with name %s' % [destinationColor,name])
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
rng.randomize()
|
||||
pass
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _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;
|
||||
add_child(guest)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=22 format=2]
|
||||
[gd_scene load_steps=23 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,6 +7,7 @@
|
|||
[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"
|
||||
|
@ -230,4 +231,10 @@ position = Vector2( 761.14, 102.634 )
|
|||
[node name="Guest3" parent="." instance=ExtResource( 5 )]
|
||||
position = Vector2( 758.143, 376.075 )
|
||||
|
||||
[node name="GuestTimer" type="Timer" parent="."]
|
||||
wait_time = 5.0
|
||||
autostart = true
|
||||
script = ExtResource( 8 )
|
||||
|
||||
[connection signal="picked_up" from="Guest" to="." method="_on_Guest_picked_up"]
|
||||
[connection signal="timeout" from="GuestTimer" to="." method="_on_GuestTimer_timeout"]
|
||||
|
|
Loading…
Reference in New Issue