property mySprite
property dragging
property mass
property velocity
property location
on exitFrame
if dragging then
set the locH of mySprite = the mouseH
set the locV of mySprite = the mouseV
set velocity = [ #X:0, #Y:0 ]
set location = [ #X: the locH of mySprite, #Y: -the locV of mySprite ]
end if
end
on push me, netForce
--Update my velocity:
set velocity = velocity + netForce / mass
--Velocity governor:
if abs( the X of velocity ) > 10.0 then
if the X of velocity < 0 then
set the X of velocity = -10.0
else
set the X of velocity = 10.0
end if
end if
if abs( the Y of velocity ) > 10.0 then
if the Y of velocity < 0 then
set the Y of velocity = -10.0
else
set the Y of velocity = 10.0
end if
end if
--now move:
set location = location + velocity
set the locH of mySprite = integer( the X of location )
set the locV of mySprite = - integer( the Y of location )
end
on mouseDown
set dragging = TRUE
end
on mouseUp
set dragging = FALSE
end
on mouseUpOutside
set dragging = FALSE
end
on registerOrbitalBodies me, theList
set myData = [ #channel:the spriteNum of me, #object: me ]
if not getOne ( theList, myData ) then
add theList, myData
end if
end
on removeOrbitalBodies me, theList
set myData = [ #channel:the spriteNum of me, #object: me ]
repeat while getOne ( theList, myData )
deleteOne theList, myData
end repeat
end
on beginSprite me
set mySprite = sprite ( the spriteNum of me )
set dragging = FALSE
sendAllSprites( #orbitalBodyReadyToRegister, me )
if mass < 10.0 then
set mass = 50.0
end if
set velocity = [ #X:0, #Y:0 ]
set location = [ #X: the locH of mySprite, #Y: -the locV of mySprite ]
return me
end
on endSprite me
sendAllSprites( #orbitalBodyReadyToRemove, me )
end
on getBehaviorDescription
return "Planetary Motion behavior."
end