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

  1. Unit GMorph; { Geo Morph }
  2.  
  3. { GMorph version 1.5 Copyright (C) 1992 Scott D. Ramsay }
  4.  
  5. {   This unit is specifically for Mode 13h (320x200x256).  It is a    }
  6. { lot faster than using the BGI drivers (VGA256.BGI).  Majority of    }
  7. { the code is written using BASM.  This will work on 286 machines or  }
  8. { higher.                                                             }
  9. {   This unit does tile based maps like the Ultima games, and number- }
  10. { ous share-ware games.  However this unit allows for transparent     }
  11. { tiles, and mutiple background and tile maps as of right now the     }
  12. { tiles can only be 16x16.  Resaon being it allows for fast math      }
  13. { just using shifts, for calcuations. Therefore no Longints, or Reals }
  14. { are used. The code is really, really, really fast for no extra      }
  15. { backgrounds. and not transparent sprite tiles                       }
  16. {    I don't remember where I heard the term GEOMORPH.  Probably on   }
  17. { the net.  Anyway it refers to the tile map sprites to create the    }
  18. { illusion of landscapes.  This works great for side or top view      }
  19. { multi-scrolling games.  Like: Ultima-top view and Super Mario-side. }
  20. { Next time you look at Mario.  Look carefully at the screen.  Every- }
  21. { thing is in blocks.                                                 }
  22. {   GMORPH.TPU can be used freely in commerical and non-commerical    }
  23. { programs.  As long as you don't give yourself credit for writing    }
  24. { this portion of the code.  When distributing it (free only), please }
  25. { include all files and samples so others may enjoy using the code.   }
  26. { Enjoy.                                                              }
  27.  
  28. { Please bear with my comments.  I'm not a tech-writer.  You're more  }
  29. { than welcome to modify the comments in this file for people to      }
  30. { understand.                                                         }
  31.  
  32. { CHANGES from 1.0:                                                   }
  33. {
  34. Interface
  35.  
  36. type
  37.   Pmorph = ^Tmorph;
  38.   Tmorph = object
  39.              ts,                           { bit to shift, for drawmap.      }
  40.                                            {  default. ts=4;                 }
  41.                                            {     ts=1   for sprite  1x1      }
  42.                                            {     ts=2   for sprite  4x4      }
  43.                                            {     ts=3               8x8      }
  44.                                            {     ts=4              16x16     }
  45.                                            {     ts=5              32x32     }
  46.                                            {   The above are the only legal  }
  47.                                            {  sizes for drawmap (Speed). Use }
  48.                                            {  drawmap_n16 for other sizes    }
  49.              gofsx,gofsy,                  { geo unaligned offset            }
  50.                                            {  gofsx,gofsy = (0,0) if perfect }
  51.                                            {  aligned                        }
  52.              gv_width,gv_height : byte;    { Width and height in Num of geos }
  53.                                            {  to calc, display.              }
  54.                                            {  gv_width=0..19                 }
  55.                                            {  gv_height=0..11                }
  56.              gmx,gmy,                      { map dimensions                  }
  57.              gsx,gsy,                      { Size of geomorph.  Default:     }
  58.                                            {  16x16, remember to change for  }
  59.                                            {  different sprite sizes         }
  60.              smapx,smapy        : integer; { top-left positon to display map }
  61.                                            {  recommend: smx = 16..304       }
  62.                                            {             smy = 16..184       }
  63.                                            { once again, I don't boundry     }
  64.                                            { check (I want speed). The       }
  65.                                            { smaller window allows for drawn }
  66.                                            { sprites not to exceede page     }
  67.                                            { boundry. sorry no full screen   }
  68.                                            { tile maps.  I don't even recall }
  69.                                            { ever seeing one?                }
  70.  
  71.              constructor init(geomx,geomy,gvw,gvh,scrx,scry:integer);
  72.              destructor done; virtual;
  73.              function geomap(x,y:integer):integer;virtual;
  74.              procedure drawmap(vx,vy:integer;var geos);virtual;
  75.              procedure drawmap_n16(vx,vy:integer;var geos);virtual;
  76.              procedure placegeo(x,y,geonum:integer;var geos);virtual;
  77.              procedure pre_map; virtual;
  78.              procedure post_map; virtual;
  79.            end;
  80.  
  81.  
  82. { See Implementation section for description of functions }
  83.  
  84. Implementation
  85.  
  86. Uses VgaKern,MiscFunc;
  87.  
  88. (***********************************************************************)
  89. constructor tmorph.init(geomx,geomy,gvw,gvh,scrx,scry:integer);
  90. { I'll show you this method, It inits values }
  91. begin
  92.   gmx := geomx; gmy := geomy;
  93.   gv_width := gvw; gv_height := gvh;
  94.   smapx := scrx; smapy := scry;
  95. end;
  96.  
  97. (***********************************************************************)
  98. destructor tmorph.done;
  99.  
  100.   Doesn't do much, cleanup
  101.  
  102. (***********************************************************************)
  103. procedure tmorph.pre_map;
  104.  
  105.   Uses this to display, images, backgrounds before map is drawn.
  106.   To give appearance of behind.
  107.  
  108.   Must Overide to use.  Does nothing now.
  109.  
  110. (***********************************************************************)
  111. procedure tmorph.post_map;
  112.  
  113.   Uses this to display, images, backgrounds after map is drawn.
  114.   To give appearance of infront of map.
  115.  
  116.   Must Overide to use.  Does nothing now.
  117.  
  118. (***********************************************************************)
  119. procedure tmorph.placegeo(x,y,geonum:integer;var geos);
  120.  
  121.    Places a geo/sprite on the current page at (x,y), geonum
  122.     is the corresponding map number for the specified position.
  123.     (Geos) is the VSP list from Tmorph.DrawMap.
  124.  
  125.     example of PlaceGeo override:
  126.  
  127.        procedure TMyMorph.placegeo(x,y,geonum:integer;var geos);
  128.        var
  129.          vsplist : array[0..16000] of pointer absolute geos;
  130.        begin
  131.          if geonum<>0    { geonum = 0, no geomorph at map location }
  132.            then fbitdraw(x,y,vsplist[geonum-1]^);
  133.  
  134.              - or -
  135.  
  136.          FastWput(x,y,MyVSPlist[geonum]^);  { <- fastest geo map }
  137.        end;
  138.  
  139. { I love using ABSOLUTE, and no-type parameters }
  140.  
  141. (***********************************************************************)
  142. function tmorph.geomap(x,y:integer):integer;
  143.  
  144.    Called by tmorph.drawmap.
  145.  
  146.    Override this method to return the map number at (x,y);
  147.  
  148.    example:
  149.  
  150.        var
  151.          MyMap : array[0..ysize,0..xsize] of integer;
  152.  
  153.        function TMyMorph.GeoMap(x,y:integer):integer;
  154.        begin
  155.          GeoMap := MyMap[y,x];
  156.        end;
  157.  
  158.  
  159. (***********************************************************************)
  160. procedure tmorph.drawmap(vx,vy:integer;var geos);
  161.  
  162.    The main guts method.  Call this to update your map.
  163.    calls: tmorph.pre_map
  164.           tmorph.placegeo
  165.           tmorph.post_map
  166.           
  167.  
  168.    VX,VY : is the user position
  169.    geos  : is the VSPlist
  170.  
  171.    note: VX,VY is always center of the display.
  172.  
  173.          (vx,vy) is in actual coordantes.
  174.          For example, if your geomorph map is 100 geos wide and 50 geos
  175.            high, the actual coordante range for  VX=0..1600,VY=0..800
  176.            (100*16),(50*16) because each geomorph is is a 16x16 box.
  177.          Using this method panning can be done down to the pixel level.
  178.  
  179. (***********************************************************************)
  180. procedure tmorph.drawmap_n16(vx,vy:integer;var geos);
  181.  
  182.     Same as tmorph.drawmap.  Draws other size geomorphs.
  183.    be sure to change GSX and GSY.
  184.  
  185.    e.g.  For a 32x8 sprite, 200x200 map initalize as:
  186.  
  187.       MyMorph := new(Pmorph,init(200,200,100,100,20,20));
  188.       MyMorph^.gsx := 32;
  189.       MyMorph^.gsy := 8;
  190.  
  191. (***********************************************************************)
  192. If you have any problems, e-mail at:
  193.  
  194.     ramsays@access.digex.com
  195.  
  196.   Sorry, I don't have permanent snail-mail address yet.  I just moved
  197.    to the Washington DC area.
  198.  
  199.   The TPU units can be used with in your programs.  If you want the
  200.   source code, more samples or swap-talk, just e-mail me.  I'll give
  201.   sample use-code for free.  Actual TPU-source code prices can be discussed.
  202.  
  203.   Scott D. Ramsay