home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-15 | 7.2 KB | 261 lines | [TEXT/PJMM] |
- unit ships;
-
- interface
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices,
- {$ENDC}
- Globals, Util, Debris, SWSound;
-
- procedure InitShips;
- procedure MoveShips;
- procedure DrawShips;
- function CheckForShipCollision (s: Integer; r: Rect): Boolean;
- procedure KillPlayer (i: Integer);
-
- implementation
-
- const
- MAX_SPEED = 3;
-
- procedure InitShips;
- var
- i, j: Integer;
- begin
- for i := 0 to MAX_PLAYERS - 1 do
- begin
- gShipRecs[i].where.v := RngRnd(25, 455);
- gShipRecs[i].where.h := RngRnd(25, 615);
- if i <> 0 then
- begin
- gShipRecs[i].vel.v := RngRnd(-MAX_SPEED, MAX_SPEED);
- gShipRecs[i].vel.h := RngRnd(-MAX_SPEED, MAX_SPEED);
- end (* if *)
- else
- begin
- gShipRecs[i].vel.v := 0;
- gShipRecs[i].vel.h := 0;
- end; (* else *)
- gShipRecs[i].dir := RngRnd(0, 7);
- gShipRecs[i].anim := RngRnd(0, 7);
- gShipRecs[i].isAlive := TRUE;
- gShipRecs[i].isAccel := FALSE;
- end; (* for *)
-
- gShipRecs[0].color := myBlue;
- gShipRecs[1].color := myRed;
- gShipRecs[2].color := myYellow;
- gShipRecs[3].color := myGreen;
-
- for i := 0 to 7 do
- for j := 0 to 7 do
- begin
- SetRect(gShipSrcRects[0, i, j], 4 + 20 * j, 12 + 20 * i, 19 + 20 * j, 27 + 20 * i);
- SetRect(gShipSrcRects[1, i, j], 164 + 20 * j, 12 + 20 * i, 179 + 20 * j, 27 + 20 * i);
- SetRect(gShipSrcRects[2, i, j], 4 + 20 * j, 172 + 20 * i, 19 + 20 * j, 187 + 20 * i);
- SetRect(gShipSrcRects[3, i, j], 164 + 20 * j, 172 + 20 * i, 179 + 20 * j, 187 + 20 * i);
- end; (* for *)
-
- end; (* InitShips() *)
-
- procedure MoveShips;
- var
- i: Integer;
- begin
- for i := 0 to MAX_PLAYERS - 1 do
- if (gShipRecs[i].isAlive) then
- begin
- if (gShipRecs[i].isAccel) then
- case (gShipRecs[i].dir) of
- 0:
- gShipRecs[i].vel.v := gShipRecs[i].vel.v - 1;
- 1:
- begin
- gShipRecs[i].vel.v := gShipRecs[i].vel.v - 1;
- gShipRecs[i].vel.h := gShipRecs[i].vel.h + 1;
- end;
- 2:
- gShipRecs[i].vel.h := gShipRecs[i].vel.h + 1;
- 3:
- begin
- gShipRecs[i].vel.v := gShipRecs[i].vel.v + 1;
- gShipRecs[i].vel.h := gShipRecs[i].vel.h + 1;
- end;
- 4:
- gShipRecs[i].vel.v := gShipRecs[i].vel.v + 1;
- 5:
- begin
- gShipRecs[i].vel.v := gShipRecs[i].vel.v + 1;
- gShipRecs[i].vel.h := gShipRecs[i].vel.h - 1;
- end;
- 6:
- gShipRecs[i].vel.h := gShipRecs[i].vel.h - 1;
- 7:
- begin
- gShipRecs[i].vel.v := gShipRecs[i].vel.v - 1;
- gShipRecs[i].vel.h := gShipRecs[i].vel.h - 1;
- end;
- end; (* switch *)
- if (gShipRecs[i].vel.h > MAX_SPEED) then
- gShipRecs[i].vel.h := MAX_SPEED;
- if (gShipRecs[i].vel.h < -MAX_SPEED) then
- gShipRecs[i].vel.h := -MAX_SPEED;
- if (gShipRecs[i].vel.v > MAX_SPEED) then
- gShipRecs[i].vel.v := MAX_SPEED;
- if (gShipRecs[i].vel.v < -MAX_SPEED) then
- gShipRecs[i].vel.v := -MAX_SPEED;
- gShipRecs[i].where.h := gShipRecs[i].where.h + gShipRecs[i].vel.h;
- gShipRecs[i].where.v := gShipRecs[i].where.v + gShipRecs[i].vel.v;
- if (gShipRecs[i].where.h > 624) then
- begin
- gShipRecs[i].vel.h := -gShipRecs[i].vel.h;
- gShipRecs[i].where.h := 624;
- end; (* if *)
- if (gShipRecs[i].where.h < 0) then
- begin
- gShipRecs[i].vel.h := -gShipRecs[i].vel.h;
- gShipRecs[i].where.h := 0;
- end; (* if *)
- if (gShipRecs[i].where.v > 464) then
- begin
- gShipRecs[i].vel.v := -gShipRecs[i].vel.v;
- gShipRecs[i].where.v := 464;
- end; (* if *)
- if (gShipRecs[i].where.v < 20) then
- begin
- gShipRecs[i].vel.v := -gShipRecs[i].vel.v;
- gShipRecs[i].where.v := 20;
- end; (* if *)
- if (gShipRecs[i].anim < 0) then
- gShipRecs[i].anim := 0;
- gShipRecs[i].anim := gShipRecs[i].anim + 1;
- if (gShipRecs[i].anim > 7) then
- gShipRecs[i].anim := 0;
- end; (* if *)
-
- end; (* MoveShips() *)
-
- procedure DrawShips;
- var
- dstRect: Rect;
- i, j: Integer;
- begin
- for i := 0 to MAX_PLAYERS - 1 do
- if (gShipRecs[i].isAlive) then
- begin
- dstRect.top := gOldShipRecs[i].where.v;
- dstRect.bottom := dstRect.top + 15;
- dstRect.left := gOldShipRecs[i].where.h;
- dstRect.right := dstRect.left + 15;
- if gOldDepth > 1 then
- begin
- RGBForeColor(myBlack);
- RGBBackColor(myBlack);
- end;
- EraseRect(dstRect);
- RGBForeColor(myBlack);
- RGBBackColor(myWhite);
- dstRect.top := gShipRecs[i].where.v;
- dstRect.bottom := dstRect.top + 15;
- dstRect.left := gShipRecs[i].where.h;
- dstRect.right := dstRect.left + 15;
- CopyBits(GrafPtr(gScrapPtr)^.portBits, GrafPtr(gOSPtr)^.portBits, gShipSrcRects[i, gShipRecs[i].dir, gShipRecs[i].anim], dstRect, srcCopy, nil);
- for j := 0 to MAX_PLAYERS - 1 do
- if (i <> j) and CheckForShipCollision(j, dstRect) then
- begin
- KillPlayer(i);
- KillPlayer(j);
- end; (* if *)
- gOldShipRecs[i] := gShipRecs[i];
- end; (* if *)
-
- end; (* DrawShips() *)
-
- function CheckForShipCollision (s: Integer; r: Rect): Boolean;
- var
- shipRect, tmpRect: Rect;
- begin
- CheckForShipCollision := false;
- if (gShipRecs[s].isAlive) then
- begin
- shipRect.top := gShipRecs[s].where.v;
- shipRect.bottom := shipRect.top + 15;
- shipRect.left := gShipRecs[s].where.h;
- shipRect.right := shipRect.left + 15;
- if (SectRect(r, shipRect, tmpRect)) then
- CheckForShipCollision := true;
- end; (* if *)
- end; (* CheckForShipCollision() *)
-
- procedure KillPlayer (i: Integer);
- var
- j: Integer;
- dstRect: Rect;
- begin
- gShipRecs[i].isAlive := FALSE;
-
- dstRect.top := gShipRecs[i].where.v;
- dstRect.bottom := dstRect.top + 15;
- dstRect.left := gShipRecs[i].where.h;
- dstRect.right := dstRect.left + 15;
- if gOldDepth > 1 then
- begin
- RGBForeColor(myBlack);
- RGBBackColor(myBlack);
- end;
- EraseRect(dstRect);
- RGBForeColor(myBlack);
- RGBBackColor(myWhite);
- dstRect.top := gOldShipRecs[i].where.v;
- dstRect.bottom := dstRect.top + 15;
- dstRect.left := gOldShipRecs[i].where.h;
- dstRect.right := dstRect.left + 15;
- if gOldDepth > 1 then
- begin
- RGBForeColor(myBlack);
- RGBBackColor(myBlack);
- end;
- EraseRect(dstRect);
- RGBForeColor(myBlack);
- RGBBackColor(myWhite);
-
- CreateDebris(5, 25, gShipRecs[i].where.h, gShipRecs[i].where.v, gShipRecs[i].vel.h, gShipRecs[i].vel.v);
- if noErr <> ASndPlay(gBoomSoundH) then
- ;
-
- if i = 0 then
- begin
- gMatchIsEnding := TRUE;
- gMatchTicker := 50;
- end (* if *)
- else
- begin
- gShipRecs[i].where.v := RngRnd(25, 455);
- gShipRecs[i].where.h := RngRnd(25, 615);
- if i <> 0 then
- begin
- gShipRecs[i].vel.v := RngRnd(-MAX_SPEED, MAX_SPEED);
- gShipRecs[i].vel.h := RngRnd(-MAX_SPEED, MAX_SPEED);
- end (* if *)
- else
- begin
- gShipRecs[i].vel.v := 0;
- gShipRecs[i].vel.h := 0;
- end; (* else *)
- gShipRecs[i].dir := RngRnd(0, 7);
- gShipRecs[i].anim := RngRnd(0, 7);
- gShipRecs[i].isAlive := TRUE;
- gShipRecs[i].isAccel := FALSE;
- end; (* else *)
-
- for j := 1 to MAX_PLAYERS - 1 do
- if gShipRecs[j].isAlive then
- exit(KillPlayer);
-
- gMatchIsEnding := TRUE;
- gMatchTicker := 50;
-
- end; (* KillPlayer() *)
-
- end.