aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_context.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-11 14:30:48 -0400
committeriamcheeseman <[email protected]>2026-05-11 14:30:48 -0400
commitf4017a52d90567c2df482c5d553076dc706ac59b (patch)
tree6cce9684cee03370188e6c46e745fabb64007a46 /teensy/teensy_context.c
parentda2585ddc49abb80e7457ccc2805fff884eb2021 (diff)
Allow user input
Diffstat (limited to 'teensy/teensy_context.c')
-rw-r--r--teensy/teensy_context.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/teensy/teensy_context.c b/teensy/teensy_context.c
index 4a812dd..9dff405 100644
--- a/teensy/teensy_context.c
+++ b/teensy/teensy_context.c
@@ -35,6 +35,18 @@ void ty_deinit(void)
ty_deinit_mem();
}
+bool ty_button_down(enum ty_button btn)
+{
+ assert(btn >= 0 && btn < TY_BTN_COUNT);
+ return ctx.down[btn];
+}
+
+bool ty_button_pressed(enum ty_button btn)
+{
+ assert(btn >= 0 && btn < TY_BTN_COUNT);
+ return ctx.pressed[btn];
+}
+
bool ty_is_game_running(void)
{
assert(is_init());
@@ -47,6 +59,16 @@ double ty_get_time(void)
return ty_platform_get_time();
}
+static
+void update_buttons(void)
+{
+ for (int btn = 0; btn < TY_BTN_COUNT; btn++) {
+ bool down = ty_platform_is_button_down(btn);
+ ctx.pressed[btn] = down && !ctx.down[btn];
+ ctx.down[btn] = down;
+ }
+}
+
int ty_tick(void)
{
assert(is_init());
@@ -56,6 +78,7 @@ int ty_tick(void)
int tics = time_since_tic / ctx.ticrate;
if (tics > 0) {
+ update_buttons();
ctx.prev_tic_ts = current_time;
ty_platform_frame(r.screen);
}