From a98bbd9c93b19062a623f499e4e2b6bffa1e298b Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Wed, 9 Sep 2026 07:18:16 +0200 Subject: [PATCH] Initial input manager --- src/input_manager.odin | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/input_manager.odin diff --git a/src/input_manager.odin b/src/input_manager.odin new file mode 100644 index 0000000..57a2dd7 --- /dev/null +++ b/src/input_manager.odin @@ -0,0 +1,38 @@ +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 independantly +// ------------------------------------------------------------------------------ + +Input_Event :: struct { + // Normalized and merged from keyboard + controller + move_dir: rl.Vector2, + pause_pressed: bool, +} + +poll_input :: proc() -> Input_Event { + input_event := Input_Event{} + input_dir := rl.Vector2{0,0} + + // ------------------------------------------------------------------------------------------------------ + // Keyboard + // ------------------------------------------------------------------------------------------------------ + if rl.IsKeyDown(.W) || rl.IsKeyDown(.UP) { input_dir.y -= 1 } + if rl.IsKeyDown(.S) || rl.IsKeyDown(.DOWN) { input_dir.y += 1 } + + // single-fire == IsKeyPressed, held == IsKeyDown + input_event.pause_pressed = rl.IsKeyPressed(.P) + + // ------------------------------------------------------------------------------------------------------ + // Movement/direction needs update + // ------------------------------------------------------------------------------------------------------ + if input_dir.x != 0 || input_dir.y != 0 { + input_dir = rl.Vector2Normalize(input_dir) + } + input_event.move_dir = input_dir + + return input_event +} \ No newline at end of file