a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 8cf5f09f24fbe29113afbbe8049d47c9330ab3de
parent e612d0b7b3ae5d7b79732259fed75cf417eda8bf
Author: amin <dev@aminmesbah.com>
Date:   Mon,  1 Jul 2019 01:09:56 +0000

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.

FossilOrigin-Name: 45c18370de9926fcce3f0e7c39e6bf476ccc99e48f58c72363dd2d247fe7cda5
Diffstat:
Msrc/game.c | 10+++++++++-
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) {