home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / delite / dxfview / firework.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-04-01  |  5.9 KB  |  220 lines

  1. unit firework;
  2.  
  3.  
  4. interface
  5.  
  6.   procedure fireworks (anz_explosions,anz_points,maxxpix,maxypix,maxcolor : word);
  7.  
  8. implementation
  9.  
  10. uses  dos,crt,kernel, VMEM;
  11.  
  12. Const max_points     = 450;
  13.       max_explosions = 9;
  14.  
  15. Type  t_palette = array[0..16] of byte;
  16.  
  17. const standard_palette : t_palette =
  18.         ($00,$01,$02,$03,$04,$05,$14,$07,
  19.          $38,$39,$3a,$3b,$3c,$3d,$3e,$3f,$00);
  20.       bright_palette   : t_palette =
  21.         ($00,$2c,$35,$26,$2e,$27,$1e,$1b,
  22.          $16,$3a,$2e,$2b,$2d,$3b,$3e,$3f,$0);
  23.  
  24. type  tp = record
  25.              x,y : integer;
  26.              dx,dy : integer;
  27.              farbe : integer;
  28.              dauer : integer;
  29.            end;
  30.       pv = array [1..max_points] of tp;
  31.       te = record
  32.              aktiv  : boolean;
  33.              finish : boolean;
  34.              mx,my  : integer;
  35.              cfeld  : array [0..2] of word;
  36.              anz_p  : word;
  37.              points : pv;
  38.            end;
  39.       TheExplosion = Array[1..Max_Explosions] of te;
  40.  
  41. var dxmin, dxmax : integer;
  42.     dymin, dymax : integer;
  43.     xdiff,ydiff  : longint;
  44.     explosions   : ^TheExplosion;
  45.     Ready        : Boolean;
  46.     MemHandle    : integer;
  47.  
  48. procedure fireworks (anz_explosions,anz_points,maxxpix,maxypix,maxcolor : word);
  49. var e_no, p_i, NextRand : word;
  50.      maxxval,maxyval    : integer;
  51.  
  52. Procedure CheckReady;
  53. Var MyEvent : EventTyp;
  54.     KeyConfirm    : Boolean;
  55.     MouseConfirmR : Boolean;
  56.     MouseConfirmL : Boolean;
  57.  
  58. Begin
  59.   GetEvent(MyEvent);
  60.   With MyEvent do
  61.     Begin
  62.       KeyConfirm    := ((Class=CtrlKey) and (Attrib = 'm')) or
  63.                        ((Class=NormKey) and (Attrib = ESC));
  64.       MouseConfirmR := (Class=LeMouse)  and (Char(Ord(Attrib)
  65.                        and Ord(LeftButtonPressed)) = LeftButtonPressed);
  66.       MouseConfirmL := (Class=LeMouse)  and (Char(Ord(Attrib)
  67.                        and Ord(RightButtonPressed)) = RIghtButtonPressed);
  68.       If KeyConFirm or MouseConfirmR or MouseConfirmL Then
  69.         Ready := True;
  70.       If (Class = NormKey) Then
  71.         Begin
  72.           Case Attrib of
  73.             '1' .. '9' : Anz_Explosions := Ord(Attrib) - 48;
  74.           End;
  75.         End
  76.     End;
  77. End;
  78.  
  79. procedure InitExplosions;
  80. var lauf : word;
  81. begin
  82.   dxmax :=  PortMaxX * 10 div 64;
  83.   dxmin := -PortMaxX * 10 div 64;
  84.  
  85.   dymax := PortMaxY;
  86.   dymin := (PortMaxY * 42) div 64;
  87.  
  88.   xdiff := dxmax-dxmin;
  89.   ydiff := dymax-dymin;
  90.   if anz_explosions > max_explosions then
  91.      anz_explosions := max_explosions;
  92.   if anz_points > max_points then
  93.      anz_points := max_points;
  94.   randomize;
  95.  
  96.   MemHandle := AllocatePage(SizeOf(Explosions));
  97.   if MemHandle <> -1 then
  98.    begin
  99.      Explosions := GetPageAddress(MemHandle);
  100.      for lauf := 1 to max_Explosions do
  101.         explosions^[lauf ].aktiv := false;
  102.    end
  103.  else
  104.    ready := true;  { Kein Platz für mich }
  105. end;
  106.  
  107. procedure newexplosion(index: word);
  108. var p_i               : word;
  109.     rndcol            : word;
  110.     x3,y3,rx,ry,vx,vy : integer;
  111.     ScaleFak          : Integer;
  112.     SoundVal          : Integer;
  113.  
  114. begin
  115.   with explosions^[index] do
  116.   begin
  117.     aktiv := true; finish := false;
  118.     mx := Random((PortMaxX * 8) div 10) + (PortMaxX div 10);
  119.     my := ((PortMaxY * 3) div 4) - random((PortMaxY * 4) div 7);
  120.     SoundVal := Random(200) + 50;
  121.     Sound(SoundVal);
  122.     rndcol := random(100);
  123.     cfeld[0] := succ(random(maxcolor-1));
  124.     if rndcol > 30 then cfeld[1] := succ(maxcolor-1)
  125.     else cfeld[1] := cfeld[0];
  126.     if rndcol > 60 then cfeld[2] := succ(random(maxcolor-1))
  127.     else cfeld[2] := cfeld[0];
  128.     anz_p := anz_points div anz_explosions;
  129.     ry := 0;
  130.     x3 := mx shl 5;
  131.     y3 := my shl 5;
  132.     ScaleFak := Random(12000) + 3000;
  133.     for p_i := 1 to anz_p do
  134.       with points[p_i] do
  135.       begin
  136.         x := x3;y := y3;
  137.         farbe := cfeld[p_i mod 3];
  138.         dauer := succ(random(50));
  139.         repeat
  140.           rx := ry;
  141.           ry := random(256);
  142.           vx := rx-128;
  143.           vy := ry-128;
  144.         until (vx*vx + vy*vy) < ScaleFak;
  145.         dx :=  dxmin + integer((rx*xdiff) shr 8);
  146.         dy := -dymin + integer((ry*ydiff) shr 8);
  147.       end;
  148.     end;
  149.   nosound;
  150. end;
  151.  
  152.  
  153. begin
  154.   initexplosions;
  155.   maxxval  := portmaxx shl 5;
  156.   maxyval  := portmaxy shl 5;
  157.   Ready    := False;
  158.   NextRand := Random(20*anz_points) + 10*anz_points;
  159.   while not Ready do
  160.     begin
  161.       e_no     := succ((e_no mod max_explosions));
  162.       NextRand := Pred(NextRand);
  163.       If (NextRand = 0) Then
  164.         Begin
  165.           anz_explosions := succ(Integer(Random(10)));
  166.           NextRand       := Random(20*anz_points) + 10*anz_points ;
  167.         End;
  168.       with explosions^[e_no] do
  169.         begin
  170.           if not aktiv then
  171.             if e_no <= anz_explosions then
  172.               newexplosion(e_no);
  173.           if aktiv then
  174.             begin
  175.               aktiv := false;
  176.               for p_i := 1 to anz_p do
  177.                 with points[p_i] do
  178.                   begin
  179.                     if dauer > 0 then SetPoint(x shr 5, y shr 5, 0)
  180.                     else setpoint(0,0,0);
  181.                     inc(x,dx);
  182.                     inc(y,dy);
  183.                     inc(dy,3);
  184.                     if finish then dec(dauer);
  185.                     if x >= maxxval then dauer := 0;
  186.                     if y >= maxyval then
  187.                       begin
  188.                         dauer := 0;
  189.                         finish := true;
  190.                       end;
  191.                     if dauer > 0 then
  192.                       begin
  193.                         setpoint(x shr 5, y shr 5, farbe);
  194.                         aktiv := true;
  195.                       end
  196.                     else setpoint(0,0,0);
  197.                   end;
  198.             end;
  199.         end;
  200.       CheckReady;
  201.     end;
  202.  
  203.   DeAllocatePage(MemHandle);
  204.  
  205. end;
  206.  
  207. procedure setallpalette(var new_palette: t_palette);
  208. var regs : dos.registers;
  209. begin
  210. end;
  211.  
  212. function points : word;
  213. var pno, error : integer;
  214. begin
  215.   points := max_points;
  216. end;
  217.  
  218.  
  219. end.
  220.