hmm
Code:
--------
| | /
| | /
| | \
|______| \
/\
/ \
'Pointless Ascii chart
Code:
FOR i = 1 TO blockamount
IF x + 2 > blocks(i).x THEN
IF y + 2 > blocks(i).y THEN
IF blocks(i).x + 6 > x THEN
IF blocks(i).y + 6 > y THEN
slope = -slope
d = -d
x = oldx
y = oldy
END IF
END IF
END IF
END IF
NEXT i
this makes a ball it bounce off the top and bottom but in order for it to bounce of the sides and to come off at the angle i need 'slope = -slope' needs to be 'd = -d'
Code:
x = x - d
y = y - slope
this moves the ball
Here is some code you can play around with =P. Remember I made this when I was little(8-9yr old) =P
Code:
CLS
DEFINT A-Z
SCREEN 12
DIM Ball(430)
CIRCLE (17, 17), 4, 14
PAINT (17, 17), 14, 14
GET (11, 12)-(23, 24), Ball
CLS
LINE (10, 10)-(630, 470), 1, B
LINE (5, 5)-(635, 475), 1, B
PAINT (7, 7), 1, 1
XQ = INT(RND * 320)
YQ = INT(RND * 240)
IF XQ <= 15 THEN XQ = XQ + 15
IF YQ <= 15 THEN YQ = YQ + 15
X = XQ: Y = YQ
X1 = 2: Y1 = 1
DO
WAIT &H3DA, 8
X = X + X1
Y = Y + Y1
IF (X < 12 OR X > 615) THEN
X1 = -X1
PLAY "MBA16"
END IF
IF (Y < 15 OR Y > 455) THEN
Y1 = -Y1
PLAY "MBA16"
END IF
PUT (X, Y), Ball, PSET
LOOP UNTIL INKEY$ <> ""
The easiest way to get a proper angle when a ball bounces over a plane is just change the sign of the speed componet perpendicular to the plane.
That will only work with horizontal and vertical planes, but if you are coding a pong game or a breakout they are enough:
When you collide with a horizontal plane:
Code:
\ /
\/
----
You just do vy = -vy, vx remains unchanged.
When you collide with a vertical plane:
Code:
\ |
\|
/|
/ |
You just do vx = -vx, vy remains unchanged.
This will provide correct angles without having to hassle with them.
@nathan: I know that.
@TheBigBasicQ: yup, thats kind of what I have but in mine I need the ball to bounce off little 6 by 6 blocks. not giant walls.
Quote:@nathan: I know that.
Sorry for replying. I thought you needed explanation about bounces.
PUT (X, Y), Ball, PSET TheBigBasicQ- questions on your code. how does pset in
Code:
PUT (X, Y), Ball, PSET
get rid of the remains of the ball as it moves.
on the loop you use X = X + X1 and X1 = -X1. so when x = 615 start subtracting way with X1 = -X1. then when x = 15 X1 = -X1 so insted of being -2 x = 2 by chagning the sign. is that right?
Try to use the Dot product.
Assing each line a Normal then if the ball hits that particular line, get the dot product. ;*)