fumarole/main.odin

106 lines
1.9 KiB
Odin

package main
import "core:fmt"
import "core:image/png"
import "util"
import "vendor:sdl3"
WIDTH :: 1600
HEIGHT :: 900
Game :: struct {
render: ^sdl3.Renderer,
units: [dynamic]Unit,
player: Unit,
time: u64,
delta: f32,
input_state: map[sdl3.Scancode]bool,
}
main :: proc() {
assert(sdl3.Init(sdl3.INIT_VIDEO))
defer sdl3.Quit()
window := sdl3.CreateWindow("Game", 1600, 900, nil)
assert(window != nil)
defer sdl3.DestroyWindow(window)
render := sdl3.CreateRenderer(window, "opengl")
assert(render != nil)
units := make([dynamic]Unit)
append(
&units,
Unit {
faction = Faction.Allied,
position = util.Position{x = 500, y = 500},
velocity = DEFAULT_VELOCITY,
hp = 100,
},
)
append(
&units,
Unit {
faction = Faction.Enemy,
position = util.Position{x = 700, y = 700},
velocity = DEFAULT_VELOCITY,
hp = 100,
},
)
input_state := make(map[sdl3.Scancode]bool)
time := sdl3.GetTicksNS()
game := Game {
render = render,
units = units,
player = Unit {
faction = Faction.Player,
position = util.Position{x = 255, y = 255},
velocity = DEFAULT_VELOCITY,
hp = 100,
},
time = time,
delta = 0.0,
input_state = input_state,
}
for {
event: sdl3.Event
for sdl3.PollEvent(&event) {
#partial switch event.type {
case .QUIT:
return
case .KEY_UP:
HandleInput(&game, event)
case .KEY_DOWN:
HandleInput(&game, event)
}
}
MovePlayer(&game)
RenderGame(&game)
UpdateTime(&game)
}
}
UpdateTime :: proc(game: ^Game) {
new_time := sdl3.GetTicksNS()
delta_ns := new_time - game.time
game.time = new_time
game.delta = f32(delta_ns) / f32(sdl3.NS_PER_SECOND)
}
RenderGame :: proc(game: ^Game) {
sdl3.SetRenderDrawColor(game.render, 0, 0, 0, 0)
sdl3.RenderClear(game.render)
for unit in game.units {
RenderUnit(unit, game)
}
RenderUnit(game.player, game)
sdl3.RenderPresent(game.render)
}