I completed this game about a month ago, and now I’ve gone back to it to try to fix a bug.
[url]http://homepage.mac.com/nemesis_256/breakout.html
Whenever the ball meets the paddle one of the sides right on the corner, the ball gets stuck on the wall and bounces back and forth (the direction changes every time it loops). At the moment I changed the starting position and direction so it goes to the bottom left corner (so move the paddle to the left right after starting). I tried to fix it by putting in this function
[code]function checkStupidBug()
{
bugPosition[bugCount] = ballLeft;
//document.getElementById(“debug”).innerHTML += bugCount + “. ” + bugPosition[bugCount] + “<br/>”;
if (ballLeft < 250)
{
if (bugPosition[1] == bugPosition[3])
{
ballLeft = 5;
ballInfo.left = ballLeft + “px”;
}
}
else if (ballLeft > 250)
{
if (bugPosition[1] == bugPosition[3])
{
ballLeft = 475;
ballInfo.left = ballLeft + “px”;
}
}
bugCount++;
if (bugCount == 4)
{
bugCount = 1;
}
}
It sill does the crazy bouncing, but only a few times, and then goes back like it should. But this code isn’t a good solution, because sometimes the if statement becomes true when the ball bounces between two blocks, which results in it going to one of the sides. When it does this, it may even get stuck.
Also, if I change the position and direction so it starts by hitting the bottom right corner (ballLeft = 318?, it bounces back, but then once it gets to the opposite wall, it gets stuck on the left wall, but not right where it hits the paddle. It’s a bit higher than it.
So is there a better solution to this? Or should I just forget about it? There only seems to be a 4 pixel or so width where the ball gets stuck.