home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-15 | 5.7 KB | 225 lines | [TEXT/PJMM] |
- unit Game;
-
- interface
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices,
- {$ENDC}
- Globals, Util, Ships, Shots, Debris, Stars, SWSound;
-
- procedure InitGame;
- procedure GameCycle;
-
- implementation
-
-
- procedure MoveObjects;
- begin
- MoveShips;
- MoveShots;
- MoveDebris;
- end; (* MoveObjects() *)
-
- procedure DrawObjects;
- begin
- DrawStars;
- DrawShips;
- DrawShots;
- DrawDebris;
- end; (* DrawObjects() *)
-
- procedure NewMatch;
- { evar Handle gNewMatchSoundH:xtern;}
- { eBoolean gMatchIsEnding:xtern; }
- begin
- AStopSnd;
- AInitSnd;
- InitStars;
- InitShips;
- InitShots;
- InitDebris;
- if noErr <> ASndPlay(gNewMatchSoundH) then
- ;
- gMatchIsEnding := FALSE;
- end; (* NewMatch() *)
-
- var
- optionStillPressed: Boolean;
- barStillPressed: Integer;
- CWStillPressed: Integer;
- CCWStillPressed: Integer;
- thStillPressed: Integer;
-
- procedure CheckKeyboard;
- {Note: Those codes are the codes on the author's keyboard - not necessarily the same on}
- {all other keyboards! They should rather be configurable.}
- const
- COMMAND_KEY = $37;(* 'CLOVER' *)
- SHIFT_KEY = $38;(* 'SHIFT' *)
- OPTION_KEY = $3A;(* 'OPTION' *)
- CONTROL_KEY = $3B;(* 'CONTROL' *)
- ESCAPE_KEY = $35;(* 'ESC' *)
- QUIT_KEY = $0C;(* 'Q' *)
- NEW_KEY = $2D;(* 'N' *)
- SPEEDUP_KEY = $18;(* '+' *)
- SLOWDOWN_KEY = $1B;(* '-' *)
- PAUSE_KEY = $23;(* 'P' *)
- INFO_KEY = $22;(* 'I' *)
- SOUND_KEY = $01;(* 'S' *)
- SHOT_KEY = $3B;(* 'CONTROL' *)
- UP_ARROW = $7E;(* 'UP ARROW' *)
- DOWN_ARROW = $7D;(* 'DOWN ARROW' *)
- LEFT_ARROW = $7B;(* 'LEFT ARROW' *)
- RIGHT_ARROW = $7C;(* 'RIGHT ARROW' *)
- THRUST_KEY = $7E;(* 'UP ARROW' *)
- DOWN_KEY = $28;(* 'K *)
- CW_KEY = $7C;(* 'RIGHT ARROW' *)
- CCW_KEY = $7B;(* 'LEFT ARROW' *)
- SPACE_BAR = $31;(* ' ' *)
- F1_KEY = $7A;(* F1 *)
- F2_KEY = $78;(* F2 *)
- F3_KEY = $63;(* F3 *)
- F4_KEY = $76;(* F4 *)
- const
- SHOT_SPEED = 7;
- begin
- if (gShipRecs[0].isAlive and IsPressed(SHOT_KEY)) then
- begin
- if barStillPressed = 0 then
- begin
- barStillPressed := 3;
- case (gShipRecs[0].dir) of
- 0:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 7, gShipRecs[0].where.v - 2, 0, gShipRecs[0].vel.v - SHOT_SPEED);
- 1:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 17, gShipRecs[0].where.v - 2, gShipRecs[0].vel.h + SHOT_SPEED, gShipRecs[0].vel.v - SHOT_SPEED);
- 2:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 17, gShipRecs[0].where.v + 7, gShipRecs[0].vel.h + SHOT_SPEED, 0);
- 3:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 17, gShipRecs[0].where.v + 17, gShipRecs[0].vel.h + SHOT_SPEED, gShipRecs[0].vel.v + SHOT_SPEED);
- 4:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 7, gShipRecs[0].where.v + 17, 0, gShipRecs[0].vel.v + SHOT_SPEED);
- 5:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h - 2, gShipRecs[0].where.v + 17, gShipRecs[0].vel.h - SHOT_SPEED, gShipRecs[0].vel.v + SHOT_SPEED);
- 6:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h - 2, gShipRecs[0].where.v + 7, gShipRecs[0].vel.h - SHOT_SPEED, 0);
- 7:
- CreateShot(gShipRecs[0].color, gShipRecs[0].where.h - 2, gShipRecs[0].where.v - 2, gShipRecs[0].vel.h - SHOT_SPEED, gShipRecs[0].vel.v - SHOT_SPEED);
- end; (* case *)
- if noErr <> ASndPlay(gShotSoundH) then
- ;
- end; (* if *)
- end; (* if *)
-
- if barStillPressed <> 0 then
- barStillPressed := barStillPressed - 1;
-
- gShipRecs[0].isAccel := FALSE;
-
- if (gShipRecs[0].isAlive and IsPressed(THRUST_KEY)) then
- begin
- if (thStillPressed = 0) then
- begin
- thStillPressed := 5;
- gShipRecs[0].isAccel := TRUE;
- end; (* if *)
- end; (* if *)
-
- if (thStillPressed <> 0) then
- thStillPressed := thStillPressed - 1;
-
-
- if (gShipRecs[0].isAlive and IsPressed(CW_KEY)) then
- begin
- if (CWStillPressed = 0) then
- begin
- CWStillPressed := 5;
- gShipRecs[0].dir := gShipRecs[0].dir + 1;
- end; (* if *)
- end; (* if *)
-
- if (CWStillPressed <> 0) then
- CWStillPressed := CWStillPressed - 1;
-
- if (gShipRecs[0].isAlive and IsPressed(CCW_KEY)) then
- begin
- if CCWStillPressed = 0 then
- begin
- CCWStillPressed := 5;
- gShipRecs[0].dir := gShipRecs[0].dir - 1;
- end; (* if *)
- end; (* if *)
-
- if CCWStillPressed <> 0 then
- CCWStillPressed := CCWStillPressed - 1;
-
- if gShipRecs[0].dir < 0 then
- gShipRecs[0].dir := 7;
- if gShipRecs[0].dir > 7 then
- gShipRecs[0].dir := 0;
-
- if (IsPressed(COMMAND_KEY) and IsPressed(NEW_KEY)) then
- begin
- InitGame;
- FlushEvents(everyEvent, 0);
- end; (* if *)
-
- { if (IsPressed(COMMAND_KEY) && IsPressed(PAUSE_KEY)) {}
- { while (!Button());}
- { FlushEvents(everyEvent, 0);}
-
- { if (IsPressed(COMMAND_KEY) && IsPressed(SOUND_KEY)) {}
- { gSoundOn:= not gSoundOn;}
- { SetChecks();}
- { FlushEvents(everyEvent, 0);}
-
- end; (* CheckKeyboard() *)
-
- procedure InitGame;
- begin
- NewMatch;
- end; (* InitGame() *)
-
- procedure GameCycle;
- const
- kMinFrameTicks = 2; {max 30 fps}
- var
- savePort: GrafPtr;
- bigRect: Rect;
- startTicks: Longint;
- begin
- startTicks := TickCount;
-
- bigRect.top := 0;
- bigRect.bottom := 479;
- bigRect.left := 0;
- bigRect.right := 639;
- GetPort(savePort);
- SetPort(GrafPtr(gPictureWindow));
- CheckKeyboard;
- MoveObjects;
- if (not gPlaying) then
- exit(GameCycle);
- DrawObjects;
- SetPort(savePort);
-
- gMatchTicker := gMatchTicker - 1;
- if (gMatchIsEnding and (gMatchTicker = 0)) then
- begin
- if gOldDepth > 1 then
- begin
- RGBForeColor(myBlack);
- RGBBackColor(myBlack);
- end;
- EraseRect(bigRect);
- RGBForeColor(myBlack);
- RGBBackColor(myWhite);
- NewMatch;
- end; (* if *)
-
- while TickCount < startTicks + kMinFrameTicks do
- ;
-
- end; (* GameCycle() *)
-
- end.