movement and input handlin (delta time based distance still needed though)
This commit is contained in:
parent
8babb48fd2
commit
22d1469b0f
3 changed files with 33 additions and 13 deletions
23
main.odin
23
main.odin
|
@ -8,9 +8,10 @@ WIDTH :: 1600
|
|||
HEIGHT :: 900
|
||||
|
||||
Game :: struct {
|
||||
render: ^sdl3.Renderer,
|
||||
units: [dynamic]Unit,
|
||||
player: Unit,
|
||||
render: ^sdl3.Renderer,
|
||||
units: [dynamic]Unit,
|
||||
player: Unit,
|
||||
input_state: map[sdl3.Scancode]bool,
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
|
@ -28,11 +29,12 @@ main :: proc() {
|
|||
units := make([dynamic]Unit)
|
||||
append(&units, Unit{faction = Faction.Allied, position = Position{x = 500, y = 500}, hp = 100})
|
||||
append(&units, Unit{faction = Faction.Enemy, position = Position{x = 700, y = 700}, hp = 100})
|
||||
|
||||
input_state := make(map[sdl3.Scancode]bool)
|
||||
game := Game {
|
||||
render = render,
|
||||
units = units,
|
||||
player = Unit{faction = Faction.Player, position = Position{x = 255, y = 255}, hp = 100},
|
||||
input_state = input_state,
|
||||
}
|
||||
|
||||
for {
|
||||
|
@ -41,18 +43,18 @@ main :: proc() {
|
|||
#partial switch event.type {
|
||||
case .QUIT:
|
||||
return
|
||||
case .KEY_UP:
|
||||
HandleInput(&game, event)
|
||||
case .KEY_DOWN:
|
||||
{
|
||||
fmt.println(event.key)
|
||||
}
|
||||
HandleInput(&game, event)
|
||||
}
|
||||
}
|
||||
|
||||
RenderGame(game)
|
||||
MovePlayer(&game)
|
||||
RenderGame(&game)
|
||||
}
|
||||
}
|
||||
|
||||
RenderGame :: proc(game: Game) {
|
||||
RenderGame :: proc(game: ^Game) {
|
||||
sdl3.SetRenderDrawColor(game.render, 0, 0, 0, 0)
|
||||
sdl3.RenderClear(game.render)
|
||||
|
||||
|
@ -63,5 +65,4 @@ RenderGame :: proc(game: Game) {
|
|||
RenderUnit(game.player, game)
|
||||
|
||||
sdl3.RenderPresent(game.render)
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue