home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-04 | 4.0 KB | 128 lines | [TEXT/PJMM] |
- unit SpriteHandlers;
-
- interface
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Fonts, Events, Packages, Menus, Dialogs, Windows,{}
- OSUtils, ToolUtils, OSEvents,
- {$ENDC}
- QDOffScreen, SpriteStructure, SpriteTools;
-
- procedure MoveSprite (theSprite: SpritePtr);
- procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
- procedure InitSprites;
-
- implementation
-
-
- (*** Custom handlers - application dependent ***)
-
- {Edit this as necessary. It should always include the following three routines:}
-
- {MoveSprite: move the sprite}
-
- {HitSprite: handle collisions between two sprites}
-
- {InitSprites: Load all faces and create initial sprites}
-
- var
- firstFace, secondFace, thirdFace: GrafPtr;
- gPlayerPosition: Point;
-
- procedure MoveSprite (theSprite: SpritePtr);
- var
- vector: Point;
- begin
- case theSprite^.kind of
- playerSprite:
- begin
- GetMouse(theSprite^.position);
- gPlayerPosition := theSprite^.position;
- end;
- hunterSprite:
- begin
- theSprite^.fixedPointPosition.h := theSprite^.fixedPointPosition.h + theSprite^.speed.h;
- theSprite^.fixedPointPosition.v := theSprite^.fixedPointPosition.v + theSprite^.speed.v;
- theSprite^.position.h := BSR(theSprite^.fixedPointPosition.h, 4);
- theSprite^.position.v := BSR(theSprite^.fixedPointPosition.v, 4);
-
- vector.h := gPlayerPosition.h - theSprite^.position.h;
- vector.v := gPlayerPosition.v - theSprite^.position.v;
-
- theSprite^.speed.h := vector.h div 8;
- theSprite^.speed.v := vector.v div 8;
- end;
- evaderSprite:
- begin
- theSprite^.fixedPointPosition.h := theSprite^.fixedPointPosition.h + theSprite^.speed.h;
- theSprite^.fixedPointPosition.v := theSprite^.fixedPointPosition.v + theSprite^.speed.v;
- theSprite^.position.h := BSR(theSprite^.fixedPointPosition.h, 4);
- theSprite^.position.v := BSR(theSprite^.fixedPointPosition.v, 4);
-
- vector.h := gPlayerPosition.h - theSprite^.position.h;
- vector.v := gPlayerPosition.v - theSprite^.position.v;
-
- theSprite^.speed.h := -vector.h div 8;
- theSprite^.speed.v := -vector.v div 8;
-
- (* Keep this sprite a bit inside the bounds so it doesn't just stand in a corner. *)
- if theSprite^.position.h < 50 then
- begin
- theSprite^.position.h := 50;
- theSprite^.fixedPointPosition.h := BSL(theSprite^.position.h, 4);
- end;
- if theSprite^.position.h > gOffScreen^.portRect.right - theSprite^.face^.portRect.right - 50 then
- begin
- theSprite^.position.h := gOffScreen^.portRect.right - theSprite^.face^.portRect.right - 50;
- theSprite^.fixedPointPosition.h := BSL(theSprite^.position.h, 4);
- end;
- if theSprite^.position.v < 50 then
- begin
- theSprite^.position.v := 50;
- theSprite^.fixedPointPosition.v := BSL(theSprite^.position.v, 4);
- end;
- if theSprite^.position.v > gOffScreen^.portRect.bottom - theSprite^.face^.portRect.bottom - 50 then
- begin
- theSprite^.position.v := gOffScreen^.portRect.bottom - theSprite^.face^.portRect.bottom - 50;
- theSprite^.fixedPointPosition.v := BSL(theSprite^.position.v, 4);
- end;
- end; {case evaderSprite}
- end; {case}
-
- if KeepOnScreen(theSprite) then
- ;
- end; (*MoveSprite*)
-
-
- procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
- begin
- end; (*HitSprite*)
-
- procedure InitSprites;
- var
- theSprite: SpritePtr;
- begin
- (*Load all pictures*)
- firstFace := LoadFaceFromCicn(128); (*cicn resource #128.*)
- secondFace := LoadFaceFromCicn(129); (*cicn resource #129.*)
- thirdFace := LoadFaceFromCicn(130); (*cicn resource #130.*)
-
- (*Create sprites*)
- theSprite := NewSprite;
- theSprite^.kind := hunterSprite;
- theSprite^.face := firstFace;
- SetPt(theSprite^.position, 100, 100);
-
- theSprite := NewSprite;
- theSprite^.kind := playerSprite;
- theSprite^.face := secondFace;
- SetPt(theSprite^.position, 50, 50);
-
- theSprite := NewSprite;
- theSprite^.kind := evaderSprite;
- theSprite^.face := thirdFace;
- SetPt(theSprite^.position, 150, 150);
- end; (*InitSprites*)
-
- end.