home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-04 | 3.1 KB | 132 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 }
-
-
- type
- ProgramPart = Record
- howLong:Integer;
- dh:Integer;
- dv:Integer;
- End;
-
- var
- program1: array[0..6] of ProgramPart;
-
-
- procedure InitProgram1;
- begin
- program1[0].howLong := 60;
- program1[0].dh := 0;
- program1[0].dv := 1;
-
- program1[1].howLong := 50;
- program1[1].dh := 1;
- program1[1].dv := 0;
-
- program1[2].howLong := 30;
- program1[2].dh := 0;
- program1[2].dv := -1;
-
- program1[3].howLong := 20;
- program1[3].dh := -1;
- program1[3].dv := 0;
-
- program1[4].howLong := 30;
- program1[4].dh := 0;
- program1[4].dv := -1;
-
- program1[5].howLong := 15;
- program1[5].dh := -2;
- program1[5].dv := 0;
-
- program1[6].howLong := -1;
- program1[6].dh := -1;
- program1[6].dv := -1;
- end; {InitProgram1}
-
- var firstFace, secondFace, thirdFace:GrafPtr;
-
-
- Procedure MoveSprite(theSprite:SpritePtr);
-
- begin
- theSprite^.position.h := theSprite^.position.h + program1[theSprite^.currentInstruction].dh;
- theSprite^.position.v := theSprite^.position.v + program1[theSprite^.currentInstruction].dv;
- theSprite^.timeOnCurrent := theSprite^.timeOnCurrent +1;;
- If (theSprite^.timeOnCurrent >= program1[theSprite^.currentInstruction].howLong) Then
-
- begin
- theSprite^.timeOnCurrent := 0;
- theSprite^.currentInstruction := theSprite^.currentInstruction + 1;
- If program1[theSprite^.currentInstruction].howLong < 0 Then
- theSprite^.currentInstruction := 0;
- End;
- if KeepOnScreen(theSprite) then;
- End; (*MoveSprite*)
-
- Procedure HitSprite(theSprite:SpritePtr; anotherSprite:SpritePtr);
- Begin End; (*HitSprite*)
-
-
- Procedure InitSprites;
-
- var theSprite:SpritePtr;
-
- (*Load all pictures*)
- begin
- 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^.timeOnCurrent := 0;
- theSprite^.currentInstruction := 0;
-
- theSprite := NewSprite;
- theSprite^.face := secondFace;
- SetPt(theSprite^.position, 50, 50);
- SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
- theSprite^.timeOnCurrent := 0;
- theSprite^.currentInstruction := 0;
-
- theSprite := NewSprite;
- theSprite^.face := thirdFace;
- SetPt(theSprite^.position, 150, 150);
- SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
- theSprite^.timeOnCurrent := 0;
- theSprite^.currentInstruction := 0;
-
- InitProgram1;
- End; (*InitSprites*)
-
- end.
-
-