/    Sign up×
Community /Pin to ProfileBookmark

Annoying bug in breakout game needs solving

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[/url]

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;
}
}[/code]

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.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@nemesis_256authorSep 22.2006 — anyone?
Copy linkTweet thisAlerts:
@nemesis_256authorSep 23.2006 — another bump...
×

Success!

Help @nemesis_256 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...