⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftbg.htm

📁 关于windows游戏编程的一些文章还有相关图形
💻 HTM
字号:
<!--Header-->
<HTML>
<HEAD>
<TITLE>GPMega - Beginners Section - Further Into Tile Techniques</TITLE>
</HEAD>
<BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#00FF00 VLINK=#00FF00 ALINK=#0000FF>
<!--End Header-->
<!--Advertiser-->
<CENTER>
<TABLE>
<TR>
<TD>
<A HREF="http://www.ugo.com/">
<IMG SRC="/GPMega/ugologo120.gif" BORDER=0 WIDTH=120 HEIGHT=60></A>
</TD>
<TD>
<IMG SRC="/GPMega/sponsored.gif" WIDTH=468 HEIGHT=10><br><br>
<SCRIPT LANGUAGE= "JavaScript">
<!--
var now = new Date();
var random_num = now.getSeconds();
document.write("<A HREF='http://www.ugo.net/RealMedia/ads/click_nx.cgi/www.perplexed.com/GPMega/beginners/ftbg.htm/" + random_num + "/@Top'>");
document.write("<IMG SRC='http://www.ugo.net/RealMedia/ads/adstream_nx.cgi/www.perplexed.com/GPMega/beginners/ftbg.htm/" + random_num + "/@Top' BORDER='0' WIDTH='468' HEIGHT='60'></A>");
//-->
</SCRIPT>
</TD>
</TR>
</TABLE>
</CENTER>
<!--End Advertiser-->
<!--Splitter-->
<BR>
<!--End Splitter-->
<!--Body-->
<FONT SIZE=2 FACE=Helvetica>
<STRONG>
<!--Top Navigation-->
<A NAME="top"></A>
<CENTER>
<TABLE WIDTH=75%>
   <TR VALIGN=MIDDLE>
   <TD ALIGN=LEFT>
      <IMG SRC="gradsplit2.jpg" WIDTH=100% HEIGHT=1><BR><BR>
      <A HREF="http://www.perplexed.com/GPMega/"><IMG SRC="logo.jpg" BORDER=0 ALT="Home" WIDTH=80 HEIGHT=47 ALIGN=CENTER></A>
      <FONT COLOR=#666666 FACE=HELVETICA SIZE=-1><I>
      This Article Is Taken From <A HREF="http://www.perplexed.com/GPMega/">The Game Programming MegaSite</A>, A Definitive Resource For Game Developers!
      </I></FONT><BR>
      <IMG SRC="gradsplit2.jpg" WIDTH=100% HEIGHT=1>
   </TD>
   </TR>
</TABLE>
</CENTER>
<BR><!--End Top Navigation-->
<!--Title-->
<H3 ALIGN=CENTER><font color="#FFF600">F</font><font color="#FFED00">u</font><font color="#FFE400">r</font><font color="#FFDB00">t</font><font color="#FFD200">h</font><font color="#FFC900">e</font><font color="#FFC000">r</font><font color="#FFB700"> </font><font color="#FFAE00">I</font><font color="#FFA500">n</font><font color="#FF9C00">t</font><font color="#FF9300">o</font><font color="#FF8A00"> </font><font color="#FF8100">T</font><font color="#FF7800">i</font><font color="#FF6F00">l</font><font color="#FF6600">e</font><font color="#FF5D00"> </font><font color="#FF5400">T</font><font color="#FF4B00">e</font><font color="#FF4200">c</font><font color="#FF3900">h</font><font color="#FF3000">n</font><font color="#FF2700">i</font><font color="#FF1E00">q</font><font color="#FF1500">u</font><font color="#FF0C00">e</font><font color="#FF0300">s</font><BR><FONT SIZE=-2>By: <A HREF="mailto:JiiQ@SoftHome.net">JiiQ</A></FONT></H3>
<!--End Title-->

<H3><FONT COLOR=YELLOW><I>Introduction</I></FONT></H3>

	<P>This is something I threw together after reading all of the other very excellent tile algorthims found on GPMega.
	In this tutorial, I'll show you how to do most of what was said in those, with some of my own twists and improvements.


<H3><FONT COLOR=YELLOW><I>Maps are HUGE</I></FONT></H3>

	<P>This has to be the most important aspect of tile based game programming. The size of your map array determines
	how much memory is needed to play the game, and even how big the file size of your exe/dat/map
	files are. Let's start from the beginning.

	<P>Most tile based games define a tile structure that holds info on each tile of the map, and so the members in those
	structures need to be as few and as small as possible. You say you want to include things like frame-delay times,
	a bitmap index for each frame, movability, and even more in your tiles? Trying to save an array of structures with
	alot of big members into a map file (or in any other format) will really hog disk space (and take forever to download). One solution to this is
	RLE compression, where instead of writing each tile at a time into the file, you write an extra number for each tile.
	The extra being the number of tiles ahead of that one that are exactly the
	same. Therefore skipping the need to write any continous identicles into the map file. But being a structure array, and having to check,
	compare, and save each member at a time, this tends to be more trouble than it's worth. The other big issue is the
	memory your map will be hogging. It's just not necessary.


<H3><FONT COLOR=YELLOW><I>Creating Tile Properties Seperate</I></FONT></H3>

	<P>First, create a 'tile_properties' structure. In this structure, include all of the static properties that are used
	in your map. For an example, say you have a grass tile that is movable, and sways the grass back and forth as if the
	wind is blowing. All of these properties are static, meaning they will never change. If, however, you're creating a top-down
	perspective, and have something like say a tree placed on only certain grass tiles, that would not be a static property.
	Because not every grass tile will have a tree. You could easily create two static 'tile_properties' members though.
	One for grass, and one for grass with a tree. This is actually not a big deal.

	<p>Anyway, back to the tile_properties array. This array will only be as big as the number of different tiles you
	will have in your game (or the current level, ect), and will look like this:

