package demonchime import rl "vendor:raylib" KeybindInput :: union { rl.KeyboardKey, rl.MouseButton, } Keybind :: struct { input: KeybindInput, pressed: bool, just_pressed: bool, } actions: struct { move_left: Keybind, move_right: Keybind, jump: Keybind, dash: Keybind, shoot: Keybind, toggle_debug_mode: Keybind, } init_keybinds :: proc() { actions.move_left.input = .A actions.move_right.input = .D actions.jump.input = .SPACE actions.dash.input = .LEFT_SHIFT actions.shoot.input = rl.MouseButton.LEFT actions.toggle_debug_mode.input = .GRAVE } is_keybind_down :: proc(keybind: Keybind) -> bool { switch val in keybind.input { case rl.KeyboardKey: return rl.IsKeyDown(val) case rl.MouseButton: return rl.IsMouseButtonDown(val) } assert(false) return false } is_keybind_just_down :: proc(keybind: Keybind) -> bool { switch val in keybind.input { case rl.KeyboardKey: return rl.IsKeyPressed(val) case rl.MouseButton: return rl.IsMouseButtonPressed(val) } assert(false) return false } get_mouse_pos :: proc() -> (mouse_pos: Vec2) { mouse_pos = Vec2{f32(rl.GetMouseX()), f32(rl.GetMouseY())} mouse_pos /= Vec2{f32(rl.GetScreenWidth()), f32(rl.GetScreenHeight())} mouse_pos *= SCREEN_SIZE return }