Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

breakout ball

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

well here is some code where a ball hits a brick but the brick reappears after it is hit.
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,0));
//copy the surface to the backbuffer
Sleep(50);	
RECT recta;//blank
recta.left = x3+=20;//370
recta.right = x4+=20;//390
recta.top = y1-=20;//310
recta.bottom = y2-=20;//330
d3ddev->StretchRect(surface, NULL, backbuffer, &recta, D3DTEXF_NONE);

d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(255,255,255));
//copy the surface to the backbuffer
Sleep(50);
RECT rectb;//colored
rectb.left = x1+=20;//390
rectb.right = x2+=20;//410
rectb.top = y3-=20;//290
rectb.bottom = y4-=20;//310
d3ddev->StretchRect(surface, NULL, backbuffer, &rectb, D3DTEXF_NONE);

if(rectb.top <= 150) 
{
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,0));
rect12.left = 400;
rect12.right = 600;
rect12.top = 100;
rect12.bottom = 150;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect12, D3DTEXF_NONE);

d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,0));
//copy the surface to the backbuffer
Sleep(50);	
RECT recta;//blank
recta.left = x3+=20;//370
recta.right = x4+=20;//390
recta.top = y1+=20;//310
recta.bottom = y2+=20;//330
d3ddev->StretchRect(surface, NULL, backbuffer, &recta, D3DTEXF_NONE);

d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(255,255,255));
//copy the surface to the backbuffer
Sleep(50);
RECT rectb;//colored
rectb.left = x1+=20;//390
rectb.right = x2+=20;//410
rectb.top = y3+=20;//290
rectb.bottom = y4+=20;//310
d3ddev->StretchRect(surface, NULL, backbuffer, &rectb, D3DTEXF_NONE);

}

Share this post


Link to post
Share on other sites
Advertisement
umm...

if rectb.top means "the top of the ball", the problem is you are drawing the brick when the ball's top is < 150, otherwise it's not drawn.

So... the ball goes up and hits the brick and it stops drawing til the ball goes back down.

Try this instead...

change:
if(rectb.top <= 150)

to
if(bBrickBroken == false)

and then above that if statement put this:

if(rectb.top <= 150)
bBrickBroken = true;

Also, dont forget to define bBrickBroken as a bool and initialize it to false.

Also, off topic, but why the sleep(50)'s?

Share this post


Link to post
Share on other sites
Quote:
Original post by phil67rpg
I know need to know how to get the ball to bounce off the invisible brick.


If it hits the top or bottom, negate the y component of its velocity. If it hits the sides, negate the x component.

Share this post


Link to post
Share on other sites
To "negate" a number means to replace it with the negative of that value. In other words, to subtract it from zero, or multiply it by -1.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!