<PRE><FONT COLOR=RED SIZE=2>

	struct tile_properties {

		int bitmap1, bitmap2, ect..		// For each frame if animated
		int delay_1, delay_2, ect..		// Also for each frame if animated
		int movable;				// If it can be walked on
		ect..					// Any number of other properties

	} tile_info[256];

</FONT></PRE>

	<P>You don't have to declare the tile_info array gobal as it seems I did above, but it may be necessary.
	Also the number (256) would be the actual ammount of different types of tiles you want to have.
	As you can see, I declared everything as int's, and not unsigned char's. The reason being that integers are
	faster to work with, and after reading on, you'll find that size isn't as big an issue in this array.


<H3><FONT COLOR=YELLOW><I>Creating the Actual Map Array</I></FONT></H3>

	<P>Before creating your map array, you need to decide how static your tiles are. If you keep characters and/or
	items stored in your tiles, you will need to create a new structure for your map to
	include those certain non-static properties into the members of your array. But first let me show you
	how to create a completely static set of tiles:

<PRE><FONT COLOR=RED SIZE=2>

	unsigned char map[MAP_X_MAX][MAP_Y_MAX];

	// or if you use pointers:

	unsigned char *map;

</FONT></PRE>

	<P>Yep, that's it. Your map array only holds one value, ranging from 0-255, for each property index.
	If you need more property types, you can declare your map as integers (this also might actually make
	it faster to work with). To assign a tile in your map to contain the certain unique properties of say tile_properties[3],
	simply do the following:

<PRE><FONT COLOR=RED SIZE=2>

	// For arrays:

	map[x][y] = 3;

	// For pointers:

	*(map+x+(y*width)) = 3;

</FONT></PRE>

	<P>And for accessing the properties of a map tile, lets just pretend we're in the middle of a move-guy function,
	and we need to check a certain tile to see if it's movable. Also pretend this function recieves the x and y
	values of the tile to check, to keep it simple:

<PRE><FONT COLOR=RED SIZE=2>

	int check_movable(int x, int y) {

		return tile_properties[map[x][y]].movable;

		// or tile_properties[*(map+x+(y*width))].movable for pointers

	}

</FONT></PRE>

	<P>When updating regular tile routines, like changing frames, you now only need to update the tile_properties
	array, and not even touch the map array.
	As you can see, we're not losing any functionality, and at the same time making our map array faster to work with and reducing the size of it
	tremendously. As said above, this method is for static-tiles only. Meaning other tiles of the same type don't
	contain any different information. But if you want, say a grass tile, to sometimes be non-movable, you would need
	to create two grass-type tile_property entries. One for movable, and one for not. This is actually not a big
	deal if you ask me, but there may be unique cases where it is. So below is the solution:

<PRE><FONT COLOR=RED SIZE=2>

	struct map_tiles {

		unsigned char p;
		int movable;

	} map[MAP_X_MAX][MAP_Y_MAX];

</FONT></PRE>

	<P>You can also declare any additional members you need for other non-static properties. The 'p' member
	is actually the same as all of the examples above, where <FONT COLOR=RED SIZE=2>map[x][y].p</FONT>
	would replace the plain <FONT COLOR=RED SIZE=2>map[x][y]</FONT>. For example:


<PRE><FONT COLOR=RED SIZE=2>

	int check_movable(int x, int y) {

		return tile_properties[map[x][y].p].movable;

		// or tile_properties[(map+x+(y*width))->p].movable for pointers

	}

</FONT></PRE>

	<P>Accessing the non-static properties would be doing so without the use of tile_properties:


<PRE><FONT COLOR=RED SIZE=2>

	int check_for_guy(int x, int y) {

		return map[x][y].is_guy_here;

		// or *(map+x+(y*width))->is_guy_here for pointers

	}

</FONT></PRE>

	<P>This tactic doesn't limit you in any way. And just as a note, I've never needed
	non-static tiles, and never had the need to create a structure for the map array. You can do just
	about everything without it, so it makes it that much better.
	If you have any ideas that add to mine, or surpass mine, I would love to hear about them. Please
	send me an email.</P>

<!--Bottom Navigation-->
<A NAME="bottom"></A>
<!--End Bottom Navigation-->
</STRONG>
</FONT>
<!--End Body-->
<!--Bottom-->
<BR>
<IMG SRC="gradbar.jpg">
<BR>
<FONT SIZE=2 COLOR=#8B8B8B FACE=Helvetica>
<I><font color="#FBFBFB">T</font><font color="#F7F7F7">h</font><font color="#F3F3F3">e</font><font color="#EFEFEF"> </font><font color="#EBEBEB">G</font><font color="#E7E7E7">a</font><font color="#E3E3E3">m</font><font color="#DFDFDF">e</font><font color="#DBDBDB"> </font><font color="#D7D7D7">P</font><font color="#D3D3D3">r</font><font color="#CFCFCF">o</font><font color="#CBCBCB">g</font><font color="#C7C7C7">r</font><font color="#C3C3C3">a</font><font color="#BFBFBF">m</font><font color="#BBBBBB">m</font><font color="#B7B7B7">i</font><font color="#B3B3B3">n</font><font color="#AFAFAF">g</font><font color="#ABABAB"> </font><font color="#A7A7A7">M</font><font color="#A3A3A3">e</font><font color="#9F9F9F">g</font><font color="#9B9B9B">a</font><font color="#979797">S</font><font color="#939393">i</font><font color="#8F8F8F">t</font><font color="#8B8B8B">e</font> - 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -