61 lines
1.3 KiB
Odin
61 lines
1.3 KiB
Odin
package main
|
|
|
|
import "util"
|
|
import "vendor:sdl3"
|
|
|
|
DEFAULT_HP :: 100
|
|
DEFAULT_VELOCITY: util.Velocity : util.Velocity{x = 0, y = 0}
|
|
DEFAULT_SPEED: f32 : 200
|
|
|
|
Faction :: enum {
|
|
Player,
|
|
Allied,
|
|
Enemy,
|
|
}
|
|
|
|
Unit :: struct {
|
|
faction: Faction,
|
|
position: util.Position,
|
|
velocity: util.Velocity,
|
|
speed: f32,
|
|
hp: u32,
|
|
}
|
|
|
|
render_unit :: proc(unit: Unit, game: ^Game) {
|
|
switch unit.faction {
|
|
case Faction.Player:
|
|
sdl3.SetRenderDrawColor(game.render, 0, 255, 0, 0)
|
|
case Faction.Enemy:
|
|
sdl3.SetRenderDrawColor(game.render, 255, 0, 0, 0)
|
|
case Faction.Allied:
|
|
sdl3.SetRenderDrawColor(game.render, 0, 0, 255, 0)
|
|
}
|
|
sdl3.RenderRect(
|
|
game.render,
|
|
&sdl3.FRect{x = unit.position.x, y = unit.position.y, w = 10, h = 10},
|
|
)
|
|
}
|
|
|
|
new_unit :: proc {
|
|
new_unit_all,
|
|
new_unit_base,
|
|
new_unit_hp,
|
|
}
|
|
|
|
new_unit_base :: proc(faction: Faction, position: util.Position) -> Unit {
|
|
return Unit{faction, position, DEFAULT_VELOCITY, DEFAULT_SPEED, DEFAULT_HP}
|
|
}
|
|
|
|
new_unit_hp :: proc(faction: Faction, position: util.Position, hp: u32) -> Unit {
|
|
return Unit{faction, position, DEFAULT_VELOCITY, DEFAULT_SPEED, hp}
|
|
}
|
|
|
|
new_unit_all :: proc(faction: Faction, position: util.Position, speed: f32, hp: u32) -> Unit {
|
|
return Unit{faction, position, DEFAULT_VELOCITY, speed, hp}
|
|
}
|
|
|
|
Projectile :: struct {
|
|
faction: Faction,
|
|
position: util.Position,
|
|
direction: util.Velocity,
|
|
}
|