reduce flickering..and more

This is a discussion on reduce flickering..and more within the Game Programming forums, part of the General Programming Boards category; How could I reduce the flickering? Is there such thing as double buffering in text mode? Also, how do I ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    reduce flickering..and more

    How could I reduce the flickering? Is there such thing as double buffering in text mode? Also, how do I stop the skipping? Say if I held D to go right it would skip some of the diamonds and left angles.
    I am using Borland C++ 4.5 to compile it for DOS.

    Attached is the source.
    wsad and q to quit.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    First of all, first column (up-left) is (1,1) so you're missing some in your drawboard()

    Second
    scr[i][rand()%MAXY] = WALL;
    scr[rand()%MAXX][i] = DEATH;

    This means that you do not initialize the whole array (it might happen, but think not). Other thing is that you initialize something that is NOT in your array (scr[200][200]!).

    Prefer to use this kind of method

    for(int i = 0; i < MAXX; i++)
    for(int j = 0; j < MAXY; j++)
    switch(rand() % 2)
    {
    case 0: scr[i][j] = WALL; break;
    ...
    }

    For the flickering. Note that you don't need to redraw the whole screen once you move. Just replace the old xy coordinates after the player has moved with the respective tile:

    void getInput(void)
    { // Gets player's input
    c = getch();
    scr[x][y] = WALL;
    gotoxy(x, y); // remember to take care of the thing I first mentioned
    printf("%c", scr[x][y]);

    If you're going to update the screen as in Dungeon Crawl dig out how to use gettext() & puttext() functions.
    Last edited by kooma; 01-02-2002 at 05:58 AM.
    kooma - t.h@iki.fi

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    First of all, first column (up-left) is (1,1)
    So then I would have to change all coordinates and counters to 1, right?
    Also, I tried to reduce the flickering by using your first solution with the above changes and now I have the problem of it exiting after drawing the board. I've put the drawboard function above main() and removed clrscr().

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    Check out http://edu.jamsa.fi/~thusu/prog/source/movegame.cpp to get a find out the usage of `old' coordinates - then place this to the `getInput()' (and remember to

    Code:
    void getInput(void)
    {  // Gets player's input
        c = getch();
    
        /*  where player was  */
        gotoxy(x+1, y+1); // Silly me...
        printf("%c", scr[x][y]);
    
    //  Handle movement
    
      if(map[x][y] == WALL)
          { x  = oldx;  y = oldy; }
    //  Rest of the specal cases
    
        gotoxy(x, y);
        printf("@");
    }
    > now I have the problem of it exiting after drawing the board.

    But, but... changes to `fillArray()' shouldn't affect there. But you might as well clean it up a bit:

    Code:
    void drawboard(void)
    { // draws player field
      int i,j;
      printf("\n");
      for(i = 0;i < MAXX;i++)
      {
    	for(j = 0;j<MAXY;j++)
    	{
         switch(scr[i][j])
         {
            case WALL: textcolor(0);  break;
            ...
         }
    	 cprintf("%c",scr[i][j]);
    	}
    	printf("\n");
      }
    }
    Note the removal of
    scr[x][y] = PLAYER;
    scr[computerx][computery] = computer;
    since the player is now kind of like a layer of its own _on_ the map (I'll leave the implementation of `computer' to a similar system to you).
    kooma - t.h@iki.fi

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I think that all your recommendations are applied properly now. The only real problem left is the one that I mentioned in my previous reply about it exiting after drawing/displaying the playing field.

    Here's my main():

    Code:
    int main()
    { srand((unsigned)time(NULL));
      textbackground(1);
      clrscr();
      fillArray();
      drawboard();
      while(game)
      {
    	computerAI();
    	while(kbhit())
    	{getInput();}
    	if(left == 0 || player.health == 0|| computer.health == 0)
    	{game = 0;}
      }
    
     return 0;
    }
    Another problem that I could use help on is to limit the number of objects. Right now it's near impossible to play without being modified first.

    wsad and ESC to quit

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Here's code updated.
    Attached Files Attached Files

  7. #7
    Unregistered
    Guest
    This one looks better... (You fix the rest - I've been online far too long...)
    Attached Files Attached Files

  8. #8
    Unregistered
    Guest
    why do I get these errors when compiling game.c with Bloodshed Dev-c++?

    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x2c):game.c: undefined reference to `textbackground'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x34):game.c: undefined reference to `clrscr'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x246):game.c: undefined reference to `textcolor'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x256):game.c: undefined reference to `textcolor'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x266):game.c: undefined reference to `textcolor'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x276):game.c: undefined reference to `textcolor'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x286):game.c: undefined reference to `textcolor'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x29c):game.c: undefined reference to `gotoxy'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x2ce):game.c: undefined reference to `cprintf'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x312):game.c: undefined reference to `gotoxy'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x34a):game.c: undefined reference to `cprintf'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x42b):game.c: undefined reference to `gotoxy'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x43b):game.c: undefined reference to `cprintf'
    C:\DOCUME~1\Alain\LOCALS~1\Temp\cc69aaaa.o(.text+0 x4c2):game.c: undefined reference to `gotoxy'

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21