From 42aa4c8cf1ec437b501c322d446dd175f9e25233 Mon Sep 17 00:00:00 2001 From: Paul_Arutyunov Date: Sat, 13 Oct 2018 13:45:02 +0300 Subject: [PATCH 1/3] Add arrow keys definitions --- src/gfx.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gfx.h b/src/gfx.h index c88e3c4..3974763 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -1,6 +1,11 @@ #ifndef GFX_H #define GFX_H +#define INPUT_UP 0 +#define INPUT_DOWN 1 +#define INPUT_LEFT 2 +#define INPUT_RIGHT 3 + #include "engine.h" struct gfx_state; From 28cd69b501349227835026f424f943e320b36d68 Mon Sep 17 00:00:00 2001 From: Paul_Arutyunov Date: Sat, 13 Oct 2018 13:45:27 +0300 Subject: [PATCH 2/3] Add arrow keys return values --- src/gfx_curses.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gfx_curses.c b/src/gfx_curses.c index 4db2467..bfa3ad0 100644 --- a/src/gfx_curses.c +++ b/src/gfx_curses.c @@ -21,6 +21,7 @@ struct gfx_state* gfx_init(struct gamestate *g) { initscr(); cbreak(); + keypad(stdscr, true); noecho(); curs_set(FALSE); refresh(); @@ -116,7 +117,27 @@ int gfx_getch(struct gfx_state *s) nodelay(s->window, TRUE); while (wgetch(s->window) != ERR); nodelay(s->window, FALSE); - return c; + + switch (c) + { + case KEY_UP: + return INPUT_UP; + break; + case KEY_DOWN: + return INPUT_DOWN; + break; + case KEY_RIGHT: + return INPUT_RIGHT; + break; + case KEY_LEFT: + return INPUT_LEFT; + break; + + default: + return c; + break; + + } } void gfx_sleep(int ms) From c5f6ca6beb4a4bd88dde5cb41891d978dd7e96a9 Mon Sep 17 00:00:00 2001 From: Paul_Arutyunov Date: Sat, 13 Oct 2018 13:45:48 +0300 Subject: [PATCH 3/3] Handle arrow keys --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index c5c62cd..268e7d8 100644 --- a/src/main.c +++ b/src/main.c @@ -39,18 +39,22 @@ get_new_key:; switch (value) { case 'h': case 'a': + case INPUT_LEFT: direction = dir_left; break; case 'l': case 'd': + case INPUT_RIGHT: direction = dir_right; break; case 'j': case 's': + case INPUT_DOWN: direction = dir_down; break; case 'k': case 'w': + case INPUT_UP: direction = dir_up; break; case 'q':