﻿<?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>Keith Hair &#187; Games</title>
	<atom:link href="http://keith-hair.net/blog/category/games/feed/" rel="self" type="application/rss+xml" />
	<link>http://keith-hair.net/blog</link>
	<description>Scripting is fun like any other hobby</description>
	<lastBuildDate>Mon, 17 May 2010 16:02:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>KeyManager Class for Detecting Key Press Combos or Sequences</title>
		<link>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/</link>
		<comments>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 23:30:12 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash 9]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[ASWD]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[dev mode]]></category>
		<category><![CDATA[easter eggs]]></category>
		<category><![CDATA[key press]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[KeyboardEvent]]></category>
		<category><![CDATA[videogames]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=189</guid>
		<description><![CDATA[When I am writing a flash app or game which uses the keyboard to control a character's movement, there is a situation that becomes annoying while controlling the character. I do not know the proper term for it ("sticky keys"?) but I will describe it... When an app or game is written we "expect" the [...]]]></description>
			<content:encoded><![CDATA[<p>When I am writing a flash app or game which uses the keyboard to control a character's movement, there is a situation that becomes annoying while controlling the character. I do not know the proper term for it ("sticky keys"?) but I will describe it...<img class="alignright" src="/blog/examples/keycontrol/typing.jpg" alt="keyboard" width="264" height="386" /></p>
<p>When an app or game is written we "expect" the user to precisely press the proper key or key combination at a time to execute programmatic actions. However, most of us have ten fingers and we use more than one finger to press more than one button on the keyboard. The expected program reaction from multiple fingered keyboard input might not occur because you have another function executing when you expect just one at a time.<br />
<span id="more-189"></span></p>
<p><strong>Key Combinations</strong><br />
Imagine you are using the keyboard to play a game. The RIGHT arrow key is for moving your character right, the LEFT arrow key is for moving your character LEFT.<br />
Ok, the action in this game is heating up, you are pressing LEFT to avoid the lasers shooting at you. You successfully dodged the lasers, now you press RIGHT to move in and attack...but in the heat of battle, your other finger is still on the LEFT button. What happens now is your character most likely gets stuck, because both movement keys are pressed telling the character to go in opposite directions!</p>
<p>In some cases allowing multiple key presses is how you want the app to react. For example you want the user to press both UP and RIGHT keys to move the characters in a diagonal direction. When to allow this and when not can be different among all of the control buttons. It becomes messy having to write "If" and "switch" statements to make the KeyboardEvent listeners work according to the different controls needed.</p>
<p><strong>Key Sequences</strong><br />
If you love video games cheats or the easter eggs developers sometimes place in apps you'll remember to access them, you will usually enter in a sequence of key presses. If you entered the sequence successfully you would have access to cool game cheats or some special developer mode of an application.</p>
<p><strong>KeyManager</strong><br />
For the above reasons I've written a KeyManager class to add key control that allows individual keys/keycombos the option to cancel out the any previous key/keycombo that are pressed down...and when key/keycombos are released, whatever key/keycombo that are still pressed will be active again. And for detecting key press sequences the KeyManager class will allow also.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_keycontrol_1545331746"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://keith-hair.net/blog/examples/keycontrol/keycontrol.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://keith-hair.net/blog/examples/keycontrol/keycontrol.swf"
			name="fm_keycontrol_1545331746"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>This is a basic example using KeyManager. The "addKey" method is for adding key press combos and the "addKeySequence" is for obviously adding<br />
key press sequences.</p>
<p>In the working flash example, you can click "singular combos" checkbox to false, to see the problem described previously about the character getting stuck when pressing RIGHT and LEFT key at the same time. When you set the checkbox back to true you will notice how each new key press overrides any others that are still down. This results in responsive execution if a user has a habit of holding down other keys while pressing new ones..</p>
<p><em><strong>Also in the working sample above if you enter in the proper key sequence you will be rewarded with an "Easter Egg" to view the source and FLA.</strong></em></p>
<p><strong>Example usage:</strong></p>
<pre class="brush: as3;">
import net.keithhair.KeyManager;

var keyManager:KeyManager;
keyManager=new KeyManager(stage);
keyManager.addKey([&quot;right&quot;], goRight,stopRight,&quot;control1&quot;);
keyManager.addKey([&quot;left&quot;], goLeft,stopLeft,&quot;control2&quot;);
keyManager.addKey([&quot;up&quot;], goUp,stopUp,&quot;control3&quot;);
keyManager.addKey([&quot;down&quot;], goDown,stopDown,&quot;control4&quot;);
keyManager.addKey([&quot;shift&quot;,&quot;w&quot;,&quot;t&quot;], toggleWindow);
keyManager.addKeySequence([&quot;up&quot;,&quot;up&quot;,&quot;down&quot;,&quot;down&quot;,&quot;left&quot;,&quot;right&quot;,&quot;left&quot;,&quot;right&quot;],openEasterEgg);
</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/&ztz=KeyManager Class for Detecting Key Press Combos or Sequences'><img src='http://keith-hair.net/blog/wp-content/plugins/hexosearch-button/logo16x16.png' width='16' height='16' border='0' style='vertical-align:middle' alt='Vote in HexoSearch' title='Vote in HexoSearch' /></a>]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2010/02/15/keymanager-class-for-detecting-key-press-combos-or-sequences/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Different signs of Cosine, Sine, and Tangent functions and radians</title>
		<link>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/</link>
		<comments>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 18:27:43 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[cartesian]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[Cosine]]></category>
		<category><![CDATA[quadrants]]></category>
		<category><![CDATA[Sine]]></category>
		<category><![CDATA[Tangent]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=176</guid>
		<description><![CDATA[This post might seem of little importance to some but today I was thinking back to my high school days and (vaguely) remember the 4 quadrants of a Cartesian coordinate plane discussed in class. Depending on the positive or negative sign of a Point's X and Y value, that point in the Cartesian coordinate plane [...]]]></description>
			<content:encoded><![CDATA[<p>
This post might seem of little importance to some but today I was thinking back to my high school days and (vaguely) remember the 4 quadrants of a Cartesian coordinate plane discussed in class. Depending on the positive or negative sign of a Point's X and Y value, that point in the Cartesian coordinate plane will be located in one of these 4 quadrants.</p>
<blockquote><p><strong>Quadrant 1 = (+,+)<br />
Quadrant 2 = (-,+)<br />
Quadrant 3 = (-,-)<br />
Quadrant 4 = (-,+)</strong></p></blockquote>
<p>My interest in this post is about the positive or negative sign of what the Cosine, Sine, and Tangent functions return for the same angle...the angle from one Point to another Point. The sign of these 3 Math functions are different also whenever a Point is located in one of the 4 quadrants.</p>
<blockquote><p><strong>Quadrant 1 = +Sine,+Cosine,+Tangent<br />
Quadrant 2 = +Sine,-Cosine,-Tangent<br />
Quadrant 3 = -Sine,-Cosine,+Tangent<br />
Quadrant 4 = -Sine,+Cosine,-Tangent</strong></p></blockquote>
<p>Personally I don't think the order or name of the quadrants are important, as long as you keep them consistent with the coordinate system. For my usage, I order my quadrants "1,2,3,4" clockwise since ActionScript's radians values go clockwise.</p>
<p>I feel this will become useful sometime in the future for me when dealing with angles of Points and determining their positions relative to each other.<br />
In a future situation I might not be given X and Y information, but may only have angle data instead. Seeing the difference of signs from the Cosign, Sine, Tangent output of the angle value will be helpful clues.</p>
<p>So some things come back to haunt you, if they are the ghosts of my math teachers, I will surely pay attention in class this time <img src='http://keith-hair.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_quadrants_1856715588"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="/blog/examples/different_signs/quadrants.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/blog/examples/different_signs/quadrants.swf"
			name="fm_quadrants_1856715588"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<span id="more-176"></span><br />
Note in Flash/Actionscript, (0,0) is wherever you set your registration point of a MovieClip. In this example I centered the registration point in Flash,<br />
so (0,0) of head's coordinate system will sit directly at the center of the head.</p>
<pre class="brush: as3;">
	/*=========================================================
	Using &quot;Math.atan2&quot; to get the angle (in radians) between
	the &quot;reddot&quot; and &quot;head&quot;.

	This radian is fed into the &quot;getSign&quot; function so
	we can see the difference of signs.
	===========================================================*/

	var radians=Math.atan2(reddot.y-head.y,reddot.x-head.x);
	var signs:Object=getSigns(radians);
	var output:String=&quot;&quot;;

	output+=&quot;Sine:&quot;+signs.sine;
	output+=&quot;\n&quot;;
	output+=&quot;Cosine:&quot;+signs.cosine;
	output+=&quot;\n&quot;;
	output+=&quot;Tangent:&quot;+signs.tangent;
	output+=&quot;\n&quot;;
	output+=&quot;\n&quot;;
	output+=&quot;Radians:&quot;+radians;

	status.text=output;
</pre>
<pre class="brush: as3;">
/*============================================
Returns an object indicating the sign
of the radian's Cosine, Sine and Tangent.
==============================================*/
function getSigns(rad:Number):Object
{
	var o:Object=new Object();
	if(Math.sin(rad) &gt;= 0){
		o.sine=&quot;+&quot;;
	}else{
		o.sine=&quot;-&quot;;
	}
	if(Math.cos(rad) &gt;= 0){
		o.cosine=&quot;+&quot;;
	}else{
		o.cosine=&quot;-&quot;;
	}
	if(Math.tan(rad) &gt;= 0){
		o.tangent=&quot;+&quot;;
	}else{
		o.tangent=&quot;-&quot;;
	}
	return o;
}
</pre>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/&ztz=Different signs of Cosine, Sine, and Tangent functions and radians'><img src='http://keith-hair.net/blog/wp-content/plugins/hexosearch-button/logo16x16.png' width='16' height='16' border='0' style='vertical-align:middle' alt='Vote in HexoSearch' title='Vote in HexoSearch' /></a>]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2010/01/24/different-signs-of-cosine-sine-and-tangent-functions-and-radians/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Follow Freeman!</title>
		<link>http://keith-hair.net/blog/2009/06/08/follow-freeman/</link>
		<comments>http://keith-hair.net/blog/2009/06/08/follow-freeman/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 23:51:21 +0000</pubDate>
		<dc:creator>Keith H</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Episode 3]]></category>
		<category><![CDATA[Gordon Freeman]]></category>
		<category><![CDATA[Half Life 2]]></category>

		<guid isPermaLink="false">http://keith-hair.net/blog/?p=80</guid>
		<description><![CDATA[I played some Half-Life 2 today, there's a lot of creativity that went into this game. As I played it again today it gave me a few laughs. If you played the first installment of Half-Life 2, you may remember the NPC characters frequently shouting "Follow Freeman". As the NPC characters stood around idle, they [...]]]></description>
			<content:encoded><![CDATA[<p>I played some Half-Life 2 today, there's a lot of creativity that went into this game. As I played it again today it gave me a few laughs.</p>
<p>If you played the first installment of Half-Life 2, you may remember the NPC characters frequently shouting "Follow Freeman".<br />
As the NPC characters stood around idle, they would make comments that sound as if they where on Twitter. LOL</p>
<p><img src="http://keith-hair.net/images/follow_freeman.jpg" alt="Follow Freeman!" /></p>
</p>
<p>Way back when the original Half-Life game came out and I played it on my ancient 3Dfx Voodoo card, the graphics blew me away. I've been loving the whole Half Life series and wait in anticipation for the next episode.<br />
I was disappointed that there was not much news of Half-Life 2 Episode 3 this year, so lately I been going back into time to enjoy the beginning of Half Life 2. I thought Half-Life 1 set the bar.<br />
This game set the bar again, the experience is so well done, that the replay value is good even for single player mode. I have lots PC games, once I finish one, I uninstall it. This is one of the few games I have worthy of staying installed for years.</p>
<a href='http://www.hexosearch.com/se/submit.aspx?zlvz=&zqz=&zurlz=http://keith-hair.net/blog/2009/06/08/follow-freeman/&ztz=Follow Freeman!'><img src='http://keith-hair.net/blog/wp-content/plugins/hexosearch-button/logo16x16.png' width='16' height='16' border='0' style='vertical-align:middle' alt='Vote in HexoSearch' title='Vote in HexoSearch' /></a>]]></content:encoded>
			<wfw:commentRss>http://keith-hair.net/blog/2009/06/08/follow-freeman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
