home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / GAMETP.ZIP / GMORPH.INT < prev    next >
Encoding:
Text File  |  1992-10-29  |  8.3 KB  |  203 lines

  1. Unit GMorph; { Geo Morph }
  2.  
  3. { GMorph version 1.0 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. "I don't know about the P5 chip though." ;)                 }
  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. Interface
  33.  
  34. type
  35.   Pmorph = ^Tmorph;
  36.   Tmorph = object
  37.              gofsx,gofsy,                  { geo unaligned offset            }
  38.                                            { gofsx,gofsy = (0,0) if perfect  }
  39.                                            { aligned                         }
  40.              gv_width,gv_height : byte;    { Width and height in Num of geos }
  41.                                            { to calc, display.               }
  42.                                            { gv_width=0..19                  }
  43.                                            { gv_height=0..11                 }
  44.              gmx,gmy,                      { map dimensions                  }
  45.              smapx,smapy        : integer; { top-left positon to display map }
  46.                                            { recommend smx = 16..304         }
  47.                                            {            smy = 16..184        }
  48.                                            { once again, I don't boundry     }
  49.                                            { check (I want speed). The       }
  50.                                            { smaller window allows for drawn }
  51.                                            { sprites not to exceede page     }
  52.                                            { boundry. sorry no full screen   }
  53.                                            { tile maps.  I don't even recall }
  54.                                            { ever seeing one?                }
  55.  
  56.              constructor init(geomx,geomy,gvw,gvh,scrx,scry:integer);
  57.              destructor done; virtual;
  58.              function geomap(x,y:integer):integer;virtual;
  59.              procedure drawmap(vx,vy:integer;var geos);virtual;
  60.              procedure placegeo(x,y,geonum:integer;var geos);virtual;
  61.              procedure pre_map; virtual;
  62.              procedure post_map; virtual;
  63.            end;
  64.  
  65.  
  66. { See Implementation section for description of functions }
  67.  
  68. Implementation
  69.  
  70. Uses VgaKern,MiscFunc;
  71.  
  72. (***********************************************************************)
  73. constructor tmorph.init(geomx,geomy,gvw,gvh,scrx,scry:integer);
  74. { I'll show you this method, It inits values }
  75. begin
  76.   gmx := geomx; gmy := geomy;
  77.   gv_width := gvw; gv_height := gvh;
  78.   smapx := scrx; smapy := scry;
  79. end;
  80.  
  81. (***********************************************************************)
  82. destructor tmorph.done;
  83.  
  84.   Doesn't do much, cleanup
  85.  
  86. (***********************************************************************)
  87. procedure tmorph.pre_map;
  88.  
  89.   Uses this to display, images, backgrounds before map is drawn.
  90.   To give appearance of behind.
  91.  
  92.   Must Overide to use.  Does nothing now.
  93.  
  94. (***********************************************************************)
  95. procedure tmorph.post_map;
  96.  
  97.   Uses this to display, images, backgrounds after map is drawn.
  98.   To give appearance of infront of map.
  99.  
  100.   Must Overide to use.  Does nothing now.
  101.  
  102. (***********************************************************************)
  103. procedure tmorph.placegeo(x,y,geonum:integer;var geos);
  104.  
  105.    Places a geo/sprite on the current page at (x,y), geonum
  106.     is the corresponding map number for the specified position.
  107.     (Geos) is the VSP list from Tmorph.DrawMap.
  108.  
  109.     example of PlaceGeo override:
  110.  
  111.        procedure TMyMorph.placegeo(x,y,geonum:integer;var geos);
  112.        var
  113.          vsplist : array[0..16000] of pointer absolute geos;
  114.        begin
  115.          if geonum<>0    { geonum = 0, no geomorph at map location }
  116.            then fbitdraw(x,y,vsplist[geonum-1]^);
  117.  
  118.              - or -
  119.  
  120.          FastWput(x,y,MyVSPlist[geonum]^);  { <- fastest geo map }
  121.        end;
  122.  
  123. { I love using ABSOLUTE, and no-type parameters }
  124.  
  125. (***********************************************************************)
  126. function tmorph.geomap(x,y:integer):integer;
  127.  
  128.    Called by tmorph.drawmap.
  129.  
  130.    Override this method to return the map number at (x,y);
  131.  
  132.    example:
  133.  
  134.        var
  135.          MyMap : array[0..ysize,0..xsize] of integer;
  136.  
  137.        function TMyMorph.GeoMap(x,y:integer):integer;
  138.        begin
  139.          GeoMap := MyMap[y,x];
  140.        end;
  141.  
  142.  
  143. (***********************************************************************)
  144. procedure tmorph.drawmap(vx,vy:integer;var geos);
  145.  
  146.    The main guts method.  Call this to update your map.
  147.    calls: tmorph.pre_map
  148.           tmorph.placegeo
  149.           tmorph.post_map
  150.           
  151.  
  152.    VX,VY : is the user position
  153.    geos  : is the VSPlist
  154.  
  155.    note: VX,VY is always center of the display.
  156.  
  157.          (vx,vy) is in actual coordantes.
  158.          For example, if your geomorph map is 100 geos wide and 50 geos
  159.            high, the actual coordante range for  VX=0..1600,VY=0..800
  160.            (100*16),(50*16) because each geomorph is is a 16x16 box.
  161.          Using this method panning can be done down to the pixel level.
  162.  
  163. (***********************************************************************)
  164.  
  165.  
  166. If you have any problems, e-mail at:
  167.  
  168.     ramsays@express.digex.com
  169.  
  170.   Sorry, I don't have permanent snail-mail address yet.  I just moved
  171.    to the Washington DC area.
  172.  
  173.   The TPU units can be used with in your programs.  With out giving
  174.    me credit.  If you want the source code, more samples or swap-talk,
  175.    just e-mail me.  I'll give sample use-code for free.  Actual TPU-source
  176.    code prices can be discussed.
  177.  
  178.   Also,  I have completed the following programs.
  179.  
  180.      GEOMAKER        Makes tile-maps quickly.
  181.      VSPMAKER        Makes the VSP files.
  182.      BKMAKER         A drawing program that can read
  183.                       VEW files (my own raw format)
  184.                       PTR files (my own compressed format)
  185.                       GIF files
  186.                       PCX files
  187.  
  188.   The three above programs are specifically designed for the 320x200x256
  189.   (game development).  I'll upload them when I think they are ready
  190.   to go. (Bout a week)
  191.  
  192.   (Artwork samples done by me.  Freeware.  Knock your-self out.
  193.    Plug.  Highly recommended.  For game programmers, try to get
  194.    Animator Pro by Autodesk.  This is an excellent program for
  195.    imaging, sprites and so forth. Very similar to the Animator,
  196.    but has better graphic features.  The 3D models are created
  197.    with 3D studio by Autodesk then ported to Animator Pro, then
  198.    scaled down/converted to my VSP files.  If you can blow a
  199.    few thousand bucks, buy the 3D studio.  You can do some amazing
  200.    3D animations. I can't afford it, I use it at work.)
  201.  
  202.  
  203.    Scott D. Ramsay