/* http://www.cyut.edu.tw/~ckhung/b/mi/ */ /* 1999-06 */ /* how to compile: gcc -Wall momentum.c -lncurses */ #include #include int main() { int width, height; double u, v, x, y; int c, go_on; initscr(); cbreak(); noecho(); nodelay(stdscr, 1); keypad(stdscr, 1); getmaxyx(stdscr, height, width); mvaddstr(0, 0, "press arrow keys to accelerate the cursor;"); mvaddstr(1, 0, "press any other key to quit"); u = v = 0; x = y = 0; go_on = 1; while (go_on) { while ((c = getch()) == ERR) { move(y, x); x += u / 1000; y += v / 1000; while (x < 0) x += width; while (x >= width) x -= width; while (y < 0) y += height; while (y >= height) y -= height; } switch (c) { case KEY_LEFT: --u; break; case KEY_RIGHT: ++u; break; case KEY_UP: --v; break; case KEY_DOWN: ++v; break; default: go_on = 0; } } endwin(); return 0; }