# Rogue-like Game Help

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all I'm making a little rogue-like game to pass the time and I was wondering if anyone knows a better way to clear the screen and redraw other than the clrscr() function. I'm wondering this because when I redraw the screen it gives me this flickering thing with my screen. It's not that big of a deal but i would like to find a way for getting rid of this flickering effect.

##### Share on other sites
i don't know it it helps but:

system ('clear');

appears to do the trick in my applications ;-)

##### Share on other sites
hmmm oddly enough that made it worse... it didn't work the syntax you gave me so I had to do it like: system("cls");
not sure if that makes a difference or not.... system ('clear'); crashed the program.

##### Share on other sites
Warning! This is not a C++ builtin or library function. The system() function itself is, but what it does is look up a program by the provided name and execute it. This relies on the program (a) existing, (b) being where it needs to be and (c) doing what you expect it to. (It's also quite inefficient, although that's unlikely to matter for clearing the screen in a console application).

To solve the general problem of dealing with roguelike-style "graphics", you really should invest the effort to look into a console graphics library such as 'ncurses'.

##### Share on other sites
I thought Conio2.h could preety much do the same thing as ncurses? I'll look into it again but are you sure that it would fix the refreshing problem in a console game... maybe I should just move on and not worry about this....

##### Share on other sites
Kudos on Making a Rogue like game btw, that's a deceptively simple game but a worthy task. If you don't believe me take a look at nethack (a great game btw).

I hope oneday to see your game up there in the halls with Angband, Rogue, and all the other fun games that have stolen a couple years of my life so far.

##### Share on other sites
heh yeah I've tried them all, my fav is actually ADOM but Nethack is up there too as my second choice. For the past 5 years I've been from DirectDraw to SDL to Direct3D to OpenGL, I've been bouncing around creating a lot of graphical stuff but now I rather just program something more complete.

Anyway, I got pdcurses set up and running and I'm still getting some flickering going on... sigh maybe I'm just doing something wrong. pdcurses is cool but the arrow keys don't seem to work I got it set up like this:

c = getch(); // Get Input    /* Act depending on the last key received. */    switch (c)    {      case KEY_LEFT:   //Right arrow key	       x++;	       break;    }

EDIT: OK I got the flickering problem fixed!! :D Only thing left is the arrow key problem.

##### Share on other sites
The text device should be considered a single-buffer device. That means instead of clearing the screen and then drawing everything, one should try to simply draw everything on top (or mantain your own "backbuffer"). Basic idea:

char buffer[80][25];void clear_buffer( void ){   for ( int x = 0 ; x < 80 ; ++x )      for ( int y = 0 ; y < 25 ; ++y )          buffer[x][y] = ' ';}void update_screen( void ){   gotoxy( 0 , 0 );   for ( int x = 0 ; x < 80 ; ++x )      for ( int y = 0 ; y < 25 ; ++y )         putchar( buffer[x][y] );}//...void CPlayer::Render( void ){    //was gotoxy(x,y); putchar( '@' );    buffer[x][y] = '@';}void main_loop( void ){    //was system("clear");    clear_buffer();    //this was the same:    player.Render();    //this was added:    update_screen();}

##### Share on other sites
As a small bit of advice. 'clear' is for Linux, 'cls' is for DOS (or windows emulating DOS).

##### Share on other sites
gosh, dumb me, surely system ('clear') works under linux. i've been programming under taht os for a while and this is why used clear. sorry, my mistake. ;-)

• 39
• 15
• 9
• 23
• 10