2021-06-12 02:28:16 +02:00
|
|
|
extends Node2D
|
|
|
|
|
2021-06-12 14:46:23 +02:00
|
|
|
onready var streets = $Streets
|
2021-06-12 18:22:58 +02:00
|
|
|
onready var used_cells = streets.get_used_cells()
|
2021-06-12 15:03:50 +02:00
|
|
|
onready var guests = $Guests
|
2021-06-13 00:33:46 +02:00
|
|
|
onready var money_label = $GUI/HBoxContainer/HBoxContainer2/Money
|
2021-06-12 02:28:16 +02:00
|
|
|
|
2021-06-12 23:28:48 +02:00
|
|
|
export var player_score = 0
|
|
|
|
|
2021-06-12 14:46:23 +02:00
|
|
|
var Guest = load("res://Guest.tscn")
|
|
|
|
|
|
|
|
var rng = RandomNumberGenerator.new()
|
2021-06-12 18:22:58 +02:00
|
|
|
var spawn_tries = 0
|
2021-06-12 18:59:42 +02:00
|
|
|
const MAX_SPAWN_TRIES = 50
|
|
|
|
|
2021-06-13 00:33:46 +02:00
|
|
|
|
2021-06-12 18:59:42 +02:00
|
|
|
onready var radius_guests = guests.get_child(0).exclusionZoneShape.shape.radius * 2
|
|
|
|
export var max_guests = 10
|
2021-06-12 02:28:16 +02:00
|
|
|
|
|
|
|
func _on_Guest_picked_up(destinationColor,name):
|
|
|
|
print('Picked Up %s with name %s' % [destinationColor,name])
|
|
|
|
|
|
|
|
func _ready():
|
2021-06-12 14:46:23 +02:00
|
|
|
rng.randomize()
|
2021-06-12 18:59:42 +02:00
|
|
|
print(radius_guests)
|
2021-06-12 14:46:23 +02:00
|
|
|
|
2021-06-12 18:22:58 +02:00
|
|
|
func _physics_process(delta):
|
2021-06-13 18:04:43 +02:00
|
|
|
if Input.is_action_just_pressed("ui_cancel"):
|
|
|
|
get_tree().quit()
|
2021-06-12 18:22:58 +02:00
|
|
|
pass
|
2021-06-12 02:28:16 +02:00
|
|
|
|
2021-06-12 14:46:23 +02:00
|
|
|
func _on_GuestTimer_timeout():
|
2021-06-12 18:22:58 +02:00
|
|
|
create_new_guest()
|
|
|
|
|
|
|
|
|
|
|
|
func create_new_guest():
|
2021-06-12 18:59:42 +02:00
|
|
|
if guests.get_children().size() >= max_guests:
|
2021-06-12 18:22:58 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
var position_found = false;
|
|
|
|
var new_guest_position
|
|
|
|
|
|
|
|
while !position_found:
|
2021-06-12 18:59:42 +02:00
|
|
|
if spawn_tries >= MAX_SPAWN_TRIES:
|
2021-06-12 23:28:48 +02:00
|
|
|
#print("Max spawn tries reached!")
|
2021-06-12 18:59:42 +02:00
|
|
|
return
|
2021-06-12 18:22:58 +02:00
|
|
|
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():
|
2021-06-12 18:59:42 +02:00
|
|
|
if (new_guest_position - guest.position).length() < radius_guests:
|
2021-06-12 18:22:58 +02:00
|
|
|
position_found = false
|
2021-06-12 18:59:42 +02:00
|
|
|
spawn_tries+=1
|
2021-06-12 18:22:58 +02:00
|
|
|
break
|
|
|
|
|
|
|
|
var new_guest = Guest.instance()
|
|
|
|
new_guest.position = new_guest_position;
|
|
|
|
guests.add_child(new_guest)
|
2021-06-12 18:59:42 +02:00
|
|
|
spawn_tries = 0
|
2021-06-12 23:28:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_Playa_scored(value:int):
|
2021-06-13 01:05:34 +02:00
|
|
|
spawn_tries = 0
|
2021-06-12 23:28:48 +02:00
|
|
|
print('Its a score of %s'% String(value))
|
|
|
|
player_score += value
|
2021-06-13 00:33:46 +02:00
|
|
|
money_label.update_text(player_score)
|