Here's the setup for the objects
#constant V2_MAX_OBJECTS 100
#constant V2_ANGLE_RIGHT 0.0
#constant V2_ANGLE_UP 90.0
#constant V2_ANGLE_LEFT 180.0
#constant V2_ANGLE_DOWN 270.0
type V2CoordTypeF
x#
y#
a#
r#
endtype
type V2ControlTypeF
maxObjects
topObject
endtype
function Vect2_Init()
global Vect2Init = 1
global V2Control as V2ControlTypeF
V2Control.maxObjects = V2_MAX_OBJECTS
V2Control.topObject = 0
dim V2Object[ V2_MAX_OBJECTS ] as V2ObjectTypeF
thisCoord as V2CoordTypeF
thisCoord = Vect2_NewCoordF()
for thisObject = 0 to V2_MAX_OBJECTS
V2Object[thisObject].isLive = 0
V2Object[thisObject].isMoving = 0
V2Object[thisObject].pos = thisCoord
V2Object[thisObject].speed = thisCoord
V2Object[thisObject].force = thisCoord
V2Object[thisObject].debugSpriteS = 0
V2Object[thisObject].debugSpriteF = 0
next thisObject
endfunction
function Vect2_NewCoordF()
thisCoordF as V2CoordTypeF
thisCoordF.x# = 0.0
thisCoordF.y# = 0.0
thisCoordF.a# = 0.0
thisCoordF.r# = 0.0
endfunction thisCoordF
And here's the loop code;
function Vect2_Update( thisTime# )
// Updates Vector2 Objects based on time
thisZoom# = 1.0 / getViewZoom()
thisHeight# = thisZoom# * 2.0
for thisObject = 0 to V2Control.topObject
if V2Object[thisObject].isLive and V2Object[thisObject].isMoving
// Apply Force
thisIsMoving = 0
thisFX# = V2Object[thisObject].force.x#
if thisFX# = 0.0
thisSX# = V2Object[thisObject].speed.x#
else
thisIsMoving = 1
thisSX# = V2Object[thisObject].speed.x# + thisFX# * thisTime#
V2Object[thisObject].speed.x# = thisSX#
endif
thisFY# = V2Object[thisObject].force.y#
if thisFY# = 0.0
thisSY# = V2Object[thisObject].speed.y#
else
thisIsMoving = 1
thisSY# = V2Object[thisObject].speed.y# + thisFY# * thisTime#
V2Object[thisObject].speed.y# = thisSY#
endif
// Apply Speed
if thisSX# = 0.0
thisPX# = V2Object[thisObject].pos.x#
else
thisIsMoving = 1
thisPX# = V2Object[thisObject].pos.x# + thisSX# * thisTime#
V2Object[thisObject].pos.x# = thisPX#
endif
if thisSY# = 0.0
thisPY# = V2Object[thisObject].pos.y#
else
thisIsMoving = 1
thisPY# = V2Object[thisObject].pos.y# + thisSY# * thisTime#
V2Object[thisObject].pos.y# = thisPY#
endif
// Calculate actual speed
thisSR# = Vect2_GetRadius( thisSX# , thisSY# )
V2Object[thisObject].speed.r# = thisSR#
// Calculate actual heading
thisSA# = Vect2_TargetAngleR( thisSX# , thisSY# , thisSR# )
V2Object[thisObject].speed.a# = thisSA#
// Calculate polar coordinates
thisPR# = Vect2_GetRadius( thisPX# , thisPY# )
V2Object[thisObject].pos.r# = thisPR#
thisPA# = Vect2_TargetAngleR( thisPX# , thisPY# , thisPR# )
V2Object[thisObject].pos.a# = thisPA#
// Move Debug Sprites
thisSprite = V2Object[thisObject].debugSpriteS
if thisSprite > 0
thisWidth# = thisSR# * thisZoom#
setSpriteSize( thisSprite , thisWidth# , thisHeight# )
setSpriteOffset( thisSprite , 0.0 , thisHeight# * 0.5 )
setSpritePositionByOffset( thisSprite , thisPX# , thisPY# )
setSpriteAngle( thisSprite , thisSA# )
setSpriteColor( thisSprite , 0 , 255 , 0 , 255 )
endif
thisSprite = V2Object[thisObject].debugSpriteF
if thisSprite > 0
thisFR# = V2Object[thisObject].force.r#
thisFA# = V2Object[thisObject].force.a# + 180.0
thisWidth# = thisFR# * thisZoom#
setSpriteSize( thisSprite , thisWidth# , thisHeight# )
setSpriteOffset( thisSprite , 0.0 , thisHeight# * 0.5 )
setSpritePositionByOffset( thisSprite , thisPX# , thisPY# )
setSpriteAngle( thisSprite , thisFA# )
setSpriteColor( thisSprite , random( 0, 255 ) , random( 0, 255 ) , random( 0, 255 ) , 255 )
endif
V2Object[thisObject].isMoving = thisIsMoving
endif
next thisObject
endfunction
and here are some functions used by the loop
function Vect2_GetRadius( offsetX# , offsetY# )
if offsetX# = 0.0 and offsetY# = 0.0
offsetR# = 0.0
elseif offsetX# = 0.0
offsetR# = abs( offsetY# )
elseif offsetY# = 0.0
offsetR# = abs( offsetX# )
else
offsetR# = sqrt( offsetX# * offsetX# + offsetY# * offsetY# )
endif
endfunction offsetR#
function Vect2_TargetAngle( offsetX# , offsetY# )
offsetR# = Vect2_GetRadius( offsetX# , offsetY# )
thisAngle# = Vect2_TargetAngleR( offsetX# , offsetY# , offsetR# )
endfunction thisAngle#
function Vect2_TargetAngleR( offsetX# , offsetY# , offsetR# )
if offsetR# = 0.0
thisAngle# = 0.0
elseif offsetY# > 0.0
thisAngle# = acos( offsetX# / offsetR# )
elseif offsetY# < 0.0
thisAngle# = 360.0 - acos( offsetX# / offsetR# )
elseif offsetX# > 0.0
thisAngle# = 0.0
elseif offsetX# < 0.0
thisAngle# = 180.0
else
// should never happen
thisAngle# = 0.0
endif
endfunction thisAngle#
function Vect2_AddObject()
thisObject = Vect2_FindFreeObject()
if thisObject > 0
if thisObject > V2Control.topObject then V2Control.topObject = thisObject
V2Object[thisObject].isLive = 1
V2Object[thisObject].isMoving = 0
thisCoord as V2CoordTypeF
thisCoord = Vect2_NewCoordF()
V2Object[thisObject].pos = thisCoord
V2Object[thisObject].speed = thisCoord
V2Object[thisObject].force = thisCoord
endif
endfunction thisObject
function Vect2_FindFreeObject()
for thisObject = 1 to V2Control.topObject
if V2Object[thisObject].isLive = 0 then exit
next thisObject
if thisObject > V2_MAX_OBJECTS then thisObject = 0
endfunction thisObject
function Vect2_ZeroForce( thisObject )
if thisObject > 0 and thisObject <= V2Control.topObject
V2Object[thisObject].force.r# = 0
V2Object[thisObject].force.a# = 0
V2Object[thisObject].force.x# = 0
V2Object[thisObject].force.y# = 0
endif
endfunction
function Vect2_ZeroSpeed( thisObject )
if thisObject > 0 and thisObject <= V2Control.topObject
V2Object[thisObject].speed.r# = 0
V2Object[thisObject].speed.a# = 0
V2Object[thisObject].speed.x# = 0
V2Object[thisObject].speed.y# = 0
endif
endfunction
function Vect2_ZeroAll( thisObject )
if thisObject > 0 and thisObject <= V2Control.topObject
Vect2_ZeroSpeed( thisObject )
Vect2_ZeroForce( thisObject )
V2Object[thisObject].isMoving = 0
endif
endfunction
function Vect2_SetPolarForce( thisObject , thisForce# , thisAngle# )
if thisObject > 0 and thisObject <= V2Control.topObject
V2Object[thisObject].force.r# = thisForce#
V2Object[thisObject].force.a# = thisAngle#
if thisForce# = 0.0
V2Object[thisObject].force.x# = 0.0
V2Object[thisObject].force.y# = 0.0
else
V2Object[thisObject].isMoving = 1
V2Object[thisObject].force.x# = thisForce# * cos( thisAngle# )
V2Object[thisObject].force.y# = thisForce# * sin( thisAngle# )
endif
endif
endfunction
function Vect2_SetPolarSpeed( thisObject , thisSpeed# , thisAngle# )
if thisObject > 0 and thisObject <= V2Control.topObject
if thisSpeed# = 0.0
V2Object[thisObject].speed.x# = 0.0
V2Object[thisObject].speed.y# = 0.0
else
V2Object[thisObject].isMoving = 1
V2Object[thisObject].speed.x# = thisSpeed# * cos( thisAngle# )
V2Object[thisObject].speed.y# = thisSpeed# * sin( thisAngle# )
endif
endif
endfunction
function Vect2_SetPolarPos( thisObject , thisRadius# , thisAngle# )
if thisObject > 0 and thisObject <= V2Control.topObject
if thisRadius# = 0.0
V2Object[thisObject].pos.x# = 0.0
V2Object[thisObject].pos.y# = 0.0
else
V2Object[thisObject].pos.x# = thisRadius# * cos( thisAngle# )
V2Object[thisObject].pos.y# = thisRadius# * sin( thisAngle# )
endif
endif
endfunction
function Vect2_SetCartPos( thisObject , thisX# , thisY# )
if thisObject > 0 and thisObject <= V2Control.topObject
V2Object[thisObject].pos.x# = thisX#
V2Object[thisObject].pos.y# = thisY#
endif
endfunction
function Vect2_AngleForSprite( thisAngle# )
thisAngle# = WrapAngleFloat( thisAngle# + 90 )
endfunction thisAngle#
It's stripped out of a project, there should be enough to get something going - I hope you can make sense of it.