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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package demonchime
import rl "vendor:raylib"
KeyboardInput :: union {
rl.KeyboardKey,
rl.MouseButton,
}
ControllerInput :: union {
}
Keybind :: struct {
input: KeyboardInput,
pressed: bool,
just_pressed: bool,
}
actions: struct {
move_left: Keybind,
move_right: Keybind,
jump: Keybind,
dash: Keybind,
shoot: Keybind,
toggle_debug_mode: Keybind,
}
init_keybinds :: proc() {
actions.move_left.input = .A
actions.move_right.input = .D
actions.jump.input = .SPACE
actions.dash.input = .LEFT_SHIFT
actions.shoot.input = rl.MouseButton.LEFT
actions.toggle_debug_mode.input = .GRAVE
}
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
}
get_mouse_pos :: proc() -> (mouse_pos: Vec2) {
mouse_pos = Vec2{f32(rl.GetMouseX()), f32(rl.GetMouseY())}
mouse_pos /= Vec2{f32(rl.GetScreenWidth()), f32(rl.GetScreenHeight())}
mouse_pos *= SCREEN_SIZE
mouse_pos += state.camera.target
return
}
|