home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-15 | 3.3 KB | 148 lines | [TEXT/PJMM] |
- unit Util;
-
- interface
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices, ToolUtils, SegLoad,
- {$ENDC}
- Globals, SWSound;
-
- function AbsVal (arg: Integer): Integer; {Use "abs" instead}
- function RngRnd (min: Integer; max: Integer): Integer;
- function IsPressed (keyID: Integer): Boolean;
- procedure SetChecks;
- procedure LoadSounds;
- procedure UnloadSounds;
- procedure LoadSound (var soundH: Handle; soundID: Integer; soundName: Str255);
- procedure UnloadSound (soundH: Handle);
- procedure ExitAppl;
- procedure ErasePort (whichPort: CGrafPtr; whatRect: Rect);
- function ColorsEqual (rgbc1, rgbc2: RGBColor): Boolean;
-
- implementation
-
- function AbsVal (arg: Integer): Integer;
- begin
- if arg < 0 then
- AbsVal := -arg
- else
- AbsVal := arg;
- end; (* AbsVal() *)
-
- function IsPressed (keyID: Integer): Boolean;
- var
- keys: KeyMap;
- begin
- GetKeys(keys);
- IsPressed := keys[keyID];
- end; (* IsPressed() *)
-
- function RngRnd (min: Integer; max: Integer): Integer;
- var
- rnd: Integer;
- range, t: LongInt;
- begin
- rnd := BitAnd(Random, $7fff);
- range := max - min;
- t := BSR(rnd * range, 15);
- RngRnd := (t + min);
- end; (* RngRnd() *)
-
-
- procedure SetChecks;
- begin
- CheckItem(gFileMenu, 2, gPauseOn);
- CheckItem(gFileMenu, 3, gSoundOn);
- end; (* SetChecks() *)
-
- procedure LoadSound (var soundH: Handle; soundID: Integer; soundName: Str255);
- begin
- soundH := GetResource('snd ', soundID);
- if soundH = nil then
- begin
- ExitAppl;
- end; (* if *)
- MoveHHi(soundH);
- HLock(soundH);
- HNoPurge(soundH);
- end; (* LoadSound() *)
-
- procedure UnloadSound (soundH: Handle);
- begin
- HUnlock(soundH);
- HPurge(soundH);
- ReleaseResource(soundH);
- end; (* UnloadSound() *)
-
-
- procedure LoadSounds;
-
- { evar Handle gNewMatchSoundH:xtern;}
- { eHandle gShotSoundH:xtern;}
- { eHandle gBoomSoundH:xtern;}
- { eHandle gEndorsementSndH:xtern;}
-
- begin
- LoadSound(gNewMatchSoundH, 501, '''snd '' New Level (501)');
- LoadSound(gShotSoundH, 502, '''snd'' Shot (502)');
- LoadSound(gBoomSoundH, 503, '''snd'' Boom (503)');
- AInitSnd;
- end; (* LoadSounds() *)
-
- procedure UnloadSounds;
- { evar Handle gNewMatchSoundH:xtern;}
- { eHandle gShotSoundH:xtern;}
- { eHandle gBoomSoundH:xtern;}
- { eHandle gEndorsementSndH:xtern;}
- begin
- UnloadSound(gNewMatchSoundH);
- UnloadSound(gShotSoundH);
- UnloadSound(gBoomSoundH);
- AStopSnd;
-
- end; (* UnloadSounds() *)
-
-
- procedure ExitAppl;
- begin
- if gPictureWindow <> nil then
- DisposeWindow(WindowPtr(gPictureWindow));
- if (gOSPtr <> nil) then
- begin
- CloseCPort(gOSPtr);
- DisposePtr(Ptr(gOSPtr));
- end; (* if *)
- if (gScrapPtr <> nil) then
- begin
- CloseCPort(gScrapPtr);
- DisposePtr(Ptr(gScrapPtr));
- end; (* if *)
- ShowCursor;
- FlushEvents(everyEvent, 0);
- UnloadSounds;
- ExitToShell;
- end; (* ExitAppl() *)
-
- procedure ErasePort (whichPort: CGrafPtr; whatRect: Rect);
- var
- savePort: GrafPtr;
- begin
- GetPort(savePort);
- SetPort(GrafPtr(whichPort));
- EraseRect(whatRect);
- SetPort(savePort);
- end; (* ErasePort() *)
-
- function ColorsEqual (rgbc1, rgbc2: RGBColor): Boolean;
- begin
- ColorsEqual := true;
- if (rgbc1.red <> rgbc2.red) then
- ColorsEqual := FALSE
- else if (rgbc1.green <> rgbc2.green) then
- ColorsEqual := FALSE
- else if (rgbc1.blue <> rgbc2.blue) then
- ColorsEqual := FALSE;
- end; (* ColorsEqual() *)
-
- end.