home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / g / gametp20.zip / BEFFECTS.INT next >
Text File  |  1992-11-06  |  7KB  |  175 lines

  1. Unit Beffects;
  2.  
  3. Interface
  4.  
  5. Uses VgaKern;
  6.  
  7. { Beffects version 1.5 Copyright (C) 1992 Scott D. Ramsay }
  8.  
  9. {   This unit is specifically for Mode 13h (320x200x256).  It is a    }
  10. { lot faster than using the BGI drivers (VGA256.BGI).  Majority of    }
  11. { the code is written using BASM.  This will work on 286 machines or  }
  12. { higher. "I don't know about the P5 chip though." ;)                 }
  13. {   This is my newest and most favorite unit.     Inspired by         }
  14. { Thunder Force III (I love Sega Genisis shoot-em ups), I wanted to   }
  15. { write games with Paralax Scrolling.  At first I thought PC's were   }
  16. { to slow. But yet I finally did it.  For full screen scrolling,      }
  17. { (320x200) I recommend a 386sx 25mhz.  But for smaller screens a     }
  18. { 16mhz machine is fine.  Even with 286 code.  I did test this on a   }
  19. { 486-50, (at work) but hell, what is slow on that machine. :>        }
  20. {   BEFFECTS.TPU can be used freely in commerical and non-commerical  }
  21. { programs.  As long as you don't give yourself credit for writing    }
  22. { this portion of the code.  When distributing it (free only), please }
  23. { include all files and samples so others may enjoy using the code.   }
  24. { Enjoy.                                                              }
  25.  
  26. { Please bear with my comments.  I'm not a tech-writer.  You're more  }
  27. { than welcome to modify the comments in this file for people to      }
  28. { understand. "Except for my name."  :)                               }
  29.  
  30. { Changes from version 1.0                                            }
  31. {     Added new variables to Tcycle                                   }
  32. {        from_x,from_y     source top-left positon of orig background }
  33. {        cycley            value for moveing vertical position        }
  34. {                            scrolling now supports all directions    }
  35. {     Procedure CycleLine modified to wrap at specified width instead }
  36. {       of a default of 320.                                          }
  37. {     Method TCycle.docycle improved.  Can't tell you how. It is more }
  38. {       efficent.                                                     }
  39.  
  40. const
  41.   wmax = 100;                           { max size for cosine table }
  42.  
  43. type
  44.   usercp       = procedure(f,t,yline:longint);
  45.                                        { type for user defined scrolling }
  46.   Pcycle       = ^Tcycle;
  47.   Tcycle       = object
  48.                    cyc_next,               { internal use value }
  49.                    from_x,from_y,          { top-left of source image }
  50.                    cyc_x,cyc_y,            { window position, top-left }
  51.                    cyc_width,              { window width  }
  52.                    cyc_height,             { window height }
  53.                    cycley,                 { value for moving vert }
  54.                    cyclex,                 { value for moving horiz }
  55.                    fr_size,                { frequency size }
  56.                    am_size         : word; { amplitude size }
  57.                    cycle_cos       : array[0..wmax-1] of integer;
  58.                                            { cosine table }
  59.                    
  60.                    constructor init(freq,size:integer);
  61.                    destructor done;virtual;
  62.                    procedure changewave(freq,size:integer);virtual;
  63.                    procedure docycle(from,too,mode:byte); virtual;
  64.                    procedure cycle_move; virtual;
  65.                  end;
  66.  
  67. { See Implementation section for description of functions }
  68.  
  69. var
  70.   usercycle : usercp;           { see Tcycle.docycle }
  71.  
  72. procedure LineMove(s,d:longint;cnt:word);
  73. procedure WordMove(var source,dest;cnt:word);
  74. procedure cycleline(f,t:longint;cyclex,cycle_width:word);
  75.  
  76. Implementation
  77.  
  78. (***********************************************************************)
  79. procedure linemove(s,d:longint;cnt:word);
  80.  
  81.    Copies (cnt) pixels from (s) to (d)
  82.      Moves in WORDS, cnt should be even and less than or equal to 320.
  83.  
  84. (***********************************************************************)
  85. procedure wordmove(var source,dest;cnt:word);
  86.  
  87.    Same as LineMove, but source and dest can be of any type.
  88.  
  89. (***********************************************************************)
  90. procedure cycleline(f,t:longint;cyclex,cycle_width:word);
  91.  
  92.    Copies a horizontal line length(cycle_width) a (f) to (t) at offset
  93.    of cyclex.  The overlapping pixels  wraps to the other side on
  94.    the same row.  { This is one of the main meat code }
  95.  
  96. (***********************************************************************)
  97. constructor Tcycle.init(freq,size:integer);
  98.  
  99.    freq : Cosine wave frequency
  100.    size : wave amplitude
  101.  
  102.    Sets vaules.  Calls  Tcycle.changewave
  103.  
  104. (***********************************************************************)
  105. destructor Tcycle.done;
  106.  
  107.   Doesn't really do much.
  108.  
  109. (***********************************************************************)
  110. procedure Tcycle.changewave(freq,size:integer);
  111.  
  112.    Recalcs the cosine table with new frequency and amplit. values.
  113.  
  114. (***********************************************************************)
  115. procedure Tcycle.cycle_move;
  116. begin
  117.   cyclex := (cyclex+1)mod 320;
  118. end;
  119.  
  120.   Simple one-liner procedure.  The above just moves cycles the image
  121.   to the left.  Decrementing cyclex moves it to the right.
  122.  
  123.  
  124. (***********************************************************************)
  125. procedure Tcycle.docycle(from,too,mode:byte);
  126.  
  127.    This is the procedure to call to do the cycling.
  128.  
  129.    from  : is the page with the background.
  130.    too   : is the destination of the modified background.
  131.    mode  : is the type of scrolling;
  132.  
  133.            0 : a straight page copy
  134.            1 : cycle left, right
  135.            2 : cycle left, right with cosine wave
  136.            3 : user defined cycle. { here is where you write you SFII
  137.                  scrolling type.  My not OOP version has it.  It takes
  138.                  more variables, e-mail me I'll send it to ya. }
  139.  
  140.    For mode 3,  each row is sent to procedure "usercycle"
  141.      example:
  142.  
  143.         procedure MyUserCycle(f,t,yline:longint);far;
  144.         { must be far procedure }
  145.         begin
  146.           { do line stuff }
  147.         end;
  148.  
  149.           .
  150.           .
  151.           .
  152.  
  153.         usercycle := MyUserCycle;
  154.  
  155.           .
  156.           .
  157.           .
  158.         p^.docycle(4,2,3); { cycle page 4 to page 2, user mode 3 }
  159.  
  160.  
  161.   { This is the other meaty procedure }
  162. (***********************************************************************)
  163.  
  164.  
  165. If you have any problems, e-mail at:
  166.  
  167.     ramsays@access.digex.com
  168.  
  169.     The TPU units can be used freely with in your programs.  If you want
  170.   the source code, more samples or swap-talk, just e-mail me.  I'll
  171.   give sample use-code for free.  Actual TPU-source code prices can be
  172.   discussed.
  173.  
  174.  
  175.    Scott D. Ramsay