Initial input manager
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user