Ball Bouncing by ACE_12003rd Oct 2006 11:55
|
---|
Summary basic 3d ball collision Description This code is a simple program where balls bounce around in a 3d box, they bounce off walls, eachother and another box moving around. balls have a little trouble bouncing off the box, if you want to fix it thats fine, tell me... Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com set display mode 1440,900,32 dim xspeed(3) xspeed(1) = 1 xspeed(2) = -1 xspeed(3) = 1 dim yspeed(3) yspeed(1) = 1 yspeed(2) = -1 yspeed(3) = 1 x=0 y=0 keyauto = 0 make camera 1 position camera 1,0,0,-200 make object sphere 1,10 color object 1,rgb(255,0,0) make object sphere 2,10 color object 2,rgb(0,0,255) make object box 3,2,100,2 make object box 4,2,100,2 make object box 5,100,1,2 make object box 6,100,1,2 make object box 7,2,20,12 position object 1,38,0,0 position object 2,-23,39,0 position object 3,-50,0,0 position object 4,50,0,0 position object 5,0,50,0 position object 6,0,-50,0 position object 7,0,0,0 `=====main loop===== do `move balls & box move object left 1,xspeed(1) move object left 2,xspeed(2) move object up 1,yspeed(1) move object up 2,yspeed(2) move object left 7,xspeed(3) `control whether box is moved by keys or automatically `if spacekey() = 1 ` if keyauto = 0 ` keyauto = 1 ` endif ` if keyauto = 1 ` keyauto = 0 ` endif `endif `if keyauto = 1 ` move object left 7,xspeed(3) `else ` `move box with cursor keys ` if upkey() = 1 then y = y + 1 ` if downkey() = 1 then y = y - 1 ` if rightkey() = 1 then x = x + 1 ` if leftkey() = 1 then x = x - 1 ` position object 7,x,y,0 `endif `object collisions for ball 1 if object collision (1,3) xspeed(1) = xspeed(1) * -1 endif if object collision (1,4) xspeed(1) = xSpeed(1) * -1 endif if object collision (1,5) yspeed(1) = ySpeed(1) * -1 endif if object collision (1,6) yspeed(1) = ySpeed(1) * -1 endif if object collision (1,7) yspeed(1) = ySpeed(1) * -1 endif if object collision (1,7) xspeed(1) = xSpeed(1) * -1 endif `object collisions for ball 2 if object collision (2,3) xspeed(2) = xSpeed(2) * -1 endif if object collision (2,4) xspeed(2) = xSpeed(2) * -1 endif if object collision (2,5) yspeed(2) = ySpeed(2) * -1 endif if object collision (2,6) yspeed(2) = ySpeed(2) * -1 endif if object collision (2,7) yspeed(2) = ySpeed(2) * -1 endif if object collision (2,7) xspeed(2) = xSpeed(2) * -1 endif `object collisions for box if object collision (7,3) xspeed(3) = xSpeed(3) * -1 endif if object collision (7,4) xspeed(3) = xSpeed(3) * -1 endif `object collisions of balls 1 & 2 if object collision (1,2) xspeed(1) = xspeed(1) * -1 xspeed(2) = xSpeed(2) * -1 yspeed(1) = yspeed(1) * -1 yspeed(2) = ySpeed(2) * -1 endif wait 10 loop |