<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Explorer: 8 &#8211; Sprite Direction</title>
	<atom:link href="http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/</link>
	<description>NES homebrew! Development blog for homebrew NES games</description>
	<lastBuildDate>Wed, 09 Jun 2010 16:06:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ramses Game: 2 &#8211; Reading NES Button Combinations &#124; Tummai Games</title>
		<link>http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/comment-page-1/#comment-209</link>
		<dc:creator>Ramses Game: 2 &#8211; Reading NES Button Combinations &#124; Tummai Games</dc:creator>
		<pubDate>Sun, 14 Feb 2010 15:42:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.tummaigames.com/blog/?p=140#comment-209</guid>
		<description>[...] overruled a lot, doesn&#039;t he?). If you want to know more about this technique, I have written about protecting against odd dpad combinations using tables [...]</description>
		<content:encoded><![CDATA[<p>[...] overruled a lot, doesn&#39;t he?). If you want to know more about this technique, I have written about protecting against odd dpad combinations using tables [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Explorer: 9 &#8211; Sprite Movement &#124; Tummai Games</title>
		<link>http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/comment-page-1/#comment-30</link>
		<dc:creator>Explorer: 9 &#8211; Sprite Movement &#124; Tummai Games</dc:creator>
		<pubDate>Sun, 26 Jul 2009 15:00:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.tummaigames.com/blog/?p=140#comment-30</guid>
		<description>[...] Tummai Games development blog for NES games      &#171; Explorer: 8 &#8211; Sprite Direction [...]</description>
		<content:encoded><![CDATA[<p>[...] Tummai Games development blog for NES games      &laquo; Explorer: 8 &#8211; Sprite Direction [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas</title>
		<link>http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/comment-page-1/#comment-29</link>
		<dc:creator>Thomas</dc:creator>
		<pubDate>Sun, 26 Jul 2009 08:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.tummaigames.com/blog/?p=140#comment-29</guid>
		<description>@miau: I didn&#039;t see your comment until after I replied to Rob.  Sorry about that.  :)

I actually don&#039;t calculate square roots.  I do what you first said.  Pressing up moves you up a pixel, pressing right moves you right a pixel and pressing up+right moves you up a pixel and right a pixel.  Mathematically, diagonal movement might be faster than straight vertical or horizontal, but it isn&#039;t really noticeable in the game.

That said, I haven&#039;t written any acceleration code yet that will take the hero to a speed above 1 pixel per frame (for each axis).  If I do, and the speed difference is really obvious, I might have to fix it.  But for now I&#039;m going to keep it simple.</description>
		<content:encoded><![CDATA[<p>@miau: I didn&#8217;t see your comment until after I replied to Rob.  Sorry about that.  :)</p>
<p>I actually don&#8217;t calculate square roots.  I do what you first said.  Pressing up moves you up a pixel, pressing right moves you right a pixel and pressing up+right moves you up a pixel and right a pixel.  Mathematically, diagonal movement might be faster than straight vertical or horizontal, but it isn&#8217;t really noticeable in the game.</p>
<p>That said, I haven&#8217;t written any acceleration code yet that will take the hero to a speed above 1 pixel per frame (for each axis).  If I do, and the speed difference is really obvious, I might have to fix it.  But for now I&#8217;m going to keep it simple.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas</title>
		<link>http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/comment-page-1/#comment-28</link>
		<dc:creator>Thomas</dc:creator>
		<pubDate>Sun, 26 Jul 2009 06:43:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.tummaigames.com/blog/?p=140#comment-28</guid>
		<description>@Rob: oh, you know that guy?  I couldn&#039;t believe it the first time I heard that someone won zelda 2 in 6 minutes :)  I used to play that game all the time with my friends when I was younger.  Brought back a lot of good memories.  It&#039;s funny how you can still know all the songs after all the years pass by :)

I did branch testing for directions the way you describe on my first NES project (the 4-way Dragon Warrior-style scroller).  It worked just fine for me there.  But you&#039;re right, it gets unwieldy the more conditions you have to check for.  Anytime I find myself with a lot of compares and branches in my code I try to see if I can find a way to use a lookup table instead.  It&#039;s a lot easier to read that way, and easier to tweak values and catch bugs too.  I use tables for the movement too (as you&#039;ll see in the next post).  I use the hero_direction again as an index into tables that hold values of $00, $01 or $FF (ie, -1).  I read from the table and add it to the hero&#039;s coordinates.  No branching needed.  

Another reason I do it this way is to separate the input handling from the rest of the engine as much as possible.  The way it works now, I check the input and set the direction and I&#039;m done.  Then the update_hero routine will take care of all the logic stuff for me.   Keeps the input routine nice and compact.

Next post will be movement and animations and then the next one will be background collision detection (with video I hope!).  Hope you&#039;ll like it.</description>
		<content:encoded><![CDATA[<p>@Rob: oh, you know that guy?  I couldn&#8217;t believe it the first time I heard that someone won zelda 2 in 6 minutes :)  I used to play that game all the time with my friends when I was younger.  Brought back a lot of good memories.  It&#8217;s funny how you can still know all the songs after all the years pass by :)</p>
<p>I did branch testing for directions the way you describe on my first NES project (the 4-way Dragon Warrior-style scroller).  It worked just fine for me there.  But you&#8217;re right, it gets unwieldy the more conditions you have to check for.  Anytime I find myself with a lot of compares and branches in my code I try to see if I can find a way to use a lookup table instead.  It&#8217;s a lot easier to read that way, and easier to tweak values and catch bugs too.  I use tables for the movement too (as you&#8217;ll see in the next post).  I use the hero_direction again as an index into tables that hold values of $00, $01 or $FF (ie, -1).  I read from the table and add it to the hero&#8217;s coordinates.  No branching needed.  </p>
<p>Another reason I do it this way is to separate the input handling from the rest of the engine as much as possible.  The way it works now, I check the input and set the direction and I&#8217;m done.  Then the update_hero routine will take care of all the logic stuff for me.   Keeps the input routine nice and compact.</p>
<p>Next post will be movement and animations and then the next one will be background collision detection (with video I hope!).  Hope you&#8217;ll like it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: miau</title>
		<link>http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/comment-page-1/#comment-27</link>
		<dc:creator>miau</dc:creator>
		<pubDate>Sun, 26 Jul 2009 03:15:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.tummaigames.com/blog/?p=140#comment-27</guid>
		<description>Yeah, my way of handling controls was different, too, and pretty naive (on my very first project, anyway). Actually, I didn&#039;t check for bad button combinations and just added/subtracted from the speed vectors depending on which of the four d-pad buttons were pressed.

It does make sense to handle each combination seperately, though, especially when having 8 directions to move into.
Diagonal movement was possible with my simple approach, but it was way faster than horizontal or vertical movement.
E.g. 
press down -&gt; input handling function sets y-speed to 1
press right -&gt; function sets x-speed to 1
press up+right -&gt; function sets y-speed and x-speed to 1

When in the last case both should actually be 1*SQRT(2) to be the same speed (as the diagonal of a square is one of its sides multiplied by the square root of two).

Now I&#039;ve probably stolen that bit from your next entry. If not, this might help beginners. It&#039;s clear to me know, but wasn&#039;t back when I started. 
(Oh well, I&#039;ve never been that math-savvy anyway) :)

Keep those updates coming!</description>
		<content:encoded><![CDATA[<p>Yeah, my way of handling controls was different, too, and pretty naive (on my very first project, anyway). Actually, I didn&#8217;t check for bad button combinations and just added/subtracted from the speed vectors depending on which of the four d-pad buttons were pressed.</p>
<p>It does make sense to handle each combination seperately, though, especially when having 8 directions to move into.<br />
Diagonal movement was possible with my simple approach, but it was way faster than horizontal or vertical movement.<br />
E.g.<br />
press down -&gt; input handling function sets y-speed to 1<br />
press right -&gt; function sets x-speed to 1<br />
press up+right -&gt; function sets y-speed and x-speed to 1</p>
<p>When in the last case both should actually be 1*SQRT(2) to be the same speed (as the diagonal of a square is one of its sides multiplied by the square root of two).</p>
<p>Now I&#8217;ve probably stolen that bit from your next entry. If not, this might help beginners. It&#8217;s clear to me know, but wasn&#8217;t back when I started.<br />
(Oh well, I&#8217;ve never been that math-savvy anyway) :)</p>
<p>Keep those updates coming!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://www.tummaigames.com/blog/2009/07/24/explorer-8-sprite-direction/comment-page-1/#comment-24</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Fri, 24 Jul 2009 22:14:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.tummaigames.com/blog/?p=140#comment-24</guid>
		<description>Oh wow! I encoded that video, which went bonkers when the commentator (my buddy Phil from Canada) uploaded it and YouTube gave it a really, REALLY crappy frame rate. ugh. I&#039;ll be downing some beers with him in Tennessee in mid-August, as a matter-of fact : )

It&#039;s funny how you did the input, because just today I was messing with how I would know which directions are available for exiting from one screen to the next on that zombie game, and came up with this:

; *********************************************************
; Screen exit types: 0=all_directions, 1=top, 2=bottom,
; 3=left, 4=right, 5=top/left, 6=top/bottom,
; 7=top/right, 8=top/left/bottom, 9=top/bottom/right,
; a=top/left/right, b=bottom/left, c=bottom/right,
; d=bottom/left/right, e=left/right, f=none
; *********************************************************

hehe That&#039;s pretty cool!

That is an interesting way to handle the controls, actually. I&#039;ll have to read that some more, as I&#039;ve always done something pretty different, but is only suited well for 4-direction movement.

test up, if pressed, move sprite up and jump over the other directional buttons routines - 
if jump is NOT pressed -
test down, if pressed, move sprite down and jump over other directional buttons routines -
if not -
etc. etc.

Can&#039;t wait to see how you do background collision, because that has been stumping me for a long time, even with people giving me a helping hand haha</description>
		<content:encoded><![CDATA[<p>Oh wow! I encoded that video, which went bonkers when the commentator (my buddy Phil from Canada) uploaded it and YouTube gave it a really, REALLY crappy frame rate. ugh. I&#8217;ll be downing some beers with him in Tennessee in mid-August, as a matter-of fact : )</p>
<p>It&#8217;s funny how you did the input, because just today I was messing with how I would know which directions are available for exiting from one screen to the next on that zombie game, and came up with this:</p>
<p>; *********************************************************<br />
; Screen exit types: 0=all_directions, 1=top, 2=bottom,<br />
; 3=left, 4=right, 5=top/left, 6=top/bottom,<br />
; 7=top/right, 8=top/left/bottom, 9=top/bottom/right,<br />
; a=top/left/right, b=bottom/left, c=bottom/right,<br />
; d=bottom/left/right, e=left/right, f=none<br />
; *********************************************************</p>
<p>hehe That&#8217;s pretty cool!</p>
<p>That is an interesting way to handle the controls, actually. I&#8217;ll have to read that some more, as I&#8217;ve always done something pretty different, but is only suited well for 4-direction movement.</p>
<p>test up, if pressed, move sprite up and jump over the other directional buttons routines &#8211;<br />
if jump is NOT pressed -<br />
test down, if pressed, move sprite down and jump over other directional buttons routines -<br />
if not -<br />
etc. etc.</p>
<p>Can&#8217;t wait to see how you do background collision, because that has been stumping me for a long time, even with people giving me a helping hand haha</p>
]]></content:encoded>
	</item>
</channel>
</rss>
