Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Finishing touches on my tetris game.

  1. Jul 19, 2006 #1
    Hello everyone. I have got quite far with a game of tetris that I am making (I'm writting in C++, and on windows, using Dev-C++ IDE and windows API). I am just touching it up, and then it will be done. One of the problems which I am having, is that when the blocks hit the bottom of the window (or they hit the blocks that should have hit the bottom of the window), the blocks disappear, so after a while, you get areas where the blocks just disappear as they come down. I think that it is something to do with my collision function, but can't spot the error.
    I will explain the variables below.
    Code (Text):

        int newx=sPiece.x+nx;
        int newy=sPiece.y+ny;

        int i,j,x,y;

        for(i=0; i< 4; i++)
            for(j=0; j< 4; j++)
                if(sPiece.size[ i ][j] != TILENODRAW)
                    if((newx + i) < 0 || (newx + i) > (MAPWIDTH - 1) ||
                        (newy + j) < 0 || (newy + j) > (MAPHEIGHT - 1))
                        return 1;

        for(x=0; x< MAPWIDTH; x++)
            for(y=0; y< MAPHEIGHT; y++)
                if(x >= newx && x < newx + 4)
                    if(y >= newy && y < newy +4)
                        if(Map[x][y] != TILEBLACK)
                            if(sPiece.size[x - newx][y - newy] != TILENODRAW)
                                return 1;
        return 0;
    MAPHEIGHT and MAPWIDTH are pretty obvious, they are constant integers. sPiece is a structure containing (integers) x & y (these refer to the current position). nx, and ny are the distances in the x and y axis respectively that the blocks have moved. Things like TILEBLACK and TILENODRAW are defined in a header file, and refer to a bitmap that I am using. There are a few other improvements I would like to make, but I think I can sort those out on my own, if I can't - I'll be back!
  2. jcsd
  3. Jul 19, 2006 #2


    User Avatar
    Science Advisor
    Homework Helper

    It's clear that this is one of a number of functions, and the error may well be somewhere else.

    It's unclear what exactly this snippet of code is supposed to do. (And as a bonus, writing a clear explanation may well help you find the bug.)
  4. Jul 19, 2006 #3
    Ok, well, when the did game run, the blocks fell like they were suppose to, but when they hit the "floor", or they hit other blocks which were already on the "floor", they disappear from sight. Obviously, this is was a little bit of a problem. I did think that it might be to do with the collision test function when I originally posted, although, I have just found the problem, and rectified it, sorry about this - Now I look like a real fool.:blushing:

    Note to moderators - This thread is not really relavent, feel free to delete.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook