paintjam2020/Scripts/GameManager.gd
2020-04-05 19:05:05 +02:00

40 lines
1021 B
GDScript

extends Node2D
onready var spawnPoints = get_tree().get_nodes_in_group("spawn_point")
onready var tmpSpawnPoints = get_tree().get_nodes_in_group("spawn_point")
var prevSpawnPoint = null
var bucket = load("res://Scene/Clopinette.tscn")
func _ready():
tmpSpawnPoints.shuffle()
func spawnBucket():
var newBucket = bucket.instance()
if tmpSpawnPoints.size() == 0:
tmpSpawnPoints = [] + spawnPoints
tmpSpawnPoints.shuffle()
var newSpawnPoint = tmpSpawnPoints[randi() % tmpSpawnPoints.size()]
self.get_parent().add_child(newBucket)
newBucket.add_to_group("bucket")
newBucket.set_position(newSpawnPoint.get_position())
tmpSpawnPoints.erase(newSpawnPoint)
func _process(_delta):
if get_tree().get_nodes_in_group("bucket").empty():
spawnBucket()
func endGame():
get_node("/root/World/CanvasLayer/Window").showEndGameWindow(getWinner())
func getWinner():
var players = get_tree().get_nodes_in_group("player")
for player in players:
if player.curLife > 0:
return player.name
return "Player1"