here is my code:
SetDisplayAspect (-1)
// Global Variables
global jump = 0
global collide = 0
// ChangeClear Color To White
SetClearColor (255,255,255)
// Load Sounds
BallSound = loadSound ("ball.wav")
// Create Ground Sprite
GroundImg = LoadImage ("floor.png")
Ground = CreateSprite (GroundImg)
SetSpriteSize (Ground,100,-1)
SetSpritePosition (Ground,0,96.6)
SetSpritePhysicsOn (Ground,1)
// Create Ball Sprite
BallImg = LoadImage ("ball.png")
Ball = CreateSprite (BallImg)
SetSpriteSize (Ball,7,-1)
SetSpritePosition (Ball,5,86)
SetSpritePhysicsOn (Ball,2)
SetSpritePhysicsRestitution (Ball,0.7)
setSpriteShapeCircle (Ball,0,0,3.4)
// Create Basket Sprite
BasketImg = LoadImage ("basket.png")
Basket = CreateSprite (BasketImg)
SetSpriteSize (Basket,18,-1)
SetSpritePosition (Basket,82,25)
SetPhysicsDebugOn()
do
gosub Mouse:
sync ()
loop
Mouse:
// Get Mouse Position
PX# = GetPointerX()
PY# = GetPointerY()
if GetSpriteY (Ball) < 82 and jump = 0
jump = 1
endif
if jump = 1
if GetPhysicsCollision (Ball,Ground) = 1
collide = 1
PlaySound (BallSound,50)
endif
endif
if (GetSpritePhysicsVelocityY (Ball) = 0 or GetSpritePhysicsVelocityY (Ball) > 10) and jump = 1 and collide = 1
jump = 0
collide = 0
SetSpritePosition (Ball,5,86)
SetSpritePhysicsVelocity (Ball,0,0)
SetSpritePhysicsAngularVelocity (Ball,0)
StopSound (BallSound)
endif
if GetPointerPressed () = 1
if GetSpriteX(ball) < 30 and GetSpriteY(ball) > 80 and collide = 0
if GetSpriteHitTest (Ball, PX#,PY#) = 1
MouseJoint = CreateMouseJoint (Ball,PX#,PY#,1000)
endif
else
if jump = 1 and collide > 0
jump = 0
collide = 0
SetSpritePosition (Ball,5,86)
SetSpritePhysicsVelocity (Ball,0,0)
SetSpritePhysicsAngularVelocity (Ball,0)
else
if GetSpriteX(ball) > 20 and GetSpriteY(ball) > 80 and collide = 0
SetSpritePosition (Ball,5,86)
SetSpritePhysicsVelocity (Ball,0,0)
SetSpritePhysicsAngularVelocity (Ball,0)
endif
endif
endif
else
if MouseJoint > 0
if GetPointerState () = 1
if PX# < 30 and PY# > 80
setJointMouseTarget (MouseJoint,PX#,PY#)
else
rem delete the mouse joint
deleteJoint(mouseJoint)
mouseJoint=0
endif
else
rem delete the mouse joint
deleteJoint(mouseJoint)
mouseJoint=0
endif
endif
endif
return