fumarole/unit.odin

62 lines
1.3 KiB
Odin
Raw Normal View History

2025-06-22 21:35:03 +02:00
package main
2025-06-28 15:08:49 +02:00
import "util"
2025-06-22 21:35:03 +02:00
import "vendor:sdl3"
2025-06-28 15:21:52 +02:00
DEFAULT_HP :: 100
DEFAULT_VELOCITY: util.Velocity : util.Velocity{x = 0, y = 0}
DEFAULT_SPEED: f32 : 200
2025-06-22 21:35:03 +02:00
Faction :: enum {
Player,
2025-06-22 21:47:58 +02:00
Allied,
2025-06-22 21:35:03 +02:00
Enemy,
}
Unit :: struct {
faction: Faction,
2025-06-28 15:08:49 +02:00
position: util.Position,
velocity: util.Velocity,
2025-06-28 15:21:52 +02:00
speed: f32,
2025-06-22 21:35:03 +02:00
hp: u32,
}
2025-06-28 15:33:39 +02:00
render_unit :: proc(unit: Unit, game: ^Game) {
2025-06-22 21:35:03 +02:00
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)
2025-06-22 21:47:58 +02:00
case Faction.Allied:
sdl3.SetRenderDrawColor(game.render, 0, 0, 255, 0)
2025-06-22 21:35:03 +02:00
}
sdl3.RenderRect(
game.render,
&sdl3.FRect{x = unit.position.x, y = unit.position.y, w = 10, h = 10},
)
}
2025-06-22 21:47:58 +02:00
2025-06-28 15:33:39 +02:00
new_unit :: proc {
new_unit_all,
new_unit_base,
new_unit_hp,
2025-06-28 15:21:52 +02:00
}
2025-06-28 15:33:39 +02:00
new_unit_base :: proc(faction: Faction, position: util.Position) -> Unit {
2025-06-28 15:21:52 +02:00
return Unit{faction, position, DEFAULT_VELOCITY, DEFAULT_SPEED, DEFAULT_HP}
}
2025-06-28 15:33:39 +02:00
new_unit_hp :: proc(faction: Faction, position: util.Position, hp: u32) -> Unit {
2025-06-28 15:21:52 +02:00
return Unit{faction, position, DEFAULT_VELOCITY, DEFAULT_SPEED, hp}
}
2025-06-28 15:33:39 +02:00
new_unit_all :: proc(faction: Faction, position: util.Position, speed: f32, hp: u32) -> Unit {
2025-06-28 15:21:52 +02:00
return Unit{faction, position, DEFAULT_VELOCITY, speed, hp}
}
2025-06-22 21:47:58 +02:00
Projectile :: struct {
faction: Faction,
2025-06-28 15:08:49 +02:00
position: util.Position,
direction: util.Velocity,
2025-06-22 21:47:58 +02:00
}