add player
This commit is contained in:
parent
aab03eafef
commit
8babb48fd2
3 changed files with 21 additions and 2 deletions
|
@ -10,6 +10,7 @@ HEIGHT :: 900
|
||||||
Game :: struct {
|
Game :: struct {
|
||||||
render: ^sdl3.Renderer,
|
render: ^sdl3.Renderer,
|
||||||
units: [dynamic]Unit,
|
units: [dynamic]Unit,
|
||||||
|
player: Unit,
|
||||||
}
|
}
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
|
@ -23,13 +24,15 @@ main :: proc() {
|
||||||
render := sdl3.CreateRenderer(window, "vulkan")
|
render := sdl3.CreateRenderer(window, "vulkan")
|
||||||
|
|
||||||
assert(render != nil)
|
assert(render != nil)
|
||||||
|
|
||||||
units := make([dynamic]Unit)
|
units := make([dynamic]Unit)
|
||||||
append(&units, Unit{faction = Faction.Player, position = Position{x = 500, y = 500}, hp = 100})
|
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.Enemy, position = Position{x = 700, y = 700}, hp = 100})
|
||||||
|
|
||||||
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},
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -57,6 +60,8 @@ RenderGame :: proc(game: Game) {
|
||||||
RenderUnit(unit, game)
|
RenderUnit(unit, game)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RenderUnit(game.player, game)
|
||||||
|
|
||||||
sdl3.RenderPresent(game.render)
|
sdl3.RenderPresent(game.render)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,7 @@ package main
|
||||||
Position :: struct {
|
Position :: struct {
|
||||||
x, y: f32,
|
x, y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Direction :: struct {
|
||||||
|
x, y: f32,
|
||||||
|
}
|
||||||
|
|
10
unit.odin
10
unit.odin
|
@ -4,6 +4,7 @@ import "vendor:sdl3"
|
||||||
|
|
||||||
Faction :: enum {
|
Faction :: enum {
|
||||||
Player,
|
Player,
|
||||||
|
Allied,
|
||||||
Enemy,
|
Enemy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +20,18 @@ RenderUnit :: proc(unit: Unit, game: Game) {
|
||||||
sdl3.SetRenderDrawColor(game.render, 0, 255, 0, 0)
|
sdl3.SetRenderDrawColor(game.render, 0, 255, 0, 0)
|
||||||
case Faction.Enemy:
|
case Faction.Enemy:
|
||||||
sdl3.SetRenderDrawColor(game.render, 255, 0, 0, 0)
|
sdl3.SetRenderDrawColor(game.render, 255, 0, 0, 0)
|
||||||
|
case Faction.Allied:
|
||||||
|
sdl3.SetRenderDrawColor(game.render, 0, 0, 255, 0)
|
||||||
}
|
}
|
||||||
sdl3.RenderRect(
|
sdl3.RenderRect(
|
||||||
game.render,
|
game.render,
|
||||||
&sdl3.FRect{x = unit.position.x, y = unit.position.y, w = 10, h = 10},
|
&sdl3.FRect{x = unit.position.x, y = unit.position.y, w = 10, h = 10},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Projectile :: struct {
|
||||||
|
faction: Faction,
|
||||||
|
position: Position,
|
||||||
|
direction: Direction,
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue