blob: 475be92ccb354649c16381b5349df93b162ff278 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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,
}
init_keybinds :: proc() {
actions.move_left.input = .A
actions.move_right.input = .D
actions.jump.input = .SPACE
actions.dash.input = .LEFT_SHIFT
}
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
}
|