Thread: Rectangle is destroyed after the other is drawn

  1. #1
    Registered User topten2016's Avatar
    Join Date
    Feb 2016
    Posts
    17

    Rectangle is destroyed after the other is drawn

    Hello. I am trying to create a "Tetris" game.
    I am drawing a rectangle which is moving on the console. The rectangle is refreshed with "InvalidateRect" At the present moment I am testing it only with key RIGHT. So when I am pressing the key RIGHT it is moving to the right
    When the rectangle is reaching a certain point, then we have another rectangle falling. As soon as I start using the "LEFT" key it is refreshing the second rectangle, BUT it is erasing the previous rectangle. How can I deal with it- I mean, how can I refresh the second rectangle, but at the same time leave first rerectangle on the field without erasing?

    Great thanx in advance!





    Here I am showing a piece of code which is related to the game function




    Code:
    void Game()
    
    
    
    {
        int i;
        int xcoord;
        int xcoord2 = 0;
        
        clrscr();
        system("color 0a");
    
        for (; ;) {
    
            const int width = 100;
            xcoord = 50;
            HWND hwnd = GetConsoleWindow();
            HDC hdc = GetDC(hwnd);
            RECT rect;
            GetClientRect(hwnd, &rect);
       
                for ( i = 10; i<80; i++)
            {
                Rectangle(hdc, xcoord, i, xcoord + 40, i + width);
    
                int cd;
             
                if (_kbhit()) {
                    char keyp;
                    keyp = _getch();
    
                    switch (keyp)
                    {
                    case UP: printf("ok");
                        break;
                    case RIGHT:
                   
                        xcoord = xcoord + 20;
                     
                         InvalidateRect(hwnd, NULL, FALSE);
                            
                        break;
                    }
    
               _getch());
                  
                }
    
        
            }
        
                }
    
          
        }
        
    
    }

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    Keep a list of all rectangles currently on the screen and redraw all of them each time.
    Or don't call InvalidateRect at all and do your own erasing of the old position of a rectangle.

  3. #3
    Registered User topten2016's Avatar
    Join Date
    Feb 2016
    Posts
    17
    algorism , great thanx for your advise!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Owner Drawn (a few questions)
    By Oldman47 in forum Windows Programming
    Replies: 2
    Last Post: 04-17-2007, 08:21 PM
  2. Have I Destroyed Gravity?
    By bumfluff in forum Game Programming
    Replies: 25
    Last Post: 12-28-2006, 04:58 PM
  3. blackjack- keep card from being drawn again
    By JackR in forum C++ Programming
    Replies: 10
    Last Post: 09-12-2006, 02:06 AM
  4. How can Bit Torrent be destroyed?
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 07-31-2006, 01:53 PM
  5. How is the cursor drawn
    By Mox in forum Windows Programming
    Replies: 2
    Last Post: 12-10-2001, 05:13 AM