Help With Breakout Killin Bricks
Author |
Message |
Ryft
|
Posted: Sun Jun 05, 2005 10:11 pm Post subject: Help With Breakout Killin Bricks |
|
|
Well after playin around with my programming alil bit and creating bricks based on 2-D arrays. I've run into another problem. Whenever my ball hits a brick it destroys every block up and to the right of the brick which the ball hit. I think I know whats casusing it, but dont know how to fix it.
code: |
for xBrick : 0 .. 4
for yBrick : 0 .. 5
bricks (xBrick, yBrick) := 8
end for
end for
proc level1
for xBrick : 0 .. 4
for yBrick : 0 .. 5
drawfillbox (25 + xBrick * 75, 315 + yBrick * 20, 75 + xBrick * 75, 325 + yBrick * 20, bricks (xBrick, yBrick))
if whatdotcolor (xBall, yBall + 6) = 8 or
whatdotcolor (xBall, yBall - 6) = 8 then
bricks (xBrick, yBrick) := 2
yDirect := -yDirect
elsif whatdotcolor (xBall, yBall + 6) = 8 or
whatdotcolor (xBall, yBall - 6) = 8 then
bricks (xBrick, yBrick) := 2
xDirect := -xDirect
else
drawfillbox (25 + xBrick * 75, 315 + yBrick * 20, 75 + xBrick * 75, 325 + yBrick * 20, bricks (xBrick, yBrick))
end if
end for
end for
end level1
|
This draws the bricks and bases the colors (bricks (xBrick,yBrick)) as the color grey. Once the ball jits one of the bricks it is supposed to turn only that one green, but for sum reason it turns all the ones up and to the right green. Any help would be appreciated. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Mon Jun 06, 2005 7:58 am Post subject: (No subject) |
|
|
Here's your problem.
Turing: |
for yBrick : 0 .. 5
drawfillbox (25 + xBrick * 75, 315 + yBrick * 20, 75 + xBrick * 75, 325 + yBrick * 20, bricks (xBrick, yBrick ))
if whatdotcolor (xBall, yBall + 6) = 8 or
whatdotcolor (xBall, yBall - 6) = 8 then
bricks (xBrick, yBrick ) := 2
yDirect := -yDirect
elsif whatdotcolor (xBall, yBall + 6) = 8 or
whatdotcolor (xBall, yBall - 6) = 8 then
bricks (xBrick, yBrick ) := 2
xDirect := -xDirect
else
drawfillbox (25 + xBrick * 75, 315 + yBrick * 20, 75 + xBrick * 75, 325 + yBrick * 20, bricks (xBrick, yBrick ))
end if
end for
|
Now in this if statement.
code: | if whatdotcolor (xBall, yBall + 6) = 8 or
whatdotcolor (xBall, yBall - 6) = 8 then
bricks (xBrick, yBrick) := 2
yDirect := -yDirect
|
You tell the current brick color to be green, but you're still running through the for loop. What you should do is just add an 'exit' to the end of the if statement so that it exits that for loop.
(Just so you dont mess it up)
code: | if whatdotcolor (xBall, yBall + 6) = 8 or
whatdotcolor (xBall, yBall - 6) = 8 then
bricks (xBrick, yBrick) := 2
yDirect := -yDirect
exit
|
You should also exit the other for loop at this time as well. You can asign a variable to determine when to exit the first for loop, which would probabily be easiest.
Next time just send your whole code so we can help you with anything else you may not know about, and also so we can test if our methods are correct.
EDIT: You should have where you draw your boxes seperate from your collision detection. |
|
|
|
|
![](images/spacer.gif) |
|
|