' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These methods tell you a sprite's width and height, in parent or global space, taking into account its current scale.
'
' The width and height of a sprite is the width of the sprite on it's own X axis, and the height of the sprite on it's own Y axis.
' Rotating the sprite therefore has no effect on these values.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Width#(GlobalSpace%=False)
End Method
Method Height#(GlobalSpace%=False)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' GetHidden returns true if the sprite is hidden.
'
' A sprite is hidden if it is hidden, or a parent of it is hidden.
' A sprite will only be visible if both it, and all parents of it, are visible.
'
' GlobalSpace = True : Method returns True if the sprite or any parent of the sprite is hidden. If it returns false, sprite is definitely visible.
' False : Method returns True if the sprite is hidden. If it returns False sprite MAY be visible.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Hidden%(GlobalSpace%=False)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Returns the speed of the current sprite, in local (parent) space.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Speed#()
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Returns the distance of OtherSprite from this sprite.
' Distance can be either local space or global space, but if local space is used, the sprites must be in the same space!
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Distance#(OtherSprite:Sprite, GlobalSpace%=False)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method translates the sprite relative to its current location.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Translate(OffsetX#, OffsetY#)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method adjusts the sprite's current angle.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Rotate(AngularOffset#)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These methods make the sprite visible and invisible. Sprites default to being visible.
'
' If you hide a sprite, all of it's children will be hidden as well, but they will all retain their hidden state, so that when you show the parent
' again, any of the children that were hidden when you hid the parent will remain hidden.
'
' This allows you to, for example, hide a menu and restore it to the state it was in when it was hidden!
'
' Tip:
' If you want a hidden parent, and a visible child, then make a sprite with no image for the parent by passing Null for the image parameter.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Show()
End Method
Method Hide()
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method draws the sprite.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Draw()
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method returns true if this sprite overlaps the specified sprite.
' This test is pixel perfect, and takes into account rotation and scale.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Overlaps%(Other:Sprite)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method returns true if this sprite overlaps the specified region of the screen.
' This test is pixel perfect, and takes into account rotation and scale.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method OverlapsRect%(RectX#, RectY#, RectWidth#, RectHeight#, RectRotation#=0)
End Method
Method OverlapsPoint%(X#, Y#)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function draws all the sprites.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function DrawAll()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method is called by the SortList function when the sprites need to be updated. You should not need to use it.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function CompareOrder%(ThisObject:Object, OtherObject:Object)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function transforms a point from the space of one sprite to another.
' Specifying 0 or Null for Source or Dest specifies GLOBAL (screen) space.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TFormPoint(X#, Y#, Source:Sprite, Dest:Sprite)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function transforms a vector from the space of one sprite to another.
' Specifying 0 or Null for Source or Dest specifies GLOBAL (screen) space.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TFormVector(Vx#, Vy#, Source:Sprite, Dest:Sprite)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function transforms a normal from the space of one sprite to another.
' Specifying 0 or Null for Source or Dest specifies GLOBAL (screen) space.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TFormNormal(Nx#, Ny#, Source:Sprite, Dest:Sprite)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These functions return the last result of a TForm operation.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TFormedX#()
End Function
Function TFormedY#()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' The animation functions have the following parameters in common:
'
' Time - Length of time it takes the animation to loop once, in milliseconds.
' Flags - See the "Mode Flags" constants section above for information on what animation mode flags are available and how to use them.
' TiggerDelay - The time in milliseconds before the action is actually triggered.
' StartAge - Allows you to prematurely age the animation so that it starts at a different point than normal. This will not affect the trigger delay!
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These functions move a sprite from one position to another, over time.
'
' You may run both X and Y position animations simulataneously and with different parameters. Keep in mind though that specifying a new PositionX() or
' PostionY() animation will only override the X or Y component of a previously applied Position() animation.
'
' You can use PositionX() and PositionY() seperately with different settings to do advanced effects like text moving in a sine wave across the screen.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimatePosition(X1#, Y1#, X2#, Y2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
Method AnimateX(X1#, X2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
Method AnimateY(Y1#, Y2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These functions animate a sprite's scale over time.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateScale(Scale1#, Scale2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
Method AnimateScaleX(ScaleX1#, ScaleX2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
Method AnimateScaleY(ScaleY1#, ScaleY2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function animates a sprite's rotation over time.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateRotation(Rotation1#, Rotation2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function changes a sprite's color, over time.
'
' A sprite's default color is 255,255,255.
' Any value other than this will make the sprite darker or give it a color tint.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateColor(R1#, G1#, B1#, R2#, G2#, B2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function changes a sprite's alpha, over time.
'
' Default alpha for a sprite is 1.
' Valid values range from 0 to 1.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateAlpha(StartAlpha#, EndAlpha#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function changes a sprite's fog, over time.
'
' Default fog for a sprite is 0.
' Valid values range from 0 to 1.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateFog(StartFog#, EndFog#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function changes a sprite's fog color, over time.
'
' A sprite's default fog color is 255,255,255.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateFogColor(R1#, G1#, B1#, R2#, G2#, B2#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function animates the sprite's image, over time.
'
' NewImage is a pointer to an image which should be applied to the sprite when the animation is triggered.
' Set NewImage to Null to avoid changing the image.
' Use NewImage with delayed triggers to avoid crashes caused by bad frame numbers, or use it to simply apply a new image for each animation.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateFrame(StartFrame#, EndFrame#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0, NewImage:TImage=Null)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method animates the sprite's order over time.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AnimateOrder(StartOrder#, EndOrder#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function adjusts the the animation speed multiplier for a specific animation or all animations linked to the specified sprite.
'
' What this function allows you to do is for example, double or halve the speed at which all or some of the animations of the specified sprite are
' playing back at, without losing track of the original animation speed.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method SetAnimationSpeed(Speed#, Transform%=ANIM_ALL)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function stops an animation that has been applied to a sprite.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method StopAnimating(Transform%=ANIM_ALL)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function tells you if a sprite is currently being animated by the system.
'
' You can check to see if a specific kind of transformation is complete, or check all of them at once.
' Only transforms which have one-shot animations will ever stop animating by themselves.
'
' Animations on a delay but which have not yet triggered are considered active for the purposes of this function.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Animating%(Transform%=ANIM_ALL)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function adds a force to a sprite. Force is defined in pixels per second per unit of mass.
'
' Ie, discounting friction, and applied for one second, a force of 10 will accelerate a mass of 2 to a speed of 5 pixels per second.
' Sprites default to a mass of 1, so unless you change that, forces will correspond 1:1 to speed.
'
' Keep in mind that if you apply a force each frame, and no friction is there to counteract it, the object will accelerate!
'
' Parameters:
' -----------
' Nx#, Ny# : Normal indicating direction of force.
' Force# : The amount of force to apply.
' Flags : You can use flags to affect the way the force is applied to the object.
'
'
'
' Tips:
' -----
' * If you want to specify a velocity vector rather than a speed and direction, just pass it via Nx#, Ny# and set Force# to 1.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method ApplyForce(Nx#, Ny#, Force#=1.0, Flags%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Thrust is a force in sprite space, meaning it changes direction as the sprite is rotated.
' The parameters are the same as those for ApplyForce, with (Nx#, Ny#) being in sprite space.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method ApplyThrust(Nx#, Ny#, Force#=1.0, Flags%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function creates a force in a direction towards or away from a sprite. Specifically, towards or away from Source.
' This force falls off with the square of the distance, starting at MinRadius.
'
' Source : The sprite which this sprite is should move towards or away from.
' MinRadius : Within this radius, the force will be at its maximum. At twice this distance, the force will be halved, and so on.
'
' Tips:
' * Use a negative force and apply it each frame to create the effect of a magnet.
' * Do the same, but ignore mass to create the effect of a planet with gravity.
' * Use a positive force with Impulse True, and apply it once to create the effect of an explosion.
' * If you do not want the force to fall off with distance, use a large MinRadius.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method ApplyField(Source:Sprite, MinRadius#, Force#=1.0, Flags%=0)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function returns a normal which points from sprite A to sprite B.
' Warning: The two sprites must be in the same space!
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method SpriteDirection(Sprite2:Sprite, Nx# Var, Ny# Var)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function returns the angle at which sprite2 is relative to sprite1.
' For the angle returned, 0 = straight up, and the angle increases clockwise.
'
' Warning: The two sprites must be in the same space!
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method SpriteAngle#(Sprite2:Sprite)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function returns the distance between two sprites.
'
' If GlobalSpace is true, the function returns the distance between the two sprites on the screen.
' If GlobalSpace is false, the function transforms the second sprite's position into the parent space of the first, and returns that distance.
'
' In other words, if sprite 1 is attached to a parent, and that parent is scaled down by 50%, then the distance calculated between the two sprites will
' be doubled, because sprite 2's position is transformed from global space into the parent space of sprite 1, and that space is compressed 2x.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method SpriteDistance#(Sprite2:Sprite, GlobalSpace%=False)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function sets the time step which the animation and physics system use.
' If using variable rate frame timing, then you will need to call this functions once each frame, before you apply any forces to the sprites.
'
' Calls to ApplyForce and ApplyThrust will use this timestep to determine the exact amount of force or thrust to apply.
'
' For example, let's say a frame takes 100 milliseconds to render. First we SetTimeStep(100) at the start of our frame. Then if we want to apply
' gravity to a sprite, we simply go SpriteName.ApplyForce(0, 1, 9.8), and the correct amount of gravity will be added each frame!
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function SetTimeStep(NewTimeStep%)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function updates the sprite positions via the animation system, and the physics system. Call it once per frame before drawing the sprites,
' and after setting the timestep.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Update()
End Function
End Type
Type Animate
Const DEFAULT_EXPONENT# = 2.0
Const DEFAULT_OSCILLATIONS# = 1.0
Global List:TList = CreateList()
Global Exponent# = DEFAULT_EXPONENT#
Global Oscillations# = DEFAULT_OSCILLATIONS#
Global _LastAnimTime%
Field _Link:TLink
Field _Sprite:Sprite
Field _Transform%
Field _StartValue#, _EndValue#
Field _NewImage:TImage
Field _Time%
Field _Flags%
Field _Age%
Field _TriggerDelay%
Field _StartAge%
Field _Paused%
Field _Speed#
Field _Exponent#
Field _Oscillations#
Field _LastX#
Field _LastY#
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function creates a new Animate instance. You should not need to call it.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Create(ThisSprite:Sprite, Transform%, StartValue#, EndValue#, Time%, Flags%=0, TriggerDelay%=0, StartAge%=0, NewImage:TImage=Null)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method frees an animation from the list of animations to be played. You should not call it.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Free()
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function stops all animations that have been applied to all sprites.
' It also frees any sprite's which the animations were told to free upon completion.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function StopAll()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These functions pause and unpause all preexisting animations.
' While paused, the animations will not progress or age, and the sprites attached to them will not be freed.
'
' New animations created after PauseAll() is called will NOT be paused. This allows you to pause everything onscreen, then bring up a menu by creating
' a new animation, and then resume everything once said menu is dismissed.
'
' Note to self:
' I should probably change this to use a stack. Or maybe allow one to pause all animnations of all sprites attached to a parent.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function PauseAll()
End Function
Function UnpauseAll()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' You should no longer call this function!
'
' This function updates all of the animated sprites.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function UpdateAll()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method updates an animation.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Update()
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function tells you if any sprites with the specified name are currently being animated by the system.
' If no name is specified, then the system checks to see if ANY sprites are being animated.
'
' Sprite names are case sensitive!
'
' You can check to see if a specific kind of transformation is complete, or check all of them at once.
' Only transforms which have one-shot animations will ever stop animating by themselves.
'
' Animations on a delay but which have not yet triggered are considered active for the purposes of this function.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Animating%(Name$="", Transform%=ANIM_ALL)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function allows you to do a linear interpolation between two values.
'
' If tween is 0, then the value returned will be x1.
' If tween is 1, then the value returned will be x1 plus 1 times the difference between x1 and x2. (Ie: x2)
' If tween is .5, then the value returned will be x1 plus 0.5 times the difference between x1 and x2.
' (Ie: The value halfway between x1 and x2)
'
' You may also specify values for tween outside the 0..1 range.
'
' For example, if you specify a value of 2 for tween, then the value returned will be x1 plus 2 times the difference
' between x1 and x2.
'
' It doesn't matter whether x1 or x2 is the larger number.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TweenLinear#(X1#, X2#, Tween#)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function allows you to do a cosine interpolation between two values.
' This cosine interpolation will cause the value to change slowly at first, pick up speed, and then decelerate.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TweenCosine#(X1#, X2#, Tween#, Oscillations#)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function allows you to do a half cosine interpolation between two values.
'
' Half = 0 : This interpolation will cause the value to change slowly at first, then pick up speed.
' Half = 1 : This interpolation will cause the value to change quickly at first, then decelerate.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TweenHalfCosine#(X1#, X2#, Tween#, Half%)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function allows you to do an exponential interpolation between two values.
'
' Pow# = A power of 1.0 will produce a linear tween.
' A power of 2.0 will cause the value to change slowly at first, then change quickly at the end.
' A power of 0.5 will do the opposite, causing the value to change quickly at first then slow down.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TweenExponential#(X1#, X2#, Tween#, Pow#=2.0)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function allows you to do the reverse of a linear interpolation between two values.
'
' Instead of specifying the tween value, you specify the value which you want the know the tween of.
'
' Essentially, this function will tell you where MidX# is between two other values. If the value is between
' the two values, then the result will be in the range of 0..1.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function InverseTween#(X1#, X2#, MidX#)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function returns true if the specified transform type is the same or a parent type of the animation's transform type.
' For example, if transform = ANIM_POSITION, then the function will return true if AnimTF = ANIM_POSITION, ANIM_POSITIONX, or ANIM_POSITIONY
' You should not need to use this function, it is for internal use.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function TransformTypeMatch%(Transform%, AnimTF%)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function frees all animations applied to a specific sprite and of a specific type which have already been triggered.
' You should never need to call this function, it is used internally by the system.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function FreeTriggered(ThisSprite:Sprite, Transform%)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function sets the exponent which will be used for the next animation created with the MODE_SPEEDUP_EXP amd MODE_SLOWDOWN_EXP flags.
' Valid value ranges are 1.0 -> Infinity, but you will probably want to use values between 2 and 16.
'
' A value of 1.0 will produce a linear tween.
' A value of 2.0 will produce a tween nearly indistinguishable from a normal cosine SPEEDUP/SLOWDOWN tween.
' A value of 3.0 will produce a nice looking acceleration that seems snappier than the cosine tween.
' A value of 4.0 will produce an interesting pause then a quick acceleration.
' A value of 8.0 is good for making alpha values hang around 1.0 longer than normal before fading out.
'
' You can use values like 3.5 if you wish as well. I find 3.5 looks nice for text that floats up, when combined with an alpha fade using 8.0.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function SetExponent(NewExp#)
End Function
End Type
Type RenderState
Global RenderStateList:TList = CreateList()
Field Alpha#
Field Blend%
Field ClsColor_R%, ClsColor_G%, ClsColor_B%
Field Color_R%, Color_G%, Color_B%
Field Handle_X#, Handle_Y#
Field ImageFont:TImageFont
Field LineWidth#
Field MaskColor_R%, MaskColor_G%, MaskColor_B%
Field Origin_X#, Origin_Y#
Field Rotation#
Field Scale_X#, Scale_Y#
Field Viewport_X%, Viewport_Y%, Viewport_Width%, Viewport_Height%
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These methods allow you to save and restore the current render settings
'
' Each time you call the push method, the current state is placed on the stack.
' Each time you call the pop method, the last state placed on the stack is restored and removed from the stack.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Push()
End Function
Function Pop()
End Function
End Type
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' If a sprite is placed on a path, then moving the sprite on its X axis moves the sprite along the path, and moving it along its Y axis moves
' it perpendicular to it.
'
' Paths are relative to the space in which a sprite is. So if a sprite is parented to another sprite, the path will be in parent space, which means you
' can scale or rotate the path, even as the child sprite is moving along it.
'
' A single path can be applied to multiple sprites.
'
' You must free a path when you are done with it by calling Path.Free()
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
Type Path
Field PointList:TList
Field PointArray:Object[]
Field Points%
Field Length#
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Create a new path and return a pointer to it.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Create:Path()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method frees all the points in a path, and all sprites on the path.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Free()
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Add a point to the path.
' If AddFirst is true, the point is inserted at the start of the path, becoming the new first point in the path.
'
' For speed, you can set Update% to false, and only the linked list will be updated. If you do this you MUST call UpdatePath() when you're done,
' or sprites will continue to move along the old path instead of the new one.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method AddPoint(X#, Y#, AddFirst%=False, Update%=True)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method adjusts the position of a point.
' It also recalculates the normals of the segments it affects, as well as the length of those segments, and of the path itself.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method PositionPoint(Point:PathPoint, X#, Y#, Update%=True)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method updates the point array so it contains the correct data for all the points in the path.
' You should use it when you set Update to false during calls to AddPoint or PositionPoint. That is the only tine it is neccessary for you to do so.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method UpdatePath()
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Convert a position from path space to cartesian space.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Transform(Px#, Py#, X# Var, Y# Var)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' These methods take an X position along the path, and returns the normal of the segment the point lies within.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Nx#(Px#)
End Method
Method Ny#(Px#)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method smooths a path by setting each point to the average position of the points on either side of it.
'
' You will probably not need to use this function for its intended purpouse (correcting paths created from images) unless your path has thousands of
' points in it, but you could use it to take a square path with segmented sides, and round the edges off if you were so inclined.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Smooth(Iterations%)
End Method
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function finds the point in the PointArray which is nearest to Value# without going over.
'
' The function works by doing a binary search on a sorted list.
'
' If you had a list of 256 points, and you stepped through them linearly, you'd have to look at, on average, 128 of them to find the one you were
' looking for. With a binary search, with discard half the path with each iteration. That means that in the WORST case, in a list of 256 points, you
' will have to examine just 8 of those points! This is interestingly, the number of bits needed to represent 256. Which means that you could find a
' point in a sorted list of 65536 points by examining just 16 points!
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method FindNearestPoint:PathPoint(Value#)
End Method
End Type
Type PathPoint
Field _Link:TLink
Field _X#
Field _Y#
Field _SegmentLength#
Field _SegmentDist#
Field _SegmentNx#
Field _SegmentNy#
Method Free()
End Method
End Type
Type Physics
Global _Vx#
Global _Vy#
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function is now called by Animate.UpdateAll(). You should call only Animate.UpdateAll() in your main loop.
'
' This function moves any sprites which have had forces applied to them.
'
' Before you call this function, make sure you read up on and have called SetTimeStep() at least once to inform the physics system of how much time
' this frame took to render.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function UpdateAll()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Call this function to check to see if any collisions have occured, and update the sprites that collided.
'
' Tip:
' You can manually create pairs of objects to collide with the collison pair functions, and when you run this function, those pairs, in addition to
' those defined by the collision sets, will have collisions done for them! This is useful for special cases like colliding sprites on a path where you
' know that a sprite at one end of a path cannot collide with any other sprites than those to either side of it.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function DoCollisions()
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function returns true if two sprites are colliding, using the specified collision shapes.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Colliding%(Sprite1:Sprite, Sprite2:Sprite, Shape1%, Shape2%)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' Call this function when two sprites have collided, and they will bounce off one another.
' The system will treat the sprites as colliding spheres.
'
' The two sprites MUST be in the same space!
'
' Sprite velocities are in the space of their parents, so you cannot directly exchange the velocity for one for the velocity of another. You could of
' course transform the velocities into the same space before doing the collision, and then transform them back to their respective spaces, but why?
'
' Generally, you will want to use this function on sprites in Global space, ie, those with no parent.
'
' Nx#, Ny# : Optional collision normal. If you want to collide sprites that behave like true rectangles, then you'll need to set this to the normal of
' the side of the sprite that was collided with, ie, Sprite2.
'
' Tips:
' If you set Sprite2 to Null, and set the collision normal to the normal of a wall, then you can collide your object with a wall of infinite mass.
' This can be used for the borders of the screen, or any immovable obstacle in your game.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Collide(Sprite1:Sprite, Sprite2:Sprite, Nx#=0, Ny#=0, MoveBack%=True)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function moves the sprites back to where they were at the start of the frame if they are overlapping.
' It should be called after Physics.Update() (which sets _LastX# and _LastY#), and after it is determined which sprites are colliding.
'
' You should not call this function as you are determining which sprites are overlapping, only after all overlaps are determined!
' Doing otherwise will lead to unstable physics!
'
' If one sprite is moving away from the other, then it is not moved back. Only a sprite which is moving towards the other will be moved back.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function MoveBack(Sprite1:Sprite, Sprite2:Sprite)
End Function
End Type
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This type is used to create collision ID's. Collision ID's allow you to specify what sort of object a sprite is for the purpouses of collision.
' They're like the numbers you would enter in Blitz3D, except you don't have to worry about duplicate numbers, and this forces you into good programming
' practice by creating named variables which you then use to reference them instead of cryptic numbers. It also allows me to optimize the search for
' sprites that need to be collided with.
'
' Example usage:
' Global CID_Bullet:CollisionID = CollisionID.Create()
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
Type CollisionID
Field SpriteList:TList
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function creates a new collision ID.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Create:CollisionID()
End Function
End Type
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' Collisions should not be used on objects which have positional animation applied.
' Collisions are intended for objects whose motions are controlled only via physics.
'
' Attempting to do otherwise may cause unpredictable results. Or it might do something really cool.
' I don't know, because I haven't tested it! Either way, it's not supported!
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
Type CollisionSet
'Field Enabled
Global _List:TList = CreateList()
Field CID1:CollisionID
Field CID2:CollisionID
Field CID1_Shape%
Field CID2_Shape%
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function makes all sprites with a specified collision ID collide with those of the target ID.
'
' Along with each ID, you also specify a shape, which defines the shape of the region used to dtermine
'
' Shape can be one of the following:
'
' SHAPE_MASK : Uses sprite's mask or alpha map. (Default)
' SHAPE_CIRCLE : Uses sprite's radius.
' SHAPE_RECT : Uses a rect which is the same size and rotation as the sprite. If sprite has no image, sprite's scale is size of rect.
'
' You may not collide masks with circles, but other combinations are okay.
'
' NOTE:
' At this time, only MASK collisions are supported.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Create(CID1:CollisionID, CID2:CollisionID, CID1_Shape%=SHAPE_MASK, CID2_Shape%=SHAPE_MASK)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function updates the list of objects which are colliding with one another.
'
' Collision Sets contain the sprites in each set, but this list contains one entry for every pair of sprites which are colliding, with no duplicates.
' This makes it easy to loop through them all in other functions.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function ListPairs()
End Function
End Type
Type CollisionPair
Global _List:TList = CreateList()
Field _Link:TLink
Field _Sprite1:Sprite
Field _Sprite2:Sprite
Field _Shape1%
Field _Shape2%
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This function creates a new collision pair.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Function Create:CollisionPair(Sprite1:Sprite, Sprite2:Sprite, Shape1%, Shape2%)
End Function
' -------------------------------------------------------------------------------------------------------------------------------------------------------
' This method removes a pair from the pair list.
' -------------------------------------------------------------------------------------------------------------------------------------------------------
Method Remove()
End Method
End Type
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function returns the number of frames in an image.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
Function ImageFrames%(Image:TImage)
End Function
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function enables solid color rendering.
'
' When rendering with solid colors, the color channels of the images you blit will be overridden with the solid color specified. The alpha channel will
' remain intact however.
'
' This allows you to render a solid color sprite, white for example, with alpha, over the original, to make it appear to glow.
' You can vary the strength of the effect by using SetAlpha() before you blit the second pass.
'
' This function will only work properly if you have called SetColor() with the desired color beforehand. If you change the color afterward the results will
' be unpredictable.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
Function EnableSolidColor()
End Function
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function disables solid color rendering.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------
Function DisableSolidColor()
End Function