From 8c1faba2535c5eb7090a922b15a3978b820e2be7 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Mon, 21 Sep 2020 11:21:28 +0200 Subject: [PATCH] =?UTF-8?q?Fixed=20the=20issue,=20thanks=20to=20Leph=C3=A9?= =?UTF-8?q?nixnoir.=20input.states=20were=20initialized=20to=200,=20which?= =?UTF-8?q?=20is=20the=20value=20of=20S=5FPRESS.=20They=20are=20now=20set?= =?UTF-8?q?=20to=20S=5FUP.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/input.h | 3 +++ src/input.c | 13 +++++++++++++ src/main.c | 6 +----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/input.h b/include/input.h index d69e89f..b63164b 100644 --- a/include/input.h +++ b/include/input.h @@ -29,6 +29,9 @@ typedef struct Input /* will check for new key inputs and update states[] */ void input_step(Input *input); +/* initialize values */ +void input_init(Input *input); + /* display all keys states and information */ void input_draw_debug(Input *input); diff --git a/src/input.c b/src/input.c index f9b02dd..283be83 100644 --- a/src/input.c +++ b/src/input.c @@ -26,6 +26,19 @@ void input_step(Input *input) } } +void input_init(Input *input) +{ + input->keys[K_LEFT] = KEY_LEFT; + input->keys[K_RIGHT] = KEY_RIGHT; + input->keys[K_UP] = KEY_UP; + input->keys[K_DOWN] = KEY_DOWN; + input->keys[K_EXIT] = KEY_EXIT; + for (int i = 0; i < KEYS_COUNT; ++i) + { + input->states[i] = S_UP; + } +} + void input_draw_debug(Input *input) { for (int i = 0; i < KEYS_COUNT; ++i) diff --git a/src/main.c b/src/main.c index 35716ac..329eca7 100644 --- a/src/main.c +++ b/src/main.c @@ -49,11 +49,7 @@ int play_level(uint level_id) /* create input manager */ Input input; - input.keys[K_LEFT] = KEY_LEFT; - input.keys[K_RIGHT] = KEY_RIGHT; - input.keys[K_UP] = KEY_UP; - input.keys[K_DOWN] = KEY_DOWN; - input.keys[K_EXIT] = KEY_EXIT; + input_init(&input); /* UPS control */ volatile int has_ticked = 1;