This is a discussion on curses Problems with Non-Blocking input within the Coding in General forums, part of the Development/Scripting category; Hi all, I'm trying to get a simple curses program working on Solaris using gcc. it compile and everything about ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
Hi all,
I'm trying to get a simple curses program working on Solaris using gcc. it compile and everything about the code is just fine appart from the part where it reads input. Its the begginings of a game (but its just nonsense at the moment, I'm just trying to get a basic input/display loop going) There are supposedly ways to make getchar() non-blocking. I found refference to them here: http://www.gsp.com/cgi-bin/man.cgi?s...opic=halfdelay I've tried them all to no avail. The proram fails to progress unless the user hits a key. Basically if it worked the way I wanted "moo" would shoot off the end of the screen instantly, and the ship would move around with keypresses. But, "moo" only moves each time the key is pressed. And I know there's no function call to make getchar() non-blocking in there at the moment, but i tried them all on the previous link (the gsp one) and none worked. Any ideas? The code is as follows: #include <curses.h> #include <string.h> #define XMAX 95 #define YMAX 76 #define XMIN 0 #define YMIN 2 void update_ship(); void update_thing(); int level = 1; int lives = 30; int ship_y = 58; int ship_x = 20; char ship1[]=" .^. "; char ship2[]="-<_>-"; int main(){ initscr(); /* Start curses mode */ noecho(); /* Don't echo() while we do getch */ keypad(stdscr, TRUE); mvprintw(level,10,"moo"); while(lives > 0){ timeout(10); int ch = getchar(); if (ch == 'a'){ ship_x--; } else if (ch == 'd'){ ship_x++; } else if (ch == 'q'){ lives = -1; } else if (ch == ' '){ //fire somehow } else if (ch == 'w'){ ship_y--; } else if (ch == 's'){ ship_y++; } initscr();//clear screen //redraw screen update_ship(); update_thing(); } endwin(); /* End curses mode */ printf("\n\nyou died you twat\n"); return 0; } void update_ship(){ mvprintw(ship_y, ship_x, ship1); mvprintw(ship_y+1, ship_x, ship2); mvprintw(0, 0, " "); refresh(); } void update_thing(){ mvprintw(level,10,"moo"); level++; refresh(); } |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Interpreting ~ from user input | al001 | Shell scripting | 2 | 04-21-2008 09:27 PM |
| blocking streaming | zafar466 | CentOS / RHEL / Fedora | 0 | 04-12-2008 04:37 AM |
| Shell script to supply or input a password passphrase | kasimani | Shell scripting | 1 | 02-21-2007 10:21 AM |
| iptables rules blocking ftp | hammooda | Linux software | 7 | 09-23-2006 05:24 PM |
| Program gets aborted on large input | Ssk | Linux software | 7 | 03-14-2005 12:04 PM |