Qbasicnews.com

Full Version: Bouncing balls Bounce off each other, Help plz
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I was just wondering if anyone could help me figure out how to get 3 bouncing ball to bounce off each other. I first went threw tutorial #3 and typed up the bouncing balls program, i took apart the program and figured what the causes and effects of each parts are, except how to get the ball when it initially starts to go down and left or up and right or up and left, i can only get it to go down and right. But thats not wut im here about. I already have the 3 balls to get bouncing around the screen all i want to figure out now is how to get them to collide (instead of just going threw each other like they do now) and how to bounce off in the other direction.

heres the code so far, Pretty much the same as the one in the tut but with 3 balls instead of 1.
Oh, and i did do the XO collision game but i havent been able to figure out how to apply that to circles yet.

CLS
SCREEN 12
x = 100: y = 200
xadj = 1: yadj = 1
a = 150: b = 150
aadj = 1: badj = 1
c = 75: d = 40
cadj = 1: dadj = 1
DO
press$ = INKEY$
WAIT &H3DA, 8
LINE (x - 12, y - 12)-(x + 12, y + 12), 0, BF
CIRCLE (x, y), 7
PAINT (x, y), 4, 15
IF y <= 20 THEN yadj = 4
IF y >= 460 THEN yadj = -4
IF x >= 620 THEN xadj = -4
IF x <= 20 THEN xadj = 4
x = x + xadj
y = y + yadj
'end of circle 1
WAIT &H3DA, 8
LINE (a - 12, b - 12)-(a + 12, b + 12), 0, BF
CIRCLE (a, b), 7
PAINT (a, b), 4, 15
IF b <= 20 THEN badj = 4
IF b >= 460 THEN badj = -4
IF a >= 620 THEN aadj = -4
IF a <= 20 THEN aadj = 4
a = a + aadj
b = b + badj
'end of circle 2
WAIT &H3DA, 8
LINE (c - 11, d - 11)-(c + 11, d + 11), 0, BF
CIRCLE (c, d), 7
PAINT (c, d), 4, 15
IF d <= 20 THEN dadj = 3
IF d >= 460 THEN dadj = -3
IF c >= 620 THEN cadj = -3
IF c <= 20 THEN cadj = 3
c = c + cadj
d = d + dadj
LOOP UNTIL press$ = "q"
END

If anyone has any hints tips or answers heres a thanks in advance. Smile
i don't know the exact physics...it always depends on the speed of the balls and their angle... but it'll help alot if you learn about "arrays" before^^

plus: you will need online one wait statement.

cheers/mariuz
Alright, i'll look up on that stuff. thx