Sign in to follow this  
phil67rpg

breakout bricks

Recommended Posts

phil67rpg    443
here is my code

//initialize bricks by number
for (row=50;row<=150;row+=50)
{
for(col=0;col<=600;col+=200)
{
count++;
brick[row][col]=col+200;
if (count % 3 ==1)
{
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(255,0,0));
bool red_brick=true;
RECT rect;
rect.left = col;
rect.right = brick[row][col];
rect.top = row-height;
rect.bottom = row;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);
}

if (count % 3 ==2)
{
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,255,0));
bool green_brick=true;
RECT rect;
rect.left = col;
rect.right = brick[row][col];
rect.top = row-height;
rect.bottom = row;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);
}
if (count % 3 ==0)
{
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,255));
bool blue_brick=true;
RECT rect;
rect.left = col;
rect.right = brick[row][col];
rect.top = row-height;
rect.bottom = row;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);
}
}
}
if (ball_top<=150&&ball_left>=0&&ball_left+20<=200)
{
bool blue_brick=false;
int row=150;
int col=0;
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,0));
RECT rect;
rect.left = col;
rect.right = brick[row][col];
rect.top = row-height;
rect.bottom = row;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);
y_vel*=-1;
}

if (ball_top<=150&&ball_left>=200&&ball_left+20<=400)
{
bool red_brick=false;
int row=150;
int col=200;
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,0));
RECT rect;
rect.left = col;
rect.right = brick[row][col];
rect.top = row-height;
rect.bottom = row;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);
y_vel*=-1;
}

if (ball_top<=150&&ball_left>=400&&ball_left+20<=600)
{
bool green_brick=false;
int row=150;
int col=400;
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,0));
RECT rect;
rect.left = col;
rect.right = brick[row][col];
rect.top = row-height;
rect.bottom = row;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);
y_vel*=-1;
}

if (ball_top<=150&&ball_left>=600&&ball_left+20<=800)
{
bool blue_brick=false;
int row=150;
int col=600;
d3ddev->ColorFill(surface, NULL, D3DCOLOR_XRGB(0,0,0));
RECT rect;
rect.left = col;
rect.right = brick[row][col];
rect.top = row-height;
rect.bottom = row;
d3ddev->StretchRect(surface, NULL, backbuffer, &rect, D3DTEXF_NONE);
y_vel*=-1;
}


Share this post


Link to post
Share on other sites
karwosts    840
You need to do some critical thinking for yourself. I've seen like 5 of these threads you've started of the form:

"Hi I want this here is code: "

If you have a specific question you can ask it and get help, but you need to stop asking for someone else to implement your features for you every time something pops into your head.

Use a debugger, use breakpoints and step through lines. Find out why the brick blinks. See when it turns back on and what triggers that. That is how you learn, not by asking someone else to do it after you spend 5 seconds thinking about it and give up. We're here to help you help yourself, not to create a game for you.

Share this post


Link to post
Share on other sites
supamike    319
To follow on from the above post, here is a link to a tutorial for the visual studio debugger (the code they're debugging is C#, but it works the same for C++).

You will need to set a breakpoint at the code that runs when the ball hits a brick, and then Step Over the code to see what happens.

Share this post


Link to post
Share on other sites
CodeMunkie    805
You should heed the advice to use your debugger. I would also consider following:

1) What do you think these lines are accomplishing:
bool red_brick=true;
...
bool green_brick=true;
...
bool blue_brick=true;

2) Each brick should have a way to indicate that it is "alive" or "dead". How do you represent these states for each brick, and where are you switching a brick from being "alive" to being "dead" after the ball hits it?

Share this post


Link to post
Share on other sites
Chad Smith    1344
Not going to give you an exact answer, because I don't agree with giving exact answers on how to get code to work in these situations, and also because I honestly did not look at your code in detail.

Though think of it this way. When the ball hits the brick, what is going to happen? It will magically disappear, right? So when do you want a brick to be drawn? When it hasn't been hit yet. This seems perfect for a nice boolean variable. Maybe:


bool alive=true;


A brick is alive, what do you want it to do? Draw it's self. But you ONLY want the brick to be drawn if it is still alive. Hmmm, a loop or something to draw the bricks that still have alive set to true might work.

When it is hit, think about this: If it is drawing the bricks when alive is true, what do you need to do to make sure that brick does not get drawn again?

Hope this gives you some ideas.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this