Public Group

# 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.

## 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)
{
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
{
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 on other sites
Quote:
 if(Blocks[x][y].there = true)

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

##### Share on other sites
Wow--- I must be tired. Thanks =)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 38
• 16
• ### Forum Statistics

• Total Topics
634128
• Total Posts
3015693
×