home *** CD-ROM | disk | FTP | other *** search
- Unit GMorph; { Geo Morph }
-
- { GMorph version 1.5 Copyright (C) 1992 Scott D. Ramsay }
-
- { This unit is specifically for Mode 13h (320x200x256). It is a }
- { lot faster than using the BGI drivers (VGA256.BGI). Majority of }
- { the code is written using BASM. This will work on 286 machines or }
- { higher. }
- { This unit does tile based maps like the Ultima games, and number- }
- { ous share-ware games. However this unit allows for transparent }
- { tiles, and mutiple background and tile maps as of right now the }
- { tiles can only be 16x16. Resaon being it allows for fast math }
- { just using shifts, for calcuations. Therefore no Longints, or Reals }
- { are used. The code is really, really, really fast for no extra }
- { backgrounds. and not transparent sprite tiles }
- { I don't remember where I heard the term GEOMORPH. Probably on }
- { the net. Anyway it refers to the tile map sprites to create the }
- { illusion of landscapes. This works great for side or top view }
- { multi-scrolling games. Like: Ultima-top view and Super Mario-side. }
- { Next time you look at Mario. Look carefully at the screen. Every- }
- { thing is in blocks. }
- { GMORPH.TPU can be used freely in commerical and non-commerical }
- { programs. As long as you don't give yourself credit for writing }
- { this portion of the code. When distributing it (free only), please }
- { include all files and samples so others may enjoy using the code. }
- { Enjoy. }
-
- { Please bear with my comments. I'm not a tech-writer. You're more }
- { than welcome to modify the comments in this file for people to }
- { understand. }
-
- { CHANGES from 1.0: }
- {
- Interface
-
- type
- Pmorph = ^Tmorph;
- Tmorph = object
- ts, { bit to shift, for drawmap. }
- { default. ts=4; }
- { ts=1 for sprite 1x1 }
- { ts=2 for sprite 4x4 }
- { ts=3 8x8 }
- { ts=4 16x16 }
- { ts=5 32x32 }
- { The above are the only legal }
- { sizes for drawmap (Speed). Use }
- { drawmap_n16 for other sizes }
- gofsx,gofsy, { geo unaligned offset }
- { gofsx,gofsy = (0,0) if perfect }
- { aligned }
- gv_width,gv_height : byte; { Width and height in Num of geos }
- { to calc, display. }
- { gv_width=0..19 }
- { gv_height=0..11 }
- gmx,gmy, { map dimensions }
- gsx,gsy, { Size of geomorph. Default: }
- { 16x16, remember to change for }
- { different sprite sizes }
- smapx,smapy : integer; { top-left positon to display map }
- { recommend: smx = 16..304 }
- { smy = 16..184 }
- { once again, I don't boundry }
- { check (I want speed). The }
- { smaller window allows for drawn }
- { sprites not to exceede page }
- { boundry. sorry no full screen }
- { tile maps. I don't even recall }
- { ever seeing one? }
-
- constructor init(geomx,geomy,gvw,gvh,scrx,scry:integer);
- destructor done; virtual;
- function geomap(x,y:integer):integer;virtual;
- procedure drawmap(vx,vy:integer;var geos);virtual;
- procedure drawmap_n16(vx,vy:integer;var geos);virtual;
- procedure placegeo(x,y,geonum:integer;var geos);virtual;
- procedure pre_map; virtual;
- procedure post_map; virtual;
- end;
-
-
- { See Implementation section for description of functions }
-
- Implementation
-
- Uses VgaKern,MiscFunc;
-
- (***********************************************************************)
- constructor tmorph.init(geomx,geomy,gvw,gvh,scrx,scry:integer);
- { I'll show you this method, It inits values }
- begin
- gmx := geomx; gmy := geomy;
- gv_width := gvw; gv_height := gvh;
- smapx := scrx; smapy := scry;
- end;
-
- (***********************************************************************)
- destructor tmorph.done;
-
- Doesn't do much, cleanup
-
- (***********************************************************************)
- procedure tmorph.pre_map;
-
- Uses this to display, images, backgrounds before map is drawn.
- To give appearance of behind.
-
- Must Overide to use. Does nothing now.
-
- (***********************************************************************)
- procedure tmorph.post_map;
-
- Uses this to display, images, backgrounds after map is drawn.
- To give appearance of infront of map.
-
- Must Overide to use. Does nothing now.
-
- (***********************************************************************)
- procedure tmorph.placegeo(x,y,geonum:integer;var geos);
-
- Places a geo/sprite on the current page at (x,y), geonum
- is the corresponding map number for the specified position.
- (Geos) is the VSP list from Tmorph.DrawMap.
-
- example of PlaceGeo override:
-
- procedure TMyMorph.placegeo(x,y,geonum:integer;var geos);
- var
- vsplist : array[0..16000] of pointer absolute geos;
- begin
- if geonum<>0 { geonum = 0, no geomorph at map location }
- then fbitdraw(x,y,vsplist[geonum-1]^);
-
- - or -
-
- FastWput(x,y,MyVSPlist[geonum]^); { <- fastest geo map }
- end;
-
- { I love using ABSOLUTE, and no-type parameters }
-
- (***********************************************************************)
- function tmorph.geomap(x,y:integer):integer;
-
- Called by tmorph.drawmap.
-
- Override this method to return the map number at (x,y);
-
- example:
-
- var
- MyMap : array[0..ysize,0..xsize] of integer;
-
- function TMyMorph.GeoMap(x,y:integer):integer;
- begin
- GeoMap := MyMap[y,x];
- end;
-
-
- (***********************************************************************)
- procedure tmorph.drawmap(vx,vy:integer;var geos);
-
- The main guts method. Call this to update your map.
- calls: tmorph.pre_map
- tmorph.placegeo
- tmorph.post_map
-
-
- VX,VY : is the user position
- geos : is the VSPlist
-
- note: VX,VY is always center of the display.
-
- (vx,vy) is in actual coordantes.
- For example, if your geomorph map is 100 geos wide and 50 geos
- high, the actual coordante range for VX=0..1600,VY=0..800
- (100*16),(50*16) because each geomorph is is a 16x16 box.
- Using this method panning can be done down to the pixel level.
-
- (***********************************************************************)
- procedure tmorph.drawmap_n16(vx,vy:integer;var geos);
-
- Same as tmorph.drawmap. Draws other size geomorphs.
- be sure to change GSX and GSY.
-
- e.g. For a 32x8 sprite, 200x200 map initalize as:
-
- MyMorph := new(Pmorph,init(200,200,100,100,20,20));
- MyMorph^.gsx := 32;
- MyMorph^.gsy := 8;
-
- (***********************************************************************)
- If you have any problems, e-mail at:
-
- ramsays@access.digex.com
-
- Sorry, I don't have permanent snail-mail address yet. I just moved
- to the Washington DC area.
-
- The TPU units can be used with in your programs. If you want the
- source code, more samples or swap-talk, just e-mail me. I'll give
- sample use-code for free. Actual TPU-source code prices can be discussed.
-
- Scott D. Ramsay