shoot projectiles

This commit is contained in:
2026-06-13 23:33:03 -07:00
parent 5f3ef33b05
commit b9235246c7
6 changed files with 123 additions and 26 deletions
+11 -12
View File
@@ -42,23 +42,23 @@ try_place_tower :: proc(world: ^World, gx, gy: int, kind: Tower_Kind) -> bool {
return true
}
find_target :: proc(tower: Tower, world: ^World) -> ^Enemy {
find_target_slot :: proc(tower: Tower, world: ^World) -> int {
arch := get_archetype(tower.kind)
best: ^Enemy = nil
best_slot: int = -1
best_dist: f32 = 999999
for i in 0 ..< MAX_ENEMIES {
e := &world.enemies[i]
if !e.active do continue
if e.path_index >= len(world.path) do continue
d := distance(tower.position, e.position)
if d <= arch.range && d < best_dist {
best = e
best_slot = i
best_dist = d
}
}
return best
return best_slot
}
update_towers :: proc(world: ^World, dt: f32) {
@@ -68,16 +68,15 @@ update_towers :: proc(world: ^World, dt: f32) {
if t.cooldown > 0 do continue
target := find_target(t^, world)
if target == nil do continue
slot := find_target_slot(t^, world)
if slot < 0 do continue
arch := get_archetype(t.kind)
target.health -= arch.damage
t.cooldown = arch.fire_rate
if target.health <= 0 {
target.active = false
push_event(world, .Enemy_Killed, gold_reward = 5)
switch t.kind {
case .Archer:
spawn_projectile(world, t.position, slot, arch.damage)
t.cooldown = arch.fire_rate
}
}
}