home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / SATminimal ƒ / sMySprite.p < prev   
Encoding:
Text File  |  1993-09-21  |  1.3 KB  |  58 lines  |  [TEXT/PJMM]

  1. {The sprite unit for SATminimal}
  2.  
  3. unit sMySprite;
  4.  
  5. interface
  6.     uses
  7.         SAT;
  8.     var
  9.         theSound: Handle;
  10.         faces: array[0..5] of FacePtr;
  11.  
  12.     procedure InitMySprite;
  13.     procedure SetupMySprite (me: SpritePtr);
  14.     procedure HandleMySprite (me: SpritePtr);
  15.  
  16. implementation
  17.  
  18. {Initialization of variables used by the sprite unit}
  19.     procedure InitMySprite;
  20.         var
  21.             i: integer;
  22.     begin
  23. {Preload the sound}
  24.         theSound := SATGetSound(128);
  25. {Preload all icons used by the sprites - 6 of them}
  26.         for i := 0 to 5 do
  27.             faces[i] := GetFace(128 + i);
  28.     end;
  29.  
  30. {Initialize a new sprite}
  31.     procedure SetupMySprite (me: SpritePtr);
  32.     begin
  33.         me^.mode := 0; {Pick a valid face number}
  34.         me^.speed.h := 2; {Set the speed}
  35.     end;
  36.  
  37. {Define the behaviour of a sprite}
  38.     procedure HandleMySprite (me: SpritePtr);
  39.     begin
  40. {Select a face. We use me^.mode as face counter, rotating through them.}
  41.         me^.mode := (me^.mode + 1) mod 6;
  42.         me^.face := faces[me^.mode];
  43.  
  44. {Move}
  45.         me^.position.h := me^.position.h + me^.speed.h; {Add the speed - horizontal only}
  46.         if me^.position.h > offSizeH - 16 then {Turn back if at the right border}
  47.             begin
  48.                 me^.speed.h := -2;
  49.                 SATSoundPlay(theSound, 1, true);
  50.             end;
  51.         if me^.position.h < -16 then {Turn back if at the left border}
  52.             begin
  53.                 me^.speed.h := 2;
  54.                 SATSoundPlay(theSound, 1, true);
  55.             end;
  56.     end;
  57.  
  58. end.