Linux / UNIX Tech Support Forum
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 ...
|
|||||||
| Coding in General Discussion on PHP/Perl/Python/Ruby/GNU C or C++. MySQL, PgSQL and (X)HTML or any other programming languages you want. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 | ||
|
|
|
||||
|
Have you tryied the getch or wgetch? They may solve your problem
let me know...
__________________
Vivek Gite Linux Evangelist |
![]() |
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 | 21-04-2008 08:27 PM |
| blocking streaming | zafar466 | CentOS / RHEL / Fedora | 0 | 12-04-2008 03:37 AM |
| Shell script to supply or input a password passphrase | kasimani | Shell scripting | 1 | 21-02-2007 09:21 AM |
| iptables rules blocking ftp | hammooda | Linux software | 7 | 23-09-2006 04:24 PM |
| Program gets aborted on large input | Ssk | Linux software | 7 | 14-03-2005 11:04 AM |