No Loadingscreen Needed. actual solution: batched spawning
This commit is contained in:
parent
e09b2d0dd1
commit
2758e057ea
3 changed files with 15 additions and 3 deletions
|
@ -136,7 +136,6 @@ start_area_corner_size = 3
|
||||||
script = ExtResource("3_o045y")
|
script = ExtResource("3_o045y")
|
||||||
bunny_prefab = ExtResource("4_hpafd")
|
bunny_prefab = ExtResource("4_hpafd")
|
||||||
player = NodePath("../Player")
|
player = NodePath("../Player")
|
||||||
player_save_distance = 320.0
|
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
|
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
|
||||||
position = Vector2(1440, 810)
|
position = Vector2(1440, 810)
|
||||||
|
|
|
@ -3,7 +3,7 @@ class_name BunnyGenerator
|
||||||
|
|
||||||
@export var bunny_prefab : Resource
|
@export var bunny_prefab : Resource
|
||||||
@export var player : CharacterBody2D
|
@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)
|
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
|
||||||
|
|
||||||
func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny:
|
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)
|
var bunny = spawn_bunny(pos, team, health)
|
||||||
bunnys.push_back(bunny)
|
bunnys.push_back(bunny)
|
||||||
return bunnys
|
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
|
||||||
|
|
|
@ -15,7 +15,7 @@ func _ready():
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
if(bunnys.size() == 0):
|
if(bunnys.size() == 0):
|
||||||
wave += 1
|
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:
|
for bunny in bunnys:
|
||||||
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
|
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
|
||||||
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
||||||
|
|
Reference in a new issue