extract math util into sub package
This commit is contained in:
parent
538c8c215f
commit
60d71ae1c0
4 changed files with 35 additions and 8 deletions
28
main.odin
28
main.odin
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:image/png"
|
import "core:image/png"
|
||||||
|
import "util"
|
||||||
import "vendor:sdl3"
|
import "vendor:sdl3"
|
||||||
|
|
||||||
WIDTH :: 1600
|
WIDTH :: 1600
|
||||||
|
@ -29,8 +30,24 @@ main :: proc() {
|
||||||
assert(render != nil)
|
assert(render != nil)
|
||||||
|
|
||||||
units := make([dynamic]Unit)
|
units := make([dynamic]Unit)
|
||||||
append(&units, Unit{faction = Faction.Allied, position = Position{x = 500, y = 500}, hp = 100})
|
append(
|
||||||
append(&units, Unit{faction = Faction.Enemy, position = Position{x = 700, y = 700}, hp = 100})
|
&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)
|
input_state := make(map[sdl3.Scancode]bool)
|
||||||
|
|
||||||
time := sdl3.GetTicksNS()
|
time := sdl3.GetTicksNS()
|
||||||
|
@ -39,7 +56,12 @@ main :: proc() {
|
||||||
game := Game {
|
game := Game {
|
||||||
render = render,
|
render = render,
|
||||||
units = units,
|
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,
|
time = time,
|
||||||
delta = 0.0,
|
delta = 0.0,
|
||||||
input_state = input_state,
|
input_state = input_state,
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
|
import "util"
|
||||||
import "vendor:sdl3"
|
import "vendor:sdl3"
|
||||||
|
|
||||||
|
DEFAULT_VELOCITY: util.Velocity : util.Velocity{x = 0, y = 0}
|
||||||
SPEED: f32 : 200
|
SPEED: f32 : 200
|
||||||
|
|
||||||
HandleInput :: proc(game: ^Game, event: sdl3.Event) {
|
HandleInput :: proc(game: ^Game, event: sdl3.Event) {
|
||||||
|
@ -15,6 +17,7 @@ MovePlayer :: proc(game: ^Game) {
|
||||||
y += game.input_state[sdl3.Scancode.S] ? SPEED : 0
|
y += game.input_state[sdl3.Scancode.S] ? SPEED : 0
|
||||||
x: f32 = game.input_state[sdl3.Scancode.A] ? -SPEED : 0
|
x: f32 = game.input_state[sdl3.Scancode.A] ? -SPEED : 0
|
||||||
x += game.input_state[sdl3.Scancode.D] ? 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.y += y * game.delta
|
||||||
game.player.position.x += x * game.delta
|
game.player.position.x += x * game.delta
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "util"
|
||||||
import "vendor:sdl3"
|
import "vendor:sdl3"
|
||||||
|
|
||||||
Faction :: enum {
|
Faction :: enum {
|
||||||
|
@ -10,7 +11,8 @@ Faction :: enum {
|
||||||
|
|
||||||
Unit :: struct {
|
Unit :: struct {
|
||||||
faction: Faction,
|
faction: Faction,
|
||||||
position: Position,
|
position: util.Position,
|
||||||
|
velocity: util.Velocity,
|
||||||
hp: u32,
|
hp: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +33,6 @@ RenderUnit :: proc(unit: Unit, game: ^Game) {
|
||||||
|
|
||||||
Projectile :: struct {
|
Projectile :: struct {
|
||||||
faction: Faction,
|
faction: Faction,
|
||||||
position: Position,
|
position: util.Position,
|
||||||
direction: Direction,
|
direction: util.Velocity,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package util
|
||||||
|
|
||||||
Position :: struct {
|
Position :: struct {
|
||||||
x, y: f32,
|
x, y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
Direction :: struct {
|
Velocity :: struct {
|
||||||
x, y: f32,
|
x, y: f32,
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue