No Loadingscreen Needed. actual solution: batched spawning

This commit is contained in:
Snoweuph 2023-04-09 22:45:00 +02:00
parent e09b2d0dd1
commit 2758e057ea
3 changed files with 15 additions and 3 deletions

View file

@ -136,7 +136,6 @@ start_area_corner_size = 3
script = ExtResource("3_o045y")
bunny_prefab = ExtResource("4_hpafd")
player = NodePath("../Player")
player_save_distance = 320.0
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
position = Vector2(1440, 810)

View file

@ -3,7 +3,7 @@ class_name BunnyGenerator
@export var bunny_prefab : Resource
@export var player : CharacterBody2D
@export var player_save_distance : float = 32.0
@export var player_save_distance : float = 400
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny:
@ -30,3 +30,16 @@ func spawn_wave(free_tiles : Array, team: int, amount : int, health : int) -> Ar
var bunny = spawn_bunny(pos, team, health)
bunnys.push_back(bunny)
return bunnys
func spawn_batched_wave(batch_size : float, batch_delay: float, free_tiles : Array, team: int, amount : int, health : int) -> Array:
var bunnys = []
var batch_count = ceil(amount / batch_size)
var actual_batch_size = floor(amount / batch_count)
var last_batch_size = amount - batch_size * batch_count
for s in batch_count:
bunnys += spawn_wave(free_tiles.duplicate(), team, actual_batch_size, health)
await get_tree().create_timer(batch_delay).timeout
bunnys += spawn_wave(free_tiles.duplicate(), team, last_batch_size, health)
await get_tree().create_timer(batch_delay).timeout
return bunnys

View file

@ -15,7 +15,7 @@ func _ready():
func _process(_delta):
if(bunnys.size() == 0):
wave += 1
bunnys = bunny_generator.spawn_wave(gen_data.free_tiles.duplicate(), TEAM.EVIL, wave * 500, 3)
bunnys = await bunny_generator.spawn_batched_wave(10.0, 0.25, gen_data.free_tiles.duplicate(), TEAM.EVIL, wave * 1, 3)
for bunny in bunnys:
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
bunny.sub_on_death(func(bunny): bunny.queue_free())