home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Tutorial ƒ / Assignment5 (hitTask).c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-09  |  1.5 KB  |  76 lines  |  [TEXT/PJMM]

  1. // Assignment 5 (hitTask)
  2.  
  3. #include "SAT.h"
  4.  
  5. short kSpeed = 5;
  6. SpritePtr ignore;
  7. short direction;
  8. Handle theSound;
  9.  
  10. pascal void SetupTarget (SpritePtr me);
  11.  
  12. pascal void HandleSprite (SpritePtr me)
  13. {
  14.     GetMouse(&me->position);
  15. }
  16.  
  17. pascal void SetupSprite (SpritePtr me)
  18. {
  19.     me->task = &HandleSprite;
  20.     me->face = SATGetFace(128);
  21.     SetRect(&me->hotRect, 0, 0, 32, 32);
  22. }
  23.  
  24. pascal void HandleTarget (SpritePtr me)
  25. {
  26.     me->position.h = me->position.h + direction;
  27.     if (me->position.h < 0)
  28.         direction = kSpeed;
  29.     if (me->position.h > 200)
  30.         direction = -kSpeed;
  31. }
  32.  
  33. pascal void HitTarget (SpritePtr me, SpritePtr him)
  34. {
  35.     if (him->task = &HandleSprite) // Check what we hit!
  36.     {
  37.         me->task = 0L;
  38.         ignore = SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), &SetupTarget);
  39.         
  40.         // We could also re-use the old sprite for a new one, if we like.
  41.         
  42.         SATSoundPlay(theSound, 1, true);
  43.     }
  44. }
  45.  
  46. pascal void SetupTarget (SpritePtr me)
  47. {
  48.     me->task = &HandleTarget;
  49.     me->hitTask = &HitTarget;
  50.     me->face = SATGetFace(129);
  51.     SetRect(&me->hotRect, 0, 0, 32, 32);
  52.     direction = kSpeed;
  53. }
  54.  
  55. main()
  56. {
  57.     short kTicksPerFrame = 2;
  58.     long t;
  59.     
  60.     SATInitToolbox();
  61.     SATConfigure(false, kVPositionSort, kForwardCollision, 32);
  62.     SATInit(128, 129, 478, 302);
  63.     ignore = SATNewSprite(0, 200, 200, &SetupSprite);
  64.     ignore = SATNewSprite(0, 0, SATRand(gSAT.offSizeV), &SetupTarget);
  65.     theSound = SATGetNamedSound("\pTestSound");
  66.     HideCursor();
  67.     do
  68.     {
  69.         t = TickCount();
  70.         SATRun(true);
  71.         while ((TickCount () - t) < kTicksPerFrame);
  72.     } while (! Button());
  73.     ShowCursor();
  74.     SATSoundShutup();
  75. }
  76.