home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-04 | 2.2 KB | 85 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;
-
- procedure MoveSprite (theSprite: SpritePtr);
- begin
- theSprite^.position.h := theSprite^.position.h + theSprite^.speed.h;
- theSprite^.position.v := theSprite^.position.v + theSprite^.speed.v;
- if KeepOnScreen(theSprite) then
- ;
- end; (*MoveSprite*)
-
-
- procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
- var
- tempSpeed: Integer;
- begin
- if RectSeparate(theSprite, anotherSprite) >= 2 then { 2 or 3: horizontal, otherwise vertical}
- begin
- tempSpeed := theSprite^.speed.h;
- theSprite^.speed.h := anotherSprite^.speed.h;
- anotherSprite^.speed.h := tempSpeed;
- end
- else
- begin
- tempSpeed := theSprite^.speed.v;
- theSprite^.speed.v := anotherSprite^.speed.v;
- anotherSprite^.speed.v := tempSpeed;
- end;
- 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^.face := firstFace;
- SetPt(theSprite^.position, 100, 100);
- SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
-
- theSprite := NewSprite;
- theSprite^.face := secondFace;
- SetPt(theSprite^.position, 50, 50);
- SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
-
- theSprite := NewSprite;
- theSprite^.face := thirdFace;
- SetPt(theSprite^.position, 150, 150);
- SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
- end; (*InitSprites*)
-
- end.