aboutsummaryrefslogtreecommitdiff
path: root/src/input.odin
diff options
context:
space:
mode:
authorXander Swan <no email>2025-12-17 18:38:21 -0500
committerXander Swan <no email>2025-12-17 18:38:21 -0500
commitce4d64bd41937d7dff18ca607122188dc338d696 (patch)
treead5f7cbdffcc1478883cbca0ea7b8365b2108d0a /src/input.odin
parent87a7a010ecbe2cb99fedf44d0cac31e2efae86d5 (diff)
switch to raylib, update some structure
Diffstat (limited to 'src/input.odin')
-rw-r--r--src/input.odin52
1 files changed, 22 insertions, 30 deletions
diff --git a/src/input.odin b/src/input.odin
index 6c02349..de2af7e 100644
--- a/src/input.odin
+++ b/src/input.odin
@@ -1,10 +1,10 @@
package demonchime
-import sapp "shared:sokol/app"
+import rl "vendor:raylib"
KeybindInput :: union {
- sapp.Keycode,
- sapp.Mousebutton,
+ rl.KeyboardKey,
+ rl.MouseButton,
}
Keybind :: struct {
@@ -13,44 +13,36 @@ Keybind :: struct {
just_pressed: bool,
}
-Input :: struct {
+actions: struct {
move_left: Keybind,
move_right: Keybind,
jump: Keybind,
-
- key_down: [sapp.MAX_KEYCODES]bool,
- key_just_down: [sapp.MAX_KEYCODES]bool,
- mouse_down: [sapp.MAX_MOUSEBUTTONS]bool,
- mouse_just_down: [sapp.MAX_MOUSEBUTTONS]bool,
}
-init_keybinds :: proc(input: ^Input) {
- input.move_left.input = sapp.Keycode.A
- input.move_right.input = sapp.Keycode.D
- input.jump.input = sapp.Keycode.SPACE
+init_keybinds :: proc() {
+ actions.move_left.input = .A
+ actions.move_right.input = .D
+ actions.jump.input = .SPACE
}
-input_event :: proc(event: ^sapp.Event, input: ^Input) {
- #partial switch event.type {
- case .KEY_DOWN:
- input.key_down[event.key_code] = true
- input.key_just_down[event.key_code] = true
- case .KEY_UP:
- input.key_down[event.key_code] = false
- case .MOUSE_DOWN:
- input.mouse_down[event.key_code] = true
- input.mouse_just_down[event.key_code] = true
- case .MOUSE_UP:
- input.mouse_down[event.key_code] = false
+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_down :: proc(input: Input, keybind: Keybind) -> bool {
+is_keybind_just_down :: proc(keybind: Keybind) -> bool {
switch val in keybind.input {
- case sapp.Keycode:
- return input.key_down[val]
- case sapp.Mousebutton:
- return input.mouse_down[val]
+ case rl.KeyboardKey:
+ return rl.IsKeyPressed(val)
+ case rl.MouseButton:
+ return rl.IsMouseButtonPressed(val)
}
assert(false)