home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-04 | 3.3 KB | 106 lines | [TEXT/MWPS] |
- 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);
- begin
- Case theSprite^.kind of
- playerSprite: begin
- GetMouse(theSprite^.position);
- gPlayerPosition := theSprite^.position;
- end;
- hunterSprite: begin
- If theSprite^.position.h < gPlayerPosition.h Then
- theSprite^.position.h := theSprite^.position.h +1
- Else If theSprite^.position.h > gPlayerPosition.h Then
- theSprite^.position.h := theSprite^.position.h -1;
- If theSprite^.position.v < gPlayerPosition.v Then
- theSprite^.position.v := theSprite^.position.v +1
- Else If theSprite^.position.v > gPlayerPosition.v Then
- theSprite^.position.v := theSprite^.position.v -1;
- end;
- evaderSprite: begin
- If theSprite^.position.h < gPlayerPosition.h Then
- theSprite^.position.h := theSprite^.position.h -1
- Else If theSprite^.position.h > gPlayerPosition.h Then
- theSprite^.position.h := theSprite^.position.h +1;
- If theSprite^.position.v < gPlayerPosition.v Then
- theSprite^.position.v := theSprite^.position.v -1
- Else If theSprite^.position.v > gPlayerPosition.v Then
- theSprite^.position.v := theSprite^.position.v +1;
-
- (* Keep this sprite a bit inside the bounds so it doesn't just stand in a corner. *)
- If theSprite^.position.h < 50 Then
- theSprite^.position.h := 50;
- If theSprite^.position.h > gOffScreen^.portRect.right - theSprite^.face^.portRect.right - 50 Then
- theSprite^.position.h := gOffScreen^.portRect.right - theSprite^.face^.portRect.right - 50;
- If theSprite^.position.v < 50 Then
- theSprite^.position.v := 50;
- If theSprite^.position.v > gOffScreen^.portRect.bottom - theSprite^.face^.portRect.bottom - 50 Then
- theSprite^.position.v := gOffScreen^.portRect.bottom - theSprite^.face^.portRect.bottom - 50;
- end;
- 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.