Merge pull request #23 from paul-arutyunov/master

Add arrow keys
This commit is contained in:
Marc Tiehuis 2018-11-18 21:48:26 +13:00 committed by GitHub
commit d5c1b9c2f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View File

@ -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;

View File

@ -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);
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)

View File

@ -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':