Advertisement Jump to content
Sign in to follow this  
Niddles

My blocks aren't disappearing.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone! So after finishing my first game (Pong), I was challenged to make breakout. I have everything set up, but When I get in game the blocks do not disappear. The ball goes right through them, and bounces off the top, and comes back. Here is my struct for blocks.
typedef struct
{
    float x;
    float y;
    float x2;
    float y2;
    bool there;
} block;

Here is the code, in my collision detection to make the blocks disappear.
    if(Ball.y2 >= 0.65)
    {
        for(int y=0; y<5; y++)
        {
            for(int x=0; x<5; x++)
            {
                if(Ball.y2 >= Blocks[x][y].y && Ball.y2 <= Blocks[x][y].y2 && Ball.x2 >= Blocks[x][y].x && Ball.x <= Blocks[x][y].x2)
                {
                    Blocks[x][y].there = false;
                }
            }
        }
    }

I have this code to draw to the screen.
    for(int y=0; y<5; y++)
    {
        for(int x=0; x<20; ++x)
        {
            if(Blocks[x][y].there = true)
            {
                glBegin(GL_QUADS);
                    if(y == 0)
                        glColor3f(1.0f, 0.0f, 0.0f);
                    if(y == 1)
                        glColor3f(0.0f, 1.0f, 0.0f);
                    if(y == 2)
                        glColor3f(0.0f, 0.0f, 1.0f);
                    if(y == 3)
                       glColor3f(1.0f, 1.0f, 0.0f);
                    if(y == 4)
                       glColor3f(0.0f, 1.0f, 1.0f);
                    glVertex2f(Blocks[x][y].x, Blocks[x][y].y);
                    glVertex2f(Blocks[x][y].x, Blocks[x][y].y2);
                    glVertex2f(Blocks[x][y].x2, Blocks[x][y].y2);
                    glVertex2f(Blocks[x][y].x2, Blocks[x][y].y);
                glEnd();
            }
            else
            {
                glBegin(GL_QUADS);
                    glColor3f(0.0f, 0.0f, 0.0f);
                    glVertex2f(Blocks[x][y].x, Blocks[x][y].y);
                    glVertex2f(Blocks[x][y].x, Blocks[x][y].y2);
                    glVertex2f(Blocks[x][y].x2, Blocks[x][y].y2);
                    glVertex2f(Blocks[x][y].x2, Blocks[x][y].y);
                glEnd();
            }
        }
    }

Can someone tell me what I am doing wrong in this code, that is making my blocks not disappear?

Share this post


Link to post
Share on other sites
Advertisement
Quote:

if(Blocks[x][y].there = true)

This line can very well be the reason
Testing for equality is done with == in C++

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!