32 lines
1 KiB
GDScript
32 lines
1 KiB
GDScript
extends Node
|
|
|
|
@export var bunny_prefab : Resource
|
|
@export var player : CharacterBody2D
|
|
@export var player_save_distance : float = 32.0
|
|
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
|
|
|
|
func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny:
|
|
var bunny = BunnyPrefab.instantiate()
|
|
self.add_child(bunny)
|
|
bunny.global_position = pos
|
|
bunny.health = health
|
|
bunny.team = team
|
|
return bunny
|
|
|
|
func spawn_wave(free_tiles : Array, amount : int, health : int):
|
|
|
|
# Make Sure that no possitions to near to the player are insdie of the list
|
|
for tile in free_tiles:
|
|
if tile.distance_to(player.global_position) <= player_save_distance:
|
|
free_tiles.erase(tile)
|
|
|
|
# Make sure amount isnt bigger then available positions
|
|
if free_tiles.size() < amount: amount = free_tiles.size()
|
|
|
|
# Spawn at random psoitions of the list
|
|
for i in amount:
|
|
var pos = free_tiles.pick_random()
|
|
free_tiles.erase(pos)
|
|
var bunny = spawn_bunny(pos, TEAM.EVIL, 3)
|
|
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
|
pass
|