Colision problem
Author |
Message |
TheCatsMeow
|
Posted: Thu Jan 13, 2011 2:10 pm Post subject: Colision problem |
|
|
What is it you are trying to achieve?
What i want to happen is make my ball bounce of of a paddle.
What is the problem you are having?
What's going wrong is.. my ball will sometimes go through the paddle and will shake, go down and then go back up and shoot off. sometimes it will deflect even if the paddle isn't there.
Describe what you have tried to solve this problem
i've look through my code, and tried changing it a litte.. (Mainly i just changed the checking part of the code)
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
loop
Draw.FillOval (ballx, bally, 7, 7, yellow) %This draws the first ball
delay (5)
Draw.FillOval (ballx, bally, 7, 7, black) %This draws the second ball behind it to make it look like a solid ball
ballx := ballx + changex * dirx %The directions for the ball.
bally := bally + changey * diry
if (ballx > maxx - 10) or (ballx <= 10) then %If the ball touchs this spot very left of very right, it deflects
dirx := dirx * - 1
end if
if (bally >= maxy - 311) or (bally <= 240) then %This sets the ceiling boundaries
diry := diry * - 1
end if
if (bally >= lpaddley ) and (bally <= lpady ) and (ballx <= left_paddle ) then %This is where the ball deflects off the left paddle
dirx := dirx * - 1
elsif (bally >= rpaddley ) and (bally <= rpady ) and (ballx >= right_paddle ) then %This makes the ball deflect off the right paddle
dirx := dirx * - 1
end if
end loop
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Thu Jan 13, 2011 2:17 pm Post subject: RE:Colision problem |
|
|
Pick one of the paddles (lets say left) and try to describe in words _all_ of the locations where a ball could be, for it to be deflected. That should point you towards some cases where problems could occur. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
|
|