package game import rl "vendor:raylib" // ------------------------------------------------------------------------------ // Input Manager, captures input events and stores them into a struct. // Passing the struct down allows for components to use inputs independently // ------------------------------------------------------------------------------ Input_Event :: struct { // Continuous movement normalized move_dir: rl.Vector2, // single frame actions UI and triggers up_pressed: bool, down_pressed: bool, confirm_pressed: bool, pause_pressed: bool, } poll_input :: proc() -> Input_Event { input_event := Input_Event{} input_dir := rl.Vector2{0, 0} // -------------------------------------------------------------------------- // Continuous Input ie movement code // -------------------------------------------------------------------------- if rl.IsKeyDown(.W) || rl.IsKeyDown(.UP) { input_dir.y -= 1 } if rl.IsKeyDown(.S) || rl.IsKeyDown(.DOWN) { input_dir.y += 1 } if input_dir.x != 0 || input_dir.y != 0 { input_dir = rl.Vector2Normalize(input_dir) } input_event.move_dir = input_dir // -------------------------------------------------------------------------- // actions single press ie menu navigation etc // -------------------------------------------------------------------------- input_event.up_pressed = rl.IsKeyPressed(.W) || rl.IsKeyPressed(.UP) input_event.down_pressed = rl.IsKeyPressed(.S) || rl.IsKeyPressed(.DOWN) input_event.confirm_pressed = rl.IsKeyPressed(.ENTER) || rl.IsKeyPressed(.SPACE) input_event.pause_pressed = rl.IsKeyPressed(.P) return input_event }