commit b0711e5ef42687c75611f06fba03889f6a70a908
parent d4033ecc533158cd9f28f4af001a7af895231746
Author: Amin Mesbah <dev@aminmesbah.com>
Date: Sun, 30 Jun 2019 18:07:17 -0700
Distinguish between key press events and key state
Now when you press F11 to toggle floating, the toggle happens only once
until you release the key and press it again.
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/game.c b/src/game.c
@@ -13,6 +13,14 @@ internal bool btn_is_down(u32 button_states, enum GameButton b)
return result;
}
+internal bool btn_was_just_pressed(struct GameInput *game_input, enum GameButton b)
+{
+ assert(game_input);
+ assert(b < NUM_GAME_BUTTONS);
+ bool result = game_input->button_downs & (1 << b);
+ return result;
+}
+
internal void move_mode_print(enum MoveMode s)
{
switch(s)
@@ -282,7 +290,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
player->velocity.x = player->velocity.x * friction;
}
- if (btn_is_down(button_states, BTN_DEBUG_FLOAT))
+ if (btn_was_just_pressed(game_input, BTN_DEBUG_FLOAT))
{
if (player->move_mode == MOVE_MODE_FLOATING)
{