<?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>Wed, 03 Apr 2013 18:54:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Dynamic hard shadows in 2d</title>
		<link>http://www.playchilla.com/dynamic-hard-shadows-in-2d</link>
		<comments>http://www.playchilla.com/dynamic-hard-shadows-in-2d#comments</comments>
		<pubDate>Sun, 23 Dec 2012 13:19:03 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Algorithms]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=917</guid>
		<description><![CDATA[Before I forget, here is how I&#8217;ve done the shadows for the new version of Shadowess. I realize that this blog post is not very detailed but rather should give you an idea of how shadow geometries can be generated. I may do a follow up with code in the future. My goal was to [...]]]></description>
				<content:encoded><![CDATA[<p>Before I forget, here is how I&#8217;ve done the shadows for the new version of <a href="http://www.playchilla.com/porting-shadowess">Shadowess</a>.</p>
<p><img src="http://www.playchilla.com/wp-content/uploads/2012/12/2d-shadows.png" alt="2d-shadows" width="639" height="256" class="alignnone size-full wp-image-936" /></p>
<p>I realize that this blog post is not very detailed but rather should give you an idea of how shadow geometries can be generated. I may do a follow up with code in the future.</p>
<p>My goal was to create faster 2d shadows than I had previously done. To do this I use the GPU for the rendering.</p>
<h4>Background</h4>
<p>First I naturally tried to use Away3d built in shadow casting system. However after adding only a few light sources I got an error message &#8220;register overflow&#8221;. After reading up on the away3D forums I came to the conclusion that it&#8217;s not built for many dynamic lights. Also it&#8217;s 3d shadows and 2d shadows would suffice for me.</p>
<p>Secondly I tried to use shaders as described <a href="http://ryanspeets.com/flash/how-i-did-my-2d-shadow-rendering-with-stage3d-tutorial/">here</a>. This is probably performance effective, as calculations are done on the GPU. However, after fiddling around for an evening or two I felt that my shader skills weren&#8217;t sufficient and I didn&#8217;t really have time to learn. So I moved on&#8230;</p>
<p>Finally I decided to generate light geometries (disc) that had the shadows carved out. This seemed like a good solution for me, since I knew I could to it technically and it was just a matter of writing the code. I was a bit worried that it would be slow to upload new geometries all the time, but it turned out that it was not any problem.</p>
<h4>Generating light geometries</h4>
<p>The algorithm to generate the light geometries is simple and straight forward. However, to be honest, I had to spend a lot of time to patch up some corner cases. E.g. when triangulating around the 360 degrees I needed to make sure that the first point and last point fit. In fact all problems I had was due to fiddling in polar coordinates (angles). If I was to rewrite it, I would try to stay in vector space.</p>
<p>Here is a broad outline of the algorithm:</p>
<p>Imagine a light source with some scattered boxes around it as seen below. Each wall has two corner points, that acts as &#8220;outposts&#8221; for the shadow casting of the geometry. From now I will call those extreme points of the wall. This is demonstrated here, the white line in the wall acts as shadow caster line stretching between the two extreme points:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_2d-dynamic-hard-shadows-1_317634531"
			class="flashmovie"
			width="640"
			height="600">
	<param name="movie" value="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-1.swf" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-1.swf"
			name="fm_2d-dynamic-hard-shadows-1_317634531"
			width="640"
			height="600">
		<param name="wmode" value="direct" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img alt="Get Adobe Flash player" src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>When we have calculated those points, we shoot rays through them to see if the rays hit a wall near wall  (the point is occluded by a wall) or a far wall (projects shadow on another wall) or not at all (shadows ends at light radius). We store this information per point in a list.</p>
<p>Now we sort the new list with points clockwise or anti clockwise w.r.t. the light source. Now we just go through the list and draw triangles, some will follow walls, other will extend all the way to the light endpoint.</p>
<p>This is demonstrated here:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_2d-dynamic-hard-shadows-2_1995893302"
			class="flashmovie"
			width="640"
			height="600">
	<param name="movie" value="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-2.swf" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-2.swf"
			name="fm_2d-dynamic-hard-shadows-2_1995893302"
			width="640"
			height="600">
		<param name="wmode" value="direct" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img alt="Get Adobe Flash player" src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
&nbsp;</p>
<p>And here with more walls:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_2d-dynamic-hard-shadows-3_307512828"
			class="flashmovie"
			width="640"
			height="600">
	<param name="movie" value="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-3.swf" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-3.swf"
			name="fm_2d-dynamic-hard-shadows-3_307512828"
			width="640"
			height="600">
		<param name="wmode" value="direct" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img alt="Get Adobe Flash player" src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Now we just need to apply a light material to the geometry and we are done, also set blend mode to add!</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_2d-dynamic-hard-shadows-4_326134331"
			class="flashmovie"
			width="640"
			height="600">
	<param name="movie" value="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-4.swf" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-4.swf"
			name="fm_2d-dynamic-hard-shadows-4_326134331"
			width="640"
			height="600">
		<param name="wmode" value="direct" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img alt="Get Adobe Flash player" src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>And with 30 walls and 20 lights (many optimization can still be done):<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_2d-dynamic-hard-shadows-5_2017194420"
			class="flashmovie"
			width="640"
			height="600">
	<param name="movie" value="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-5.swf" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/shadow_cast/2d-dynamic-hard-shadows-5.swf"
			name="fm_2d-dynamic-hard-shadows-5_2017194420"
			width="640"
			height="600">
		<param name="wmode" value="direct" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img alt="Get Adobe Flash player" src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" /></a><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/dynamic-hard-shadows-in-2d/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Experimental chatbot</title>
		<link>http://www.playchilla.com/experimental-chatbot</link>
		<comments>http://www.playchilla.com/experimental-chatbot#comments</comments>
		<pubDate>Sat, 15 Dec 2012 19:32:33 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=881</guid>
		<description><![CDATA[Chat with the bot Click to chat with the bot. Read on for some technical info. Background Last spring I started working on a chat bot. I downloaded a dump of wikitionary and let the bot read it. From that it created a two graphs. One graph with syntactic rules (VERB-&#62;PREPOSITION-&#62;NOUN etc). The second graph [...]]]></description>
				<content:encoded><![CDATA[<h4>Chat with the bot</h4>
<p>Click to <a href="http://www.playchilla.com/ve">chat with the bot</a>. Read on for some technical info.</p>
<h4>Background</h4>
<p>Last spring I started working on a chat bot. I downloaded a dump of <a href="http://wiktionary.org">wikitionary</a> and let the bot read it. From that it created a two graphs. One graph with syntactic rules (VERB-&gt;PREPOSITION-&gt;NOUN etc). The second graph could be searched to find associations between words (finding a path between &#8216;socialism&#8217; and &#8216;color&#8217; could generate: &#8216;socialism&#8217;-&gt;red&#8217;-&gt;&#8217;color&#8217; etc).</p>
<p>It did show pretty cool behavior sometimes. But it had no idea how to answer to &#8216;How are you?&#8217;.</p>
<p>So the next step would be to add some everyday chat data into the mix. It turned out that it was very hard to find any public chat data that I could use for this. This is probably due to privacy issues. Even though I did find some corporas they were all not clean enough (e.g. IRC rooms with many people). I wanted peer to peer plain chat logs and gigabytes of them.</p>
<p>Then I ran into a chat bot called <a href="http://www.cleverbot.com/">Cleverbot</a>, and I was amazed how well it worked on every day phrases. So I though, I would try to do something similar to collect chat data for my bot.</p>
<p><a href="http://www.playchilla.com/ve" rel="attachment wp-att-897"><img class="alignnone size-full wp-image-897" alt="ve" src="http://www.playchilla.com/wp-content/uploads/2012/12/ve.png" width="610" height="544" /></a></p>
<p><a href="http://www.playchilla.com/ve">Try chatting to Ve here.</a></p>
<h4>Gamification of the chatting</h4>
<p>On top of that I quickly wrote a flash client with a simple visualization of the bots &#8216;brain&#8217;. The more particles &#8211; the smarted bot. Particles actually doesn&#8217;t relate to the number of nodes (phrases) but rather to the strength of relationships in the graph.</p>
<p>What I really would want to do with the client is to gamify it, so that the user gets rewards from chatting to it and leveling it up. Sort of becoming a part of the development of the bot (just as parents feel involved with their kids are learning). Not there yet &#8211; this is just a preliminary test to reveal what I need to fix to make the model working.</p>
<h4>Server</h4>
<p>I had a good idea of how to build such a system, but wasn&#8217;t sure how to store the graphs so I entered &#8216;graph database&#8217; into Goolge and <a href="http://neo4j.org">Neo4j</a> showed up, after reading up a bit I decided to give it a try. Using it went as a breeze. Usually when I deal with SQL databases it really gives me a headache. It&#8217;s really frustrating to think in rows in column for many problems. Neo4j suited my problem exactly and within hours I had it up and running. Each node is a phrase, and relations are the next phrase in a chat transcript. Relations are strengthen only when humans walk the path. Also there are prediction relations that points more then one node ahead. This will give the another hint of how to branch as a function of the context.</p>
<h4>No content filter yet</h4>
<p>I&#8217;ve not written any content filter yet so it will probably be rude say really ugly things and try to offend you. Don&#8217;t take it personally &#8211; it&#8217;s just those internet trolls thinking they are funny.</p>
<h4>Slow?</h4>
<p>I&#8217;m running it on a free Amazon Micro instance with very limited memory and CPU &#8211; so if it&#8217;s slow, don&#8217;t be surprised.</p>
<p><a href="http://www.playchilla.com/ve">Try chatting to Ve here.</p>
<p></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/experimental-chatbot/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Porting Shadowess</title>
		<link>http://www.playchilla.com/porting-shadowess</link>
		<comments>http://www.playchilla.com/porting-shadowess#comments</comments>
		<pubDate>Sun, 14 Oct 2012 19:10:42 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[shadowess]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=863</guid>
		<description><![CDATA[The next project i&#8217;m doing is porting my old game &#8216;Shadowess&#8216; to stage 3D to benefit from the power of the GPU. By doing so I can see how this game could work on mobiles (with different controls, point-and-move). The reason I want to try this is because it go very good rating on game [...]]]></description>
				<content:encoded><![CDATA[<p>The next project i&#8217;m doing is porting my old game &#8216;<a title="Shadowess" href="http://www.playchilla.com/shadowess">Shadowess</a>&#8216; to stage 3D to benefit from the power of the GPU. By doing so I can see how this game could work on mobiles (with different controls, point-and-move). The reason I want to try this is because it go very good rating on game sites (4.00 on newgrounds.com).</p>
<p>Last weekend I wrote the new lightning system (hard dynamic 2d shadows for Stage 3D). I will probably write a little post on how i did this when I get time. This weekend I started the port and I was surprised how far it got. Since levels will be larger and richer I decided to start with a random level generator just to have something to play with.</p>
<p>Here is the result so far. Beware of general ugliness, most meshes/colors are placeholders &#8211; this is the first port version <img src='http://www.playchilla.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Controls</strong><br />
WASD &#8211; Move (Up/Down arrows also)<br />
ARROWS &#8211; Turn (QE)<br />
SHIFT &#8211; Move slowly</p>
<p>Mouse control is not implemented yet. Be patient while loading (1.5MB)</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_loader_28486158"
			class="flashmovie"
			width="640"
			height="640">
	<param name="movie" value="http://www.playchilla.com/swf/loader.swf?v=0001" />
	<param name="flashvars" value="swfUrl=http://www.playchilla.com/swf/shadowess2.swf?v=0052_4&amp;estimatedSize=1500000" />
	<param name="wmode" value="direct" />
	<param name="allowfullscreen" value="true" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/loader.swf?v=0001"
			name="fm_loader_28486158"
			width="640"
			height="640">
		<param name="flashvars" value="swfUrl=http://www.playchilla.com/swf/shadowess2.swf?v=0052_4&amp;estimatedSize=1500000" />
		<param name="wmode" value="direct" />
		<param name="allowfullscreen" value="true" />
	<!--<![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>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/porting-shadowess/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Ludum Dare &#8211; cell.evolve</title>
		<link>http://www.playchilla.com/ludum-dare-cell-evolve</link>
		<comments>http://www.playchilla.com/ludum-dare-cell-evolve#comments</comments>
		<pubDate>Sun, 26 Aug 2012 20:36:35 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[AI and game development]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=836</guid>
		<description><![CDATA[Ludum dare is a game competition where you make a game in 48h. By making a game I mean making everything, music, sound fx, graphics and coding. Coding is no problem, but with the rest I am so noob. Anyways, I finally pulled my self together to participate. I decided to sleep all I needed [...]]]></description>
				<content:encoded><![CDATA[<p>Ludum dare is a game competition where you make a game in 48h. By making a game I mean making everything, music, sound fx, graphics and coding. Coding is no problem, but with the rest I am so noob.</p>
<p>Anyways, I finally pulled my self together to participate. I decided to sleep all I needed and not stress. In total I put 8h + 13h into the making. Today was a bit stressful. But I am happy that I can go to bed soon.</p>
<p>The things I didn&#8217;t have time to finish was for the player to upgrade the ai of the unselected cells (now they are just randomly walking around). For the evil cells there are four behaviors RandomWalk, FindFood, FindBooster and FindEnemy. Cells are created with a random combination of those. I didn&#8217;t have time to add a AvoidDanger behaviour either. Also, I wanted to add a laser gun for the surprise.</p>
<p>I was inspired by a game called <a href="http://www.hemispheregames.com/osmos/">Osmos</a>. And I used the same &#8220;material spitting out when moving&#8221; effect as they did (since I loved it so much). As of the mechanics I think cell.evolve is different since you split cells and control a whole army against many competing ais. To avoid being mixed up I should probably put it in a different atmosphere and not added the farts.</p>
<p>The theme is &#8216;Evolution&#8217; and here is my contribution called cell.evolve (2 MB &#8211; be patient):</p>
<p><strong>Complete a level by: Divide into 5 (by eating) and terminate all evil cells</strong><br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_cell_evolve_561516874"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://www.playchilla.com/cell_evolve/cell_evolve.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/cell_evolve/cell_evolve.swf"
			name="fm_cell_evolve_561516874"
			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>- Click on the blue cell to and click where you want to move<br />
- Eat food and boosters (speed + metabolism)<br />
- Avoid ugly stuff (poison, evil cells)<br />
- ESC toggles menu<br />
- SPACE restarts level<br />
- R restarts from level 1</p>
<p>Graphics, SoundFx (generated in <a href="http://www.superflashbros.net/as3sfxr/">as3sfxr</a>), Music (generated in <a href="http://tones.wolfram.com/">WolframTone</a>) and code by me. (I love being able to tell I&#8217;ve made the music even though I just pulled some sliders).</p>
<p>Over and out, also here is the <a href="http://www.playchilla.com/cell_evolve/cell_evolve.zip">source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/ludum-dare-cell-evolve/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Lunerun</title>
		<link>http://playchilla.com/runner</link>
		<comments>http://playchilla.com/runner#comments</comments>
		<pubDate>Sat, 14 Apr 2012 21:30:49 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=781</guid>
		<description><![CDATA[Try this high paced one button run and jump game!]]></description>
				<content:encoded><![CDATA[<p>Try this high paced one button run and jump game!</p>
]]></content:encoded>
			<wfw:commentRss>http://playchilla.com/runner/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run &amp; Jump future plans</title>
		<link>http://www.playchilla.com/run-and-jump-future-plans</link>
		<comments>http://www.playchilla.com/run-and-jump-future-plans#comments</comments>
		<pubDate>Thu, 05 Apr 2012 19:38:14 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=761</guid>
		<description><![CDATA[Since there was so much positive feedback on the prototype I will make a game out of it. I&#8217;ll not make a big project, just try to keep it simple and focus on the fast run and jump feel. I will try to avoid adding &#8220;fluff&#8221; mostly because I think it&#8217;s so boring to code [...]]]></description>
				<content:encoded><![CDATA[<p>Since there was so much positive feedback on the prototype I will make a game out of it. I&#8217;ll not make a big project, just try to keep it simple and focus on the fast run and jump feel. I will try to avoid adding &#8220;fluff&#8221; mostly because I think it&#8217;s so boring to code stuff like achievements, Facebook integration, explanatory tutorials etc. The only fluff I can think of now is adding some kind of scoring mechanism and a high score system.</p>
<p>Anna did this sketch<br />
<a href="http://www.playchilla.com/wp-content/uploads/2012/04/concept.png"><img src="http://www.playchilla.com/wp-content/uploads/2012/04/concept-1024x723.png" alt="" title="concept" width="640" class="alignnone size-large wp-image-762" /></a></p>
<p>Here is what I will do:<br />
- spend Easter in Paris with Anna, Philip &#038; Louise<br />
- twisting tracks<br />
- looping tracks<br />
- more weird ambient background stuff<br />
- better lightning<br />
- levels in different difficulty<br />
- random levels<br />
- high score<br />
- an infinite track with where you can see how far people have run (markers along the track)<br />
- hardest part: find a good name for the game<br />
- possible to make own levels with json?</p>
<p>This list should be doable in reasonable time, something for me to do in the evenings and on weekends.</p>
<p><a href="http://playchilla.com/run-and-jump">PLAY IT HERE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/run-and-jump-future-plans/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Run and jump</title>
		<link>http://www.playchilla.com/run-and-jump</link>
		<comments>http://www.playchilla.com/run-and-jump#comments</comments>
		<pubDate>Sat, 31 Mar 2012 20:18:47 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=737</guid>
		<description><![CDATA[Play the LATEST VERSION here. Here is a little running game I made this week, it&#8217;s a one button game. I came across a cool game called Fotonica and thought I would make a similar using the same control (only space). I wanted the character to be a female and get a bit of the [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.playchilla.com/runner" title="Runner">Play the LATEST VERSION here</a>.</p>
<p>Here is a little running game I made this week, it&#8217;s a one button game. I came across a cool game called <a href="http://www.fotonica-game.com/">Fotonica</a> and thought I would make a similar using the same control (only space). I wanted the character to be a female and get a bit of the feel from Mirrors Edge (so far I only managed to add some female sounds).</p>
<p>The 10 levels are randomly generated and not tweaked at all, some might not be finishable? If you finish a level you will snap to the start again.</p>
<p>Anyways, try it here: (no loader, you may have to wait a while)</p>
<p><a href="http://www.playchilla.com/runner" title="Runner">Runner has moved to here</a>.</p>
<p>Music by <a href="http://ccmixter.org/people/7OOP3D">7OOP3D </a> song called Triggernometry (instrumental version)</p>
<p>If I continue with this game I will probably make the track twist and bend, just like in the olden c64 Stunt Car Racer which I used to play a lot when I was young. But I thought I would start simple just making a forward track where segments differs in height. Also I might bring in some Tiny Wings action, timing landings with downhills to get more speed.</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2012/03/stunt_car_racer_08.gif"><img src="http://www.playchilla.com/wp-content/uploads/2012/03/stunt_car_racer_08.gif" alt="" title="stunt_car_racer_08" width="320" height="200" class="alignnone size-full wp-image-748" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/run-and-jump/feed</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
		<item>
		<title>Beadly prototype 2</title>
		<link>http://www.playchilla.com/beadly-prototype-2</link>
		<comments>http://www.playchilla.com/beadly-prototype-2#comments</comments>
		<pubDate>Sat, 17 Mar 2012 19:21:54 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=724</guid>
		<description><![CDATA[Not much has happen here lately, for one I&#8217;ve been away for on GDC &#8211; which was great. Than I caught an ugly cold that kept me in bed for an entire week. Today is the first day I&#8217;ve been somewhat normally operational so I decided to get the core stuff into the bead editor [...]]]></description>
				<content:encoded><![CDATA[<p>Not much has happen here lately, for one I&#8217;ve been away for on GDC &#8211; which was great. Than I caught an ugly cold that kept me in bed for an entire week. Today is the first day I&#8217;ve been somewhat normally operational so I decided to get the core stuff into the bead editor and try to gather feedback on it.</p>
<p>I&#8217;m specifically looking for feedback on the bead putting interface/controls as I want it to be as good as possible, also I want it to apply to touch screens which means some extra limitations (I had to scrap the bead piles that was in the first version). I&#8217;ve tested the latest prototype on my phone and it works alright. All the menus and icons are mock ups so don&#8217;t go mental on them.</p>
<p>To get more feedback I added a &#8220;leave feedback&#8221; box in the editor, this saves users the trouble of registering on the blog etc.</p>
<p>This is what I did:<br />
<a href="http://www.playchilla.com/wp-content/uploads/2012/03/mario.png"><img src="http://www.playchilla.com/wp-content/uploads/2012/03/mario.png" alt="" title="mario" width="383" height="369" class="alignnone size-full wp-image-725" /></a></p>
<p>I&#8217;m calling it &#8216;Beadly&#8217; for now. I don&#8217;t if that is going to be the final name.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_bead_1858132311"
			class="flashmovie"
			width="800"
			height="600">
	<param name="movie" value="http://www.playchilla.com/swf/bead.swf?v=104" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/bead.swf?v=104"
			name="fm_bead_1858132311"
			width="800"
			height="600">
		<param name="wmode" value="direct" />
	<!--<![endif]-->
		<br />
<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><br />

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/beadly-prototype-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beads</title>
		<link>http://www.playchilla.com/beads</link>
		<comments>http://www.playchilla.com/beads#comments</comments>
		<pubDate>Sun, 26 Feb 2012 18:43:49 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.playchilla.com/?p=701</guid>
		<description><![CDATA[Yesterday I was at a dinner, when we arrived we had to choose a beermat for our drinks. All beermats where customized for the guests and you had to figure out which one was yours. For me it was really simple (unfortunately I broke it): The next day I woke up with an urge to [...]]]></description>
				<content:encoded><![CDATA[<p>Yesterday I was at a dinner, when we arrived we had to choose a beermat for our drinks. All beermats where customized for the guests and you had to figure out which one was yours. For me it was really simple (unfortunately I broke it):</p>
<p><a href="http://www.playchilla.com/wp-content/uploads/2012/02/IMG_20120226_192512.jpg"><img class="alignnone size-medium wp-image-702" title="IMG_20120226_192512" src="http://www.playchilla.com/wp-content/uploads/2012/02/IMG_20120226_192512-225x300.jpg" alt="" width="225" height="300" /></a></p>
<p>The next day I woke up with an urge to implement a digital bead creator. Actually the idea to this came from my my girlfriend Anna and her friend Matilda who did a cool artsy project a year ago. They had the idea of doing something interactively with digital beads. Check out the <a href="http://ibeadyou.blogspot.com/">I bead you</a> project.</p>
<p>Also I have wanted to try out flash GPU support for some time but never gotten around to do it so I decided to strike two flies in one hit (as we say in Sweden). This was very easy and I only ran into one problem: The GPU support didn&#8217;t work at all at first. After an hour of browsing and reading forums I decided to try update my device drivers and viola, there where more triangles than I could count. I looked around a bit for a 3D engine to use and finally went with Away3D 4 beta. It was really easy to use. Here is the result (you can&#8217;t save your creations or anything so screenshot it if you want to keep).</p>
<p>Latest change list 17/3/2012<br />
- Added mock up menus, new UI, feedback box</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_bead_1610654883"
			class="flashmovie"
			width="800"
			height="600">
	<param name="movie" value="http://www.playchilla.com/swf/bead.swf?v=104" />
	<param name="wmode" value="direct" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.playchilla.com/swf/bead.swf?v=104"
			name="fm_bead_1610654883"
			width="800"
			height="600">
		<param name="wmode" value="direct" />
	<!--<![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>I have a cool idea on some expansions of this, not sure if it&#8217;s possible to do yet.. more on that later.</p>
<p>This is what Anna did:<br />
<a href="http://www.playchilla.com/wp-content/uploads/2012/02/bead.png"><img class="alignnone  wp-image-712" title="bead" src="http://www.playchilla.com/wp-content/uploads/2012/02/bead-300x265.png" alt="" width="338" height="299" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.playchilla.com/beads/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<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>8</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_1448049301"
			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_1448049301"
			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>
	</channel>
</rss>
