refactor world wave
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ run :: proc() {
|
||||
delete(world.path)
|
||||
delete(world.combat.towers)
|
||||
delete(world.events)
|
||||
delete(world.spawner.recipe)
|
||||
delete(world.wave.spawner.recipe)
|
||||
}
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ spawn_enemy :: proc(world: ^World, kind: Enemy_Kind) {
|
||||
e := acquire_enemy(world) // grab a free slot
|
||||
if e == nil do return // if there are no slots, skil spawning
|
||||
|
||||
arch := get_enemy_archetype(kind, world.wave)
|
||||
arch := get_enemy_archetype(kind, world.wave.current_wave)
|
||||
e^ = Enemy {
|
||||
position = world.path[0],
|
||||
health = arch.health,
|
||||
|
||||
+8
-8
@@ -17,13 +17,13 @@ Wave_Spawner :: struct {
|
||||
|
||||
start_wave :: proc(world: ^World) {
|
||||
if world.phase != .Build do return
|
||||
world.wave += 1
|
||||
world.wave.current_wave += 1
|
||||
world.phase = .Combat
|
||||
delete(world.spawner.recipe)
|
||||
world.spawner = Wave_Spawner {
|
||||
delete(world.wave.spawner.recipe)
|
||||
world.wave.spawner = Wave_Spawner {
|
||||
spawn_timer = 0,
|
||||
spawn_interval = 0.55,
|
||||
recipe = build_wave_recipe(world.wave),
|
||||
recipe = build_wave_recipe(world.wave.current_wave),
|
||||
recipe_index = 0,
|
||||
entry_remaining = 0,
|
||||
}
|
||||
@@ -56,7 +56,7 @@ build_wave_recipe :: proc(wave: int) -> [dynamic]Wave_Entry {
|
||||
}
|
||||
|
||||
load_next_recipe_entry :: proc(world: ^World) {
|
||||
s := &world.spawner
|
||||
s := &world.wave.spawner
|
||||
if s.recipe_index >= len(s.recipe) {
|
||||
s.entry_remaining = 0
|
||||
return
|
||||
@@ -66,7 +66,7 @@ load_next_recipe_entry :: proc(world: ^World) {
|
||||
}
|
||||
|
||||
clear_wave :: proc(world: ^World) -> bool {
|
||||
s := world.spawner
|
||||
s := world.wave.spawner
|
||||
if s.recipe_index < len(s.recipe) do return false
|
||||
if s.entry_remaining > 0 do return false
|
||||
return active_enemy_count(world) == 0
|
||||
@@ -74,7 +74,7 @@ clear_wave :: proc(world: ^World) -> bool {
|
||||
|
||||
update_wave :: proc(world: ^World, dt: f32) {
|
||||
if world.phase != .Combat do return
|
||||
s := &world.spawner
|
||||
s := &world.wave.spawner
|
||||
if s.entry_remaining <= 0 && s.recipe_index >= len(s.recipe) do return
|
||||
|
||||
s.spawn_timer -= dt
|
||||
@@ -105,7 +105,7 @@ check_end :: proc(world: ^World) {
|
||||
world.phase = .Game_Over
|
||||
}
|
||||
|
||||
if world.wave >= MAX_WAVES && world.phase == .Build && clear_wave(world) {
|
||||
if world.wave.current_wave >= MAX_WAVES && world.phase == .Build && clear_wave(world) {
|
||||
world.phase = .Victory
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -8,8 +8,7 @@ World :: struct {
|
||||
path: [dynamic]Vec2,
|
||||
events: [dynamic]Event,
|
||||
phase: Game_Phase,
|
||||
wave: int,
|
||||
spawner: Wave_Spawner,
|
||||
wave: Wave,
|
||||
selected_tower: Tower_Kind,
|
||||
}
|
||||
|
||||
@@ -23,6 +22,11 @@ Combat :: struct {
|
||||
projectiles: [MAX_PROJECTILES]Projectile,
|
||||
}
|
||||
|
||||
Wave :: struct {
|
||||
current_wave: int,
|
||||
spawner: Wave_Spawner,
|
||||
}
|
||||
|
||||
init_world :: proc() -> World {
|
||||
economy := Economy {
|
||||
gold = 100,
|
||||
|
||||
Reference in New Issue
Block a user