Finishing touches on my tetris game.

  • Thread starter Thread starter finchie_88
  • Start date Start date
  • Tags Tags
    Game
Click For Summary
SUMMARY

The discussion centers on a Tetris game developed in C++ using the Dev-C++ IDE and Windows API. The main issue addressed was the disappearance of blocks upon collision with the bottom of the window or other blocks, attributed to a flaw in the collision detection function. The user identified and resolved the problem, which involved ensuring that blocks were rendered correctly when they reached their final positions. The conversation highlights the importance of debugging and understanding collision detection in game development.

PREREQUISITES
  • C++ programming language proficiency
  • Understanding of Windows API for graphical applications
  • Knowledge of game development concepts, particularly collision detection
  • Familiarity with data structures in C++, such as structs
NEXT STEPS
  • Explore advanced collision detection algorithms in game development
  • Learn about debugging techniques in C++ using Dev-C++ IDE
  • Investigate rendering techniques for 2D graphics in Windows API
  • Study the implementation of game loops and state management in C++
USEFUL FOR

Game developers, particularly those working with C++ and Windows API, as well as programmers interested in collision detection and debugging techniques in game design.

finchie_88
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:
    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!
 
Technology news on Phys.org
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.)
 
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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
3K
Replies
1
Views
2K
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K