Compare commits

...

2 commits

Author SHA1 Message Date
60d71ae1c0
extract math util into sub package 2025-06-28 15:08:49 +02:00
538c8c215f
use opengl instead of vulkan for compat 2025-06-27 10:18:13 +02:00
4 changed files with 36 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package main
import "core:fmt"
import "core:image/png"
import "util"
import "vendor:sdl3"
WIDTH :: 1600
@ -24,13 +25,29 @@ main :: proc() {
assert(window != nil)
defer sdl3.DestroyWindow(window)
render := sdl3.CreateRenderer(window, "vulkan")
render := sdl3.CreateRenderer(window, "opengl")
assert(render != nil)
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})
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()
@ -39,7 +56,12 @@ main :: proc() {
game := Game {
render = render,
units = units,
player = Unit{faction = Faction.Player, position = Position{x = 255, y = 255}, hp = 100},
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,

View file

@ -1,8 +1,10 @@
package main
import "core:fmt"
import "util"
import "vendor:sdl3"
DEFAULT_VELOCITY: util.Velocity : util.Velocity{x = 0, y = 0}
SPEED: f32 : 200
HandleInput :: proc(game: ^Game, event: sdl3.Event) {
@ -15,6 +17,7 @@ MovePlayer :: proc(game: ^Game) {
y += game.input_state[sdl3.Scancode.S] ? SPEED : 0
x: f32 = game.input_state[sdl3.Scancode.A] ? -SPEED : 0
x += game.input_state[sdl3.Scancode.D] ? SPEED : 0
game.player.velocity = util.Velocity{x, y}
game.player.position.y += y * game.delta
game.player.position.x += x * game.delta

View file

@ -1,5 +1,6 @@
package main
import "util"
import "vendor:sdl3"
Faction :: enum {
@ -10,7 +11,8 @@ Faction :: enum {
Unit :: struct {
faction: Faction,
position: Position,
position: util.Position,
velocity: util.Velocity,
hp: u32,
}
@ -31,6 +33,6 @@ RenderUnit :: proc(unit: Unit, game: ^Game) {
Projectile :: struct {
faction: Faction,
position: Position,
direction: Direction,
position: util.Position,
direction: util.Velocity,
}

View file

@ -1,9 +1,9 @@
package main
package util
Position :: struct {
x, y: f32,
}
Direction :: struct {
Velocity :: struct {
x, y: f32,
}