<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>406 Not Acceptable &#187; game development</title>
	<atom:link href="http://406notacceptable.com/tag/game-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://406notacceptable.com</link>
	<description>406 Not Acceptable, not just an error message, but now a blog!</description>
	<lastBuildDate>Tue, 28 Jun 2011 15:13:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Collision detection in J2ME</title>
		<link>http://406notacceptable.com/java/j2me/collision-detection-in-j2me/</link>
		<comments>http://406notacceptable.com/java/j2me/collision-detection-in-j2me/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 13:20:49 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[java code]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[j2me code]]></category>

		<guid isPermaLink="false">http://www.406notacceptable.com/?p=144</guid>
		<description><![CDATA[I am going to show a basic exclusion collision algorithm for J2ME. Whilst the Sprite class has collision detection methods, they are not very flexible and are useless when checking how objects collide. For example, in a bat and ball game you probably will want to know which edge the ball collides with in order [...]


Related posts:<ol><li><a href='http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/' rel='bookmark' title='Permanent Link: ArrayList in J2ME and generics'>ArrayList in J2ME and generics</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I am going to show a basic exclusion collision algorithm for J2ME. Whilst the Sprite class has collision detection methods, they are not very flexible and are useless when checking how objects collide. For example, in a bat and ball game you probably will want to know which edge the ball collides with in order to bet the ball to bounce correctly.</p>
<p>Exclusion collision detection is done by checking where certain parts of the two items are in correspondence to each other. Basically if the highest point of item A is lower than the lowest part of item B, it is not possible for the items to collide.</p>
<p>In addition, you can order your method based on which direction you are expecting collisions to usually occur from. This will then be more efficient than even the box detection method offered by the Sprite class.</p>
<p>public boolean collisionBetween(Sprite a, Sprite b)</p>
<p>{</p>
<p>if (a.getY() &gt; (b.getY() + b.getHeight()))<br />
{<br />
//Not collided b is above a</p>
<p>return false;<br />
}<br />
else<br />
{<br />
if ((a.getY() + a.getHeight()) &lt; b.getY())<br />
{<br />
//Not collided b is below a</p>
<p>return false;<br />
}<br />
else<br />
{<br />
if (a.getX() &gt; (b.getY() + b.getWidth()))<br />
{<br />
//Not collided b is to the left of a</p>
<p>return false;<br />
}<br />
else<br />
{<br />
if ((a.getX() + a.getWidth()) &lt; b.getX())<br />
{<br />
//Not collided b is to the right of a</p>
<p>return false;<br />
}<br />
}<br />
}<br />
}</p>
<p>//There is a collision</p>
<p>return true;</p>
<p>}<br />
There might be a parenthesis error in here, as I did this in notepad at work. So I couldn&#8217;t check the syntax! From the formatting &#8212; which Wordpress kindly destroyed &#8212; it looks fine though.</p>


<p>Related posts:<ol><li><a href='http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/' rel='bookmark' title='Permanent Link: ArrayList in J2ME and generics'>ArrayList in J2ME and generics</a></li>
</ol></p><hr />
<p><small>&copy; jim for <a href="http://406notacceptable.com">406 Not Acceptable</a>, 2008. |
<a href="http://406notacceptable.com/java/j2me/collision-detection-in-j2me/">Permalink</a> |
<a href="http://406notacceptable.com/java/j2me/collision-detection-in-j2me/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://406notacceptable.com/java/j2me/collision-detection-in-j2me/&amp;title=Collision detection in J2ME">del.icio.us</a>
<br/>
Post tags: <a href="http://406notacceptable.com/tag/game-development/" rel="tag">game development</a>, <a href="http://406notacceptable.com/tag/j2me/" rel="tag">j2me</a>, <a href="http://406notacceptable.com/tag/j2me-code/" rel="tag">j2me code</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://406notacceptable.com/java/j2me/collision-detection-in-j2me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

