home *** CD-ROM | disk | FTP | other *** search
-
- #include "swar.h"
-
- extern RGBColor myWhite, myBlack, myRed, myBlue, myYellow, myGreen, myOrange, myGray, myDkBlue;
-
- #define COMMAND_KEY 0x37 /* 'CLOVER' */
- #define SHIFT_KEY 0x38 /* 'SHIFT' */
- #define OPTION_KEY 0x3A /* 'OPTION' */
- #define CONTROL_KEY 0x3B /* 'CONTROL' */
- #define ESCAPE_KEY 0x35 /* 'ESC' */
- #define QUIT_KEY 0x0C /* 'Q' */
- #define NEW_KEY 0x2D /* 'N' */
- #define SPEEDUP_KEY 0x18 /* '+' */
- #define SLOWDOWN_KEY 0x1B /* '-' */
- #define PAUSE_KEY 0x23 /* 'P' */
- #define INFO_KEY 0x22 /* 'I' */
- #define SOUND_KEY 0x01 /* 'S' */
- #define SHOT_KEY 0x3B /* 'CONTROL' */
- #define UP_ARROW 0x7E /* 'UP ARROW' */
- #define DOWN_ARROW 0x7D /* 'DOWN ARROW' */
- #define LEFT_ARROW 0x7B /* 'LEFT ARROW' */
- #define RIGHT_ARROW 0x7C /* 'RIGHT ARROW' */
- #define THRUST_KEY 0x7E /* 'UP ARROW' */
- #define DOWN_KEY 0x28 /* 'K */
- #define CW_KEY 0x7C /* 'RIGHT ARROW' */
- #define CCW_KEY 0x7B /* 'LEFT ARROW' */
- #define SPACE_BAR 0x31 /* ' ' */
- #define F1_KEY 0x7A /* F1 */
- #define F2_KEY 0x78 /* F2 */
- #define F3_KEY 0x63 /* F3 */
- #define F4_KEY 0x76 /* F4 */
-
- int
- AbsVal(arg)
- int arg;
- {
- return(((arg < 0) ? 0 - arg: arg));
-
- } /* AbsVal() */
-
- pascal char
- isPressed(unsigned short keyID)
- {
- KeyMap keys;
- char *kp;
-
- GetKeys(keys);
- kp = (char *) keys;
- return(((kp[(keyID>>3)] >> (keyID & 7)) & 1));
-
- } /* isPressed() */
-
- int
- RngRnd(short min, short max)
- {
- unsigned rnd;
- long range, t;
-
- rnd = Random();
- range = max - min;
- t = (rnd * range) / 65536;
- return(t + min);
-
- } /* RngRnd() */
-
- CheckKeyboard()
- {
- extern Boolean gSoundOn;
- extern SHIPREC gShipRecs[MAX_PLAYERS];
- static Boolean optionStillPressed;
- static short barStillPressed;
- static short CWStillPressed;
- static short CCWStillPressed;
- static short thStillPressed;
- extern Handle gShotSoundH;
-
- #define SHOT_SPEED 7
-
- if (gShipRecs[0].isAlive && isPressed(SHOT_KEY)) {
- if (!barStillPressed) {
- barStillPressed = 3;
- switch (gShipRecs[0].dir) {
- case 0: CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 7,
- gShipRecs[0].where.v - 2,
- 0,
- gShipRecs[0].vel.v - SHOT_SPEED);
- break;
- case 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);
- break;
- case 2: CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 17,
- gShipRecs[0].where.v + 7,
- gShipRecs[0].vel.h + SHOT_SPEED,
- 0);
- break;
- case 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);
- break;
- case 4: CreateShot(gShipRecs[0].color, gShipRecs[0].where.h + 7,
- gShipRecs[0].where.v + 17,
- 0,
- gShipRecs[0].vel.v + SHOT_SPEED);
- break;
- case 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);
- break;
- case 6: CreateShot(gShipRecs[0].color, gShipRecs[0].where.h - 2,
- gShipRecs[0].where.v + 7,
- gShipRecs[0].vel.h - SHOT_SPEED,
- 0);
- break;
- case 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);
- break;
- } /* switch */
- ASndPlay(gShotSoundH);
- } /* if */
- } /* if */
-
- if (barStillPressed)
- barStillPressed--;
-
- gShipRecs[0].isAccel = FALSE;
-
- if (gShipRecs[0].isAlive && isPressed(THRUST_KEY)) {
- if (!thStillPressed) {
- thStillPressed = 5;
- gShipRecs[0].isAccel = TRUE;
- } /* if */
- } /* if */
-
- if (thStillPressed)
- thStillPressed--;
-
-
- if (gShipRecs[0].isAlive && isPressed(CW_KEY)) {
- if (!CWStillPressed) {
- CWStillPressed = 5;
- gShipRecs[0].dir++;
- } /* if */
- } /* if */
-
- if (CWStillPressed)
- CWStillPressed--;
-
- if (gShipRecs[0].isAlive && isPressed(CCW_KEY)) {
- if (!CCWStillPressed) {
- CCWStillPressed = 5;
- gShipRecs[0].dir--;
- } /* if */
- } /* if */
-
- if (CCWStillPressed)
- CCWStillPressed--;
-
- if (gShipRecs[0].dir < 0)
- gShipRecs[0].dir = 7;
- if (gShipRecs[0].dir > 7)
- gShipRecs[0].dir = 0;
-
- if (isPressed(COMMAND_KEY) && isPressed(NEW_KEY)) {
- InitGame();
- FlushEvents(everyEvent, 0);
- } /* if */
-
- // if (isPressed(COMMAND_KEY) && isPressed(PAUSE_KEY)) {
- // while (!Button());
- // FlushEvents(everyEvent, 0);
- // } /* if */
-
- // if (isPressed(COMMAND_KEY) && isPressed(SOUND_KEY)) {
- // if (gSoundOn)
- // gSoundOn = FALSE;
- // else
- // gSoundOn = TRUE;
- // SetChecks();
- // FlushEvents(everyEvent, 0);
- // } /* if */
-
- } /* CheckKeyboard() */
-
- SetChecks()
- {
- extern MenuHandle gFileMenu;
- extern Boolean gSoundOn, gPauseOn;
-
- if (gPauseOn)
- SetItemMark (gFileMenu, 2, '\022');
- else
- SetItemMark (gFileMenu, 2, noMark);
-
- if (gSoundOn)
- SetItemMark (gFileMenu, 3, '\022');
- else
- SetItemMark (gFileMenu, 3, noMark);
-
- } /* SetChecks() */
-
- LoadSound(soundH, soundID, soundName)
- Handle *soundH;
- short soundID;
- Str255 soundName;
- {
- if ((*soundH = GetResource('snd ', soundID)) == 0L) {
- ExitAppl();
- } /* if */
- MoveHHi(*soundH);
- HLock(*soundH);
- HNoPurge(*soundH);
-
- } /* LoadSound() */
-
- UnloadSound(soundH)
- Handle soundH;
- {
- HUnlock(soundH);
- HPurge(soundH);
- ReleaseResource(soundH);
-
- } /* UnloadSound() */
-
- ExitAppl()
- {
- extern CWindowPtr gPictureWindow;
- extern CGrafPort *gOSPtr, *gScrapPtr;
-
- if (gPictureWindow)
- DisposeWindow((WindowPtr)gPictureWindow);
- if (gOSPtr) {
- CloseCPort(gOSPtr);
- DisposePtr((Ptr)gOSPtr);
- } /* if */
- if (gScrapPtr) {
- CloseCPort(gScrapPtr);
- DisposePtr((Ptr)gScrapPtr);
- } /* if */
- ShowCursor();
- FlushEvents(everyEvent, 0);
- UnloadSounds();
- ExitToShell();
-
- } /* ExitAppl() */
-
- ErasePort(whichPort, whatRect)
- CGrafPort *whichPort;
- Rect whatRect;
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort((GrafPtr)whichPort);
- EraseRect (&whatRect);
- SetPort(savePort);
-
- } /* ErasePort() */
-
- Boolean
- ColorsEqual(rgbc1, rgbc2)
- RGBColor rgbc1, rgbc2;
- {
- if (rgbc1.red != rgbc2.red)
- return(FALSE);
- if (rgbc1.green != rgbc2.green)
- return(FALSE);
- if (rgbc1.blue != rgbc2.blue)
- return(FALSE);
-
- return(TRUE);
-
- } /* ColorsEqual() */
-