home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SDI.ZIP / EXPBOX.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-11-26  |  5.6 KB  |  145 lines

  1.  
  2. { *********************************************************************** }
  3. {                                                                         }
  4. {  ExpBox V1.02 explodes a Box on the display using BGI routines.         }
  5. {  You define the final box area, how many steps in the explosion,        }
  6. {  the speed at which the explosion occurs, and where the explosion       }
  7. {  is to start at. You also define the color and pattern of the           }
  8. {  exploding box. You can optionally specifiy a rectangle to follow       }
  9. {  the exploding box to provide more action. The color of the rectangle   }
  10. {  can also be defined.                                                   }
  11. {    Uses the TP graph unit and the CRT unit (only uses the Delay         }
  12. {  function from the CRT unit). If you don't use the CRT unit, then you   }
  13. {  might want to consider using the CRTI unit from the Borland TP4        }
  14. {  library on CompuServe which allows you to remove unwanted functions.   }
  15. {                                                                         }
  16. {      Originally written by Michael Day as 20 November 1988              }
  17. {                  Copyright 1988 by Michael Day                          }
  18. {           This release (V1.02) as of 25 November 1988                   }
  19. {            Released to the public domain by author.                     }
  20. {                                                                         }
  21. { *********************************************************************** }
  22. { History:                                                                }
  23. { V1.01 - Original release                                                }
  24. { V1.02 - Removed excess unused code                                      }
  25.  
  26. unit ExpBox;
  27. interface
  28.  
  29. uses graph,CRT;
  30.  
  31. { *********************************************************************** }
  32. {--                    External access definitions                      --}
  33. { *********************************************************************** }
  34.  
  35. {-------------------------------------------------------------------------}
  36. {Explodes a box on the screen}
  37. {x1,y1,x2,y2=final box size, Step=explosion steps, }
  38. {Speed=delay in ms between explosions, Style=how to explode}
  39. {Color=box color, Pattern=background pattern, }
  40. {RColor=rectangle color (if used) }
  41.  
  42. procedure ExplodeBox(x1,y1,x2,y2:integer;
  43.                      Speed,Step,Style:word;
  44.                      Color,Pattern,RColor:byte);
  45.  
  46.  
  47. { *********************************************************************** }
  48.  
  49. implementation
  50.  
  51.  
  52. procedure ExpRect(x1,y1,x2,y2:integer; Style:word);
  53. var i,Rc,rx,ry,ix,iy:integer;
  54. begin
  55.    bar(X1, Y1, X2, Y2);
  56.    Rc := (style shr 5) and 7;
  57.    if Rc > 0 then
  58.    begin
  59.      ix := ((x2-x1)shr 1)shr rc;
  60.      iy := ((y2-y1)shr 1)shr rc;
  61.      for i := Rc downto 1 do
  62.      begin
  63.        rx := ((x2-x1)shr(i))-ix;
  64.        ry := ((y2-y1)shr(i))-iy;
  65.        rectangle(succ(X1+rx), succ(Y1+ry), pred(X2-rx), pred(Y2-ry) );
  66.      end;
  67.    end;
  68. end;
  69.  
  70. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  71. {                         misc special effects                            }
  72. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  73.  
  74. {-------------------------------------------------------------------------}
  75. {Explodes a box on the screen}
  76.  
  77. {Styles: 0=explode from center, 1=explode from top, 2=explode from bottom,}
  78. {3=explode from left, 4=explode from right, 5=explode from top left corner,}
  79. {6=explode bot left corner, 7=explode top right corner, }
  80. {8=explode from bottom right corner. 9 and Above = no explode.}
  81. {if Style bits 5,6,7 are set, then rectangles will be drawn while exploding.}
  82. {a Step value of 0 or 1 will not cause an explode, the value must be larger}
  83. {than 1 to get an explode to happen. Speed sets the delay in ms between}
  84. {explode steps. Color and Pattern set the exploding box color and pattern.}
  85. {RColor sets the rectangle color (when used). If Style bit 4 is on, then }
  86. {sound effects will also be added.}
  87.  
  88. procedure ExplodeBox(x1,y1,x2,y2:integer;
  89.                      Speed,Step,Style:word;
  90.                      Color,Pattern,RColor:byte);
  91. var si,i,Sx,Sy : integer;
  92. begin
  93.    if Step > 0 then
  94.    begin
  95.      if (Style and $10) = $10 then NoSound;
  96.      Sx := (x2-x1) div Step;
  97.      Sy := (y2-y1) div Step;
  98.      SetFillStyle(Pattern,Color);
  99.      setcolor(RColor);
  100.      for i := pred(Step) downto 1 do
  101.      begin
  102.        case (Style and $f) of
  103.          {center explode}
  104.          0: ExpRect(x1+((Sx*i)shr 1), y1+((Sy*i)shr 1),
  105.                     x2-((Sx*i)shr 1), y2-((Sy*i)shr 1), Style);
  106.  
  107.          {top explode}
  108.          1: ExpRect(x1, y1, x2, y2-(Sy*i), Style);
  109.  
  110.          {bot explode}
  111.          2: ExpRect(x1, y1+(Sy*i), x2, y2, Style);
  112.  
  113.          {left explode}
  114.          3: ExpRect(x1, y1, x2-(Sx*i), y2, Style);
  115.  
  116.          {right explode}
  117.          4: ExpRect(x1+(Sx*i), y1, x2, y2, Style);
  118.  
  119.          {top left explode}
  120.          5: ExpRect(x1, y1, x2-(Sx*i), y2-(Sy*i), Style);
  121.  
  122.          {bot left explode}
  123.          6: ExpRect(x1, y1+(Sy*i), x2-(Sx*i), y2, Style);
  124.  
  125.          {top right explode}
  126.          7: ExpRect(x1+(Sx*i), y1, x2, y2-(Sy*i), Style);
  127.  
  128.          {bot right explode}
  129.          8: ExpRect(x1+(Sx*i), y1+(Sy*i), x2, y2, Style);
  130.  
  131.        end; {case}
  132.  
  133.        if (Style and $10) = $10 then Sound(i shl 8);
  134.        if (Style and $f) < 9 then delay(Speed);
  135.      end;
  136.      bar(x1,y1,x2,y2);  {draw final box}
  137.      if (Style and $10) = $10 then NoSound; {turn the sound off if was on}
  138.    end;
  139. end;
  140.  
  141.  
  142. { *********************************************************************** }
  143.  
  144. end.
  145.