30 lines
544 B
Odin
30 lines
544 B
Odin
package game
|
|
|
|
Enemy :: struct {
|
|
position: Vec2,
|
|
health: int,
|
|
active: bool,
|
|
speed: f32,
|
|
}
|
|
|
|
spawn_enemy :: proc(world: ^World) {
|
|
if len(world.path) == 0 do return // don't spawn enemies if no paths exist
|
|
|
|
world.enemy = Enemy {
|
|
position = world.path[0],
|
|
health = 40,
|
|
speed = 60,
|
|
active = true,
|
|
}
|
|
}
|
|
|
|
update_enemy :: proc(world: ^World, dt: f32) {
|
|
e := &world.enemy
|
|
if !e.active do return
|
|
if len(world.path) == 0 do return
|
|
|
|
target := world.path[len(world.path) - 1]
|
|
move_toward(&e.position, target, e.speed, dt)
|
|
}
|
|
|