Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

quick question

This topic is 2912 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

I am programming a "breakout" game using c++ and directx9. I am able to get the ball to bounce off the bricks but cant get the brick to turn off permanently. Basically if flashes off and on and when hit.I am probably overlooking a very minor detail in my code.

Share this post


Link to post
Share on other sites
Advertisement
yes you are prolly over looking something in your code. what it is no one knows because you display none of your code. this is what i think you are prolly doing.

you have all your bricks in a list or array. every frame you see if the ball hits a brick in this array. you prolly have a bool variable per brick that determines if it is displayed or not. and if you get a hit then you toggle the bool. what you are prolly NOT doing is on the collision detection....ignore the collision if the brick is not displayed. which is what you need to do.

Share this post


Link to post
Share on other sites
here is some of my code.

int col_index;
(int)col_index = 0.005 * ball_left;
int row_index;
(int)row_index = 0.02 * ball_top;

if(bricks[row_index][col_index]==1)
{
bricks[row_index][col_index]=0;
//draw black brick
RECT rect;
rect.left = col_index*200;
rect.right = col_index*200+200;
rect.top = row_index*50;
rect.bottom = row_index*50+50;
d3ddev->StretchRect(surface_six, NULL, backbuffer, &rect, D3DTEXF_NONE);
y_vel*=-1;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by phil67rpg
here is some of my code.
*** Source Snippet Removed ***
The code you provided by itself doesn't tell much. I bet in some other part of your code you essentially reinitialize the 'bricks' 2d array with what was in it originally. Again, hard to say without more detail.

Other issues you probably will encounter based on that code. You change the y_vel if the ball position meets the brick position. But if the ball hits the side of a block then the x_vel should update not the y_vel. Basically you need to know which side of the brick you hit to tell what direction the ball should bounce.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!