Source Code: MoveOrbit2D( )
MoveObject2D - move an object in an orbit around a point
Syntax
NewX#, NewY# = MoveObject2D# ( OrbitX#, OrbitY#, CenterX#, CenterY#, Speed#, Dist# )
- NewX# - new calculated x position
- NewY# - new calculated y position
- OrbitX# - current orbiting object's x position
- OrbitY# - current orbiting object's y position
- CenterX# - x position of the center of the orbit
- CenterY# - y position of the center of the orbit
- Speed# - speed of the movement
- Dist# - distance from the center point
Explanation
MoveOrbit2D() calculates a circular movement around a central point.
Examples
Make One Object Orbit Another
SetFPS 60
PlayerX# = GetScreenWidth() / 2
PlayerY# = GetScreenHeight() / 2
ObjectX# = 0
ObjectY# = 0
Do
ObjectX#, ObjectY# = MoveOrbit2D( ObjectX#, ObjectY#, PlayerX#, PlayerY#, 2, 50 )
Cls 0
Circle PlayerX#, PlayerY#, 10, True
Circle ObjectX#, ObjectY#, 5, False
Sync
Loop
PSub MoveOrbit2D( X#, Y#, CX#, CY#, Speed#, Dist# )
Angle# = GetAngle2D( CX#, CY#, x#, y#)
Angle# = WrapAngle( Angle#, Speed# )
NewX# = CosRadius( Angle#, Dist#) + CX#
NewY# = SinRadius( Angle#, Dist#) + CY#
EndPSub NewX#, NewY#
Source Code
These two PSubs work with types.
PSub MoveOrbitX2D( X#, Y#, CX#, CY#, Speed#, Dist# )
Angle# = GetAngle2D( CX#, CY#, x#, y#)
Angle# = WrapAngle( Angle#, Speed# )
NewX# = CosRadius( Angle#, Dist#) + CX#
EndPSub NewX#
PSub MoveOrbitY2D( X#, Y#, CX#, CY#, Speed#, Dist# )
Angle# = GetAngle2D( CX#, CY#, x#, y#)
Angle# = WrapAngle( Angle#, Speed# )
NewY# = SinRadius( Angle#, Dist#) + CY#
EndPSub NewY#
This version works with variables, but not with types.
PSub MoveOrbit2D( X#, Y#, CX#, CY#, Speed#, Dist# )
Angle# = GetAngle2D( CX#, CY#, x#, y#)
Angle# = WrapAngle( Angle#, Speed# )
NewX# = CosRadius( Angle#, Dist#) + CX#
NewY# = SinRadius( Angle#, Dist#) + CY#
EndPSub NewX#, NewY#
Related Pages
Source Code
| Categories: Source Code |