home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-06 | 4.3 KB | 138 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
- randomPositionFace, randomSpeedFace, changeSometimesFace, randomImpulseFace:GrafPtr;
-
-
- Procedure MoveSprite(theSprite:SpritePtr);
- function Sgn(i:Integer):Integer;
- begin
- if i > 0 then Sgn := 1
- else
- if i < 0 then Sgn := -1
- else
- Sgn := 0;
- end; {Sgn}
- begin
- Case theSprite^.kind of
- randomPositionSprite:
- begin
- theSprite^.position.h := theSprite^.position.h + Rand(7) - 3;
- theSprite^.position.v := theSprite^.position.v + Rand(7) - 3;
- if KeepOnScreen(theSprite) then ;
- end;
- randomSpeedSprite:
- 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);
- If KeepOnScreenFixed(theSprite) Then
- begin
- theSprite^.speed.h := theSprite^.speed.h - Sgn(theSprite^.speed.h);
- theSprite^.speed.v := theSprite^.speed.v - Sgn(theSprite^.speed.v);
- End;
- theSprite^.speed.h := theSprite^.speed.h + Rand(15) - 7;
- theSprite^.speed.v := theSprite^.speed.v + Rand(15) - 7;
- end;
- changeSometimesSprite:
- 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);
- if KeepOnScreenFixed(theSprite) then ;
- If (Rand(500) < 10) Then
- begin
- theSprite^.speed.h := Rand(63) - 31;
- theSprite^.speed.v := Rand(63) - 31;
- End;
- end;
- randomImpulseSprite:
- 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);
- if KeepOnScreenFixed(theSprite) then ;
- theSprite^.speed.h := theSprite^.speed.h * 19 div 20;
- theSprite^.speed.v := theSprite^.speed.v * 19 div 20;
- If (theSprite^.speed.h = 0) AND (theSprite^.speed.v = 0) Then
- begin
- theSprite^.speed.h := Rand(511) - 255;
- theSprite^.speed.v := Rand(511) - 255;
- End;
- end;
- End;
-
- End; (*MoveSprite*)
-
-
- Procedure HitSprite(theSprite:SpritePtr; anotherSprite:SpritePtr);
- Begin End; (*HitSprite*)
-
-
-
- Procedure InitSprites;
- var theSprite:SpritePtr;
- (*Load all pictures*)
- begin
- randomPositionFace := LoadFaceFromCicn(128); (*cicn resource #128.*)
- randomSpeedFace := LoadFaceFromCicn(129); (*cicn resource #129.*)
- changeSometimesFace := LoadFaceFromCicn(130); (*cicn resource #130.*)
- randomImpulseFace := LoadFaceFromCicn(131); (*cicn resource #131.*)
-
- (*Create sprites*)
- theSprite := NewSprite;
- theSprite^.kind := randomPositionSprite;
- theSprite^.face := randomPositionFace;
- SetPt(theSprite^.position, 50, 50);
-
- theSprite := NewSprite;
- theSprite^.kind := randomSpeedSprite;
- theSprite^.face := randomSpeedFace;
- SetPt(theSprite^.fixedPointPosition, BSL(100,4), BSL(100,4));
- SetPt(theSprite^.speed, 0, 0);
-
- theSprite := NewSprite;
- theSprite^.kind := changeSometimesSprite;
- theSprite^.face := changeSometimesFace;
- SetPt(theSprite^.fixedPointPosition, BSL(150,4), BSL(150,4));
- SetPt(theSprite^.speed, 0, 0);
-
- theSprite := NewSprite;
- theSprite^.kind := randomImpulseSprite;
- theSprite^.face := randomImpulseFace;
- SetPt(theSprite^.fixedPointPosition, BSL(200,4), BSL(200,4));
- SetPt(theSprite^.speed, 0, 0);
- End; (*InitSprites*)
- end.
-
-