diff --git a/main.odin b/main.odin index c4e9577..f19726e 100644 --- a/main.odin +++ b/main.odin @@ -2,6 +2,7 @@ package main import "core:fmt" import "core:image/png" +import "util" import "vendor:sdl3" WIDTH :: 1600 @@ -29,8 +30,24 @@ main :: proc() { 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, diff --git a/movement.odin b/movement.odin index 01ba0bd..2e75864 100644 --- a/movement.odin +++ b/movement.odin @@ -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 diff --git a/unit.odin b/unit.odin index 1f8ca94..3bc6d29 100644 --- a/unit.odin +++ b/unit.odin @@ -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, } diff --git a/math.odin b/util/math.odin similarity index 59% rename from math.odin rename to util/math.odin index a255820..69b3642 100644 --- a/math.odin +++ b/util/math.odin @@ -1,9 +1,9 @@ -package main +package util Position :: struct { x, y: f32, } -Direction :: struct { +Velocity :: struct { x, y: f32, }