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; 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) 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':