From 9fb75de9be0db9a78f568e73f2f374673f2ed52e Mon Sep 17 00:00:00 2001 From: morrigan Date: Sat, 28 Jun 2025 15:33:39 +0200 Subject: [PATCH] use snake case for functions --- main.odin | 24 ++++++++++++------------ movement.odin | 4 ++-- unit.odin | 16 ++++++++-------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/main.odin b/main.odin index 6232f3c..dea26ef 100644 --- a/main.odin +++ b/main.odin @@ -30,8 +30,8 @@ main :: proc() { assert(render != nil) units := make([dynamic]Unit) - append(&units, NewUnit(Faction.Allied, util.Position{500, 500})) - append(&units, NewUnit(Faction.Enemy, util.Position{700, 700})) + append(&units, new_unit(Faction.Allied, util.Position{500, 500})) + append(&units, new_unit(Faction.Enemy, util.Position{700, 700})) input_state := make(map[sdl3.Scancode]bool) time := sdl3.GetTicksNS() @@ -40,7 +40,7 @@ main :: proc() { game := Game { render = render, units = units, - player = NewUnit(Faction.Player, util.Position{100, 100}, 200), + player = new_unit(Faction.Player, util.Position{100, 100}, 200), time = time, delta = 0.0, input_state = input_state, @@ -53,33 +53,33 @@ main :: proc() { case .QUIT: return case .KEY_UP: - HandleInput(&game, event) + handle_input(&game, event) case .KEY_DOWN: - HandleInput(&game, event) + handle_input(&game, event) } } - MovePlayer(&game) - RenderGame(&game) - UpdateTime(&game) + move_player(&game) + render_game(&game) + update_time(&game) } } -UpdateTime :: proc(game: ^Game) { +update_time :: proc(game: ^Game) { new_time := sdl3.GetTicksNS() delta_ns := new_time - game.time game.time = new_time game.delta = f32(delta_ns) / f32(sdl3.NS_PER_SECOND) } -RenderGame :: proc(game: ^Game) { +render_game :: proc(game: ^Game) { sdl3.SetRenderDrawColor(game.render, 0, 0, 0, 0) sdl3.RenderClear(game.render) for unit in game.units { - RenderUnit(unit, game) + render_unit(unit, game) } - RenderUnit(game.player, game) + render_unit(game.player, game) sdl3.RenderPresent(game.render) } diff --git a/movement.odin b/movement.odin index 83ac987..b70dd58 100644 --- a/movement.odin +++ b/movement.odin @@ -4,12 +4,12 @@ import "core:fmt" import "util" import "vendor:sdl3" -HandleInput :: proc(game: ^Game, event: sdl3.Event) { +handle_input :: proc(game: ^Game, event: sdl3.Event) { effect := event.type == sdl3.EventType.KEY_DOWN ? true : false game.input_state[event.key.scancode] = effect } -MovePlayer :: proc(game: ^Game) { +move_player :: proc(game: ^Game) { speed := game.player.speed y: f32 = game.input_state[sdl3.Scancode.W] ? -speed : 0 diff --git a/unit.odin b/unit.odin index e4f4c03..0a286fb 100644 --- a/unit.odin +++ b/unit.odin @@ -21,7 +21,7 @@ Unit :: struct { hp: u32, } -RenderUnit :: proc(unit: Unit, game: ^Game) { +render_unit :: proc(unit: Unit, game: ^Game) { switch unit.faction { case Faction.Player: sdl3.SetRenderDrawColor(game.render, 0, 255, 0, 0) @@ -36,21 +36,21 @@ RenderUnit :: proc(unit: Unit, game: ^Game) { ) } -NewUnit :: proc { - NewUnitBase, - NewUnitHp, - NewUnitAll +new_unit :: proc { + new_unit_all, + new_unit_base, + new_unit_hp, } -NewUnitBase :: proc(faction: Faction, position: util.Position) -> Unit { +new_unit_base :: proc(faction: Faction, position: util.Position) -> Unit { return Unit{faction, position, DEFAULT_VELOCITY, DEFAULT_SPEED, DEFAULT_HP} } -NewUnitHp :: proc(faction: Faction, position: util.Position, hp: u32) -> Unit { +new_unit_hp :: proc(faction: Faction, position: util.Position, hp: u32) -> Unit { return Unit{faction, position, DEFAULT_VELOCITY, DEFAULT_SPEED, hp} } -NewUnitAll :: proc(faction: Faction, position: util.Position, speed: f32, hp: u32) -> Unit { +new_unit_all :: proc(faction: Faction, position: util.Position, speed: f32, hp: u32) -> Unit { return Unit{faction, position, DEFAULT_VELOCITY, speed, hp} }