An initial attempt to implement urw-keys
This commit is contained in:
commit
8e501fd497
|
@ -0,0 +1,3 @@
|
|||
ntown
|
||||
*.swp
|
||||
a.out
|
|
@ -0,0 +1,82 @@
|
|||
#include <ncurses.h>
|
||||
#include <ctime>
|
||||
|
||||
enum dir {
|
||||
N = 0, NE = 1, E = 2, SE = 3, S = 4, SW = 5, W = 6, NW = 7
|
||||
};
|
||||
|
||||
dir rotate(dir initial_d, int rot_dir) {
|
||||
return (dir)((initial_d + rot_dir) % 8);
|
||||
}
|
||||
|
||||
int main() {
|
||||
initscr();
|
||||
start_color();
|
||||
cbreak();
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
curs_set(0);
|
||||
int pos_x = 1;
|
||||
int pos_y = 1;
|
||||
dir direction = dir::E;
|
||||
mvaddch(pos_y, pos_x, 'O');
|
||||
int ch;
|
||||
while ((ch = wgetch(stdscr)) != 'q') {
|
||||
int rotd = 0;
|
||||
int movval = 0;
|
||||
switch (ch) {
|
||||
case KEY_LEFT:
|
||||
rotd = -1;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
rotd = 1;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
movval = -1;
|
||||
break;
|
||||
case KEY_UP:
|
||||
movval = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
direction = rotate(direction, rotd);
|
||||
switch (direction) {
|
||||
case dir::N:
|
||||
pos_x -= movval;
|
||||
break;
|
||||
case dir::S:
|
||||
pos_x += movval;
|
||||
break;
|
||||
case dir::W:
|
||||
pos_y -= movval;
|
||||
break;
|
||||
case dir::E:
|
||||
pos_y += movval;
|
||||
break;
|
||||
case dir::NE:
|
||||
pos_x += movval;
|
||||
pos_y -= movval;
|
||||
break;
|
||||
case dir::NW:
|
||||
pos_x -= movval;
|
||||
pos_y -= movval;
|
||||
break;
|
||||
case dir::SE:
|
||||
pos_x += movval;
|
||||
pos_y += movval;
|
||||
break;
|
||||
case dir::SW:
|
||||
pos_x -= movval;
|
||||
pos_y += movval;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
pos_x = pos_x % COLS;
|
||||
pos_y = pos_y % LINES;
|
||||
refresh();
|
||||
mvaddch(pos_y, pos_x, 'O');
|
||||
}
|
||||
endwin();
|
||||
}
|
Loading…
Reference in New Issue