home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glypha II 1.21 / source / Code ƒ / D-GameUtils.p < prev    next >
Encoding:
Text File  |  1993-07-01  |  29.5 KB  |  982 lines  |  [TEXT/PJMM]

  1. unit GameUtils;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Sound, Palettes, Globals, Dialogs;
  7.  
  8.     procedure CenterZeroRect (var theRect: Rect);
  9.     procedure NewLightning;
  10.     procedure StrikeLightning (whichLevel: Integer);
  11.     procedure DoTheSound (whichOne: Str255; priority: Integer);
  12.     function DoRandom (range: Integer): Integer;
  13.     procedure ChangeRect;
  14.     procedure DrawPlayer (newRect, oldRect: Rect);
  15.     procedure DrawBeasts;
  16.     procedure DrawHand;
  17.     procedure RedoTheBackground;
  18.     procedure ShowScore;
  19.     procedure ShowMortals;
  20.     procedure ShowLevel;
  21.     procedure CheckExtraMortal;
  22.     procedure ReDrawHiScores;
  23.     procedure ReadInScores;
  24.     procedure WriteOutScores;
  25.     procedure FinalScore;
  26.     procedure DoHelpScreen;
  27.     procedure FlushTheScores;
  28.  
  29. {=================================}
  30.  
  31. implementation
  32.  
  33. {=================================}
  34.  
  35.     procedure CenterZeroRect;
  36.     begin
  37.         OffsetRect(theRect, -theRect.left, -theRect.top);
  38.         OffsetRect(theRect, (theRect.left - theRect.right) div 2, (theRect.top - theRect.bottom) div 2);
  39.     end;
  40. {=================================}
  41.  
  42.     procedure NewLightning;
  43.  
  44.         const
  45.             obeliskHeight = 250;
  46.             obel1left = 172;
  47.             obel2left = 468;
  48.             pylonToCenter = 148;
  49.  
  50.             upperHeight = 180;
  51.             lowerHeight = 425;
  52.  
  53.             upperDelta = upperHeight - obeliskHeight;
  54.             lowerDelta = lowerHeight - obeliskHeight;
  55.  
  56.             upperEyeDelta = upperEyeHeight - obeliskHeight;
  57.             lowerEyeDelta = lowerEyeHeight - obeliskHeight;
  58.  
  59.         var
  60.             index, index2, travel, hori, vert: Integer;
  61.  
  62.     begin
  63.  
  64.         with lightning do
  65.             begin
  66.                 levelStriking := upperLevel;
  67.                 leftMode := DoRandom(4);
  68.                 rightMode := DoRandom(4);
  69.                 for index := 0 to 3 do
  70.                     begin
  71.                         SetPt(leftBolts[upperLevel, index, 0], obel1left, obeliskHeight);
  72.                         SetPt(rightBolts[upperLevel, index, 0], obel2left, obeliskHeight);
  73.                         SetPt(leftBolts[lowerLevel, index, 0], obel1left, obeliskHeight);
  74.                         SetPt(rightBolts[lowerLevel, index, 0], obel2left, obeliskHeight);
  75.                         SetPt(leftBolts[upperEye, index, 0], obel1left, obeliskHeight);
  76.                         SetPt(rightBolts[upperEye, index, 0], obel2left, obeliskHeight);
  77.                         SetPt(leftBolts[lowerEye, index, 0], obel1left, obeliskHeight);
  78.                         SetPt(rightBolts[lowerEye, index, 0], obel2left, obeliskHeight);
  79.                     end;
  80.                 for index := 0 to 3 do
  81.                     for index2 := 1 to 10 do
  82.                         begin
  83.                             travel := (6 - ABS(index2 - 6)) * 5;
  84.  
  85.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  86.                             vert := obeliskHeight + (index2 * (upperDelta div 12));
  87.                             vert := vert + DoRandom(travel * 2) - travel;
  88.                             SetPt(leftBolts[upperLevel, index, index2], hori, vert);
  89.  
  90.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  91.                             vert := obeliskHeight + (index2 * (upperDelta div 12));
  92.                             vert := vert + DoRandom(travel * 2) - travel;
  93.                             SetPt(rightBolts[upperLevel, index, index2], hori, vert);
  94.  
  95.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  96.                             vert := obeliskHeight + (index2 * (lowerDelta div 12));
  97.                             vert := vert + DoRandom(travel * 2) - travel;
  98.                             SetPt(leftBolts[lowerLevel, index, index2], hori, vert);
  99.  
  100.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  101.                             vert := obeliskHeight + (index2 * (lowerDelta div 12));
  102.                             vert := vert + DoRandom(travel * 2) - travel;
  103.                             SetPt(rightBolts[lowerLevel, index, index2], hori, vert);
  104.  
  105.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  106.                             vert := obeliskHeight + (index2 * (upperEyeDelta div 12));
  107.                             vert := vert + DoRandom(travel * 2) - travel;
  108.                             SetPt(leftBolts[upperEye, index, index2], hori, vert);
  109.  
  110.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  111.                             vert := obeliskHeight + (index2 * (upperEyeDelta div 12));
  112.                             vert := vert + DoRandom(travel * 2) - travel;
  113.                             SetPt(rightBolts[upperEye, index, index2], hori, vert);
  114.  
  115.                             hori := obel1left + (index2 * (pylonToCenter div 12));
  116.                             vert := obeliskHeight + (index2 * (lowerEyeDelta div 12));
  117.                             vert := vert + DoRandom(travel * 2) - travel;
  118.                             SetPt(leftBolts[lowerEye, index, index2], hori, vert);
  119.  
  120.                             hori := obel2left - (index2 * (pylonToCenter div 12));
  121.                             vert := obeliskHeight + (index2 * (lowerEyeDelta div 12));
  122.                             vert := vert + DoRandom(travel * 2) - travel;
  123.                             SetPt(rightBolts[lowerEye, index, index2], hori, vert);
  124.                         end;
  125.                 for index := 0 to 3 do
  126.                     begin
  127.                         SetPt(leftBolts[upperLevel, index, 11], 320, upperHeight);
  128.                         SetPt(rightBolts[upperLevel, index, 11], 318, upperHeight);
  129.                         SetPt(leftBolts[lowerLevel, index, 11], 320, lowerHeight);
  130.                         SetPt(rightBolts[lowerLevel, index, 11], 318, lowerHeight);
  131.                         SetPt(leftBolts[upperEye, index, 11], 320, upperEyeHeight);
  132.                         SetPt(rightBolts[upperEye, index, 11], 318, upperEyeHeight);
  133.                         SetPt(leftBolts[lowerEye, index, 11], 320, lowerEyeHeight);
  134.                         SetPt(rightBolts[lowerEye, index, 11], 318, lowerEyeHeight);
  135.                     end;
  136.             end;
  137.     end;
  138.  
  139. {=================================}
  140.  
  141.     procedure StrikeLightning;
  142.         var
  143.             index: Integer;
  144.             isPoint, wasPoint: Point;
  145.             savedPort: GrafPtr;
  146.     begin
  147.         GetPort(savedPort);
  148.         SetPort(GrafPtr(mainWndo));
  149.  
  150.         InvertRgn(obeliskRgn1);
  151.         InvertRgn(obeliskRgn2);
  152.         PenNormal;
  153.         PenSize(2, 2);
  154.         PenMode(patXOr);
  155.         with lightning do
  156.             begin
  157.                 leftMode := DoRandom(4);
  158.                 rightMode := DoRandom(4);
  159.                 for index := 1 to 11 do
  160.                     begin
  161.                         isPoint := leftBolts[whichLevel, leftMode, index];
  162.                         wasPoint := leftBolts[whichLevel, leftMode, index - 1];
  163.                         MoveTo(wasPoint.h, wasPoint.v);
  164.                         LineTo(isPoint.h - 2, isPoint.v);
  165.                         isPoint := rightBolts[whichLevel, leftMode, index];
  166.                         wasPoint := rightBolts[whichLevel, leftMode, index - 1];
  167.                         MoveTo(wasPoint.h, wasPoint.v);
  168.                         LineTo(isPoint.h + 2, isPoint.v);
  169.                     end;
  170.                 for index := 1 to 11 do
  171.                     begin
  172.                         isPoint := leftBolts[whichLevel, leftMode, index];
  173.                         wasPoint := leftBolts[whichLevel, leftMode, index - 1];
  174.                         MoveTo(wasPoint.h, wasPoint.v);
  175.                         LineTo(isPoint.h - 2, isPoint.v);
  176.                         isPoint := rightBolts[whichLevel, leftMode, index];
  177.                         wasPoint := rightBolts[whichLevel, leftMode, index - 1];
  178.                         MoveTo(wasPoint.h, wasPoint.v);
  179.                         LineTo(isPoint.h + 2, isPoint.v);
  180.                     end;
  181.             end;
  182.         InvertRgn(obeliskRgn1);
  183.         InvertRgn(obeliskRgn2);
  184.         SetPort(GrafPtr(savedPort));
  185.     end;
  186.  
  187. {=================================}
  188.  
  189.     function GetA5: LONGINT;
  190.     inline
  191.         $2E8D; {MOVE.L A5,(A7)}
  192.  
  193. {=================================}
  194.  
  195.     function LoadA5 (newA5: LONGINT): LONGINT;
  196.     inline
  197.         $2F4D, $0004, $2A5F;
  198.  
  199. {=================================}
  200.  
  201.     procedure ChanCallBack (chan: SndChannelPtr; cmd: SndCommand);
  202.         var
  203.             oldA5: LongInt;
  204.     begin
  205.         if cmd.param1 <> 12345 then
  206.             Exit(ChanCallBack);             { Skip err callBackCmd w/ System 6.0.4 }
  207.         oldA5 := LoadA5(cmd.param2);        { get the application's A5 and set it }
  208.         soundPriority := noSound;
  209.         oldA5 := LoadA5(oldA5);            { restore old A5 }
  210.     end;
  211.  
  212. {=================================}
  213.  
  214.     procedure DoTheSound;
  215.         var
  216.             aCommand: SndCommand;
  217.             theSnd: Handle;
  218.             err: OSErr;
  219.     begin
  220.         if (not soundOn) then
  221.             Exit(DoTheSound);
  222.  
  223.         if (priority < soundPriority) then
  224.             Exit(DoTheSound);
  225.  
  226.         theSnd := GetNamedResource('snd ', whichOne);
  227.  
  228.         if (theSnd^ = nil) then
  229.             Exit(DoTheSound);
  230.  
  231.         if (chanPtr <> nil) then
  232.             begin
  233.                 with aCommand do
  234.                     begin
  235.                         cmd := quietCmd;
  236.                         param1 := 0;
  237.                         param2 := 0;
  238.                     end;
  239.                 err := SndDoImmediate(chanPtr, aCommand);
  240.                 err := SndDisposeChannel(chanPtr, TRUE);
  241.                 chanPtr := nil;
  242.             end;
  243.  
  244.         err := SndNewChannel(chanPtr, 0, initMono + $0004, @ChanCallBack);
  245.         if (err = noErr) then
  246.             err := SndPlay(chanPtr, theSnd, TRUE);
  247.         with aCommand do
  248.             begin
  249.                 cmd := callBackCmd;
  250.                 param1 := 12345;
  251.                 param2 := GetA5;
  252.             end;
  253.         if (err = noErr) then
  254.             err := SndDoCommand(chanPtr, aCommand, FALSE);
  255.  
  256.         if (err = noErr) then
  257.             soundPriority := priority
  258.         else
  259.             soundPriority := noSound;
  260.     end;
  261.  
  262. {=================================}
  263.  
  264.     function DoRandom;
  265.         var
  266.             rawResult: LongInt;
  267.     begin
  268.         rawResult := Abs(Random);
  269.         DoRandom := (rawResult * range) div 32768
  270.     end;
  271.  
  272. {=================================}
  273.  
  274.     procedure ChangeRect;
  275.         var
  276.             hori, vert: Integer;
  277.     begin
  278.         with thePlayer do
  279.             begin
  280.                 hori := dest.left;
  281.                 vert := dest.top;
  282.                 if (mode < 6) then
  283.                     begin
  284.                         dest := playerRects[facing, mode];
  285.                         OffsetRect(dest, -dest.left, -dest.top);
  286.                     end
  287.                 else
  288.                     begin
  289.                         SetRect(dest, 0, 0, 45, 22);        {pile of bones rect}
  290.                         dest.top := dest.top + 17;            { h diff from skeleton to bone pile}
  291.                         dest.bottom := dest.bottom + 17;
  292.                     end;
  293.                 dest.left := dest.left + hori;
  294.                 dest.right := dest.right + hori;
  295.                 dest.top := dest.top + vert;
  296.                 dest.bottom := dest.bottom + vert;
  297.             end;
  298.     end;
  299.  
  300. {=================================}
  301.  
  302.     procedure DrawPlayer;
  303.         var
  304.             index, hori, vert: integer;
  305.             dummyLong: LongInt;
  306.             standInRect, standInRect2, tempRect: Rect;
  307.     begin
  308.         with thePlayer do
  309.             case mode of
  310.                 0..5: 
  311.                     begin
  312.                         UnionRect(oldRect, newRect, wholeRect);
  313.                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  314.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, playerRects[facing, mode], playerRects[facing, mode], newRect);
  315.                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  316.                         if (otherState) then        {brief flash as player dies and turns to a falling skeleton}
  317.                             begin
  318.                                 mode := 6;
  319.                                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  320.                                 hori := newRect.left;
  321.                                 vert := newRect.top;
  322.                                 newRect := boneRects[0, 6];
  323.                                 OffsetRect(newRect, -newRect.left, -newRect.top);
  324.                                 tempRect := newRect;
  325.                                 OffsetRect(newRect, hori, vert);
  326.                                 dest := newRect;
  327.                                 if (dest.bottom < 200) then
  328.                                     OffsetRect(tempRect, 0, 200);
  329.                                 SetPort(GrafPtr(loadCPtr));
  330.                                 for index := 1 to 10 do
  331.                                     begin
  332.                                         EraseRect(tempRect);
  333.                                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, newRect, tempRect, srcCopy, nil);
  334.                                         CopyMask(BitMapPtr(loadCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, tempRect, boneRects[facing, mode], newRect);
  335.                                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, newRect, newRect, srcCopy, playRgn);
  336.                                         Delay(1, dummyLong);
  337.                                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, newRect, newRect, srcCopy, nil);
  338.                                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, boneRects[facing, mode], boneRects[facing, mode], newRect);
  339.                                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, newRect, newRect, srcCopy, playRgn);
  340.                                     end;
  341.                                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, newRect, newRect, srcCopy, playRgn);
  342.                             end;
  343.                     end;
  344.                 6:                     {falling skeleton}
  345.                     begin
  346.                         UnionRect(oldRect, newRect, wholeRect);
  347.                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  348.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, boneRects[facing, mode], boneRects[facing, mode], newRect);
  349.                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  350.                     end;
  351.                 7..100:         {sinking bones}
  352.                     begin
  353.                         UnionRect(oldRect, newRect, wholeRect);
  354.                         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  355.                         standInRect := boneRects[facing, 7];
  356.                         standInRect2 := boneRects[facing, 7];
  357.                         vert := dest.bottom - dest.top;
  358.                         standInRect.bottom := standInRect.top + vert;
  359.                         standInRect2.bottom := standInRect2.top + vert;
  360.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, standInRect, standInRect2, newRect);
  361.                         CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  362.                     end;
  363.                 otherwise
  364.                     begin
  365.                     end;
  366.             end;
  367.     end;
  368.  
  369. {=================================}
  370.  
  371.     procedure DrawHand;
  372.     begin
  373.         with theHand do
  374.             begin
  375.                 UnionRect(oldDest, dest, wholeRect);
  376.                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  377.                 CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, handRects[mode], handRects[mode], dest);
  378.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  379.             end;
  380.     end;
  381.  
  382. {=================================}
  383.  
  384.     procedure DrawBeasts;
  385.         var
  386.             index: Integer;
  387.             otherRect, otherMask, tempSrc, tempMask: Rect;
  388.     begin
  389.  
  390.         if (levelOn < 11) then    {swap flames on background}
  391.             begin
  392.                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, flameRect[0], flameRect[0], srcCopy, nil);
  393.                 CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, flameRect[1], flameRect[0], srcCopy, nil);
  394.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, flameRect[0], flameRect[1], srcCopy, nil);
  395.             end;
  396.  
  397. {copy all neccesary background rects to the load map}
  398.         with theEye do
  399.             if (mode > 0) then
  400.                 begin
  401.                     UnionRect(oldDest, dest, wholeRect);
  402.                     CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  403.                 end;
  404.  
  405.         for index := 1 to numberOfEnemies do
  406.             with theEnemies[index] do
  407.                 begin
  408.                     UnionRect(oldDest, dest, wholeRect);
  409.                     CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, BitMapPtr(loadCPtr^.portPixMap^)^, wholeRect, wholeRect, srcCopy, nil);
  410.                     oldDest := dest;
  411.                 end;
  412.  
  413. {copy the beasts through their masks onto the load map}
  414.         for index := 1 to numberOfEnemies do
  415.             with theEnemies[index] do
  416.                 case mode of
  417.                     -1000..-1: 
  418.                         begin
  419.                             tempSrc := eggRects;
  420.                             tempMask := eggRects;
  421.                             tempSrc.bottom := tempSrc.top + (dest.bottom - dest.top);
  422.                             tempMask.bottom := tempMask.top + (dest.bottom - dest.top);
  423.                             CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, tempSrc, tempMask, dest);
  424.                         end;
  425.                     0..5: 
  426.                         CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, enemyRects[otherMode, mode, facing], enemyRects[otherMode, mode, facing], dest);
  427.                     6: 
  428.                         begin
  429.                             otherRect := enemyRects[otherMode, 1, facing];
  430.                             otherRect.bottom := otherRect.top + (dest.bottom - dest.top);
  431.                             otherMask := enemyRects[otherMode, 1, facing];
  432.                             otherMask.bottom := otherMask.top + (dest.bottom - dest.top);
  433.                             CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, otherRect, otherMask, dest);
  434.                         end;
  435.                     otherwise
  436.                         ;
  437.                 end;    {case}
  438.  
  439.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, flameRect[0], flameRect[0], srcCopy, nil);
  440.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, flameRect[1], flameRect[1], srcCopy, nil);
  441.         {copy the sum bitmaps to the screen}
  442.         for index := 1 to numberOfEnemies do
  443.             with theEnemies[index] do
  444.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  445.  
  446.         with theEye do
  447.             if (mode > 0) then
  448.                 begin
  449.                     CopyMask(BitMapPtr(objectCPtr^.portPixMap^)^, offMaskMap, BitMapPtr(loadCPtr^.portPixMap^)^, eyeRects[otherMode], eyeRects[otherMode], dest);
  450.                     CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, wholeRect, wholeRect, srcCopy, playRgn);
  451.                     oldDest := dest;
  452.                 end;
  453.     end;
  454.  
  455. {=================================}
  456.  
  457.     procedure RedoTheBackground;
  458.         var
  459.             tempRect, anotherRect: Rect;
  460.             thePict: PicHandle;
  461.  
  462.     begin
  463.         SetPort(GrafPtr(virginCPtr));                        {Set the port to my window}
  464.         thePict := GetPicture(backPictID);            {Get Picture into memory}
  465.         if (thePict <> nil) then                                {Only use handle if it is valid}
  466.             begin
  467.                 ClipRect(wholeArea);                                {Clip picture to this rectangle}
  468.                 HLock(Handle(thePict));                            {Lock the handle before using it}
  469.                 tempRect := thePict^^.picFrame;
  470.                 DrawPicture(thePict, tempRect);
  471.                 HUnLock(Handle(thePict));                        {Unlock the picture again}
  472.                 ReleaseResource(Handle(thePict));
  473.             end;
  474.  
  475.         if (numberOfStones > 2) then
  476.             begin            {draw top floor end stones}
  477.                 tempRect := longStoneSrc;
  478.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  479.                 OffsetRect(tempRect, tombRects[3].left, tombRects[3].top);
  480.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, nil);
  481.  
  482.                 tempRect := longStoneSrc;
  483.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  484.                 OffsetRect(tempRect, tombRects[4].left, tombRects[4].top);
  485.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, nil);
  486.             end;
  487.  
  488.         if ((numberOfStones > 4) and (levelOn <> 3)) then
  489.             begin
  490.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, shortStoneSrc, tombRects[5], srcCopy, nil);
  491.             end;
  492.  
  493.         if (levelOn < 3) then
  494.             begin                            {put covers over acid pools}
  495.                 tempRect := longStoneSrc;
  496.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  497.                 OffsetRect(tempRect, tombRects[-5].left, tombRects[-5].top);
  498.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, playRgn);
  499.  
  500.                 tempRect := longStoneSrc;
  501.                 OffsetRect(tempRect, -tempRect.left, -tempRect.top);    {Get it in upper left}
  502.                 OffsetRect(tempRect, tombRects[-4].left, tombRects[-4].top);
  503.                 CopyBits(BitMapPtr(objectCPtr^.portPixMap^)^, BitMapPtr(virginCPtr^.portPixMap^)^, longStoneSrc, tempRect, srcCopy, playRgn);
  504.             end;
  505.  
  506.         if (levelOn > 10) then
  507.             begin
  508.                 SetPort(GrafPtr(virginCPtr));
  509.                 FillRect(flameRect[0], black);
  510.                 FillRect(flameRect[1], black);
  511.             end;
  512.  
  513.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, mainWndo^.visRgn);
  514.         ShowScore;
  515.         ShowMortals;
  516.         ShowLevel;
  517.     end;
  518.  
  519. {=================================}
  520.  
  521.     procedure ShowScore;
  522.         var
  523.             wasPort: GrafPtr;
  524.             tempStr: Str255;
  525.             tempRect: Rect;
  526.     begin
  527.         GetPort(wasPort);
  528.         SetPort(GrafPtr(mainWndo));
  529.         SetRect(tempRect, 268, 438, 364, 458);
  530.         TextFont(0);
  531.         TextSize(12);
  532.         NumToString(score, tempStr);
  533.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, mainWndo^.visRgn);
  534.         RGBForeColor(rgbWhite);
  535.         PenMode(srcOr);
  536.         MoveTo(270, 456);
  537.         DrawString(tempStr);
  538.         RGBForeColor(rgbBlack);
  539.         SetPort(GrafPtr(wasPort));
  540.     end;
  541.  
  542. {=================================}
  543.  
  544.     procedure ShowMortals;
  545.         var
  546.             wasPort: GrafPtr;
  547.             tempStr: Str255;
  548.             tempRect: Rect;
  549.     begin
  550.         GetPort(wasPort);
  551.         SetPort(GrafPtr(mainWndo));
  552.         SetRect(tempRect, 218, 438, 266, 458);
  553.         TextFont(0);
  554.         TextSize(12);
  555.         NumToString(mortals, tempStr);
  556.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, mainWndo^.visRgn);
  557.         RGBForeColor(rgbWhite);
  558.         PenMode(srcOr);
  559.         MoveTo(220, 456);
  560.         DrawString(tempStr);
  561.         RGBForeColor(rgbBlack);
  562.         SetPort(GrafPtr(wasPort));
  563.     end;
  564.  
  565. {=================================}
  566.  
  567.     procedure ShowLevel;
  568.         var
  569.             wasPort: GrafPtr;
  570.             tempStr: Str255;
  571.             tempRect: Rect;
  572.     begin
  573.         GetPort(wasPort);
  574.         SetPort(GrafPtr(mainWndo));
  575.         SetRect(tempRect, 378, 438, 426, 458);
  576.         TextFont(0);
  577.         TextSize(12);
  578.         NumToString(levelOn, tempStr);
  579.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, mainWndo^.visRgn);
  580.         RGBForeColor(rgbWhite);
  581.         PenMode(srcOr);
  582.         MoveTo(380, 456);
  583.         DrawString(tempStr);
  584.         RGBForeColor(rgbBlack);
  585.         SetPort(GrafPtr(wasPort));
  586.     end;
  587.  
  588. {=================================}
  589.  
  590.     procedure CheckExtraMortal;
  591.     begin
  592.         if (score > nextMortal) then
  593.             begin
  594.                 DoTheSound('bonus.snd', highPriority);    {You got an extra player!}
  595.                 mortals := mortals + 1;
  596.                 ShowMortals;
  597.                 nextMortal := nextMortal + newMortalPts;
  598.             end;
  599.     end;
  600.  
  601. {=================================}
  602.  
  603.     procedure ReDrawHiScores;
  604.         var
  605.             index, heightIs: Integer;
  606.             dummyLong: LongInt;
  607.             tempRect: Rect;
  608.             dummyString: Str255;
  609.     begin
  610.         SetPort(GrafPtr(loadCPtr));
  611.         PenNormal;
  612.         SetRect(tempRect, 207, 168, 434, 388);
  613.         FillRect(tempRect, black);
  614.         TextFont(1);
  615.         TextSize(9);
  616.         for index := 1 to 10 do    {Now we're going to loop through all the scores    }
  617.             begin
  618.                 RGBForeColor(rgbYellow);
  619.                 MoveTo(tempRect.left + 20, index * 14 + tempRect.top + 50);
  620.                 DrawString(hiStrings[index]);                            {Draw the name of person}
  621.                 RGBForeColor(rgbRed);
  622.                 MoveTo(370, index * 14 + tempRect.top + 50);
  623.                 NumToString(hiScores[index], dummyString);
  624.                 DrawString(dummyString);                                    {And draw their score}
  625.             end;                                                                                {Copy screen to virgin for updates}
  626.         RGBForeColor(rgbBlack);
  627.         heightIs := tempRect.bottom - tempRect.top;
  628.         tempRect.top := tempRect.bottom;
  629.         for index := 1 to heightIs div 4 do
  630.             begin
  631.                 tempRect.top := tempRect.top - 4;
  632.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, tempRect, tempRect, srcCopy, mainWndo^.visRgn);
  633.             end;
  634.  
  635.         SetPort(GrafPtr(mainWndo));
  636.         TextFont(0);
  637.         TextSize(12);
  638.         PenMode(srcOr);
  639.         RGBForeColor(rgbLtBlue);
  640.         MoveTo(tempRect.left + 20, tempRect.top + 30);
  641.         DrawString('Glypha II 1.2 High Scores');
  642.         RGBForeColor(rgbBlack);
  643.  
  644.         CopyBits(mainWndo^.portBits, BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portRect, mainWndo^.portRect, srcCopy, nil);
  645.     end;
  646.  
  647. {=================================}
  648.  
  649.     procedure ReadInScores;
  650.         type
  651.             scoreHandle = ^scorePtr;
  652.             scorePtr = ^score;
  653.             score = record
  654.                     data: array[0..9] of LongInt;
  655.                 end;
  656.  
  657.             nameHandle = ^namePtr;
  658.             namePtr = ^name;
  659.             name = record
  660.                     data: array[0..9, 0..14] of Char;
  661.                 end;
  662.  
  663.             prefHandle = ^prefPtr;
  664.             prefPtr = ^pref;
  665.             pref = record
  666.                     data: array[0..31] of Char;
  667.                 end;
  668.  
  669.         var
  670.             index, index2, tempVolume: Integer;
  671.             dummyStr: Str255;
  672.             theScores: scoreHandle;
  673.             theNames: nameHandle;
  674.             thePrefs: prefHandle;
  675.  
  676.     begin
  677.         theScores := scoreHandle(NewHandle(SIZEOF(score)));
  678.         if (theScores = nil) then
  679.             begin
  680.                 GenericAlert(4);
  681.                 ExitToShell;
  682.             end;
  683.         MoveHHi(Handle(theScores));
  684.         HLock(Handle(theScores));
  685.         Handle(theScores) := GetResource('scrs', 128);
  686.         for index := 0 to 9 do
  687.             hiScores[index + 1] := theScores^^.data[index];
  688.         HUnlock(Handle(theScores));
  689.         ReleaseResource(Handle(theScores));
  690.         DisposHandle(Handle(theScores));
  691.  
  692.         theNames := nameHandle(NewHandle(SIZEOF(name)));
  693.         if (theNames = nil) then
  694.             begin
  695.                 GenericAlert(4);
  696.                 ExitToShell;
  697.             end;
  698.         MoveHHi(Handle(theNames));
  699.         HLock(Handle(theNames));
  700.         Handle(theNames) := GetResource('name', 128);
  701.         for index := 0 to 9 do
  702.             begin
  703.                 dummyStr := '';
  704.                 for index2 := 0 to 14 do
  705.                     dummyStr := CONCAT(dummyStr, theNames^^.data[index, index2]);
  706.                 hiStrings[index + 1] := dummyStr;
  707.             end;
  708.         HUnlock(Handle(theNames));
  709.         ReleaseResource(Handle(theNames));
  710.         DisposHandle(Handle(theNames));
  711.  
  712.         thePrefs := prefHandle(NewHandle(SIZEOF(pref)));
  713.         if (thePrefs = nil) then
  714.             begin
  715.                 GenericAlert(4);
  716.                 ExitToShell;
  717.             end;
  718.         MoveHHi(Handle(thePrefs));
  719.         HLock(Handle(thePrefs));
  720.         Handle(thePrefs) := GetResource('pref', 128);
  721.  
  722.         if (thePrefs^^.data[0] = 'M') then
  723.             keyboardControl := FALSE
  724.         else
  725.             keyboardControl := TRUE;
  726.         if (thePrefs^^.data[1] = 'S') then
  727.             soundOn := TRUE
  728.         else
  729.             soundOn := FALSE;
  730.         if (inhibitSound) then
  731.             soundOn := FALSE;
  732.         GetSoundVol(tempVolume);
  733.         if (tempVolume = 0) then
  734.             soundOn := FALSE;
  735.  
  736.         case thePrefs^^.data[2] of
  737.             'S': 
  738.                 gameSpeed := slow;
  739.             'F': 
  740.                 gameSpeed := fast;
  741.             otherwise
  742.                 gameSpeed := fast;
  743.         end;
  744.  
  745.         nameUsing := '';
  746.         for index := 1 to 15 do
  747.             nameUsing := CONCAT(nameUsing, thePrefs^^.data[index + 16]);
  748.  
  749.         HUnlock(Handle(thePrefs));
  750.         ReleaseResource(Handle(thePrefs));
  751.         DisposHandle(Handle(thePrefs));
  752.  
  753.         scoresChanged := FALSE;
  754.     end;
  755.  
  756. {=================================}
  757.  
  758.     procedure WriteOutScores;
  759.         type
  760.             scoreHandle = ^scorePtr;
  761.             scorePtr = ^score;
  762.             score = record
  763.                     data: array[0..9] of LongInt;
  764.                 end;
  765.  
  766.             nameHandle = ^namePtr;
  767.             namePtr = ^name;
  768.             name = record
  769.                     data: array[0..9, 0..14] of Char;
  770.                 end;
  771.  
  772.             prefHandle = ^prefPtr;
  773.             prefPtr = ^pref;
  774.             pref = record
  775.                     data: array[0..31] of Char;
  776.                 end;
  777.  
  778.         var
  779.             index, index2: Integer;
  780.             dummyStr: Str255;
  781.             theScores: scoreHandle;
  782.             theNames: nameHandle;
  783.             thePrefs: prefHandle;
  784.  
  785.     begin
  786.         thePrefs := prefHandle(NewHandle(SIZEOF(pref)));
  787.         if (thePrefs = nil) then
  788.             begin
  789.                 GenericAlert(4);
  790.                 ExitToShell;
  791.             end;
  792.         HLock(Handle(thePrefs));
  793.         Handle(thePrefs) := GetResource('pref', 128);
  794.         if (keyboardControl) then
  795.             thePrefs^^.data[0] := 'K'
  796.         else
  797.             thePrefs^^.data[0] := 'M';
  798.         if (soundOn) then
  799.             thePrefs^^.data[1] := 'S'
  800.         else
  801.             thePrefs^^.data[1] := 'N';
  802.  
  803.         if (gameSpeed = slow) then
  804.             thePrefs^^.data[2] := 'S'
  805.         else
  806.             thePrefs^^.data[2] := 'F';
  807.  
  808.         for index := 1 to 15 do
  809.             thePrefs^^.data[index + 16] := COPY(nameUsing, index, 1);
  810.         ChangedResource(Handle(thePrefs));
  811.         WriteResource(Handle(thePrefs));
  812.         HUnlock(Handle(thePrefs));
  813.         ReleaseResource(Handle(thePrefs));
  814.         DisposHandle(Handle(thePrefs));
  815.  
  816.         if (scoresChanged) then
  817.             begin
  818.                 theScores := scoreHandle(NewHandle(SIZEOF(score)));
  819.                 if (theScores = nil) then
  820.                     begin
  821.                         GenericAlert(4);
  822.                         ExitToShell;
  823.                     end;
  824.                 MoveHHi(Handle(theScores));
  825.                 HLock(Handle(theScores));
  826.                 Handle(theScores) := GetResource('scrs', 128);
  827.                 for index := 0 to 9 do
  828.                     theScores^^.data[index] := hiScores[index + 1];
  829.                 ChangedResource(Handle(theScores));
  830.                 WriteResource(Handle(theScores));
  831.                 HUnlock(Handle(theScores));
  832.                 ReleaseResource(Handle(theScores));
  833.                 DisposHandle(Handle(theScores));
  834.  
  835.                 theNames := nameHandle(NewHandle(SIZEOF(name)));
  836.                 if (theNames = nil) then
  837.                     begin
  838.                         GenericAlert(4);
  839.                         ExitToShell;
  840.                     end;
  841.                 HLock(Handle(theNames));
  842.                 Handle(theNames) := GetResource('name', 128);
  843.                 for index := 0 to 9 do
  844.                     for index2 := 0 to 14 do
  845.                         theNames^^.data[index, index2] := COPY(hiStrings[index + 1], index2 + 1, 1);
  846.                 ChangedResource(Handle(theNames));
  847.                 WriteResource(Handle(theNames));
  848.                 HUnlock(Handle(theNames));
  849.                 ReleaseResource(Handle(theNames));
  850.                 DisposHandle(Handle(theNames));
  851.             end;
  852.     end;
  853.  
  854. {=================================}
  855.  
  856.     procedure FinalScore;
  857.         var
  858.             index, ranking: Integer;
  859.     begin
  860.         FlushEvents(everyEvent, 0);                                    {Clear all the keystrokes    }
  861.         if (score > hiScores[10]) and (mortalsStart = defaultNum) then        {Is it a high score?            }
  862.             begin
  863.                 scoresChanged := TRUE;                        {Mark scores as changed            }
  864.                 DoTheSound('bonus.snd', highPriority);        {Play the bonus sound.            }
  865.                 ranking := 10;                                        {And sort through the high    }
  866.                 for index := 9 downto 1 do                {scores to find the players    }
  867.                     begin                                                        {ranking.                                        }
  868.                         if (score > hiScores[index]) then
  869.                             ranking := index;
  870.                     end;
  871.                 for index := 10 downto ranking + 1 do
  872.                     begin
  873.                         hiScores[index] := hiScores[index - 1];        {Move everyone's score}
  874.                         hiStrings[index] := hiStrings[index - 1];    {down the list.                }
  875.                     end;
  876.                 hiScores[ranking] := score;
  877.                 SetPort(GrafPtr(mainWndo));
  878.                 WhosHiScore(nameUsing);
  879.                 hiStrings[ranking] := nameUsing;
  880.             end;
  881.     end;
  882.  
  883. {=================================}
  884.  
  885.     procedure DoHelpScreen;
  886.         const
  887.             helpLeft = 208;
  888.             helpTop = 170;
  889.         var
  890.             index: Integer;
  891.             srcRect, dropRect, tempRect: Rect;
  892.             thePict: PicHandle;
  893.     begin
  894.         SetPort(GrafPtr(loadCPtr));
  895.         thePict := GetPicture(helpPictID);
  896.         SetRect(dropRect, 0, 0, 452, 440);
  897.         if (thePict <> nil) then
  898.             begin
  899.                 HLock(Handle(thePict));
  900.                 tempRect := thePict^^.picFrame;
  901.                 DrawPicture(thePict, tempRect);
  902.                 HUnLock(Handle(thePict));
  903.                 ReleaseResource(Handle(thePict));
  904.             end
  905.         else
  906.             Exit(DoHelpScreen);
  907.  
  908.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  909.         SetRect(srcRect, 0, 0, 226, 0);
  910.         for index := 1 to 110 do
  911.             begin
  912.                 dropRect.top := dropRect.top - 2;
  913.                 srcRect.bottom := srcRect.bottom + 2;
  914.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, mainWndo^.visRgn);
  915.             end;
  916.         repeat
  917.         until not Button;
  918.         repeat
  919.         until Button;
  920.  
  921.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  922.         SetRect(srcRect, 226, 0, 452, 0);
  923.         for index := 1 to 110 do
  924.             begin
  925.                 dropRect.top := dropRect.top - 2;
  926.                 srcRect.bottom := srcRect.bottom + 2;
  927.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, mainWndo^.visRgn);
  928.             end;
  929.         repeat
  930.         until not Button;
  931.         repeat
  932.         until Button;
  933.  
  934.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  935.         SetRect(srcRect, 226, 220, 452, 220);
  936.         for index := 1 to 110 do
  937.             begin
  938.                 dropRect.top := dropRect.top - 2;
  939.                 srcRect.bottom := srcRect.bottom + 2;
  940.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, mainWndo^.visRgn);
  941.             end;
  942.         repeat
  943.         until not Button;
  944.         repeat
  945.         until Button;
  946.  
  947.         SetRect(dropRect, 0 + helpLeft, helpTop + 220, 226 + helpLeft, helpTop + 220);
  948.         SetRect(srcRect, 0, 220, 226, 220);
  949.         for index := 1 to 110 do
  950.             begin
  951.                 dropRect.top := dropRect.top - 2;
  952.                 srcRect.bottom := srcRect.bottom + 2;
  953.                 CopyBits(BitMapPtr(loadCPtr^.portPixMap^)^, mainWndo^.portBits, srcRect, dropRect, srcCopy, mainWndo^.visRgn);
  954.             end;
  955.         repeat
  956.         until not Button;
  957.         repeat
  958.         until Button;
  959.  
  960.         FlushEvents(everyEvent, 0);
  961.         RedrawHiScores;
  962.     end;
  963.  
  964. {=================================}
  965.  
  966.     procedure FlushTheScores;
  967.         var
  968.             index: Integer;
  969.     begin
  970.         for index := 1 to 10 do
  971.             begin
  972.                 hiScores[index] := 0;
  973.                 hiStrings[index] := 'Play Me .......';
  974.             end;
  975.         scoresChanged := TRUE;
  976.         CopyBits(BitMapPtr(virginCPtr^.portPixMap^)^, mainWndo^.portBits, wholeArea, wholeArea, srcCopy, mainWndo^.visRgn);
  977.         RedrawHiScores;
  978.     end;
  979.  
  980. {=================================}
  981.  
  982. end.