<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Terrain with masked bitmaps</title>
		<link>http://www.allegro.cc/forums/view/590388</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 05 Mar 2007 17:51:57 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I would like to code a game that has Liero-style terrain destruction. (Think worms, scorched earth, etc). I get the theory behind what I am trying to do, I am just having trouble thinking about how to translate it into code.</p><p>Maps have two bitmaps: the actual fresh, clean map that isn&#39;t touched, and the mask, that has the information about which pixels can be destroyed, solid, already empty, etc.</p><p>To accomplish this, I need to be able to do this:<br /><a href="http://img258.imageshack.us/img258/7730/masksdn9.png">http://img258.imageshack.us/img258/7730/masksdn9.png</a></p><p>I do not believe the magic pink color would not work for this method, because there will be multiple colors that I will be checking.</p><p>Thank you for your help <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ingo)</author>
		<pubDate>Mon, 05 Mar 2007 00:33:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What do you mean by &#39;checking multiple colours&#39;?<br />You can only (AFAIK) use magic pink or palette[0] as invisible...</p><p>EDIT:<br />I am doing destructable environments in my current game. I haven&#39;t started coding it yet, but when I was thinking I ran into a problem: Magic pink is invisible, so drawing that on to something will have no difference. You blit the mask on and then use a couple of nested for loops to convert your mask colour to magic pink. Unless anybody knows of a more elegant solution...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Mon, 05 Mar 2007 03:33:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Magic pink is invisible, so drawing that on to something will have no difference.
</p></div></div><p>Unless you use regular blit <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kauhiz)</author>
		<pubDate>Mon, 05 Mar 2007 03:50:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I used <a href="http://www.allegro.cc/forums/thread/286840/287306#target">this post</a> to help me, but it required a lot of changing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 05 Mar 2007 03:58:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I know, you can only use the magic pink by default. This is why I am not asking anything about the built in functions.</p><p>Like i said before, there will be the map that looks all pretty, and then a colored mask for that map. To explain in more detail, the colored mask has different colors to specify what&#39;s going on. For example, anything that is black is solid, anything that is grey is destroyable, anything that is red is insta-death, anything that is white is free space. I am horrible about explaining things, so here is a diagram i found:</p><p><a href="http://jnrdev.72dpiarmy.com/en/jnrdev5/files/1_bmp2map.gif">http://jnrdev.72dpiarmy.com/en/jnrdev5/files/1_bmp2map.gif</a></p><p>that should pretty much explain it. See how the mask is multicolored? Basically i want to use the mask as a cookie cutter. Any pixel on the mask that is white, don&#39;t draw it when displaying the map. there are <b>two</b> bitmaps- a mask and a map. The map isn&#39;t manipulated at all at runtime, only the mask. Does this make more sense?</p><p>Thank you for all your responses. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ingo)</author>
		<pubDate>Mon, 05 Mar 2007 04:32:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Er, just use three bitmaps. Draw the entire terrain mask, and when you destroy terrain form that, blit the transparent mask color to it. Then blit the non-destroyable mask over the destroyable mask, that way one cannot destroy the non-destroyable mask.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 05 Mar 2007 04:39:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the replies, but my main question still hasn&#39;t been answered (although I am getting some good extra information). So people understand, I&#39;ll try once more to see if this makes more sense on what I am asking.</p><p>I have mask.bmp and map.bmp. They are the same size. How do I get map.bmp to only display what the mask wants?</p><p>Here is that picture again:<br /><a href="http://img258.imageshack.us/img258/7730/masksdn9.png">http://img258.imageshack.us/img258/7730/masksdn9.png</a><br />Showing mask.bmp and map.bmp, and the final screen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ingo)</author>
		<pubDate>Mon, 05 Mar 2007 05:34:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The only way I can think of doing this would be to use <span class="source-code"><a href="http://www.allegro.cc/manual/putpixel" target="_blank"><span class="a">putpixel</span></a></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a></span></p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> terrain<span class="k2">;</span></td></tr><tr><td class="number">2</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> mask<span class="k2">;</span></td></tr><tr><td class="number">3</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> map<span class="k2">;</span></td></tr><tr><td class="number">4</td><td><a href="http://www.allegro.cc/manual/PALETTE" target="_blank"><span class="a">PALETTE</span></a> palette<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td>terrain <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"terrain.bmp"</span>, palette<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td>mask <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"mask.bmp"</span>, palette<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>map <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span>terrain-&gt;w, terrain-&gt;h<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td><span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> y <span class="k3">&lt;</span> terrain-&gt;h<span class="k2">;</span> y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">11</td><td><span class="k2">{</span></td></tr><tr><td class="number">12</td><td>  <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> x <span class="k3">&lt;</span> terrain-&gt;w<span class="k2">;</span> x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">13</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">14</td><td>    <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a><span class="k2">(</span>mask, x, y<span class="k2">)</span> <span class="k3">=</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="c">/*YOUR MASK COLOR HERE*/</span><span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">15</td><td>    <span class="k2">{</span></td></tr><tr><td class="number">16</td><td>      <a href="http://www.allegro.cc/manual/putpixel" target="_blank"><span class="a">putpixel</span></a><span class="k2">(</span>map, x, y, <a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a><span class="k2">(</span>terrain, x, y<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">18</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">19</td><td><span class="k2">}</span></td></tr><tr><td class="number">20</td><td>&#160;</td></tr><tr><td class="number">21</td><td><a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>terrain<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td><a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>mask<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td><a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>map<span class="k2">)</span><span class="k2">;</span></td></tr></tbody></table></div></div><p>

I didn&#39;t compile that of course.  I hope that&#39;s what you were looking for.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Dalrymple)</author>
		<pubDate>Mon, 05 Mar 2007 05:46:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Exactly what I was looking for, Matthew! Thanks a bunch. Also, thanks to all who inputted, you&#39;ve given me solutions to other questions too. Cheers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ingo)</author>
		<pubDate>Mon, 05 Mar 2007 05:54:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
makecol(/*YOUR MASK COLOR HERE*/))
</p></div></div><p>
<span class="source-code"><a href="http://www.allegro.cc/manual/bitmap_mask_color" target="_blank"><span class="a">bitmap_mask_color</span></a><span class="k2">(</span><span class="k2">)</span></span><br /><img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /><br />And move it <i>outside</i> the loop. Also, use the &quot;unsafe&quot; versions of getpixel and putpixel to make it a bit less horribly slow. Which leads me to the last point, which is that you don&#39;t want to do that every frame - you&#39;ll want something along the lines of what CGames suggested.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Mon, 05 Mar 2007 06:00:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, I have a function called update_map() that does what Matt suggested. It is only called at the beginning, and then whenever I need the map to change.</p><p>Thanks for the bitmap_mask_color() function.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ingo)</author>
		<pubDate>Mon, 05 Mar 2007 06:54:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I have mask.bmp and map.bmp. They are the same size. How do I get map.bmp to only display what the mask wants?
</p></div></div><p>Okay, that was answered in my first post. But apparently you&#39;re happy with 3 FPS <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Mon, 05 Mar 2007 14:38:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Unless you use regular blit
</p></div></div><p>
If you use a regular blit you have to apply colour to the whole image. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (James Stanley)</author>
		<pubDate>Mon, 05 Mar 2007 17:51:57 +0000</pubDate>
	</item>
</rss>
