home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Add-ons / Sprite behavior / SATToolbox.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-01  |  3.8 KB  |  86 lines  |  [TEXT/KAHL]

  1. /* SAT Toolbox*/
  2. /*This unit holds a set of utility routines that may simplify your sprite programming,*/
  3. /*but that are in no way mandatory.*/
  4.  
  5. /*MoveSprite: Moves a sprite according to speed*/
  6. /*KeepOnScreen: Performs border checks for a sprite*/
  7. /*RectSeparate: Moves two sprites apart*/
  8. /*RegionHit: Checks if the regions of two sprites overlap*/
  9. /*SplitVector: A utility for splitting a vector in components parallel and*/
  10. /*perpendicular to another vector*/
  11. /**/
  12. /*Sinus, Cosinus, SquareRoot: Useful look-up table based operations.*/
  13.  
  14. #ifndef __SATToolbox__
  15.  
  16. #define __SATToolbox__
  17.  
  18. #include <SAT.h>
  19.     
  20. /* Sprite record for sprites with fixed-point movement */
  21.  
  22.          typedef struct {
  23. /* Variables that you should change as appropriate */
  24.                 short kind; /* Used for identification. >0: friend. <0 foe */
  25.                 Point position;
  26.                 Rect hotRect, hotRect2; /* Tells how large the sprite is; hotRect is centered around origo */
  27.                                     /*hotRect is set by you. hotRect2 is offset to the current position.*/
  28.                 FacePtr face;            /* Pointer to the Face (appearance) to be used. */
  29.                 ProcPtr task;            /* Callback-routine, called once per frame. If task=nil, the sprite is removed. */
  30.                 ProcPtr hitTask;        /* Callback in collisions. */
  31.                 ProcPtr destructTask;    /* Called when a sprite is disposed. (Usually nil.) */
  32.                 RgnHandle clip;            /*Clip region to be used when this sprite is drawn.*/
  33. /* SAT variables that you shouldn't change: */
  34.                 Point oldpos;                /*Used by RunSAT2*/
  35.                 SpritePtr next, prev;    /*You may change them in your own sorting routine, but be careful if you do.*/
  36.                 Rect r, oldr;                /*Rectangle telling where to draw. Avoid messing with it.*/
  37.                 FacePtr oldFace;            /*Used by RunSAT2*/
  38.                 Boolean dirty;            /*Used by RunSAT2*/
  39. /*Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default*/
  40. /*set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately*/
  41. /*after initializing (before any sprites are created)!*/
  42.                 short layer; /*For layer-sorting. When not used for that, use freely.*/
  43.                 Point speed; /* Can be used for speed, but not necessarily. */
  44.                 short mode; /* Usually used for different modes and/or to determine what image to show next. */
  45.                 Point fixedPointPosition; /*fixed point position*/
  46.                 long appLong; /*Longint for free use by the application.*/
  47.             } FixSprite, *FixSpritePtr;
  48.  
  49. /*Constants for separation/bounceoff between sprites*/
  50.  
  51. #define kPushBoth 0
  52. #define kPushMe 1
  53. #define kPushHim 2
  54.  
  55. /*Sprite utilities*/
  56. pascal void MoveSprite(SpritePtr theSprite);
  57. pascal Boolean KeepOnScreen(SpritePtr theSprite);
  58. pascal void MoveSpriteFixedPoint(FixSpritePtr theSprite);
  59. pascal Boolean KeepOnScreenFixed(FixSpritePtr theSprite);
  60. pascal Boolean KeepSpriteInRect(SpritePtr theSprite, Rect r);
  61. pascal short RectSeparate(SpritePtr theSprite, SpritePtr anotherSprite, short push);
  62. pascal void RectBounce(SpritePtr me, SpritePtr him, short push);
  63. pascal void RectBounceFixed(FixSpritePtr me, FixSpritePtr him, short push);
  64. pascal Boolean PtInSpriteRgn(Point p, SpritePtr theSprite);
  65. pascal Boolean RegionHit(SpritePtr theSprite, SpritePtr anotherSprite);
  66. pascal void SplitVector(Point v, Point d, Point * p, Point * n);
  67. pascal Boolean RegionBounce(FixSpritePtr s1, FixSpritePtr s2, short elasticity);
  68. pascal Boolean RegionBounce2(FixSpritePtr s1, FixSpritePtr s2, short elasticity);
  69.  
  70. /* Don't change these constants without changing it in SATToolbox.p*/
  71. /* (and recompiling the lib if you use one)!*/
  72.  
  73. #define    kFixedPointShift    4    /*Number of fixed-point positions*/
  74. #define    kFixedOne    16            /*The "one" in the fixed-point system being used!*/
  75.  
  76. pascal void InitTables();
  77. pascal long SquareRoot(long arg);
  78. pascal long Sinus(long arg);
  79. pascal long Cosinus(long arg);
  80. pascal long VectorLength(Point vector);
  81. pascal long FPVectorLength(Point vector);
  82. pascal long ApproxVectorLength(Point vector);
  83.  
  84.  
  85. #endif
  86.