home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / pascal / passrc / sprite.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-11-18  |  4.2 KB  |  120 lines

  1. { -----------------------------------------------------------------------------
  2.  
  3.                                  NOTICE:
  4.  
  5.       THESE MATERIALS are UNSUPPORTED by OSS!  If you do not understand how to
  6.       use them do not contact OSS for help!  We will not teach you how to 
  7.       program in Pascal.  If you find an error in these materials, feel free
  8.       to SEND US A LETTER explaining the error, and how to fix it.
  9.  
  10.       THE BOTTOM LINE:
  11.  
  12.          Use it, enjoy it, but you are on your own when using these materials!
  13.  
  14.  
  15.                                DISCLAIMER:
  16.  
  17.       OSS makes no representations or warranties with respect to the contents
  18.       hereof and specifically disclaim all warranties of merchantability or
  19.       fitness for any particular purpose.   This document is subject to change
  20.       without notice.
  21.       
  22.       OSS provides these materials for use with Personal Pascal.  Use them in
  23.       any way you wish.
  24.  
  25.    -------------------------------------------------------------------------- }
  26.  
  27.  
  28. PROGRAM sprites ;
  29.  
  30. { this is an example of using two screens, one off screen to save stuff }
  31. { draws a box on a medium rez screen then copies it to an off screen buffer
  32.   in a new location.  Then it copies it back to the physical screen }
  33.  
  34. { by Ron Rautenberg  72777,2277         May 1986
  35.      15 San Juan Dr
  36.      Salinas, Ca 93901
  37.         408-757-6481 }
  38.  
  39.   CONST
  40.     {$I GEMCONST.PAS}
  41.     box_x = 100; box_y = 50;    { dimensions of our box }
  42.     box_wid = 64; box_ht = 20;
  43.  
  44.     new_x = 200; new_y = 100;   { where we're going to move it to }
  45.  
  46.   TYPE
  47.     {$I gemtype.pas}
  48.  
  49.                 { this is for our off screen buffer }
  50.    scrn_memory = array[1..16000] of integer;
  51.  
  52.                 { MFDB for raster copies - must be an array, not a record }
  53.                 { apparantly records aren't allocated sequentially in Pers. P }
  54.    mfdb_fields = (addr1,addr2,wid_pix,ht_pix,wid_wds,flag,num_planes,r1,r2,r3);
  55.    mfdb = array[mfdb_fields] of integer;
  56.  
  57.   VAR
  58.     screen,backup : MFDB;       { one physical, one off-screen }
  59.     screen_buffer : scrn_memory;
  60.  
  61.     msg : Message_Buffer;       { stuff }
  62.     i,key,event : integer;
  63.  
  64.                 { these procedures must be in second module so that we can
  65.                   convert an address to integers }
  66. PROCEDURE init_form(var form : MFDB; var addr : scrn_memory); EXTERNAL;
  67. PROCEDURE copy_rect(var s,d : MFDB;
  68.                   from_x,from_y,to_x,to_y,wid,ht : integer);  EXTERNAL;
  69.  
  70.   {$I gemsubs}          { GEM subroutines }
  71.  
  72. { *************************************************************************** }
  73. { main program }
  74.  
  75.   BEGIN
  76.     IF Init_Gem >= 0 THEN
  77.       BEGIN
  78.          clear_screen;
  79.                 { put some background lines on screen }
  80.          Draw_mode(replace_mode);
  81.          Line_Color(Green);
  82.          Line_Style(Solid);
  83.          for i := 1 to 39 do begin
  84.             Line(i*16,0,i*16,200);
  85.             Line(0,i*5,640,i*5);
  86.          end;
  87.                 { put a figure on top of background }
  88.          Paint_Color(Red);
  89.          Paint_Style(Solid);
  90.          Paint_Rect(box_x,box_y,box_wid,box_ht);
  91.  
  92.                 { initialize screen form }
  93.          screen[addr1] := 0;    { the physical screen }
  94.          screen[addr2] := 0;
  95.  
  96.                 { initialize backup form }
  97.          init_form(backup,screen_buffer);
  98.  
  99.                 { now wait for key press }
  100.          event := Get_Event(E_Keyboard,0,0,0,0,false,0,0,0,0,
  101.                             false,0,0,0,0,msg,key,key,key,key,key,key);
  102.  
  103.                 { and copy stuff to backup screen in new location }
  104.          copy_rect(screen,backup,box_x,box_y,new_x,new_y,box_wid,box_ht);
  105.  
  106.                 { and wait for another key press }
  107.          event := Get_Event(E_Keyboard,0,0,0,0,false,0,0,0,0,
  108.                             false,0,0,0,0,msg,key,key,key,key,key,key);
  109.  
  110.                 { and copy back to screen }
  111.          copy_rect(backup,screen,new_x,new_y,new_x,new_y,box_wid,box_ht);
  112.  
  113.                 { and wait for another key press }
  114.          event := Get_Event(E_Keyboard,0,0,0,0,false,0,0,0,0,
  115.                           false,0,0,0,0,msg,key,key,key,key,key,key);
  116.          Exit_Gem ;
  117.       END ;
  118.   END.                          { Thats all folks }
  119.  
  120.