<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Pixel perfect collision implementation for allegro 5</title>
		<link>http://www.allegro.cc/forums/view/616330</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 10 Jun 2016 01:06:36 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m making a simple allegro game and I need to detect the collision between two bitmaps. I tried to use the bounding box method, but, since my two sprites aren&#39;t squares nor rectangles, it is pretty unaccurate. Searching around for a solution, I found the so-called pixel perfect method and it is implementable in Allegro 4 with the PMASK library but not in Allegro <b>5</b>. Searching around I found <a href="http://fixbyproximity.com/public_files/MaskedCollisionDemo.zip">this library</a> which does work with Allegro 5, but it&#39;s not fully optimised so the collision detection is not precise. Does someone know how to use this system with Allegro 5 or where I can find a completely working library?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nova99)</author>
		<pubDate>Wed, 08 Jun 2016 01:02:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>you can do it yourself by first checking bounding box then double checking by normalizing the coordinates and using getpixel to see if the normalized coordinate of both bitmaps is non-transparent, for each pixel on one of your bitmaps (or you could be more clever, and only for the pixels in the overlapping sub-region of both bitmaps).</p><p>something like</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">int</span> y<span class="k2">;</span>
<span class="number">  2</span><span class="k1">for</span><span class="k2">(</span>y<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>y<span class="k3">&lt;</span><a href="http://www.allegro.cc/manual/al_get_bitmap_height"><span class="a">al_get_bitmap_height</span></a><span class="k2">(</span>bmp1<span class="k2">)</span><span class="k2">;</span><span class="k3">+</span><span class="k3">+</span>y<span class="k2">)</span>
<span class="number">  3</span><span class="k2">{</span>
<span class="number">  4</span><span class="k1">int</span> x<span class="k2">;</span>
<span class="number">  5</span><span class="k1">for</span><span class="k2">(</span>x<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>x<span class="k3">&lt;</span><a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span>bmp1<span class="k2">)</span><span class="k2">;</span><span class="k3">+</span><span class="k3">+</span>x<span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>
<span class="number">  8</span><span class="k1">int</span> screen_x<span class="k2">;</span>
<span class="number">  9</span><span class="k1">int</span> screen_y<span class="k2">;</span>
<span class="number"> 10</span><a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> pixel<span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>screen_x <span class="k3">=</span> bmp1_pos_x <span class="k3">+</span> x<span class="k2">;</span>
<span class="number"> 13</span>screen_y <span class="k3">=</span> bmp1_pos_y <span class="k3">+</span> y<span class="k2">;</span>
<span class="number"> 14</span>pixel <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_pixel"><span class="a">al_get_pixel</span></a><span class="k2">(</span>bmp1,screen_x <span class="k3">-</span> bmp1_pos_x, screen_y <span class="k3">-</span> bmp1_pos_y<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span><span class="c">//if transparent then continue to the next loop, i.e. "continue;" statement</span>
<span class="number"> 16</span>pixel <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_pixel"><span class="a">al_get_pixel</span></a><span class="k2">(</span>bmp2, screen_x <span class="k3">-</span> bmp2_pos_x, screen_y <span class="k3">-</span> bmp2_pos_y<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span><span class="c">//if non transparent, we have a collision</span>
<span class="number"> 18</span>
<span class="number"> 19</span><span class="k2">}</span>
<span class="number"> 20</span><span class="k2">}</span>
</div></div><p>

i used a4 where getpixel returns bitmap_mask_color(bmp) for transparent and -1 if the coordinates are outside of the bitmap, but for a5 not sure on that part
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (m c)</author>
		<pubDate>Wed, 08 Jun 2016 02:44:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>thanks <b>a lot</b> it works perfectly <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nova99)</author>
		<pubDate>Fri, 10 Jun 2016 01:06:36 +0000</pubDate>
	</item>
</rss>
