<?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>playchilla.com</title>
	<atom:link href="http://www.playchilla.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.playchilla.com</link>
	<description>Sharing our side projects.</description>
	<lastBuildDate>Tue, 21 Feb 2012 20:34:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Started on campaign</title>
		<link>http://www.playchilla.com/started-on-campaign</link>
		<comments>http://www.playchilla.com/started-on-campaign#comments</comments>
		<pubDate>Tue, 21 Feb 2012 20:32:34 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Tower Defense]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=690</guid>
		<description><![CDATA[Now that I got the level editor running making levels is pretty easy. So I spent some hours throwing together a bunch of levels. I want the start levels to be really easy and basic and incrementally get more complex. I decided to build a world with clusters of levels &#8211; each cluster introduces a [...]]]></description>
			<content:encoded><![CDATA[<p>Now that I got the level editor running making levels is pretty easy. So I spent some hours throwing together a bunch of levels. I want the start levels to be really easy and basic and incrementally get more complex. I decided to build a world with clusters of levels &#8211; each cluster introduces a new tower or enemy or something like that and get unlocked as the player completes levels. I also wanted to add some freedom of choosing a path through the world. You might not want to play all levels.</p>
<p>As you unlock levels you also unlock new towers and upgrades on previously unlocked towers. I&#8217;m not entirely sure how to make all this self explanatory yet. Also, it feels like the game is missing something, it feels kind of stiff. Not sure what exactly. I like the simple graphics and I don&#8217;t wont to spend to much time on that, but it might be that enemy movements are too much moving along a rail. I might make that more organic in a future version.</p>
<p>Thanks to everyone who is testing it and leaving feedback!</p>
<p><a href="http://www.playchilla.com/tower-defense">Try it here and let me know what you think!</a></p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2012/02/campaign.png"><img src="http://www.playchilla.com/wp-content/uploads/2012/02/campaign.png" alt="" title="campaign" width="640" class="alignnone size-full wp-image-691" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/started-on-campaign/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Laser Towers</title>
		<link>http://www.playchilla.com/laser-towers</link>
		<comments>http://www.playchilla.com/laser-towers#comments</comments>
		<pubDate>Mon, 06 Feb 2012 19:09:53 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Tower Defense]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=670</guid>
		<description><![CDATA[I had a very productive weekend. Previously I had designed levels directly in xml/json with a standalone simplistic &#8220;level paint program&#8221;. I didn&#8217;t like this setup for many reasons, one being code maintenance in two places another being longer iteration times. Even though I really don&#8217;t like programming editors I decided to spend last weekend [...]]]></description>
			<content:encoded><![CDATA[<p>I had a very productive weekend. Previously I had designed levels directly in xml/json with a standalone simplistic &#8220;level paint program&#8221;. I didn&#8217;t like this setup for many reasons, one being code maintenance in two places another being longer iteration times. Even though I really don&#8217;t like programming editors I decided to spend last weekend just doing that.</p>
<h3>Level Format</h3>
<p>I managed to remove all xml formats and convert them to json and build the editor in game. This means I can actually edit levels while playing them. It was totally worth the effort. I converted the xml because json is so much simpler and lightweight.</p>
<p>If anyone is interested this is how the level format looks:</p>
<pre class="brush:as3">{
	"name": "Algorithmic",
	"uid": "r2_algorithmic",
	"mapPos": [0, 0],
	"mapSize": [12, 12],
	"numberOfLives": 10,
	"seed": 5,
	"energy": 120,
	"easyWaves": 10,
	"mediumWaves": 20,
	"hardWaves": 30,
	"waveInterval": {"init": 7, "add": -0.2, "min":3},
	"level": {"init":1, "add": 0.4, "mul": 1.05},
	"waveSizeDef": {"init":5, "add":0.5},
	"waitDef": false,
	"waves":
	[
		{"queue": ["Xor"]},
		{"queue": ["XorSpeed"]},
		{"queue": ["Xor", "XorSpeed"]},
		{
			"wait": true,
			"size": {"init": 1, "add": 0.2},
			"queue": ["XorBoss"]
		}
	],
	"allowedTowers": ["bullet", "slow"],
	"tilesData": "sssssssssssssssspppsssssssssppppssssssspptppsssssssppttppsssssppprpppssssspptrrtppssspptppptppssspprpppprppsppttpppttppspptptpptptpprrpprrrpprpp",
	"overlayData": "00000000000000000x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b00000000000000000000000000000e"
}</pre>
<p>On top of this I added an tree based EditView that allows me to edit instantiated level object on the fly. This was boring to do since it involved so much UI program (which I really dislike). On the right in the image below you can see the palette, all the different tiles and overlays (bases, entrances and exits). I think now it&#8217;s gonna be fun to create levels.</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2012/02/towdef_editor.png"><img src="http://www.playchilla.com/wp-content/uploads/2012/02/towdef_editor.png" alt="" title="towdef_editor" width="600" class="alignnone size-full wp-image-672" /></a></p>
<p>I will include the level editor when it is usable for and has less bugs.</p>
<h3>New level &#038; laser towers</h3>
<p>So I built a level in my new editor and added a new tower type: Laser Towers. Those shoots beams through one or more enemies giving mass damage. Place it carefully to hit as many as possible.</p>
<p><a href="http://www.playchilla.com/ai-tower-defense"><img src="http://www.playchilla.com/wp-content/uploads/2012/02/towdef_laser.png" alt="" title="towdef_laser" width="332" height="309" class="alignnone size-full wp-image-676" /></a></p>
<p><a href="http://www.playchilla.com/ai-tower-defense">Now go and play the new level here</a>! Remember to leave feedback on what sucks and needs to be improved (and what you like).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/laser-towers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tower Defense is now playable</title>
		<link>http://www.playchilla.com/tower-defense-is-now-playable</link>
		<comments>http://www.playchilla.com/tower-defense-is-now-playable#comments</comments>
		<pubDate>Tue, 31 Jan 2012 19:35:46 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=640</guid>
		<description><![CDATA[I&#8217;ve just released a playable level of the tower defense I&#8217;m working on. This first level only contains two simple towers (bullet + slow) and three different enemies, it&#8217;s nothing fancy just plain tower defense. Feedback is appreciated This is a first test in order to get some feedback on controls and game play and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just released a playable level of the tower defense I&#8217;m working on. This first level only contains two simple towers (bullet + slow) and three different enemies, it&#8217;s nothing fancy just plain tower defense.</p>
<h3>Feedback is appreciated</h3>
<p>This is a first test in order to get some feedback on controls and game play and the general feel of the game. Please comment if you try it out.</p>
<h3>Toplist and ads</h3>
<p>I also added a top list to make it a little bit more fun. At first I designed an own high score system (on paper) then, in order to save time, I decided to use an already made API. After some hours of reading I wasn&#8217;t any wiser on what system to use so I decided just to pick one that looked decent (sometimes it&#8217;s more efficient to just try stuff in practice than trying to figure them out in theory). I ended up with mochi media. I wanted to turn off the ads, at least during development but it seems that I had no such option.</p>
<p>As I final note my record has already been broken, a player &#8220;fghj&#8221; managed to stay alive for 33 waves vs my 27.</p>
<p><a href="http://www.playchilla.com/ai-tower-defense">PLAY IY HERE</a></p>
<p><a href="http://www.playchilla.com/ai-tower-defense"><img src="http://www.playchilla.com/wp-content/uploads/2011/12/towdef.png" alt="" title="towdef" width="624" height="650" class="alignnone size-full wp-image-498" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/tower-defense-is-now-playable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AI Tower Defense</title>
		<link>http://www.playchilla.com/tower-defense</link>
		<comments>http://www.playchilla.com/tower-defense#comments</comments>
		<pubDate>Sat, 14 Jan 2012 17:16:06 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=578</guid>
		<description><![CDATA[I&#8217;m making a tower defense game, check the teaser out!]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m making a tower defense game, check the teaser out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/tower-defense/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a puzzle game in 4 days</title>
		<link>http://www.playchilla.com/making-a-puzzle-game-in-4-days</link>
		<comments>http://www.playchilla.com/making-a-puzzle-game-in-4-days#comments</comments>
		<pubDate>Mon, 09 Jan 2012 18:35:02 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=553</guid>
		<description><![CDATA[Howdy hackers, once again I got side tracked from the tower defense game and decided to create a puzzle game. The goal was to make it as quickly as possible and not spend time on building overly complicated stuff. The puzzle game is inspired from one of the Machinarium in-game puzzles: I found this puzzle [...]]]></description>
			<content:encoded><![CDATA[<p>Howdy hackers, once again I got side tracked from the tower defense game and decided to create a puzzle game. The goal was to make it as quickly as possible and not spend time on building overly complicated stuff. The puzzle game is inspired from one of the Machinarium in-game puzzles:</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2012/01/machinarium.jpg"><img class="alignnone size-medium wp-image-554" title="machinarium" src="http://www.playchilla.com/wp-content/uploads/2012/01/machinarium.jpg" alt="" width="600" height="398" /></a></p>
<p>I found this puzzle a lot of fun and decided to create a dedicated game. The objective is to move over all tiles without getting trapped. Select a starting point then choose a direction in which the tiles will be lit all the way until a wall is hit, then select a new direction. You can&#8217;t move through yourself so you need to make sure you don&#8217;t get trapped.</p>
<p>Last weekend was extra long and that was the time span I sat out to do this within.</p>
<h3>Initial development</h3>
<p>I started by created a level format, I kept it simple and used a char matrix to describe the board. Then I implemented a simple view on this that drew rectangles in different colors. And on top of this I added the ability to move over tiles. This was all straight forward and playable within a couple of hours.</p>
<h3>Level Generation</h3>
<p>Once I could actually play some test levels I went ahead and wrote a level generator. This was also pretty straight forward and very brute force. The only thing I had to put some effort in was the difficulty calculations so the levels could be categories into easy, medium and hard. I ended up using the number of choices needed to solve a puzzle going the easiest way (fewest moves). Another thing that I had to do was to remember to throw away duplicates, to do this I mirrored and rotated each solvable to make sure every level was unique. Totally more than 300 levels are used for the game. All in all I probably spent 10 hours on this.</p>
<h3>Adding some nice graphics</h3>
<p>Once this was done, the boring programming was left. Building some kind of menu, making games save, showing dialogs upon level completion or failure. This took the rest of the time. Anna did some cool buttons and tiles for the game to make it look better. This probably took 20 hours. All the fiddling with mouse overs etc. Phew.</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2012/01/puzzle_27_medium.png"><img class="size-full wp-image-555 alignleft" style="margin-right: 20px; margin-bottom: 20px;" title="puzzle_27_medium" src="http://www.playchilla.com/wp-content/uploads/2012/01/puzzle_27_medium.png" alt="" width="240" height="400" /></a></p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2012/01/puzzle_21_hard.png"><img class="alignnone size-full wp-image-559" title="puzzle_21_hard" src="http://www.playchilla.com/wp-content/uploads/2012/01/puzzle_21_hard.png" alt="" width="240" height="400" /></a></p>
<p>&nbsp;</p>
<h3>Name: Touch All Puzzle</h3>
<p>For now the game is available for free in the Android market. The name is &#8220;Touch All Puzzle&#8221;. I&#8217;m not very happy with the name, but it will do. I will make an IOS and flash version as well.</p>
<p><a class="without_u" href="https://market.android.com/details?id=air.com.playchilla.maze&#038;feature=search_result"><img src="http://www.playchilla.com/wp-content/uploads/2011/07/android_market.png" title="android_market" /></a></p>
<h3>Whats next</h3>
<p>Also I would like to experiment with monetizing it as well. This is something I am really bad at. I&#8217;ve written free software for 15 years now but starting to feel that some money would be nice.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/making-a-puzzle-game-in-4-days/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Shooting at a moving target as3</title>
		<link>http://www.playchilla.com/shooting-at-a-moving-target-as3</link>
		<comments>http://www.playchilla.com/shooting-at-a-moving-target-as3#comments</comments>
		<pubDate>Mon, 26 Dec 2011 11:48:03 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>
		<category><![CDATA[Algorithms]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=520</guid>
		<description><![CDATA[As I was implementing the towers I needed them to aim and shoot on the anticipated position of an enemy, assuming they are moving linearly (no acceleration). This is because the bullets in my game are physics entities that won&#8217;t hit the enemy instantly but after some time as it travels towards the predicted interception [...]]]></description>
			<content:encoded><![CDATA[<p>As I was implementing the towers I needed them to aim and shoot on the anticipated position of an enemy, assuming they are moving linearly (no acceleration). This is because the bullets in my game are physics entities that won&#8217;t hit the enemy instantly but after some time as it travels towards the predicted interception point. As a human you do those predictions all the time, for example passing a football to a running team mate, you predict where to pass so that your friend don&#8217;t have to stop and wait for the football to arrive. This is sometimes called leading a target, aim prediction or simply shooting at a moving target.</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2011/12/aiming.png"><img src="http://www.playchilla.com/wp-content/uploads/2011/12/aiming.png" alt="" title="aiming" width="324" height="304" class="alignnone size-full wp-image-539" /></a></p>
<p>I though I would write up how I did this, much for my own sake (haven&#8217;t fiddled with this in a long time) and as they say repetition is the mother of all knowledge. You can skip to the bottom part to get the code directly. Also sorry for not using a proper font for math symbols. At least I tried to be consistant, * is the dot product and for scalar multiplication I didn&#8217;t use the mul sign (e.g. st).</p>
<p>These are the variables:<br />
v = enemy velocity<br />
p = enemy position in relation to tower (enemyPos-towerPos)<br />
s = bullet speed<br />
t = the time of impact (unknown &#8211; what we want to find out)</p>
<p>Now assuming that the enemy will continue in its path we can calculate where to shoot to get a hit.</p>
<p>The first equation we set up is:<br />
<strong>|p+vt| = st</strong></p>
<p>This happens when the distance from the tower to the bullet and enemy is the same. You can think of p+vt as a point along a line, starting at the enemy pos (p) and extending in the direction of its velocity (v) as the time (t) grows. The |p+vt| simply means the distance (from the tower) of a point on the line at a given time. st is the distance the bullet have traveled after t time units (remember distance = time * speed).</p>
<p>What we want to do is to find out the time (t) when they are at equal distances. To solve it we need to rearrange the expression a bit. Remember that |v| = sqrt(v*v) (* = dot product), in order to &#8220;free&#8221; t from its walls |p + v * t| we start by squaring both sides:</p>
<p><strong>|p+vt|^2 = s^2t^2</strong></p>
<p>Freeing t out of the distance operator (|):<br />
|p+vt|^2 = sqrt((p+vt)*(p+vt))^2 =<br />
(p+vt)*(p+vt) =<br />
p*p + 2p*vt + v*vt^2 = s^2*t^2</p>
<p>Now we set it up as a quadratic equation just as we learnt in school.</p>
<p>v*vt^2 &#8211; s^2t^2 + 2p*vt + p*p = 0</p>
<p><strong>(v*v &#8211; s^2)t^2 + 2p*vt + p*p = 0 </strong>(This is the <a href="http://en.wikipedia.org/wiki/Quadratic_equation">quadratic</a> form ax^2 + bx + c = 0).</p>
<p>Now we only have to solve it, so we plug it into the olden equation:</p>
<p>t1 = (-b + sqrt(d)) / 2a<br />
t2 = (-b &#8211; sqrt(d)) / 2a</p>
<p>where d=b^2-4ac</p>
<p>There are two possible solutions to quadratic equations. The factor inside the sqrt is called the discriminant, d, and reveals information about the solutions, a positive d means we have two real solutions, if d is zero there is only one solution and if it&#8217;s below zero we have complex solutions this means that we don&#8217;t have anyway of hitting the enemy (enemy moving away faster than bullet).</p>
<p>a = v*v &#8211; s^2</p>
<p>b = 2*p*v</p>
<p>c = p * p</p>
<p>This is basically what I implemented, than after I got the solutions I returned the lowest positive t via some ugly if statements. I wasn&#8217;t really happy with this so I kept looking around and ran into  slembcke&#8217;s post &#8216;<a href="http://howlingmoonsoftware.com/wordpress/?p=358">leading target</a>&#8216;, in addition to illustrating the equations nicely with graphs he points out that we can use the <a href="http://en.wikipedia.org/wiki/Quadratic_equation#Alternative_quadratic_formula">alternate quadratic formula</a> if we only are interested in the first possible time of impact (works when there is a positive solution).</p>
<p>t = 2c / (-b+sqrt(d))</p>
<p>After unittesting this bad boy I felt pretty comfortable that it was what I was looking for, even though I haven&#8217;t proved it for myself. One thing to keep in mind is that this will return 2c/0 (division by zero) if  sqrt(d)=b, this happens when the enemy is moving away at the exact  speed as the bullet, in one of the towers axis (the bullet can&#8217;t catch up nor fall behind). I solved this by checking if the t == Infinity, if so I handle it just as if there are no solutions (negative t).</p>
<p>Another small improvement that  <a href="http://playtechs.blogspot.com/2007/04/aiming-at-moving-target.html">James McNeill</a> pointed out is that you can cancel the 2 factor in b. As for this aiming problem we get 2*p*v for our b factor, squaring this in d (b*b) , gives us sqrt(4(pv)^2 &#8211; 4ac) =&gt; 2 * sqrt((pv)^2 &#8211; ac) so now we can cancel the 2 in the top 2c.</p>
<p>The equation we end up with is:</p>
<p>a = v*v &#8211; s^2</p>
<p>b = p*v (removed the 2 factor)</p>
<p>c = p * p</p>
<p>d = b*b &#8211; ac (removed the 4 factor)</p>
<p><strong>t = c / (sqrt(d) &#8211; b)</strong></p>
<p>Here is AS3 source code to calculate how to aim on a moving target:</p>
<pre class="brush:as3">private function _getToi(targetDir:Vec2Const, targetVel:Vec2Const, bulletSpeed:Number):Number
{
	const a:Number = targetVel.lengthSqr() - bulletSpeed * bulletSpeed;
	const b:Number = targetDir.dot(targetVel);
	const c:Number = targetDir.lengthSqr();
	const d:Number = b * b - a * c;
	if (d &lt;= 0) return -1;
	return c / (Math.sqrt(d) - b);
}</pre>
<p>Once you have the time of impact, you check if it&#8217;s negative or infinity &#8211; if so there is no firing solution. Otherwise you can easily calculate the aim position or direction by interpolating from the enemy position in by it&#8217;s velocity scaled by the time:</p>
<pre class="brush:as3">public function getAimPos(shooterPos:Vec2Const, targetPos:Vec2Const, targetVel:Vec2Const, bulletSpeed:Number):Vec2
{
	const targetDir:Vec2Const = targetPos.sub(shooterPos);
	const toi:Number = _getToi(targetDir, targetVel, bulletSpeed);
	if (toi == -1 || toi == Infinity) return null;
	return targetPos.add(targetVel.scale(toi));
}</pre>
<p>As a final note, I assumed that the shooters (towers) are standing still, you can easily modify this by adding a shooterVelocity and pass the relative velocity to the _getToi method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/shooting-at-a-moving-target-as3/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Real Time Fluids</title>
		<link>http://www.playchilla.com/real-time-fluids</link>
		<comments>http://www.playchilla.com/real-time-fluids#comments</comments>
		<pubDate>Fri, 23 Dec 2011 17:00:17 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Algorithms]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=510</guid>
		<description><![CDATA[This Jul (Swedish for Christmas) I&#8217;m not only eating Julbord, Julfika, Julgröt and drinking Julöl (basically put &#8216;Jul&#8217; before any word and there you go), I&#8217;m also doing some Julcoding. Some time ago I ported a c implementation of a Naiver-Stokes fluid simulation to AS3 and I thought I should share it. It&#8217;s all based [...]]]></description>
			<content:encoded><![CDATA[<p>This Jul (Swedish for Christmas) I&#8217;m not only eating Julbord, Julfika, Julgröt and drinking Julöl (basically put &#8216;Jul&#8217; before any word and there you go), I&#8217;m also doing some Julcoding.</p>
<p>Some time ago I ported a c implementation of a Naiver-Stokes fluid simulation to AS3 and I thought I should share it. It&#8217;s all based on this paper &#8216;<a href="http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf">Real Time Fluid Dynamics for Games</a>&#8216; from by Joe Stam. If you want to understand the details about this I suggest you read it, or look around on the web. But the concept is to  set up a velocity and density field to which you add external velocities and densities. For each update you solve the velocities by iterating over the grid and then move the densities accordingly.</p>
<p>On top of that I added some balls that you can play around with by moving a ball with the mouse, it&#8217;s visually not very impressive but it should give an idea of what you can do with it.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_fluiddemo_1298352951"
			class="flashmovie"
			width="300"
			height="300">
	<param name="movie" value="http://www.playchilla.com/swf/fluiddemo.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/fluiddemo.swf"
			name="fm_fluiddemo_1298352951"
			width="300"
			height="300">
	<!--<![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>It seems like the flash bottleneck is the memory access (all the _v[index] etc), I think using Alchemy for memory access would speed it up a lot, and you could probably do really cool simulations. If you decide to try it, let me know how it works!</p>
<p>Use the method &#8216;getDensities&#8217; for rendering (just iterate it and plot it). Here is the AS3 code for the fluid solver:</p>
<pre class="brush:as3">package com.playchilla.algorithm.fluid
{
	public class FluidSolver
	{
		public function FluidSolver(
			width:int,
			height:int,
			solveIterations:int,
			diffusion:Number,
			viscosity:Number)
		{
			_width = width;
			_height = height;
			_solveIterations = solveIterations;
			_diff = diffusion;
			_visc = viscosity;

			_n2 = _width * _height;
			_size = (_width + 2) * (_height + 2);
			_d = _createArr();
			_d0 = _createArr();
			_u = _createArr();
			_v = _createArr();
			_u0 = _createArr();
			_v0 = _createArr();

			_rowAdder = _width + 2;
		}

		public function update(dt:Number):void
		{
			// Add sources from previous to current (last += new)
			_addSource(_u, _u0, dt);
			_addSource(_v, _v0, dt);

			// Diffuse new with old
			_diffuse(1, _u0, _u, _visc, dt);
			_diffuse(2, _v0, _v, _visc, dt);

			// Project velocities onto new velocities
			_project(_u0, _v0, _u, _v);

			// enforce new velocities to uv
			_advect(1, _u, _u0, _u0, _v0, dt);
			_advect(2, _v, _v0, _u0, _v0, dt);

			_project(_u, _v, _u0, _v0);

			// Density step
			_addSource(_d, _d0, dt);
			_diffuse(0, _d0, _d, _diff, dt);
			_advect(0, _d, _d0, _u, _v, dt);

			for (var i:int = 0; i &lt; _size ; i++)
				_d0[i] = _u0[i] = _v0[i] = 0;
		}

		public function getDensities():Vector.&lt;Number&gt; { return _d; }
		public function addDensity(x:int, y:int, amount:Number):void { _d0[_index(x,y)] += amount; }
		public function addVelocity(x:int, y:int, velocityX:Number, velocityY:Number):void
		{
			const index:int = _index(x, y);
			_u0[index] += velocityX;
			_v0[index] += velocityY;
		}
		public function setVelocity(x:int, y:int, velocityX:Number, velocityY:Number):void
		{
			const index:int = _index(x, y);
			_u0[index] = velocityX;
			_v0[index] = velocityY;
		}

		public function getWidth():Number { return _width; }
		public function getHeight():Number { return _height; }

		private function _addSource(x:Vector.&lt;Number&gt;, s:Vector.&lt;Number&gt;, dt:Number):void
		{
			for (var i:int = 0; i &lt; _size; ++i)
				x[i] += dt * s[i];
		}

		private function _diffuse(b:int, x:Vector.&lt;Number&gt;, x0:Vector.&lt;Number&gt;, diff:Number, dt:Number):void
		{
			const a:Number = dt * diff * _n2;
			_linearlySolve(x, x0, a, b, 1 + 4 * a);
		}

		private function _linearlySolve(x:Vector.&lt;Number&gt;, x0:Vector.&lt;Number&gt;, a:Number, b:Number, c:Number):void
		{
			for (var k:int = 0; k &lt; _solveIterations; ++k)
			{
				for (var j:int = 1; j &lt;= _height; ++j)
				{
					var current:int = j * _rowAdder;
					for (var i:int = 1 ; i &lt;= _width; ++i)
					{
						++current;
						x[current] =
							(x0[current] +
							a *
							(x[current-1] +
							 x[current+1] +
							 x[current-_rowAdder] +
							 x[current+_rowAdder])) / c;
					}
				}

				_setBnd(b, x);
			}
		}

		private function _advect(b:Number, d:Vector.&lt;Number&gt;, d0:Vector.&lt;Number&gt;, u:Vector.&lt;Number&gt;, v:Vector.&lt;Number&gt;, dt:Number):void
		{
			const dt0:Number = dt * _width; // FIX
			for (var j:int = 1; j &lt;= _height; ++j)
			{
				const current:int = j * _rowAdder;
				for (var i:int = 1 ; i &lt;= _width; ++i)
				{
					++current;
					const x:Number = Math.min(Math.max(i - dt0 * u[current], 0.5), _width + 0.5);
					const y:Number = Math.min(Math.max(j - dt0 * v[current], 0.5), _height + 0.5);

					const i0:int = int(x);
					const i1:int = i0 + 1;
					const j0:int = int(y);
					const j1:int = j0+1;

					const s1:Number = x - i0;
					const s0:Number = 1 - s1;
					const t1:Number = y - j0;
					const t0:Number = 1 - t1;

					d[current] = s0 *
						(t0 * d0[_index(i0, j0)] +
						 t1 * d0[_index(i0, j1)]) + s1 *
						(t0 * d0[_index(i1, j0)] +
						 t1 * d0[_index(i1, j1)]);
				}
			}
			_setBnd(b, d);
		}

		private function _project(u:Vector.&lt;Number&gt;, v:Vector.&lt;Number&gt;, p:Vector.&lt;Number&gt;, div:Vector.&lt;Number&gt;):void
		{
			for (var j:int = 1; j &lt;= _height; ++j)
			{
				var current:int = j * _rowAdder;
				for (var i:int = 1; i &lt;= _width; ++i)
				{
					++current;
					div[current] = -0.5 *
						(u[current+1] -
						u[current-1] +
						v[current+_rowAdder] -
						v[current-_rowAdder]) / _width; // FIX /_N

					p[current] = 0;
				}
			}

			_setBnd(0, div);
			_setBnd(0, p);
			_linearlySolve(p, div, 1, 0, 4);

			for (j = 1; j &lt;= _height; ++j)
			{
				current = j * _rowAdder;
				for (i = 1 ; i &lt;= _width; ++i)
				{
					++current;
					u[current] -= 0.5 * _width * (p[current+1] - p[current-1]);
					v[current] -= 0.5 * _height * (p[current+_rowAdder] - p[current-_rowAdder]);
				}
			}

			_setBnd(1, u);
			_setBnd(2, v);
		}

		private function _setBnd(b:int, x:Vector.&lt;Number&gt;):void
		{
			for (var i:int = 1; i &lt;= _height; ++i)
			{
				x[_index(0, i)] = b==1 ? -x[_index(1, i)] : x[_index(1, i)];
				x[_index(_width+1, i)] = b==1 ? -x[_index(_width, i)] : x[_index(_width, i)];
			}

			for (i = 0; i &lt;= _width; ++i)
			{
				x[_index(i, 0)] = b == 2 ? -x[_index(i, 1)] : x[_index(i, 1)];
				x[_index(i,_height + 1)] = b == 2 ? -x[_index(i, _height)] : x[_index(i, _height)];
			}

			x[_index(0, 0)] = 0.5 * (x[_index(1,0  )]+x[_index(0  ,1)]);
			x[_index(0, _height + 1)] = 0.5 * (x[_index(1, _height + 1)] + x[_index(0 , _height)]);
			x[_index(_width + 1, 0)] = 0.5 * (x[_index(_width, 0)] + x[_index(_width + 1, 1)]);
			x[_index(_width + 1, _height + 1)] = 0.5 * (x[_index(_width, _height + 1)] + x[_index(_width+1, _height)]);
		}

		private function _index(x:int, y:int):int {	return x + y * _rowAdder; }

		private function _createArr():Vector.&lt;Number&gt;
		{
			const arr:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(_size, true);
			for (var i:int = 0; i &lt; _size; ++i)
				arr[i] = 0;
			return arr;
		}

		private var _solveIterations:int;
		private var _diff:Number;
		private var _visc:Number;
		private var _width:int;
		private var _height:int;

		private var _n2:int;
		private var _size:int;
		private var _rowAdder:int;

		private var _d:Vector.&lt;Number&gt;; // dens
		private var _d0:Vector.&lt;Number&gt;; // prev dens
		private var _u:Vector.&lt;Number&gt;; // vel x
		private var _u0:Vector.&lt;Number&gt;;
		private var _v:Vector.&lt;Number&gt;; // vel y
		private var _v0:Vector.&lt;Number&gt;;
	}
}</pre>
<p>Merry Christmas!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/real-time-fluids/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making of a Tower Defense</title>
		<link>http://www.playchilla.com/making-tower-defense</link>
		<comments>http://www.playchilla.com/making-tower-defense#comments</comments>
		<pubDate>Wed, 21 Dec 2011 13:46:19 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Tower Defense]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=496</guid>
		<description><![CDATA[Right now I&#8217;m between two jobs which gives me a week of creative coding, oh yeah! As I said in an earlier post I wanted to create a tower defense game, then I got sidetracked and made &#8220;Shadowess&#8221; instead, which was a lot of fun and created some of the foundations for this game. I want to create a [...]]]></description>
			<content:encoded><![CDATA[<p>Right now I&#8217;m between two jobs which gives me a week of creative coding, oh yeah! As I said in an earlier post I wanted to create a tower defense game, then I got sidetracked and made &#8220;Shadowess&#8221; instead, which was a lot of fun and created some of the foundations for this game.</p>
<p>I want to create a sandbox Tower Defense game instead of a linear. Here are two key features I am adding:</p>
<p><strong>1) Physics.</strong> Shoot creeps with big canons and knock them off their path, even make them fall of the map.</p>
<p><strong>2) Behaviors.</strong> Creeps can posses different behaviors. So far I&#8217;ve implemented a behavior to avoid incoming artillery fire, this looks really cool &#8211; shooting into a group scatters it as they are fleeing all over. Another behavior is to avoid towers by taking advantage of a weighted graph they can find their way to the goal exposing themselves to as little danger as possible. More to come.</p>
<p>Also I created a little level editor in which I can draw maps using a hexagonal layout. I will not spend so much time on graphics instead focus on the game play. Your objective is to protect your &#8220;souls&#8221; which the creeps try to steal. I&#8217;ve a story line for this in the back of  my head as well, but that&#8217;s for the future.</p>
<p>Here is a first screenshot to show you the progress. This level has allows 2 types of towers, a normal canon and a slow tower, creeps enter at the bottom right and exits in the top. I&#8217;ve built a windy path for them to follow.</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2011/12/towdef.png"><img class="alignnone size-full wp-image-498" title="towdef" src="http://www.playchilla.com/wp-content/uploads/2011/12/towdef.png" alt="" width="624" height="650" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/making-tower-defense/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shadowess update</title>
		<link>http://www.playchilla.com/shadowess-update</link>
		<comments>http://www.playchilla.com/shadowess-update#comments</comments>
		<pubDate>Wed, 19 Oct 2011 17:14:13 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[shadowess]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=466</guid>
		<description><![CDATA[I did a few level additions and adjustments to Shadowess and a added simple plot. My hope is to wrap this game up pretty soon, and get back on track with my original mission building a tower defense with some cool AI in it. There are many good things that have come out of this [...]]]></description>
			<content:encoded><![CDATA[<p>I did a few level additions and adjustments to Shadowess and a added simple plot. My hope is to wrap this game up pretty soon, and get back on track with my original mission building a tower defense with some cool AI in it.</p>
<p>There are many good things that have come out of this side project, I have a pretty robust testbed for AI, goal selection, astar, physics integration etc.</p>
<p><a href="http://www.playchilla.com/shadowess">TRY IT HERE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/shadowess-update/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shadowess &#8211; skill puzzle</title>
		<link>http://www.playchilla.com/shadowess</link>
		<comments>http://www.playchilla.com/shadowess#comments</comments>
		<pubDate>Sat, 08 Oct 2011 08:59:40 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=460</guid>
		<description><![CDATA[Tactical shadow game, sneak around, don&#8217;t get heard and stay in the darkness. Quite difficult.]]></description>
			<content:encoded><![CDATA[<p>Tactical shadow game, sneak around, don&#8217;t get heard and stay in the darkness. Quite difficult.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/shadowess/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shadowess new atmoshpere</title>
		<link>http://www.playchilla.com/shadowess-new-atmoshpere</link>
		<comments>http://www.playchilla.com/shadowess-new-atmoshpere#comments</comments>
		<pubDate>Tue, 04 Oct 2011 16:34:05 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[shadowess]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=447</guid>
		<description><![CDATA[I&#8217;ve recently not had a lot of time to blog, however I&#8217;ve spent some evenings adding some more atmosphere to the game. I&#8217;ve also adding a simple scoring mechanism and a preliminary main menu. This is all crude, and the graphical theme will probably be refined. I&#8217;ve set a kind of dark setting, perhaps on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently not had a lot of time to blog, however I&#8217;ve spent some evenings adding some more atmosphere to the game. I&#8217;ve also adding a simple scoring mechanism and a preliminary main menu.</p>
<p>This is all crude, and the graphical theme will probably be refined. I&#8217;ve set a kind of dark setting, perhaps on an occupied space ship. I will probably add some little background story to it at some point to make it more interesting.</p>
<p>Well try it and let me know what you think can improve. Any info on levels that are too hard or easy is important.</p>
<p><a href="http://www.playchilla.com/shadowess">TRY IT HERE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/shadowess-new-atmoshpere/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shadowess teaser, physics and more</title>
		<link>http://www.playchilla.com/shadowess-teaser-physics-and-more</link>
		<comments>http://www.playchilla.com/shadowess-teaser-physics-and-more#comments</comments>
		<pubDate>Wed, 21 Sep 2011 08:10:36 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[shadowess]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=435</guid>
		<description><![CDATA[Lately things have been hectic at work, every weekend has been filled with birthdays and I also caught a cold. In short, I&#8217;ve had little time to work on my hobby projects. But fear not, progress has been done. I decided to create a teaser video, this took me two evenings and was a lot [...]]]></description>
			<content:encoded><![CDATA[<p>Lately things have been hectic at work, every weekend has been filled with birthdays and I also caught a cold. In short, I&#8217;ve had little time to work on my hobby projects.</p>
<p>But fear not, progress has been done. I decided to create a teaser video, this took me two evenings and was a lot of fun. While looking for music on different free sound sites I found <a href="http://www.bubaproducer.com">Buba Producer</a> on <a href="http://www.soundcloud.com">SoundCloud</a>. This guy creates really high quality scores and shares them freely for attribution. I think that is really cool. The only &#8220;bad&#8221; thing is that the music quality is so much higher than my video.</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/ar63-q5K33g" frameborder="0" allowfullscreen></iframe></p>
<p>I also had some trouble with the compression &#8211; some walls were removed when uploading to youtube. I don&#8217;t want to spend to much time on polishing the video so I will just leave it like that, and improve if I make another one in the future.</p>
<h4>Physics</h4>
<p>Another problem I ran into was level creation, I noticed that I needed a new game play element in order not to repeat myself. I decided to add balls that the player can push and hide in it&#8217;s shadow projection. Now creating levels was easy again.</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2011/09/shadowess_phys.jpg"><img src="http://www.playchilla.com/wp-content/uploads/2011/09/shadowess_phys.jpg" alt="" title="shadowess_phys" width="459" height="435" class="alignnone size-full wp-image-438" /></a><br />
Pushing the ball to get to the key unseen.</p>
<p>Another idea I&#8217;ve is to shape up the level editor and let you guys create levels and put them into the game? This will probably mean more variation.</p>
<h4>Play it</h4>
<p>Use <strong>ARROWS</strong> to move. Use <strong>MOUSE</strong> to throw pebbles. Use <strong>&#8216;R&#8217;</strong> to restart level. Be quiet. <strong>Stay in the darkness.</strong></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_shadowess_02_182326516"
			class="flashmovie"
			width="640"
			height="960">
	<param name="movie" value="http://www.playchilla.com/shadowess_swf/shadowess_02.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/shadowess_swf/shadowess_02.swf"
			name="fm_shadowess_02_182326516"
			width="640"
			height="960">
	<!--<![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>You will always find the latest version under the <a href="http://www.playchilla.com/shadowess">shadowess project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/shadowess-teaser-physics-and-more/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Shadowess</title>
		<link>http://www.playchilla.com/projectshadowess</link>
		<comments>http://www.playchilla.com/projectshadowess#comments</comments>
		<pubDate>Wed, 07 Sep 2011 19:04:22 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=417</guid>
		<description><![CDATA[I think the prototype offspring I&#8217;ve been playing with is decent enough to develop further. Therefore I&#8217;ve decided to go forward with it and make a little game. It will probably be a short story, with no spectacular graphics that requires movement and puzzle skills. I&#8217;ll probably make about 30 levels, with only a few [...]]]></description>
			<content:encoded><![CDATA[<p>I think the prototype offspring I&#8217;ve been playing with is decent enough to develop further. Therefore I&#8217;ve decided to go forward with it and make a little game. It will probably be a short story, with no spectacular graphics that requires movement and puzzle skills. I&#8217;ll probably make about 30 levels, with only a few pickups and maybe some physics elements. I also decided to change the original format of the game (square) to something that might fit on an iPhone, (just in case). The problem with iPhone will probably be the control since you will be needing some precision. However in worst case this could be adjusted with a slower iPhone game or easier levels if necessary.</p>
<p>I won&#8217;t tell you more about my ideas now. The &#8216;Shadowess&#8217; page will always contain the latest version of the game (I&#8217;ll not post it in individual blog posts any longer).</p>
<p><a href="http://www.playchilla.com/shadowess">CHECK IT OUT</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/projectshadowess/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game Prototype 2</title>
		<link>http://www.playchilla.com/game-prototype-2</link>
		<comments>http://www.playchilla.com/game-prototype-2#comments</comments>
		<pubDate>Sun, 04 Sep 2011 12:47:17 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=408</guid>
		<description><![CDATA[I&#8217;ve redone some of the previous levels and added a few new. I also added a new pickup that will reveal itself on the last level (12), if anyone can get there. I think some levels are pretty hard, but I won&#8217;t spend too much time on tweaking since this is a prototype. Update: - [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve redone some of the previous levels and added a few new. I also added a new pickup that will reveal itself on the last level (12), if anyone can get there. I think some levels are pretty hard, but I won&#8217;t spend too much time on tweaking since this is a prototype.</p>
<p>Update:<br />
- Random directions<br />
- Random turn speeds<br />
- Minor control tweak<br />
- More levels<br />
- A new pickup (pebbles)</p>
<p>Use the MOUSE for the last pickup, use ARROWS to control the bot, press &#8216;R&#8217; to restart a level.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_aidef_06_1619806443"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://www.playchilla.com/aidef/aidef_06.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/aidef/aidef_06.swf"
			name="fm_aidef_06_1619806443"
			width="600"
			height="600">
	<!--<![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>What I probably should fix:<br />
- Bots must be able to chase player off the path grap (now the just look crazy)<br />
- Fix different hearing distances<br />
- Make the investigate goal less &#8220;dumb&#8221; (now everyone just runs the shortest path to the sound source)<br />
- Perhaps add some memory to the bots (as soon as player is out of sight the just forget him)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/game-prototype-2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Random direction in 2d</title>
		<link>http://www.playchilla.com/random-direction-in-2d</link>
		<comments>http://www.playchilla.com/random-direction-in-2d#comments</comments>
		<pubDate>Sat, 03 Sep 2011 14:44:33 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Algorithms]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=376</guid>
		<description><![CDATA[Randomness adds an extra flavor to games by injecting some unpredictability, something that can surprise the player. It also makes the game less mechanical and more organic. In the game prototype I posted earlier, bots always initialized their look directions to (1, 0). So every time a level starts all bots looks in this direction [...]]]></description>
			<content:encoded><![CDATA[<p>Randomness adds an extra flavor to games by injecting some unpredictability, something that can surprise the player. It also makes the game less mechanical and more organic. In the <a href="http://www.playchilla.com/game-prototype">game prototype</a> I posted earlier, bots always initialized their look directions to (1, 0). So every time a level starts all bots looks in this direction after which they start to behave randomly. This may seem like a smally but as a matter of fact it&#8217;s kind of disturbing also it gives the player the handicap of always knowing in what direction the bots will look at startup. Thanks <a href="http://retrocade.net">Maurycy Zarzycki</a> for pointing this out.</p>
<h4>Generating a random direction, three different algorithms</h4>
<p>When I was going to implement this I noticed that I didn&#8217;t have any central code to create a vector in a random direction. This is something I use frequently so I decided to do a proper implementation.</p>
<p>Randomizing a direction can be done in many ways, but be aware: some intuitive approaches are simply wrong and doesn&#8217;t provide a uniform distribution.</p>
<h4>Wrong: normalizing random points in a square</h4>
<p>The first time I was doing this, I didn&#8217;t realize this until a code review. The reviewer asked me if I was aware that my code generated biased directions. It all seemed random in my testing, I replied. I guess my first draft of the code looked a bit like this:</p>
<pre class="brush:as3">private function createRandomDirBad():Vec2
{
	const u:Number = 2 * Math.random() - 1;
	const v:Number = 2 * Math.random() - 1;
	const l:Number = Math.sqrt(u * u + v * v);
	return new Vec2(u / l, v / l);
}</pre>
<p>Can you see why this is skewed? This generates a random point in a square which is normalized to have length one &#8211; this means that diagonal directions will be biased because points outside the circle are &#8220;pushed&#8221; inside. The image below illustrates this bias. (Points are drawn in the circle rather than on the outline to demonstrate this)<br />
<a href="http://www.playchilla.com/wp-content/uploads/2011/09/square_bad.jpg"><img class="alignnone size-full wp-image-387" title="square_bad" src="http://www.playchilla.com/wp-content/uploads/2011/09/square_bad.jpg" alt="" width="237" height="236" /></a></p>
<h4>Discarding points outside of the circle</h4>
<p>I was quickly convinced and changed my code. I fixed it by discarding all randomly generated points outside of the circle (x*x + y*y &gt; 1). This requires more iterations but gives an uniform distribution of points within a circle. See distribution B below.</p>
<pre class="brush:as3">private function createRandomDirSquare():Vec2
{
	var p:Vec2;
	while (true)
	{
		const u:Number = 2 * Math.random() - 1;
		const v:Number = 2 * Math.random() - 1;
		const s:Number = u * u + v * v;
		if (s > 1 || s < Vec2Const.EpsilonSqr) continue;
		const l:Number = Math.sqrt(s);
		p = new Vec2(u / l, v / l);
		break;
	}
	return p;
}
</pre>
<p>Here is the distribution within the circle (on the circle surface it's uniform - but not over the area):<br />
<a href="http://www.playchilla.com/wp-content/uploads/2011/09/square_dir.jpg"><img src="http://www.playchilla.com/wp-content/uploads/2011/09/square_dir.jpg" alt="" title="square_dir" width="227" height="228" class="alignnone size-full wp-image-394" /></a></p>
<h4>Using trigonometry</h4>
<p>Another method for random generation of points in a circle is to use trigonometric functions. This perhaps the most straightforward way, we just grab a random angle and create a vector in that direction:</p>
<pre class="brush:as3">
private function createRandomDirTrigonometry():Vec2
{
	const rads:Number = Math.random() * Math.PI * 2;
	return new Vec2(Math.cos(rads), Math.sin(rads));
}
</pre>
<p>This will put points uniformly along a circle outline.</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2011/09/circle_trig.jpg"><img src="http://www.playchilla.com/wp-content/uploads/2011/09/circle_trig.jpg" alt="" title="circle_trig" width="247" height="235" class="alignnone size-full wp-image-396"/></a></p>
<h4>No square roots, no trigonometry</h4>
<p>While looking around, I <a href="http://www.gnu.org/s/gsl/manual/html_node/Spherical-Vector-Distributions.html">found</a> a method attributed to <a href="http://en.wikipedia.org/wiki/John_von_Neumann">Von Neumann</a>. This trick allows us to generate a random direction without any use of square roots or trigonometry which can be useful if those are slow.</p>
<pre class="brush:as3">
public static function createRandomDirKnuth():Vec2
{
	var p:Vec2;
	while (true)
	{
		const u:Number = 2 * Math.random() - 1;
		const v:Number = 2 * Math.random() - 1;
		const l:Number = u * u + v * v;
		if (l > 1 || l < EpsilonSqr) continue;
		p = new Vec2((u * u - v * v) / l, 2 * u * v / l);
		break;
	}
	return p;
}
</pre>
<p><a href="http://www.playchilla.com/wp-content/uploads/2011/09/square_neumann.jpg"><img src="http://www.playchilla.com/wp-content/uploads/2011/09/square_neumann.jpg" alt="" title="square_neumann" width="222" height="220" class="alignnone size-full wp-image-399" /></a></p>
<h4>Final note on performance</h3>
<p>The difference from the three methods is very small, today sin and cos are mostly hardware accelerated and as it turns out in my measurements this is the fastest way to do this. So perhaps I would recommend using the one with sin and cos, if not for its performance for its simplicity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/random-direction-in-2d/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game prototype</title>
		<link>http://www.playchilla.com/game-prototype</link>
		<comments>http://www.playchilla.com/game-prototype#comments</comments>
		<pubDate>Thu, 01 Sep 2011 18:52:47 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=365</guid>
		<description><![CDATA[I have composed a small prototype of a &#8220;hide in the shadows from the evil bots&#8221; game. This was not the original plan, but it seemed fun so I went with it. This prototype only consists of 7 small levels (once you completed the last you will spawn on the first again). It has no [...]]]></description>
			<content:encoded><![CDATA[<p>I have composed a small prototype of a &#8220;hide in the shadows from the evil bots&#8221; game. This was not the original plan, but it seemed fun so I went with it.</p>
<p>This prototype only consists of 7 small levels (once you completed the last you will spawn on the first again). It has no fancy stuff, just some basic game logic and some sounds and some scary bots.</p>
<p>Use ARROWS, press &#8216;R&#8217; to restart the current level you are on! Be quiet. Stay in the darkness.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_aidef_05_1786283832"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://www.playchilla.com/aidef/aidef_05.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/aidef/aidef_05.swf"
			name="fm_aidef_05_1786283832"
			width="600"
			height="600">
	<!--<![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>It would be interesting the hear what you think? Could this eventually be a fun game?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/game-prototype/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Shadow Casting in 2D</title>
		<link>http://www.playchilla.com/simple-shadow-casting-in-2d</link>
		<comments>http://www.playchilla.com/simple-shadow-casting-in-2d#comments</comments>
		<pubDate>Sun, 28 Aug 2011 16:23:11 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[AS3 Coding]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=347</guid>
		<description><![CDATA[Unaccordingly to my plan I spent yesterday rewriting my shadow casting routines. What I need is a frustum, or flashlight type of light source. Before, I had solved this by first drawing a full circle onto which I drew masking triangles, carving out the frustum pie. This mask was very expensive to draw (imagine a [...]]]></description>
			<content:encoded><![CDATA[<p>Unaccordingly to my plan I spent yesterday rewriting my shadow casting routines.</p>
<p>What I need is a frustum, or flashlight type of light source. Before, I had solved this by first drawing a full circle onto which I drew masking triangles, carving out the frustum pie. This mask was very expensive to draw (imagine a small frustum, then the mask would be huge in order to cover the non-pie circle parts).</p>
<h3>Drawing the light</h3>
<p>My new approach is far from optimal, but way better. Instead of carving out the view cone, I only draw the cone as the light once, then I apply shadows to this. In order to draw this pie I used line segments, so pie end is not circular, but made up of n line segments covering the light radius. See the jacked arc in image below (outlines by the red line).</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2011/08/frustum_pie1.jpg"><img class="alignnone size-full wp-image-349" title="frustum_pie" src="http://www.playchilla.com/wp-content/uploads/2011/08/frustum_pie1.jpg" alt="" width="600" height="744" /></a><a href="http://www.playchilla.com/wp-content/uploads/2011/08/frustum_pie.jpg"><br />
</a></p>
<p>Here is the core of drawing the pie:</p>
<pre class="brush:as3">
const rd:int = left.crossDet(right) > 0 ? -1 : 1;
const rotDir:int = (lightBody.getFovDeg() > 180) ? -1 * rd : rd;
const spinor:Vec2Const = new Vec2(1, 0).rotateSelf(Conv.deg2rad(15) * rotDir);
const parts:int = lightBody.getFovDeg() / 15;

const g:Graphics = _lightData.graphics;
g.beginGradientFill(GradientType.RADIAL, [0xffffff, 0x000000], [0.3, 0], [0, 255], matrix);
g.moveTo(0, 0);
g.lineTo(right.x, right.y);
_tmp.copy(right);
while (parts-- &gt; 0)
{
	_tmp.rotateSpinorSelf(spinor);
	g.lineTo(_tmp.x, _tmp.y);
}
g.lineTo(left.x, left.y);
g.lineTo(0, 0);
g.endFill();</pre>
<p>In short, the vector left is the left frustum &#8220;tentacle&#8221; and right the other. The arc is drawn in the while loop. The next segment in the arc is calculated by simply rotating the right vector one step at a time, until we have covered the pie all the way to the left vector (parts times of segments). The nifty thing with spinors is that you don&#8217;t have to leave vector space for rotations. The spinor is only created once, in this case with 15 degrees, then each time it&#8217;s applied to a vector the vector is rotated by 15 degrees. So instead of fiddling with sin and cos you can just apply it by multiplication. This is more efficient and clean. If you are interested you can find the rotateSpinor methods in my <a href="http://www.playchilla.com/vector-2d-for-as3">vector 2d class</a>.</p>
<h3>Drawing the shadows</h3>
<p>Once the light is in place it&#8217;s time to apply the shadows over it. This is done by projecting rays through each &#8220;extreme&#8221; wall vertex as far as the light source can reach. An extreme vertex is one that is the  &#8220;right or left&#8221;-most point with respect to the light source. Then it&#8217;s just to draw the shadow between each such ray pair and close it up with the same arc as drawn for the light pie above.</p>
<p>Here are the shadows, outlined with yellow lines:</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2011/08/shadow_cast.jpg"><img class="alignnone size-full wp-image-350" title="shadow_cast" src="http://www.playchilla.com/wp-content/uploads/2011/08/shadow_cast.jpg" alt="" width="608" height="623" /></a></p>
<p>Here is the algorithm outline:<br />
1. For each obstacle within the frustum view<br />
2. &#8211; Find the two extreme points (if we are only looking at Axis Aligned Bounding Boxes the simplest way is probably to check in which octant the light source is.)<br />
3. &#8211; Draw a line between those two extreme points<br />
4. &#8211; Draw lines from the extremes in the direction of the light passing through until it hits the frustum end.<br />
5. &#8211; Connect the end points from (4) by drawing an arc (same way as described under &#8220;Drawing the light&#8221;).<br />
6. &#8211; Fill this area with a shadowy color</p>
<p>Once this has been accomplished, I set the blendMode of the sprite to ADD &#8211; in this way two light sources interacts in a decent manner. The problem with setting the blendMode is that it&#8217;s very slow.</p>
<h3>The result</h3>
<p>You can run around with a 360 deg light bulb on your head. Don&#8217;t worry about the other bots as you have cleverly  disguised yourself as one of them for this experiment. (Use ARROWS)<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_aidef_04_838974729"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://www.playchilla.com/aidef/aidef_04.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/aidef/aidef_04.swf"
			name="fm_aidef_04_838974729"
			width="600"
			height="600">
	<!--<![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>
<h3>Possible improvements</h3>
<p>The biggest performance hit with this method is due to the blendMode. A solution would probably be to only draw the light (absense of light = shadow) This can be achieved by scanning each vertex in one direction creating a light area while moving along. Imagine standing in front of a couple of walls at different distances &#8211; then taking a laser gun that has a burning continuous beam, and while holding the trigger turning. This will leave a burnt lines along the walls and everything it hits &#8211; if there are no walls the beam will hit an imaginary frustum back wall. Once you are done with turning you can look at this area, outlined by the burnt lines (and start &#038; stop dir) from above and fill this area with light &#8211; and you are done.</p>
<p>With this approach you aren&#8217;t drawing any shadows (e.g. black) so interactions with other lightsources in shadows will work (instead of overdrawing a light with a shadow) without having to use a blendMode. You probably have to tweak the alpha values to get this to look decent (perhaps it&#8217;s hard to to get it as nice as with blendMode.ADD?). </p>
<p>Well perhaps there is a simpler way of doing this but this is the first I came to think of?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/simple-shadow-casting-in-2d/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multiple bots</title>
		<link>http://www.playchilla.com/multiple-bots</link>
		<comments>http://www.playchilla.com/multiple-bots#comments</comments>
		<pubDate>Tue, 23 Aug 2011 18:51:42 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=343</guid>
		<description><![CDATA[Here is a small update, instead of just having one bot running around there are now many of them. I still haven&#8217;t been able to tag all of them on the first level. I also tweaked the control a bit for better control for the user. Another thing I did was to disable shadow casting [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small update, instead of just having one bot running around there are now many of them. I still haven&#8217;t been able to tag all of them on the first level. I also tweaked the control a bit for better control for the user. Another thing I did was to disable shadow casting for now since it was way to slow with all the masking.</p>
<p>As you may notice bots bump into each other, this is because there is no dynamic avoidance. I&#8217;m not sure if this will be a problem or not for this experiment. If it turns out to be a problem, I will either disable collision between bots or add some dynamic avoidance (probably potential fields, since that is something I have worked with before).</p>
<p>Use arrows, tag bots without them seeing you, you can also use the mouse to move around again.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_aidef_03_1847649854"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://www.playchilla.com/aidef/aidef_03.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/aidef/aidef_03.swf"
			name="fm_aidef_03_1847649854"
			width="600"
			height="600">
	<!--<![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>To make it a bit easier for the player, I will probably add some weapon pickups, maybe even the bots will be able to grab this pickup. This should naturally make me incorporate some aim prediction which will be fun to revisit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/multiple-bots/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ray casting in a Spatial Hash with DDA</title>
		<link>http://www.playchilla.com/ray-casting-spatial-hash-dda</link>
		<comments>http://www.playchilla.com/ray-casting-spatial-hash-dda#comments</comments>
		<pubDate>Mon, 22 Aug 2011 21:31:41 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Algorithms]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=327</guid>
		<description><![CDATA[For quite some time I have been thinking of adding some ray casting into the Spatial Hash. The Spatial Hash is used for broad phase culling, eliminating objects that can&#8217;t intersect with what we want to test. My former implementation only allowed tests against rectangles &#8211; when shooting a ray this might be very inefficient. [...]]]></description>
			<content:encoded><![CDATA[<p>For quite some time I have been thinking of adding some ray casting into the <a href="http://www.playchilla.com/spatial-hash">Spatial Hash</a>. The Spatial Hash is used for broad phase culling, eliminating objects that can&#8217;t intersect with what we want to test.</p>
<p>My former implementation only allowed tests against rectangles &#8211; when shooting a ray this might be very inefficient. For example, consider a diagonal ray going from x,y (0,0) to (100,100) in world coordinates. This world is represented in a spatial hash with, say, cell size 10. This means that the Spatial Hash would return all objects from the 100 cells that are overlapped by the rectangle set up by the ray. If we instead could only return the cells that the ray touches on its way from (0,0) to (100,100) we would reduce the number of potential objects a lot. Once we have obtained this subset we can do the narrow phase testing (fine grained ray tracing).</p>
<h3>DDA</h3>
<p>Now walking along a line from point A to B can be done in many ways, the most common is perhaps Bresenhams line algorithm. The problem with this approach is that it can make diagonal jumps and hence miss cells that the line actually pass over. This is where the DDA, or Digital Differential Analyzer yada yada, comes into the picture. I don&#8217;t know why anybody would name it such. Perhaps it&#8217;s just me that don&#8217;t get it. Bresenham seems like a decent guy, &#8220;hey I have a line algorithm, lets name it after myself and with the word line to it.&#8221;</p>
<p>Anyway, as opposed to Bresenhams line algorithm, DDA will touch all cells the line is moving over. So if you move from (0,0) to (1,1) it will not make a direct jump to (1,1) but first go via (1,0) or (0,1). This is exactly what we need to make sure we capture all cells along a rays direction.</p>
<h3>A visual demo</h3>
<p>Click somewhere in the flash to mark the start position of the line, then click again to mark the end pos. The grid is the cells in the spatial hash and the objects are random hash values. Objects that are returned by the raycast are highlighten.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_spatial_dda_1836085296"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://www.playchilla.com/test/spatial_dda.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/test/spatial_dda.swf"
			name="fm_spatial_dda_1836085296"
			width="600"
			height="600">
	<!--<![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>
<h3>Code</h3>
<p>Here is the code! Sorry about the copying pasting trouble here, I might set up a code repository to make all this easier.</p>
<p><strong>DDA.as</strong></p>
<p>&nbsp;</p>
<pre class="brush:as3">package com.playchilla.algorithm.spatial
{
	/**
	 * DDA line algorithm.
	 *
	 * @author playchilla.com
	 */
	public class DDA
	{
		public function DDA(cellSizeX:Number, cellSizeY:Number)
		{
			_cellSizeX = cellSizeX;
			_cellSizeY = cellSizeY;
		}

		public function run(x1:Number, y1:Number, x2:Number, y2:Number, traverseCallback:IDDACallback):void
		{
			var gridPosX:int = int(x1 / _cellSizeX);
			var gridPosY:int = int(y1 / _cellSizeY);
			if (!traverseCallback.onTraverse(gridPosX, gridPosY))
				return;

			var dirX:Number = x2 - x1;
			var dirY:Number = y2 - y1;
			const distSqr:Number = dirX * dirX + dirY * dirY;
			if (distSqr &lt; 0.00000001)
				return;

			const nf:Number = 1 / Math.sqrt(distSqr);
			dirX *= nf;
			dirY *= nf;

			const deltaX:Number = _cellSizeX / Math.abs(dirX);
			const deltaY:Number = _cellSizeY / Math.abs(dirY);

			var maxX:Number = gridPosX * _cellSizeX - x1;
			var maxY:Number = gridPosY * _cellSizeY - y1;
			if (dirX &gt;= 0) maxX += _cellSizeX;
			if (dirY &gt;= 0) maxY += _cellSizeY;
			maxX /= dirX;
			maxY /= dirY;

			const stepX:int = dirX &lt; 0 ? -1 : 1;
			const stepY:int = dirY &lt; 0 ? -1 : 1;
			const gridGoalX:int = int(x2 / _cellSizeX);
			const gridGoalY:int = int(y2 / _cellSizeY);
			while(gridPosX != gridGoalX || gridPosY != gridGoalY)
			{
				if (maxX &lt; maxY)
				{
					maxX += deltaX;
					gridPosX += stepX;
				}
				else
				{
					maxY += deltaY;
					gridPosY += stepY;
				}

				if (!traverseCallback.onTraverse(gridPosX, gridPosY))
					return;
			}
		}

		private var _cellSizeX:Number;
		private var _cellSizeY:Number;
	}
}</pre>
<p><strong>IDDACallback.as</strong></p>
<pre class="brush:as3">package com.playchilla.algorithm.spatial
{
	/**
	 * ...
	 * @author playchilla.com
	 */
	public interface IDDACallback
	{
		/**
		 * Return false to cancel traversal.
		 */
		function onTraverse(cx:int, cy:int):Boolean;
	}
}</pre>
<p><strong>Paste into SpatialHash.as</strong><br />
Also:<br />
- Make the SpatialHash implement IDDACallback<br />
- put this in the constructor &#8220;_dda = new DDA(cellSize, cellSize);&#8221;<br />
- put this at the bottom &#8220;private var _dda:DDA;&#8221;<br />
- put this at the bottom &#8220;private var _rayCastResult:Vector.<SpatialHashValue>;&#8221;</p>
<p>Perhaps time to open up an account on google code or similar? <img src='http://www.playchilla.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush:as3">
public function rayCast(startPos:Vec2Const, stopPos:Vec2Const):Vector.&lt;SpatialHashValue&gt;
{
	_rayCastResult = new Vector.&lt;SpatialHashValue&gt;;
	_dda.run(startPos.x, startPos.y, stopPos.x, stopPos.y, this);
	++_timeStamp;
	return _rayCastResult;
}

public function onTraverse(cx:int, cy:int):Boolean
{
	const bucket:Vector.&lt;SpatialHashValue&gt; = _hash[_getKey(cx, cy)];
	if (bucket == null)	return true;
	for each (var b:SpatialHashValue in bucket)
	{
		if (b.timeStamp &gt;= _timeStamp) continue;
		b.timeStamp = _timeStamp;
		_rayCastResult.push(b);
	}
	return true;
}</pre>
<p><strong>Credits</strong><br />
When I first wrote the DDA code perhaps 2 years ago I remember reading a pdf that explained it and had some c/c++ code. I can&#8217;t find this article anymore, however, thank you mysterious author. Also thanks to Maurycy Zarzycki for inspiring me to finally get around to do this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/ray-casting-spatial-hash-dda/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A goal driven bot</title>
		<link>http://www.playchilla.com/a-goal-driven-bot</link>
		<comments>http://www.playchilla.com/a-goal-driven-bot#comments</comments>
		<pubDate>Sun, 21 Aug 2011 09:36:29 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=313</guid>
		<description><![CDATA[After some productive hours I managed to assemble a bot with a few goals, reusing some old code and adding some new. In the example below I added four goals 1) LookAround &#8211; the head of the bot looking in random directions (visualized with the flashlight) 2) RandomWalk &#8211; the bot picks a random spot [...]]]></description>
			<content:encoded><![CDATA[<p>After some productive hours I managed to assemble a bot with a few goals, reusing some old code and adding some new.</p>
<p>In the example below I added four goals<br />
1) LookAround &#8211; the head of the bot looking in random directions (visualized with the flashlight)<br />
2) RandomWalk &#8211; the bot picks a random spot in the sandbox and move there.<br />
3) Investigate &#8211; if the player accidentally bumps into a wall within a limited distance from the bot, the bot will hear this and the investigate goal will kick in to find out whats going on.<br />
4) Chase &#8211; if the player is in the seeing frustum (flashlight) the bot will start to chase the player</p>
<p>I am trying to set up a simple model that allow the bot to run multiple goals at the same time. So for example the RandomWalk goal can run at the same time as the LookAround goal. This is managed by booking resources on the bot. E.g. LookAround only utilized the head, while the RandomWalk utilized its wheels &#8211; therefore they can run simultaneously. So basically all goals that can run at the same time are selected from a prioritized queue.</p>
<h3>Tag-a-bot</h3>
<p>To add some flavor I made a little tag game, try tagging the bot without him seeing you, sneaking up from behind, for each successful tag a new level is generated the bot will get more vision and speed. However if the bot catches you in the flashlight the game will fall back one &#8220;level&#8221;. (USE ARROWS)</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_aidef_02_306441904"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://www.playchilla.com/aidef/aidef_02.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/aidef/aidef_02.swf"
			name="fm_aidef_02_306441904"
			width="600"
			height="600">
	<!--<![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 />
Move the ball with arrows, avoid being seen by the red bots, try bumping into them from behind unseen.</p>
<p>Again, possible future articles:<br />
- Goal selection<br />
- Controlling a bot with physics (forces)<br />
- 2D shadow casting</p>
<p>Not sure what to do next, perhaps drop down multiple bots and to play along in the sandbox. This usually involves making sure they don&#8217;t want to go to the same spot all the time, or collide into each other and instead not getting anywhere. Not sure if this is needed for the plan, a reactive tower defense game, but for a little shooter or so it would be cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/a-goal-driven-bot/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

