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 / SATStrictGridToolbox.h < prev    next >
Encoding:
Text File  |  1997-03-01  |  2.8 KB  |  60 lines  |  [TEXT/KAHL]

  1. //• SATStrictGridToolbox;
  2.  
  3. // Routines for "strict" grid movement, like PacMan.
  4.  
  5. // You need to make a copy of SATGridStubs.p, edit it as appropriate and include in
  6. // the same project. Also, SATStrictGridToolbox.p needs to be included, as source-code,
  7. // not as a library.
  8.  
  9. #include <SAT.h>
  10. #include <SATToolbox.h>
  11. #include <SATGridToolbox.h>
  12.  
  13.  typedef struct {
  14. /* Variables that you should change as appropriate */
  15.                 short kind; /* Used for identification. >0: friend. <0 foe */
  16.                 Point position;
  17.                 Rect hotRect, hotRect2; /* Tells how large the sprite is; hotRect is centered around origo */
  18.                                     /*hotRect is set by you. hotRect2 is offset to the current position.*/
  19.                 FacePtr face;            /* Pointer to the Face (appearance) to be used. */
  20.                 ProcPtr task;            /* Callback-routine, called once per frame. If task=nil, the sprite is removed. */
  21.                 ProcPtr hitTask;        /* Callback in collisions. */
  22.                 ProcPtr destructTask;    /* Called when a sprite is disposed. (Usually nil.) */
  23.                 RgnHandle clip;            /*Clip region to be used when this sprite is drawn.*/
  24. /* SAT variables that you shouldn't change: */
  25.                 Point oldpos;                /*Used by RunSAT2*/
  26.                 SpritePtr next, prev;    /*You may change them in your own sorting routine, but be careful if you do.*/
  27.                 Rect r, oldr;                /*Rectangle telling where to draw. Avoid messing with it.*/
  28.                 FacePtr oldFace;            /*Used by RunSAT2*/
  29.                 Boolean dirty;            /*Used by RunSAT2*/
  30. /*Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default*/
  31. /*set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately*/
  32. /*after initializing (before any sprites are created)!*/
  33.                 short layer; /*For layer-sorting. When not used for that, use freely.*/
  34.                 Point gridPos; /* Position in grid coordinate. */
  35.                 short mode; /* Usually used for different modes and/or to determine what image to show next. */
  36.                 long whatever; /*free for any use*/
  37.                 SignedByte direction, partMove;
  38.                 short appInt; /*free for any use.*/
  39.             } GridSprite, *GridSpritePtr;
  40.  
  41. pascal void InitStrictGrid();
  42. pascal Boolean GridMoveSprite(GridSpritePtr theSprite, short howFar);
  43. pascal void GridTurnAroundSprite(GridSpritePtr theSprite);
  44. pascal void GridRectBounce(GridSpritePtr theSprite, GridSpritePtr anotherSprite, short push);
  45. pascal Boolean KeepInGrid(GridSpritePtr theSprite);
  46. pascal Boolean GridPtInGrid(Point p);
  47. pascal Boolean PossibleMove(GridSpritePtr sp, short direction);
  48. pascal Point GetGridStep(Point fromP, short direction, short distance);
  49.  
  50. #define kUp 0
  51. #define kLeft 1
  52. #define kDown 2
  53. #define kRight 3
  54. #define kSnapDist 2
  55. /*How far from a junction can a sprite freely change direction if pushed?*/
  56.  
  57. extern Point dirTable[4];    /*One step in each direction*/
  58. extern short sizeTable[4];    /*Size of grid spaces in each direction*/
  59.  
  60.