Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990package sim
Move_Direction :: enum u8 { None, N, NE, E, SE, S, SW, W, NW,}
@(private="file")move_deltas: [Move_Direction]Vec2_Fixed = { .None = {Fixed(0), Fixed(0)}, .N = {Fixed(0), -PLAYER_MOVE_CARDINAL}, .NE = {PLAYER_MOVE_DIAGONAL, -PLAYER_MOVE_DIAGONAL}, .E = {PLAYER_MOVE_CARDINAL, Fixed(0)}, .SE = {PLAYER_MOVE_DIAGONAL, PLAYER_MOVE_DIAGONAL}, .S = {Fixed(0), PLAYER_MOVE_CARDINAL}, .SW = {-PLAYER_MOVE_DIAGONAL, PLAYER_MOVE_DIAGONAL}, .W = {-PLAYER_MOVE_CARDINAL, Fixed(0)}, .NW = {-PLAYER_MOVE_DIAGONAL, -PLAYER_MOVE_DIAGONAL},}
// Input_Command is the narrow bridge between the outside world and deterministic// simulation. Hardware, UI, and AI can all produce commands; sim only consumes them.Input_Command :: struct { move: Move_Direction, aim: Vec2_Q, attack: bool,}
input_command_from_digital :: proc( move_left, move_right, move_up, move_down: bool, attack := false,) -> Input_Command { command: Input_Command command.move = move_direction_from_digital(move_left, move_right, move_up, move_down) command.attack = attack return command}
move_direction_from_digital :: proc( move_left, move_right, move_up, move_down: bool,) -> Move_Direction { x := i8(0) y := i8(0)
if move_left { x -= 1 } if move_right { x += 1 } if move_up { y -= 1 } if move_down { y += 1 }
switch { case x == 0 && y < 0: return .N case x > 0 && y < 0: return .NE case x > 0 && y == 0: return .E case x > 0 && y > 0: return .SE case x == 0 && y > 0: return .S case x < 0 && y > 0: return .SW case x < 0 && y == 0: return .W case x < 0 && y < 0: return .NW }
return .None}
move_delta :: proc(direction: Move_Direction) -> Vec2_Fixed { return move_deltas[direction]}