aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_context.c
diff options
context:
space:
mode:
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);
}