Simple Games using ncurses
Menu
#include <ncurses.h> #include <stdlib.h> #include <time.h> using namespace std; int main() { home: int clock_1=0; bool quit=false; int x=14; int y=6; int player_dir=0; int ch;//getkey srand(time(NULL)); initscr(); noecho(); curs_set(0); keypad(stdscr, TRUE); timeout(175); //initiate color function start_color(); bkgd(COLOR_PAIR(1)); init_pair(1,COLOR_CYAN, COLOR_BLACK); while (!quit) { ch = getch(); switch (ch) { case 'a': player_dir = 1; break; case 'd': player_dir = 2;break; case 'w':player_dir= 3;break; case 'z':player_dir= 4;break; case 'p': timeout(555555); break; case 'u': timeout(225); break; case 'q': quit=true; } erase(); clock_1++;//timer for whatever... //player continues to move in the direction when certain keys are pressed once. switch (player_dir) { case 1: x--; break; case 2: x++; break; case 3: y--; break; case 4: y++; break; } //player y,x mvprintw(y,x,"0"); }//while !quit closing brace timeout(-1); refresh(); getch(); endwin(); goto home; }
0 Comments
Leave a Reply. |
Archives
March 2016
Categories |