home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / grafik / sprite / demo6.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-18  |  11.0 KB  |  270 lines

  1. {$R-}    {Bereichsprüfung aus}
  2. {$B+}    {vollständige Auswertung boolscher Ausdrücke}
  3. {$S+}    {Stackprüfung an}
  4. {$I+}    {I/O-Prüfung an}
  5. {$N-}    {kein numerischer Coprozessor}
  6. {$M 65500,16384,655360} {3.0-Standardvorgaben für Stack&Heap}
  7.  
  8.  
  9.     (* ************************************************************** *)
  10.     (*                                                                *)
  11.     (*                        SpriteDemo6.Pas                         *)
  12.     (*                                                                *)
  13.     (*   This program shows how to use sprites for multiple page      *)
  14.     (*   animation. The basic strategy is to use three pages:         *)
  15.     (*   the colorscreen, a hidden workbuffer which is a identical    *)
  16.     (*   and may be written to unseen, and a third buffer which is    *)
  17.     (*   the part of the scene that does not change. One creates      *)
  18.     (*   the background and stores it both in backgroundbuffer and    *)
  19.     (*   in the workbuffer. Next, one writes to the workbuffer        *)
  20.     (*   ( that is, draws the sprites ).  Next the workbuffer is      *)
  21.     (*   displayed by transferring it to the colorscreen. Then one    *)
  22.     (*   erases the workbuffer by transferring the backgroundbuffer   *)
  23.     (*   to it. The now blank workscreen can again be modified,       *)
  24.     (*   displayed, and erased again ... and again ... and ...        *)
  25.     (*                                                                *)
  26.     (*   The workbuffer and the backgroundbuffer each use 16K of      *)
  27.     (*   your data segment ( 32K out of your total of 64K ). You can  *)
  28.     (*   easily reduce this to 16K if after writing the background-   *)
  29.     (*   buffer you store it in the heapspace rather than in the      *)
  30.     (*   the data segment. However, in this small program it is not   *)
  31.     (*   necessary.                                                   *)
  32.     (*                                                                *)
  33.     (*   These techniques are similar to those of Demo1, but the      *)
  34.     (*   present example is more complicated.                         *)
  35.     (*                                                                *)
  36.     (*                            (c) Donald L. Pavia                 *)
  37.     (*        Ver 2.0             Department of Chemistry             *)
  38.     (*                            Western Washington University       *)
  39.     (*                            Bellingham, Washington  98225       *)
  40.     (*                                         January 25, 1986       *)
  41.     (*                                                                *)
  42.     (* ************************************************************** *)
  43.  
  44. program SpriteDemo6;
  45.  
  46. {----------------------------------------------------------------------------}
  47.  
  48. uses
  49.   Crt,
  50.   turbo3,
  51.   Graph3;
  52.  
  53. {$I Sprites.Lib}
  54. {----------------------------------------------------------------------------}
  55.  
  56. const SoundOn : boolean = true;
  57.  
  58. var   k,l : integer;
  59.  
  60. {----------------------------------------------------------------------------}
  61. procedure Introduction;
  62.  
  63. begin
  64.      TextColor (3);
  65.      gotoxy (2,5); write ('TURBO PASCAL');
  66.      TextColor (1);
  67.      gotoxy (7,7); write ('SPRITE DESIGNER');
  68.      TextColor (3);
  69.      gotoxy (12,9); write ('AND');
  70.      TextColor (1); write (' ANIMATION PACKAGE ');
  71.      TextColor (3); write ('DEMO');
  72.      gotoxy (1,21); write ('Action Continues Until a KeyPress');
  73.      gotoxy (1,23); write ('Donald Pavia, December 1985');
  74.      gotoxy (29,17); TextColor (2);
  75.      gotoxy (25,17); write ('Press <Enter>');
  76.      TextColor (3);
  77.      read (kbd,Wait);
  78. {! 4. Kbd e^rfordert das Unit Turbo3 - verwenden Sie ReadKey (im Unit Crt)}
  79.  
  80. end; { procedure Introduction }
  81. {----------------------------------------------------------------------------}
  82.  
  83. BEGIN
  84.      clrscr;
  85.      GraphColorMode; GraphBackGround (1); Palette (2);
  86.  
  87.      WorkBuffer := ColorBuffer;     { copy blank screen into workbuffer }
  88.  
  89.      LoadTable ('DEMO1.TAB');       { load the table of sprites }
  90.  
  91.      Introduction;
  92.  
  93. REPEAT
  94.         {----- Create BackGround Screen and Display ------------------}
  95.  
  96.          for times := 1 to 14 do
  97.             begin                { XorSpriteW writes to hidden workbuffer }
  98.                                  { - row of 14 dwarf sprites is created   }
  99.  
  100.               Sprite := Table[ 9];            { Dwarf1 - upper body }
  101.               XorSpriteW (20 * times,90);
  102.  
  103.               Sprite := Table[17];            { Dwarf2 - lower body }
  104.               XorSpriteW (20 * times,110);
  105.  
  106.             end;
  107.  
  108.      ColorBuffer := WorkBuffer;              { display workbuffer }
  109.  
  110.      BackGroundBuffer := WorkBuffer;   { copy workbuffer into background  }
  111.                                        { to use for refresh of workbuffer }
  112.         {------------------------------------------------------------}
  113.  
  114.   Repeat
  115.      count := 8;
  116.  
  117.      (* ******* REPEAT LOOP ONE ************************************* *)
  118.  
  119.      repeat
  120.  
  121.         {-- Display Cycle One ----------------------------------------}
  122.                                      { write to blank workbuffer }
  123.          count := count + 8;
  124.  
  125.          Sprite := Table[12]; XorSpriteW (220,20);         {Dragon}
  126.  
  127.          Sprite := Table[2];                               {Dog1}
  128.          if count < 307 then XorSpriteW (count,153);
  129.  
  130.          Sprite := Table[5];                               {Duck1}
  131.          if count < 300 then XorSpriteW (count+8,141);
  132.  
  133.          Sprite := Table[20];                              {Boy1}
  134.          if (count >48) and (count < 204) then XorSpriteW (count-40,140);
  135.  
  136.          Sprite := Table[20];                              {Boy1}
  137.          if count >= 204 then XorSpriteW (164,140);
  138.  
  139.          ColorBuffer := WorkBuffer;           { display workbuffer }
  140.          WorkBuffer := BackGroundBuffer;      { erase workbuffer   }
  141.  
  142.         {-- Display Cycle Two ----------------------------------------}
  143.                                        { write to blank workbuffer }
  144.          count := count + 8;
  145.  
  146.          Sprite := Table[13]; XorSpriteW (220,20);         {Dragon2}
  147.  
  148.          Sprite := Table[3];                               {Dog2}
  149.          if count < 307 then XorSpriteW (count,153);
  150.  
  151.          Sprite := Table[6];                               {Duck2}
  152.          if count < 300 then XorSpriteW (count+16,136);
  153.  
  154.          Sprite := Table[21];                              {Boy2}
  155.          if (count > 56) and (count < 212) then XorSpriteW (count-40,140);
  156.  
  157.          Sprite := Table[20];                              {Boy1}
  158.          if (count > 212) then XorSpriteW (164,140);
  159.  
  160.          ColorBuffer := WorkBuffer;           { display workbuffer }
  161.          WorkBuffer := BackGroundBuffer;      { erase workbuffer   }
  162.  
  163.         {-------------------------------------------------------------}
  164.                                        { naive attempt at dog bark }
  165.          if SoundOn then begin
  166.            if ((count > 32) and (count < 128))
  167.             or (count > 210) then   begin
  168.            Sound ( 40); delay (10);   Sound (120); delay (20);
  169.            Sound (400); delay (15);   Sound (880); delay (20);
  170.            Sound (1600); NoSound;   end;   end;
  171.         {-------------------------------------------------------------}
  172.  
  173.      until count >= 340;
  174.  
  175.      (* ******* END LOOP ONE ****************************************** *)
  176.  
  177.      count := 4;
  178.  
  179.      (* ******** REPEAT LOOP TWO ************************************* *)
  180.  
  181.      repeat
  182.         {-- Display Cycle Three --------------------------------------}
  183.                                          { write to hidden workbuffer }
  184.          count := count + 8;
  185.  
  186.          Sprite := Table[12]; XorSpriteW (220,20);         {Dragon}
  187.  
  188.          Sprite := Table[23];  XorSpriteW (244,20);        {Blast}
  189.  
  190.          Sprite := Table[2];                               {Dog1}
  191.          if count < 307 then XorSpriteW (count,153);
  192.  
  193.          Sprite := Table[5];                               {Duck1}
  194.          if count < 300 then XorSpriteW (count+8,141);
  195.  
  196.          Sprite := Table[22];                              {Boy3}
  197.          if count < 180 then XorSpriteW (164,140);
  198.  
  199.          if (count >= 180) and (count < 204) then begin
  200.                 Sprite := Table[20];                       {Boy1}
  201.                 XorSpriteW (164,140); end;
  202.  
  203.          Sprite := Table[20];                              {Boy1}
  204.          if count >= 204 then XorSpriteW (count-40,140);
  205.  
  206.          ColorBuffer := WorkBuffer;             { display workbuffer }
  207.          WorkBuffer := BackGroundBuffer;        { erase workbuffer   }
  208.  
  209.         {-- Display Cycle Four ---------------------------------------}
  210.                                          { write to hidden workbuffer }
  211.          count := count + 8;
  212.  
  213.          Sprite := Table[13]; XorSpriteW (220,20);         {Dragon2}
  214.  
  215.          Sprite := Table[3];                               {Dog2}
  216.          if count < 307 then XorSpriteW (count,153);
  217.  
  218.          Sprite := Table[6];                               {Duck2}
  219.          if count < 300 then XorSpriteW (count+16,136);
  220.  
  221.          Sprite := Table[22];                              {Boy3}
  222.          if (count < 188) then XorSpriteW (164,140);
  223.  
  224.          if (count >= 188) and (count < 212) then begin
  225.                  Sprite := Table[20];                      {Boy1}
  226.                  XorSpriteW (164,140); end;
  227.  
  228.          Sprite := Table[21];                              {Boy2}
  229.          if count >= 212 then XorSpriteW (count-40,140);
  230.  
  231.          ColorBuffer := WorkBuffer;           { display workbuffer }
  232.          WorkBuffer := BackGroundBuffer;      { erase workbuffer   }
  233.  
  234.     {--------------------------------------------------------------}
  235.                                      { barking again }
  236.          if SoundOn then begin
  237.            if ((count > 32) and (count < 128))
  238.             or (count > 210) then   begin
  239.            Sound ( 40); delay (10);   Sound (120); delay (20);
  240.            Sound (400); delay (15);   Sound (880); delay (20);
  241.            Sound (1600); NoSound;   end;   end;
  242.     {-------------------------------------------------------------}
  243.  
  244.      until count >= 340;
  245.  
  246.     (* ******** END LOOP TWO ************************************* *)
  247.  
  248.    Until keypressed;
  249.  
  250.    {---------------------------------------------------------------------}
  251.      FIllChar (ColorBuffer,16192,0);             { erase everything }
  252.      FillChar (WorkBuffer,16192,0);              { clrscr doesn't   }
  253.      FillChar (BackGroundBuffer,16192,0);        { work in graphics }
  254.  
  255.      gotoxy (10,10); write ('Repeat Again ? Y/N ?  ');
  256.        repeat
  257.           read (Kbd,Again);
  258. {! 5. Kbd erford^ert das Unit Turbo3 - verwenden Sie ReadKey (im Unit Crt)}
  259.        until UpCase(Again) in ['Y','N'];
  260.  
  261.      FillChar (WorkBuffer,16383,0);
  262.    {---------------------------------------------------------------------}
  263.  
  264. UNTIL UpCase(Again) = 'N';
  265.  
  266.       gotoxy (1,23);
  267.       TextMode (c80); clrscr;                     { exit gracefully }
  268.  
  269. END.
  270.