home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SpriteEngine / SE FixedPoint / SpriteHanders.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-10  |  1.6 KB  |  67 lines  |  [TEXT/MMCC]

  1. #include "SpriteTools.h"
  2.  
  3. // SpriteTools.h includes SpriteHandlers.h
  4.  
  5.  
  6. /*** Custom handlers - application dependent ***
  7.  
  8. Edit this as necessary. It should always include the following three routines:
  9.  
  10. MoveSprite: move the sprite
  11.  
  12. HitSprite: handle collisions between two sprites
  13.  
  14. InitSprites: Load all faces and create initial sprites
  15.  
  16. ***/
  17.  
  18.  
  19.  
  20. GrafPtr    firstFace, secondFace, thirdFace;
  21.  
  22.  
  23. void MoveSprite(SpritePtr theSprite)
  24. {
  25.     Point    where;
  26.     
  27.     theSprite->fixedPointPosition.h += theSprite->speed.h;
  28.     theSprite->fixedPointPosition.v += theSprite->speed.v;
  29.     theSprite->position.h = theSprite->fixedPointPosition.h >> 4;
  30.     theSprite->position.v = theSprite->fixedPointPosition.v >> 4;
  31.     KeepOnScreenFixed(theSprite);
  32.  
  33. } /*MoveSprite*/
  34.  
  35.  
  36. void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
  37. {
  38. // No collision handlling in this demo!
  39. } /*HitSprite*/
  40.  
  41.  
  42. void InitSprites()
  43. {
  44.     SpritePtr    theSprite;
  45.  
  46. /*Load all pictures*/
  47.     firstFace = LoadFaceFromCicn(128);            /*cicn resource #128.*/
  48.     secondFace = LoadFaceFromCicn(129);            /*cicn resource #129.*/
  49.     thirdFace = LoadFaceFromCicn(130);            /*cicn resource #130.*/
  50.  
  51. /*Create sprites*/
  52.     theSprite = NewSprite();
  53.     theSprite->face = firstFace;
  54.     SetPt(&theSprite->fixedPointPosition, 100 << 4, 100 << 4);
  55.     SetPt(&theSprite->speed, 1, 16);
  56.  
  57.     theSprite = NewSprite();
  58.     theSprite->face = secondFace;
  59.     SetPt(&theSprite->fixedPointPosition, 50 << 4, 50 << 4);
  60.     SetPt(&theSprite->speed, 16, 1);
  61.  
  62.     theSprite = NewSprite();
  63.     theSprite->face = thirdFace;
  64.     SetPt(&theSprite->fixedPointPosition, 150 << 4, 150 << 4);
  65.     SetPt(&theSprite->speed, Rand(7)-3, Rand(7)-3);
  66. } /*InitSprites*/
  67.