This is a little bit of code whipped up to use the mouse as a ball in a game of 2 player pong. Up/Down keys are to move the player 2 paddle up/down. W/S are to move the player 1 paddle up/down. Also, this is media-less. So. That's a good thing too I guess.
` Syncing Stuff... Of Course
sync on
sync rate 60
` Mouse Starting Position in Middle of Screen.
x=320
y=240
` Set the movement speed.
speedx=3
speedy=-3
` Get the small image for collision (will represent the mouse in collision code)
get image 1,0,0,2,2
` make the paddles
box 0,0,5,50
get image 2,0,0,5,50
` Make sprite for mouse, but this is ony a small 2x2 transparent image mind you
sprite 1,x,y,1
` Player Info
p1x=10
p2x=600
p1y=240
p2y=240
sprite 2,10,240,2
sprite 3,600,240,2
p1sc=0
p2sc=0
` Position Mouse in middle, we could also do position mouse x,y or
` just let it stay as it is automatically moved to center on start up
position mouse 320,240
do
` Print Scores
text 5,5,"Player 1 : "+str$(p1sc)+" Player 2: "+str$(p2sc)
` Move mouse to x,y co-ordinates
position mouse x,y
` Move the colls-mouse with the real mouse
sprite 1,x,y,1
` Move paddles to x,y
sprite 2,p1x,p1y,2
sprite 3,p2x,p2y,2
` Move mouse
x=x+speedx
y=y+speedy
` If mouse is out of bounds
if x < 0 then x=320:p2sc=p2sc+1:y=240
if x > 640 then x=320:p1sc=p1sc+1:y=240
` If mouse hits top of screen
if y < 0 then speedy=speedy*-1
if y > 480 then speedy=speedy*-1
` If mouse hits the paddles, reflect
if sprite hit(1,3) >0 then speedx=speedx*-1 : x=x-10
if sprite hit(1,2) >0 then speedx=speedx*-1 : x=x+10
` Movement of paddles player 2 (right)
if upkey()=1 and p2y > 10 then p2y=p2y-3
if downkey()=1 and p2y < 440 then p2y=p2y+3
` Movement of paddles player 1 (left)
if keystate(17)=1 and p1y > 10 then p1y=p1y-3
if keystate(31)=1 and p1y < 440 then p1y=p1y+3
sync
loop
And from Robot's Translation for DBC:
` Syncing Stuff... Of Course
sync on
sync rate 60
` Mouse Starting Position in Middle of Screen.
x=320
y=240
` Set the movement speed.
speedx=3
speedy=-3
` Get the small image for collision (will represent the mouse in collision code)
cls rgb(255,255,255)
get image 1,0,0,2,2
` make the paddles
box 0,0,5,50
get image 2,0,0,5,50
cls 0
` Make sprite for mouse, but this is ony a small 2x2 transparent image mind you
sprite 1,x,y,1
` Player Info
p1x=10
p2x=600
p1y=240
p2y=240
sprite 2,10,240,2
sprite 3,600,240,2
p1sc=0
p2sc=0
set text opaque
hide sprite 1
` Position Mouse in middle, we could also do position mouse x,y or
` just let it stay as it is automatically moved to center on start up
position mouse 320,240
do
` Print Scores
text 5,5,"Player 1 : "+str$(p1sc)+" Player 2: "+str$(p2sc)
` Move mouse to x,y co-ordinates
position mouse x,y
` Move the colls-mouse with the real mouse
sprite 1,x,y,1
` Move paddles to x,y
sprite 2,p1x,p1y,2
sprite 3,p2x,p2y,2
` Move mouse
x=x+speedx
y=y+speedy
` If mouse is out of bounds
if x < 0 then x=320:p2sc=p2sc+1:y=240
if x > 640 then x=320:p1sc=p1sc+1:y=240
` If mouse hits top of screen
if y < 0 then speedy=speedy*-1
if y > 480 then speedy=speedy*-1
` If mouse hits the paddles, reflect
if sprite hit(1,3) >0 then speedx=speedx*(0-1) : x=x-10
if sprite hit(1,2) >0 then speedx=speedx*(0-1) : x=x+10
` Movement of paddles player 2 (right)
if upkey()=1 and p2y > 10 then p2y=p2y-3
if downkey()=1 and p2y < 440 then p2y=p2y+3
` Movement of paddles player 1 (left)
if keystate(17)=1 and p1y > 10 then p1y=p1y-3
if keystate(31)=1 and p1y < 440 then p1y=p1y+3
sync
loop
Take heed, never take advantage of the things you need, never let your self be overcome by greed. Walk a strigh line, pick up your speed and try. Everyone deserves a piece of the pie By: Shaggy