home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Pascal / Book Demos in Pascal / SpriteEngine / SE Gravity FixedPoint / SpriteHandlers.p < prev    next >
Encoding:
Text File  |  1995-04-04  |  2.1 KB  |  74 lines  |  [TEXT/MWPS]

  1. unit SpriteHandlers;
  2.  
  3. interface
  4.  
  5.     uses
  6. {$IFC UNDEFINED THINK_PASCAL}
  7.         Types, QuickDraw, Fonts, Events, Packages, Menus, Dialogs, Windows,{}
  8.         OSUtils, ToolUtils, OSEvents, 
  9. {$ENDC}
  10.         QDOffScreen, SpriteStructure, SpriteTools;
  11.  
  12.     procedure MoveSprite (theSprite: SpritePtr);
  13.     procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
  14.     procedure InitSprites;
  15.  
  16. implementation
  17.  
  18.  
  19. (*** Custom handlers - application dependent ***)
  20.  
  21. {Edit this as necessary. It should always include the following three routines:}
  22.  
  23. {MoveSprite: move the sprite}
  24.  
  25. {HitSprite: handle collisions between two sprites}
  26.  
  27. {InitSprites: Load all faces and create initial sprites}
  28.  
  29.     var
  30.         firstFace, secondFace, thirdFace: GrafPtr;
  31.  
  32.     procedure MoveSprite (theSprite: SpritePtr);
  33.     begin
  34.         theSprite^.speed.v := theSprite^.speed.v + 1;
  35.         theSprite^.fixedPointPosition.h := theSprite^.fixedPointPosition.h + theSprite^.speed.h;
  36.         theSprite^.fixedPointPosition.v := theSprite^.fixedPointPosition.v + theSprite^.speed.v;
  37.         theSprite^.position.h := BSR(theSprite^.fixedPointPosition.h, 4);
  38.         theSprite^.position.v := BSR(theSprite^.fixedPointPosition.v, 4);
  39.         if KeepOnScreenFixed(theSprite) then
  40.             ;
  41.     end; (*MoveSprite*)
  42.  
  43.  
  44.     procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
  45.     begin
  46.     end; (*HitSprite*)
  47.  
  48.     procedure InitSprites;
  49.         var
  50.             theSprite: SpritePtr;
  51.     begin
  52. (*Load all pictures*)
  53.         firstFace := LoadFaceFromCicn(128);            (*cicn resource #128.*)
  54.         secondFace := LoadFaceFromCicn(129);            (*cicn resource #129.*)
  55.         thirdFace := LoadFaceFromCicn(130);            (*cicn resource #130.*)
  56.  
  57. (*Create sprites*)
  58.         theSprite := NewSprite;
  59.         theSprite^.face := firstFace;
  60.         SetPt(theSprite^.fixedPointPosition, BSL(100, 4), BSL(100, 4));
  61.         SetPt(theSprite^.speed, 1, 16);
  62.  
  63.         theSprite := NewSprite;
  64.         theSprite^.face := secondFace;
  65.         SetPt(theSprite^.fixedPointPosition, BSL(50, 4), BSL(50, 4));
  66.         SetPt(theSprite^.speed, 16, 1);
  67.  
  68.         theSprite := NewSprite;
  69.         theSprite^.face := thirdFace;
  70.         SetPt(theSprite^.fixedPointPosition, BSL(150, 4), BSL(150, 4));
  71.         SetPt(theSprite^.speed, Rand(7) - 3, Rand(7) - 3);
  72.     end; (*InitSprites*)
  73.  
  74. end.