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 / SpriteHandlers.p < prev    next >
Encoding:
Text File  |  1995-04-04  |  1.8 KB  |  72 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^.position.h := theSprite^.position.h + theSprite^.speed.h;
  36.         theSprite^.position.v := theSprite^.position.v + theSprite^.speed.v;
  37.         if KeepOnScreen(theSprite) then
  38.             ;
  39.     end; (*MoveSprite*)
  40.  
  41.  
  42.     procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
  43.     begin
  44.     end; (*HitSprite*)
  45.  
  46.     procedure InitSprites;
  47.         var
  48.             theSprite: SpritePtr;
  49.     begin
  50. (*Load all pictures*)
  51.         firstFace := LoadFaceFromCicn(128);            (*cicn resource #128.*)
  52.         secondFace := LoadFaceFromCicn(129);            (*cicn resource #129.*)
  53.         thirdFace := LoadFaceFromCicn(130);            (*cicn resource #130.*)
  54.  
  55. (*Create sprites*)
  56.         theSprite := NewSprite;
  57.         theSprite^.face := firstFace;
  58.         SetPt(theSprite^.position, 100, 100);
  59.         SetPt(theSprite^.speed, Rand(7) - 3, Rand(7) - 3);
  60.  
  61.         theSprite := NewSprite;
  62.         theSprite^.face := secondFace;
  63.         SetPt(theSprite^.position, 50, 50);
  64.         SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
  65.  
  66.         theSprite := NewSprite;
  67.         theSprite^.face := thirdFace;
  68.         SetPt(theSprite^.position, 150, 150);
  69.         SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
  70.     end; (*InitSprites*)
  71.  
  72. end.