<?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>Yarrcade.com</title>
	<atom:link href="http://www.yarrcade.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yarrcade.com</link>
	<description>A heavy metal pirate&#039;s blog about free online flash games and their monetization as well as game design and development tutorials with actionscript3 and flash cs3 and some tricks to outperform in Microsoft Office ...</description>
	<lastBuildDate>Thu, 15 Sep 2011 15:05:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Excel: Preparing/Categorizing data for contour plots, surface plots and 3D histograms</title>
		<link>http://www.yarrcade.com/2011/08/25/excel-preparingcategorizing-data-for-contour-plots-surface-plots-and-3d-histogram/</link>
		<comments>http://www.yarrcade.com/2011/08/25/excel-preparingcategorizing-data-for-contour-plots-surface-plots-and-3d-histogram/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 02:50:24 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[MS Office]]></category>
		<category><![CDATA[histogram]]></category>
		<category><![CDATA[surface plot]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1710</guid>
		<description><![CDATA[Coming in with a lot of (continuous numerical) data, I struggled to find a neat chart type to display it. I went for a contour plot but it needs the data sorted in rows and columns while my data consisted &#8230; <a href="http://www.yarrcade.com/2011/08/25/excel-preparingcategorizing-data-for-contour-plots-surface-plots-and-3d-histogram/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://www.yarrcade.com/wp-content/uploads/2011/08/thumb_100x100_srfc.png" alt="surface data thumb" width="100" height="100" align="right" hspace="5"></div>
<p>Coming in with a lot of (continuous numerical) data, I struggled to find a neat chart type to display it. I went for a contour plot but it needs the data sorted in rows and columns while my data consisted of 5000 rows and two columns. Manual ordering would have been possible but to work intensive (5000 rows!). And since <code>COUNTIF</code> does not come with the ability two compare two criteria (or I just did not find it) I figured out a pretty good workaround. By the way, this works in Excel2007 but should work in 2003 and 2010 too.<br />
<span id="more-1710"></span><br />
Let&#8217;s assume I have got the data for a process (like a flow and a temperature) and I would like to see where the main operating point of a piece of equipment is. This requires three dimensions and is best shown in a <a href="http://en.wikipedia.org/wiki/Contour_line">countour plot</a> (<i>fig. a</i>).<br />
<div id="attachment_1712" class="wp-caption aligncenter" style="width: 413px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/08/contourplot.png" alt="contour plot" title="contour plot" width="403" height="300" class="size-full wp-image-1712" /><p class="wp-caption-text">Fig. a) The contour plot</p></div></p>
<p>The data structure we need can be seen <a href="http://office.microsoft.com/en-us/excel-help/creating-a-surface-chart-HA001117939.aspx">here</a>. In the case of TL;DR we need columns for x values (or x value categories in the case of continuous numerical data) and rows for the y values (or categories). What I needed was the number of value pairs (x and y) fitting into each of the category pairs. But before that:</p>
<h3>Setting up the data grid</h3>
<p><i>An example spreadsheed follows at the end of this article, feel free to peek into it to follow my explanations.</i><br />
Since we want to sort values (value pairs) we need some categories they fit in. To set up a category grid I first retrieved the following variables:</p>
<dt>x value range</dt>
<dd>the minimal and maximal value in x</dd>
<dt>y value range</dt>
<dd>the minimal and maximal value in y</dd>
<dt>x span</dt>
<dd>the actual difference between the max and min x values</dd>
<dt>y span</dt>
<dd>same as above for y</dd>
<dt>grid size</dt>
<dd>the number of categories for x and y, the higher this number the finer the grid (do twice for a non square grid)</dd>
<dt>x step</dt>
<dd>the range between the lower and upper bound of one category, determined by x span and grid size</dd>
<dt>y step</dt>
<dd>see x step</dd>
<p>The value ranges can be retrieved by the functions <code>MIN</code> and <code>MAX</code>. To have even values as categories, it is proven useful to nest those into<code>FLOOR</code> respectively <code>CEILING</code>. Caveat: <code>FLOOR</code> and <code>CEILING</code> in excel do round AWAY from zero and need a significance related to the actual value.<br />
So, if you&#8217;d like to <code>FLOOR</code> all values (away from zero) and you&#8217;ve got positive and negative numbers you could write <code>=FLOOR(yourCell,IF(yourCell>=0, 1,-1))</code>.<br />
If you&#8217;d rather like to have a floor rounding like in ActionsScript you would need to write <code>=IF(yourCell<0, CEILING(yourCell, -1), FLOOR(yourCell,1))</code> or the other way around for the 'real' ceiling rounding.</p>
<p>I recommend the second if you need categories in the negative to get the best bounds. The significance also has potential to influence the display of the data, so choose that depending on what you got or looks best.</p>
<p>The span just is the difference between min and max range value. I will not post the formula for this one. If you can't figure that out, you probably should not use excel or look it up in the attached example spreadsheet.</p>
<p>The step size is the quotient of span by grid size.</p>
<h3>Categorization</h3>
<p>Now that we have that, we set up three more columns:</p>
<dt>x category</dt>
<dd>the category, that the actual x value is in</dd>
<dt>y category</dt>
<dd>the category, that the actual y value is in</dd>
<dt>category</dt>
<dd>the final name of the category for the value pair, used for the <code>COUNTIF</code> function as a single criterion</dd>
<p>The x and y category column hold the quotients of the actual value by step size. Using <code>FLOOR</code> returns the value by means of <i>greater than or equal to</i> the lower bound and <i>less than</i> the upper bound.</p>
<p>The core piece of this workaround is the category column. With <code>=CONCATENATE(x category cell, "-", y category cell)</code> a hybrid label is created, in that case it returns something like "1-3" or "4-2" which is exactly one of the combinations we later look for with <code>COUNTIF</code>. If your gird size is equal to or exceeds 10 you may need to add leading zeros by <code>=CONCATENATE(IF(I3<10, "0", ""), I3, "-", IF(J3<10, "0", ""), J3)</code>. The returned values the look like "01-10" or "04-04". But that is more of an aesthetical thing.</p>
<h3>The grid data and the chart</h3>
<p>Now that's pretty simple again. Set up a table with x categories as the column headers and y categories as row headers. Enter <code>=COUNTIF(category column, CONCATENATE(IF(x catgory<10,"0",""),x category,"-",IF(y category<10,"0",""),y category))</code>. What it does is computing the category name (the combination) on the fly and counting how many labels in the category column it equals.</p>
<div id="attachment_1713" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.yarrcade.com/wp-content/uploads/2011/08/dataview.png"><img src="http://www.yarrcade.com/wp-content/uploads/2011/08/dataview-1024x518.png" alt="The surface.xlsx spreadsheet" title="The surface.xlsx spreadsheet" width="640" height="323" class="size-large wp-image-1713" /></a><p class="wp-caption-text">The surface.xlsx spreadsheet</p></div>
<p>Then just mark the cells (insert some row and column headings to use in the chart if you like first) and insert a surface chart or contour plot.</p>
<div id="attachment_1715" class="wp-caption aligncenter" style="width: 432px"><a href="http://www.yarrcade.com/wp-content/uploads/2011/08/surfaceplot.png"><img src="http://www.yarrcade.com/wp-content/uploads/2011/08/surfaceplot.png" alt="surface plot" title="surface plot" width="422" height="300" class="size-full wp-image-1715" /></a><p class="wp-caption-text">surface plot</p></div>
<p>Something I tested also, was a 3D column chart as a 3D histogram.</p>
<div id="attachment_1714" class="wp-caption aligncenter" style="width: 383px"><a href="http://www.yarrcade.com/wp-content/uploads/2011/08/histogram.png"><img src="http://www.yarrcade.com/wp-content/uploads/2011/08/histogram.png" alt="histogram" title="histogram" width="373" height="300" class="size-full wp-image-1714" /></a><p class="wp-caption-text">histogram</p></div>
<p>It might sound difficult at first but feel free to play with the example and make some nice charts. If there are questions just post a comment.<br />
Source: <a href='http://www.yarrcade.com/wp-content/uploads/2011/08/SurfaceData.xlsx'>SurfaceData.xlsx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2011/08/25/excel-preparingcategorizing-data-for-contour-plots-surface-plots-and-3d-histogram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Probably useful snippets: Circle Text</title>
		<link>http://www.yarrcade.com/2011/07/26/probably-useful-snippets-circle-text/</link>
		<comments>http://www.yarrcade.com/2011/07/26/probably-useful-snippets-circle-text/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 08:19:29 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[circular text]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1695</guid>
		<description><![CDATA[Circular text can be useful in several designs, so here is a little class that produces the following: What the swf shows is first the &#8216;debug-version&#8217; which changes after a click to the naked text version. Consecutive clicks will produce &#8230; <a href="http://www.yarrcade.com/2011/07/26/probably-useful-snippets-circle-text/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://www.yarrcade.com/wp-content/uploads/2011/07/thumbnail_100x100.png" alt=" circle text thumb" width="100" height="100" align="right" hspace="5"></div>
<p>Circular text can be useful in several designs, so here is a little class that produces the following:</p>
<div class="centerswf">
<embed src="http://www.yarrcade.com/wp-content/uploads/2011/07/CircleText.swf" width="320" height="240"></embed>
</div>
<p>What the swf shows is first the &#8216;debug-version&#8217; which changes after a click to the naked text version. Consecutive clicks will produce the same for randomized values.<br />
<span id="more-1695"></span></p>
<h3>CircleText.as</h3>
<pre>
package
{
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	/**
	 * CircleText.as
	 * @author kegogrog
	 */
	public class CircleText extends Sprite
	{
		private static const degToRad:Number = Math.PI / 180;</pre>
<p>These are the basic imports and the private var degToRad used for the conversion of degrees into radians.</p>
<pre>
		public function CircleText( startAngle:Number = -90, endAngle:Number = 90, radius:Number = 80, inner:Boolean = false, text:String = "This text is a test.", debug:Boolean = true )</pre>
<p>The class accepts several inputs, the most important are <code>startAngle</code>, <code>endAngle</code> and <code>radius</code>. I hope I do not need to explain those. <code>inner</code> defines if the text is located on the outside of the circle or on the inside. <code>text</code> should be pretty obvious and debug just defines what one can see. I recommend to delete that once the class is implemented while it is nothing the user has to see.</p>
<pre>
		{
			var tff:TextFormat = new TextFormat();
			tff.font = "calibri";
			tff.size = 20;</pre>
<p>It is important to use an embedded font, so here I am just defining a text format. One could also reference that in the constructor or use a global format.</p>
<pre>
			var sr:Number = startAngle * degToRad;
			var er:Number = endAngle * degToRad;

			if ( debug )
			{
				this.graphics.lineStyle(0, 0xcccccc);
				this.graphics.drawCircle(0, 0, 3);
				this.graphics.drawCircle(0, 0, radius);
				this.graphics.drawCircle(Math.sin(sr) * radius, -Math.cos(sr) * radius, 4);
				this.graphics.drawCircle(Math.sin(er) * radius, -Math.cos(er) * radius, 2);
			}</pre>
<p>The angles are converted to radians and if debug is true the midpoint, the circle itself are drawn and the start and end of the text is marked.</p>
<pre>
			var i:int;
			var tf:TextField;
			var m:Matrix;
			for ( i = 0; i < text.length; i++ )
			{
				tf = new TextField();
				tf.selectable = false;
				tf.autoSize = TextFieldAutoSize.LEFT;
				tf.defaultTextFormat = tff;
				tf.embedFonts = true;
				tf.text = text.charAt(i);

				if ( debug )
				{
					tf.background = true;
					tf.backgroundColor = 0xcccccc;
					tf.alpha = 0.8;
				}

				m = new Matrix();
				m.translate( -tf.width * 0.5, -tf.height * ( inner ? 0 : 1 ) - radius );
				m.rotate( sr + ( ( er - sr ) / ( text.length - 1 ) ) * i );
				tf.transform.matrix = m;

				addChild(tf);
			}
		}
	}
}</pre>
<p>The biggest code chunk here splits the string into single characters, creates a textfield for each one and applies translation (depending on <code>inner</code>) and rotation according to the start and end angle and the characters position in the string. The translation in x moves the textfield so that it is centered.</p>
<p>I was using FlashDevelop for this presentation with the following</p>
<h3>Main.as</h3>
<p>:</p>
<pre>
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 * Main.as for CircleText
	 * @author kegogrog
	 */
	public class Main extends Sprite
	{
		[Embed(
			source = 'font/calibri.ttf',
			fontName = "calibri",
			fontWeight = "normal",
			advancedAntiAliasing = "true",
			mimeType = "application/x-font",
			fontStyle = "normal",
			embedAsCFF = 'false',
			unicodeRange = 'U+0020-U+007E'
			)]
		private var calibri:Class;

		private var startAngle:Number = -90;
		private var endAngle:Number = 90;
		private var radius:Number = 80;
		private var inner:Boolean = false;
		private var text:String = "This text is a test.";
		private var debug:Boolean = true;

		private var ct:CircleText;

		public function Main():void
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point

			buildText();
			stage.addEventListener(MouseEvent.CLICK, buildText);
		}

		private function buildText(event:MouseEvent = null):void
		{
			if ( ct )
			{
				removeChild(ct);
			}
			ct = new CircleText( startAngle, endAngle, radius, inner, text, debug );
			ct.x = stage.stageWidth >> 1;
			ct.y = stage.stageHeight >> 1;
			addChild(ct);

			if ( !debug )
			{
				startAngle = Math.random() * 360;
				endAngle = startAngle + Math.random() * 180 + 90;
				radius = Math.random() * 30 + 50;
				inner ? inner = false : inner = true;
			}
			debug ? debug = false : debug = true;
		}
	}
}</pre>
<p><code>buildText</code> takes the predefined variables and adds a new CircleText. With the next click it shows the non-debug version and and changes the variables prior to the next click.</p>
<p>Being a sprite, CircleText can be rotated by its own <code>rotation</code> property. One could also put all text fields into an array and animate them, maybe flying of the screen from the center. Have fun playing with that.</p>
<p>Yoho!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2011/07/26/probably-useful-snippets-circle-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game: TripleDrop</title>
		<link>http://www.yarrcade.com/2011/05/06/game-tripledrop/</link>
		<comments>http://www.yarrcade.com/2011/05/06/game-tripledrop/#comments</comments>
		<pubDate>Fri, 06 May 2011 15:15:13 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[game development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[mochiads]]></category>
		<category><![CDATA[bubble smile]]></category>
		<category><![CDATA[bubblesmile]]></category>
		<category><![CDATA[flash game]]></category>
		<category><![CDATA[match three]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1667</guid>
		<description><![CDATA[Yay, new game! What, another match three? Come on, that&#8217;s going to get boring. But wait, there is something different in there. Alright, here is my new game. Years ago, I had this on a phone and really liked it &#8230; <a href="http://www.yarrcade.com/2011/05/06/game-tripledrop/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://yarrcade.com/gamefiles/tripledrop/_thumb_100x100.png" alt="TripleDrop" width="100" height="100" align="right" hspace="5"></div>
<p>Yay, new <a href="http://www.yarrcade.com/games/tripledrop/#more" target="_blank">game</a>! What, another match three? Come on, that&#8217;s going to get boring. But wait, there is something different in there.<br />
Alright, here is my new game. Years ago, I had this on a phone and really liked it but never found anything like it in flash. So, I made it. Again with <a href="http://www.flashdevelop.org/" target="_blank">FlashDevelop</a> and without any single graphical asset. Seems I developed an interest in computer generated graphics. With all the given filters in flash it&#8217;s pretty simple though to make something shiny.<br />
<span id="more-1667"></span><br />
Ok, some facts and pictures. The first fact: I forgot why I choose blue as the main theme.<br />
<div class="wp-caption aligncenter" style="width: 650px"><a href="http://www.yarrcade.com/gamefiles/tripledrop/screens/screenMenu.png"><img alt="The menu screen with kegMenu™" src="http://www.yarrcade.com/gamefiles/tripledrop/screens/screenMenu.png" title="The menu screen with kegMenu™" width="640" height="480" /></a><p class="wp-caption-text">The menu screen with kegMenu™, German &#038; muted</p></div></p>
<p>Programming the game took approximately 2 days. Doing the framework was the harder part. Or shall I say overdoing. That&#8217;s what I tend to. All communication between classes is now done with custom events. And wow, these are powerful. I used a state machine for the first time and that makes sense when creating a game without lag.</p>
<p>The game itself comes, like <a href="http://www.yarrcade.com/2011/02/26/game-tripop/" target="_blank">TriPop</a>, with a timed mode, where one has several seconds to score as many points as possible, and my favourite skilled mode, where only moves cost energy and no clock stresses the player. The new thing here is the hexagonal positioning of the balls and that you need to turn triplets either clockwise or counterclockwise to form lines (basic match three game description goes here&#8230;) of three or more balls of the same color. With chains longer than three balls or more than one chain on the initial turn you can regain energy. So, choose wisely and play forever. Balancing was big part here, since the timed mode in <a href="http://www.yarrcade.com/2011/02/26/game-tripop/" target="_blank">TriPop</a> allowed the player to swap gems at no cost and thus create really long chains and score high, higher, woot. This time, turning the triplet comes with energy cost (evil grin here).</p>
<p>I first wanted to include a simple pattern mode (different colored balls displaying different patterns) for a better differentiation between the different balls that could be usable for e.g. colorblind people. It turned out, that I made the patterns, which were simple dots at first, a little bit more entertaining.<br />
<div class="wp-caption aligncenter" style="width: 650px"><a href="http://www.yarrcade.com/gamefiles/tripledrop/screens/screenGame.png"><img alt="The game with pattern mode turned off (above) and on" src="http://www.yarrcade.com/gamefiles/tripledrop/screens/screenGame.png" title="The game with pattern mode turned off (above) and on" width="640" height="480" /></a><p class="wp-caption-text">The game with pattern mode turned off (above) and on</p></div></p>
<p>The game comes in 10 languages. English and German were done by me, the rest was done by a part of the great Mochi Community, namely:</p>
<ul>
<li><a href="http://games-garden.com" target="_blank">Ernesto Quezada</a>, Spanish</li>
<li><a href=http://lustigames.hu" target="_blank">LustiGames</a>, Hungarian</li>
<li><a href="http://maras.own3d.cz/" target="_blank">Maras</a>, Czech</li>
<li><a href="http://www.kcnhgames.com" target="_blank">kcnh</a>, Dutch</li>
<li><a href="http://www.kou-games.blogspot.com" target="_blank">kou</a>, Greek</li>
<li><a href="mailto:starready@yandex.ru" target="_blank">Pavel</a>, Russian</li>
<li><a href="http://www.prahadise.com" target="_blank">J.K.S.</a>, Finnish</li>
<li><a href="http://www.ihaveagame.com" target="_blank">José Ferreira</a>, Portuguese</li>
</ul>
<p>So, in the attempt to let people help you on a specific task, the most important thing I learned is: BE SPECIFIC ABOUT WHAT YOU WANT. I did send out the strings I needed to be translated and installed a test version of the game. What I should have done in addition would have been some descriptions for my dearest translation team to really know that I mean, because aside from SPO there may be other differences in languages&#8230; Well, that was one learning. It went pretty good though for a first try. Use short sentences and don&#8217;t focus on reusability of single words. The second important was, you may need a fallback font for special characters. Or, upfront, choose a font that supports those. There is a file size optimization possibility I did use for the first languages. It is &#8216;only embed the needed fonts&#8217;. But you can run into trouble there. So be careful. Write a little program, feed it all your strings, let it sort out the uniques and embed those. Otherwise you may miss one or two.</p>
<p>So, aside from all that I included some progression. With every game played, the points are summed and with every level gained the player gets more energy for the next game. Let&#8217;s see if I can make it to level 99 (it&#8217;s unlimited by the way).<br />
<div class="wp-caption aligncenter" style="width: 650px"><a href="http://www.yarrcade.com/gamefiles/tripledrop/screens/ScreenScore.png"><img alt="The game over screen showing the players progress" src="http://www.yarrcade.com/gamefiles/tripledrop/screens/ScreenScore.png" title="The game over screen showing the players progress" width="640" height="480" /></a><p class="wp-caption-text">The game over screen showing the players progress</p></div></p>
<p>The player&#8217;s level is also accessible from the kegMenu™ and there is another leaderboard for the level reached. So, if you are interested you can track my addiction to this game.</p>
<p>Since it&#8217;s above 30 degrees Celsius now I&#8217;m running out of all the cool stuff I wanted to write. Oh, nearly forgot, here is a <a href="http://www.yarrcade.com/games/tripledrop/#more" target="_blank">link to the game</a>.</p>
<p>Yoho, the game (you just lost it). I love memebase.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2011/05/06/game-tripledrop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting your game on Facebook the easy way</title>
		<link>http://www.yarrcade.com/2011/03/05/getting-your-game-on-facebook-the-easy-way/</link>
		<comments>http://www.yarrcade.com/2011/03/05/getting-your-game-on-facebook-the-easy-way/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 11:49:49 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[mochiads]]></category>
		<category><![CDATA[monetization]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook app]]></category>
		<category><![CDATA[flash game]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1603</guid>
		<description><![CDATA[What&#8217;s necessary for putting a flash game on facebook? Not much. I did that by putting a php file onto my server which acts as the canvas file. Into the same folder I unpacked the FB PHP SDK. FB likes &#8230; <a href="http://www.yarrcade.com/2011/03/05/getting-your-game-on-facebook-the-easy-way/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://www.yarrcade.com/wp-content/uploads/2011/03/20110305_FBapps_thumb100x100.png" alt="FBthumb" width="100" height="100" align="right" hspace="5"></div>
<p>What&#8217;s necessary for putting a flash game on facebook? Not much. I did that by putting a php file onto my server which acts as the canvas file. Into the same folder I unpacked the <a href="https://github.com/facebook/php-sdk/" target="_blank">FB PHP SDK</a>. FB likes developers and thus gives you an application profile page, the only thing you have to worry about is the actual canvas page.<br />
<span id="more-1603"></span></p>
<p>To create an app for TriPop I followed the normal procedure, added an app in the developer section, copied the given keys, created the php file, filled out several, mostly self explaining, fields including the path to my file and there it is. <a href="http://www.facebook.com/apps/application.php?id=169834366397818" target="_blank">TriPop&#8217;s application profile page</a> and the <a href="http://apps.facebook.com/tripop-game/" target="_blank">TriPop application</a> itself.</p>
<p>The FB SDK, once unpacked needs to go onto the server to as the php will refer to it.</p>
<p>The code for a simple application canvas (no approval by the user required because no user data is used) looks like this:</p>
<pre>
&#60;?php
// Awesome Facebook Application
//
// Name: Application Name
//

require_once 'facebook-php-sdk/src/facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId' =&#62; '***************',
  'secret' =&#62; '********************************',
  'cookie' =&#62; false,
)); 

?&#62;

&#60;div style = " text-align: right; width: 640px; margin-bottom: 5px; "&#62;
	Back to
	&#60;fb:application-name
		linked="true"
	/&#62;
	's application page
&#60;/div&#62;

&#60;div style = " text-align: center; width: 640px; margin-bottom: 5px; "&#62;
	&#60;fb:swf
		swfbgcolor="ffffff"
		swfsrc='http://www.yarrcade.com/gamefiles/tripop/TriPop.swf'
		width='640' height='480'
	/&#62;
&#60;/div&#62;
</pre>
<p>The first div is just for a text field at the top that can be used as a back button to the application profile page. The next div encloses the swf. And that is all. Really&#8230;</p>
<p>For more information refer to the <a href=" http://developers.facebook.com/docs/guides/canvas/" target="_blank">FB Developer Documentation</a>. Just if you need to go deeper or if you want to use more functions. Moreover, for dedicated development on the FB platform you may want to have a look at <a href="http://gamedev.michaeljameswilliams.com/2011/01/10/flash-facebook-development-book/#more-1186" target="_blank">Michael&#8217;s</a> <a href="https://www.packtpub.com/sites/default/files/0744-chapter-2-welcome-to-the-graph.pdf" target="_blank">new book</a>.</p>
<div class="centerswf">
<iframe src="http://rcm.amazon.com/e/cm?t=yarrcade-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=184969074X&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2011/03/05/getting-your-game-on-facebook-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding assets in FlashDevelop</title>
		<link>http://www.yarrcade.com/2011/03/05/embedding-assets-in-flashdevelop/</link>
		<comments>http://www.yarrcade.com/2011/03/05/embedding-assets-in-flashdevelop/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 11:12:13 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[mochiads]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[flash develop]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1602</guid>
		<description><![CDATA[Embedding asstes into your FD project is pretty simple. In fact it is as easy as 1, 2, 3. One: Copy, two: embed, three: use. Let&#8217;s go! 1. Copy Alright, with your assets ready you should create a folder in &#8230; <a href="http://www.yarrcade.com/2011/03/05/embedding-assets-in-flashdevelop/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://www.yarrcade.com/wp-content/uploads/2011/03/20110305_fdthumb_100x100.png" alt="FDthumb" width="100" height="100" align="right" hspace="5"></div>
<p>Embedding asstes into your FD project is pretty simple. In fact it is as easy as 1, 2, 3. One: Copy, two: embed, three: use. Let&#8217;s go!<br />
<span id="more-1602"></span></p>
<h3>1. Copy</h3>
<p>Alright, with your assets ready you should create a folder in your project folder or even in <code>src</code>. For the following example I created the folder <code>sounds</code> for (obviuosly) sounds and copied the font directly into <code>src</code>.<br />
<div id="attachment_1605" class="wp-caption aligncenter" style="width: 335px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/03/project-folder.png" alt="The FD project folder" title="The FD project folder" width="325" height="271" class="size-full wp-image-1605" /><p class="wp-caption-text">The FD project folder</p></div></p>
<h3>2. Embed</h3>
<p>Embedding a font efficiently means knowing which glyphs you need. The following is a great source for finding <a href="http://www.unicode.org/Public/UNIDATA/NamesList.txt" target="_blank">Unicode ranges</a>.</p>
<pre>
	public dynamic class Main extends MovieClip
	{
		[Embed(
			source = 'BERLIN.TTF',
			fontName = "berlinSans",
			fontWeight = "bold",
			advancedAntiAliasing = "true",
			mimeType = "application/x-font",
			fontStyle = "normal",
			embedAsCFF = 'false',
			unicodeRange = 'U+0020,
					U+0041-U+005A,
					U+0061-U+007A,
					U+0030-U+0039,
					U+002E, U+002F,
					U+0027, U+00A9,
					U+00E4, U+00FC'
			)]
		private var berlinSans:Class;

		[Embed( source = 'sounds/SoundPop.mp3')]
		private var SoundPop:Class;
		public var soundPop:Sound;

		[Embed(source = 'sounds/sound12.mp3')]
		private var SoundSwap:Class;
		public var soundSwap:Sound;

		[Embed(source = 'sounds/WintersDream.mp3')]
		private var Music:Class;
		public var music:Sound;
</pre>
<p>All embeds are followed directly by private vars, defining the embedded assets as classes. To use them public vars are created. Caveat: If you create folders anywhere, remember the path ( for <code>source</code>)!</p>
<h3>3. Use</h3>
<pre>
		public function Main():void
		{
			music = new Music();
			soundPop = new SoundPop();
			soundSwap = new SoundSwap();
</pre>
<p>The fonts are used simply by referring to the <code>fontName</code> you set in the <code>embed</code> section. By setting <code>yourTextField.embedFonts</code> you can use your font.</p>
<pre>
			iFormat = new TextFormat();
			iFormat.font = "berlinSans";
			iFormat.color = 0xaaaaaa;
			iFormat.size = 24;

			gameName = new TextField();
			gameName.embedFonts = true;
			gameName.defaultTextFormat = iFormat;
			gameName.text = "yourText here";
			addChild(gameName);
			gameName.selectable = false;
			gameName.autoSize = TextFieldAutoSize.LEFT;
</pre>
<p>Pretty much always you should set <code>yourTextField.selectable</code> to <code>false</code>. As a player I am always a bit picky when it comes to buttons where the text selection tool shows up.</p>
<p>The same thing goes with graphics I think though I didn&#8217;t try that.</p>
<p>Yoho!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2011/03/05/embedding-assets-in-flashdevelop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game: TriPop</title>
		<link>http://www.yarrcade.com/2011/02/26/game-tripop/</link>
		<comments>http://www.yarrcade.com/2011/02/26/game-tripop/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 10:15:33 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[game development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[mochiads]]></category>
		<category><![CDATA[match 3]]></category>
		<category><![CDATA[match three]]></category>
		<category><![CDATA[tripop]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1579</guid>
		<description><![CDATA[The selfish creation. I like match three games, so I made one. What I don&#8217;t like in games is time pressure whatever more &#8216;excitement&#8217; it may bring. So I made me a little relaxing game. When I thought about making &#8230; <a href="http://www.yarrcade.com/2011/02/26/game-tripop/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://yarrcade.com/gamefiles/tripop/thumb_100x100.png" alt="TriPop" width="100" height="100" align="right" hspace="5"></div>
<p>The selfish creation. I like match three games, so I made one. What I don&#8217;t like in games is time pressure whatever more &#8216;excitement&#8217; it may bring. So I made me a little relaxing game. When I thought about making it public I added a timed mode, because there are people who like that. The most interesting fact from the developer side of view: I did the whole game in <a href="http://www.flashdevelop.org/" target="_blank">FlashDevelop</a> and there is not a single graphical asset included. It&#8217;s all code generated.<br />
<span id="more-1579"></span><br />
Strategic alignment:</p>
<ul>
<li>Create a casual game as expandable and thus exploitable template</li>
<li>Learn to work with FlashDevelop</li>
</ul>
<p>The mechanism of a match three is trickier than thought. I decided against a flood fill check algorithm and instead used a double loop (rows, then columns). That way the first check is cheaper because only the swapped region (1 row and 2 cloumns or 2 rows and 1 column) is checked. I managed to implement detection of all kinds of combos. By checking rows first and columns later there are combinations that aren&#8217;t easily marked as having the same elements. But a little backwards loop over all found matches afterwards did that.</p>
<p>The game features:</p>
<ul>
<li>A title screen with the expanded kegMenu<sup>&#174;</sup> and some fluffy clouds floating around. The game uses automatic language detection via <code>System.Capabilities</code> for english and german.</li>
<div id="attachment_1587" class="wp-caption aligncenter" style="width: 650px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/02/screenMenu.png" alt="The TriPop menu screen" title="The TriPop menu screen" width="640" height="480" class="size-full wp-image-1587" /><p class="wp-caption-text">The TriPop menu screen</p></div>
<li>A settings screen with full sound control (main, music and effects) as well a language choice.</li>
<div id="attachment_1589" class="wp-caption aligncenter" style="width: 650px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/02/screenSettings.png" alt="The TriPop settings screen" title="The TriPop settings screen" width="640" height="480" class="size-full wp-image-1589" /><p class="wp-caption-text">The TriPop settings screen</p></div>
<li>A screen showing the basic instructions</li>
<div id="attachment_1592" class="wp-caption aligncenter" style="width: 650px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/02/screenHelp.png" alt="The TriPop help screen" title="The TriPop help screen" width="640" height="480" class="size-full wp-image-1592" /><p class="wp-caption-text">The TriPop help screen</p></div>
<li>A screen that informs the player that a link he clicked is not working. This is mostly due to the parameters <code>allowNetworking</code> or <code>allowScriptAccess</code> set by the site owner. When it is detected via <code>try...catch</code> the link is copied to the clipboard and the user is informed that he can just paste it into the address bar. I didn&#8217;t want to block the game at this moment. One could include the domain where the links are blocked for a dynamic blacklist or something but blocking the game would be rather annoying for the player.</li>
<div id="attachment_1593" class="wp-caption aligncenter" style="width: 650px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/02/screenLinkBlock.png" alt="The TriPop link block alert" title="The TriPop link block alert" width="640" height="480" class="size-full wp-image-1593" /><p class="wp-caption-text">The TriPop link block alert</p></div>
<li>And a little &#8216;console screen&#8217; though no input is possible. I included it just for me to see if the game is working correctly. It is accessible via keyboard input &#8216;IDDQD&#8217;. In-game this leads to a faster game end, a feature that I needed to test the leaderboards.</li>
<div id="attachment_1594" class="wp-caption aligncenter" style="width: 650px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/02/screenDev.png" alt="The TriPop developer console" title="The TriPop developer console" width="640" height="480" class="size-full wp-image-1594" /><p class="wp-caption-text">The TriPop developer console</p></div>
<li>And of course the game. As this is the developer log I just wanted to show off the gimmicks first. As already mentioned, all graphics are code generated. The size of the final swf including the MochiAds preloader is 307KB with:
<ul>
<li>238KB for the background loop (&#8216;Winter&#8217;s Dream&#8217;, also on <a href="http://www.newgrounds.com/audio/listen/401812" target="_blank">NewGrounds Audio</a>)</li>
<li>10KB for the sound effects</li>
<li>39KB for the game itself</li>
</ul>
</li>
<div id="attachment_1582" class="wp-caption aligncenter" style="width: 650px"><img src="http://www.yarrcade.com/wp-content/uploads/2011/02/Unbenannt-2.png" alt="A TriPop game screenshot" title="A TriPop game screenshot" width="640" height="480" class="size-full wp-image-1582" /><p class="wp-caption-text">A TriPop game screenshot</p></div>
</ul>
<p>And here is the <a href="http://www.yarrcade.com/games/tripop/#more" target="_blank">game link</a>.</p>
<p>Have fun playing it and leave a comment if you like to. Though it is still no &#8216;industrial standard&#8217;, I feel that this is my most professional work and I had a lot of fun developing it with only free tools. FlashDevelop is very comfortable for writing code, not only regarding the space on the screen for conding on a laptop monitor.</p>
<p>Yoho!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2011/02/26/game-tripop/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>More Moving 3D Environments in Flash</title>
		<link>http://www.yarrcade.com/2010/12/11/more-moving-3d-environments-in-flash/</link>
		<comments>http://www.yarrcade.com/2010/12/11/more-moving-3d-environments-in-flash/#comments</comments>
		<pubDate>Sat, 11 Dec 2010 18:58:26 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[grids]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[CS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1558</guid>
		<description><![CDATA[A little further experiment with 3D makes me want to play LHX or D-Track. If the movie does not react to keyboard input, click once inside of it to give it focus. There are a lot of optimization opportunities, though &#8230; <a href="http://www.yarrcade.com/2010/12/11/more-moving-3d-environments-in-flash/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://www.yarrcade.com/wp-content/uploads/2010/12/3Dexp1.png" alt="Moving 3D Environments" title="Moving 3D Environments" width="100" height="100"></div>
<p>A little further experiment with 3D makes me want to play <a href="http://en.wikipedia.org/wiki/LHX_Attack_Chopper" target="_blank">LHX</a> or <a href="http://en.wikipedia.org/wiki/Death_track" target="_blank">D-Track</a>.</p>
<p><span id="more-1558"></span></p>
<div class="centerswf">
<embed src="http://www.yarrcade.com/wp-content/uploads/2010/12/drunk11.swf" width="640" height="480"></embed>
</div>
<p>If the movie does not react to keyboard input, click once inside of it to give it focus.</p>
<p>There are a lot of optimization opportunities, though the frame rate seems to be pretty stable. Smoothing the terrain could be next, depth sorting is obviuosly not the best. Well, that&#8217;s what weekends are for, right?</p>
<p>Source? Sure: <a href="http://www.yarrcade.com/wp-content/uploads/2010/12/drunk11.zip" target="_blank">ZIP (13.9 KB)</a></p>
<p>Please tell me in the comments if it works for you and if you experience any lags.</p>
<p>Yoho!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2010/12/11/more-moving-3d-environments-in-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>3D Movement in a moving 3D Environment 2</title>
		<link>http://www.yarrcade.com/2010/11/28/3d-movement-in-a-moving-3d-environment-2/</link>
		<comments>http://www.yarrcade.com/2010/11/28/3d-movement-in-a-moving-3d-environment-2/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 16:14:17 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[mochiads]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1554</guid>
		<description><![CDATA[Click the movie to give focus to the keyboard.]]></description>
			<content:encoded><![CDATA[<div class="centerswf">
<embed src="http://www.yarrcade.com/wp-content/uploads/2010/11/drunk4.swf" width="640" height="480"></embed>
</div>
<p>Click the movie to give focus to the keyboard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2010/11/28/3d-movement-in-a-moving-3d-environment-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D Movement in a moving 3D Environment</title>
		<link>http://www.yarrcade.com/2010/11/28/3d-movement-in-a-moving-3d-environment/</link>
		<comments>http://www.yarrcade.com/2010/11/28/3d-movement-in-a-moving-3d-environment/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 11:40:40 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[mochiads]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1539</guid>
		<description><![CDATA[With the code derived from the last post I wanted to try to get multiple (partly moving) objects into an environment that moves. Done. There are two &#8220;racers&#8221; on a plane. One of the racers is moving while the &#8220;camera&#8221; &#8230; <a href="http://www.yarrcade.com/2010/11/28/3d-movement-in-a-moving-3d-environment/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://www.yarrcade.com/wp-content/uploads/2010/11/drunk2.png" alt="3D Movement in a moving 3D Environment" title="3D Movement in a moving 3D Environment" width="100" height="100"></div>
<p>With the code derived from the <a href="http://www.yarrcade.com/2010/11/26/what-3d-and-cs3-and-spam-comments-and-programming-drunk/">last post</a> I wanted to try to get multiple (partly moving) objects into an environment that moves. Done. There are two &#8220;racers&#8221; on a plane. One of the racers is moving while the &#8220;camera&#8221; is panning around the plane.</p>
<p><span id="more-1539"></span></p>
<div class="centerswf">
<embed src="http://www.yarrcade.com/wp-content/uploads/2010/11/drunk3.swf" width="640" height="480"></embed>
</div>
<p>Interested in the source? It would definitely look better if it wasn&#8217;t timeline code.</p>
<pre>
var world:MovieClip = new MovieClip();
world.x = stage.stageWidth*0.5;
world.y = stage.stageHeight*0.5;
addChild( world );

var focalLength:Number = 500;

var allPointsArray:Array = new Array();
var centerPointsArray:Array = new Array();

var triangleArray:Array = new Array();

var plane = new Object();
plane.center = make3DCenter( 0, 0, 0, plane );
plane.rot = make3DCenter( 0, 0, 0, plane );
plane.pointsArray = [
					make3DPoint(-200,-200,0, plane),
					make3DPoint(-200,200,0, plane),
					make3DPoint(200,200,0, plane),
					make3DPoint(200,-200,0, plane),
					];

plane.triangles = [
				   makeTriangle(plane.pointsArray[0], plane.pointsArray[1], plane.pointsArray[2], 0x000000),
				   makeTriangle(plane.pointsArray[0], plane.pointsArray[2], plane.pointsArray[3], 0xdddddd)
				   ];

var object1 = new Object();
object1.center = make3DCenter( 0, 100, 0, object1 );
object1.rot = make3DCenter( 0, 0, 0, object1 );
object1.pointsArray = [
					   make3DPoint( 30,  0,  0, object1),
					   make3DPoint(-30,  0,  -20, object1),
					   make3DPoint(-30,-20,  0, object1),
					   make3DPoint(-30, 20,  0, object1)

];
object1.triangles = [
					 makeTriangle( object1.pointsArray[0], object1.pointsArray[2], object1.pointsArray[1], 0xff0000),
					 makeTriangle( object1.pointsArray[0], object1.pointsArray[1], object1.pointsArray[3], 0x0000ff),
					 makeTriangle( object1.pointsArray[1], object1.pointsArray[2], object1.pointsArray[3], 0x00ff00)
					 ];
object1.vx = 5;
object1.vy = 5;

var object2 = new Object();
object2.center = make3DCenter( 100, 100, 0, object2 );
object2.rot = make3DCenter( 0, 0, 0, object2 );
object2.pointsArray = [
					   make3DPoint( 30,  0,  0, object2),
					   make3DPoint(-30,  0,  -20, object2),
					   make3DPoint(-30,-20,  0, object2),
					   make3DPoint(-30, 20,  0, object2)

];
object2.triangles = [
					 makeTriangle( object2.pointsArray[0], object2.pointsArray[2], object2.pointsArray[1], 0xff0000),
					 makeTriangle( object2.pointsArray[0], object2.pointsArray[1], object2.pointsArray[3], 0x0000ff),
					 makeTriangle( object2.pointsArray[1], object2.pointsArray[2], object2.pointsArray[3], 0x00ff00)
					 ];
object2.vx = 0;
object2.vy = 0;

function makeTriangle( p1, p2, p3, col)
{
	var triangle = new Object();
	triangle.points = [p1, p2, p3];
	triangle.col = col;
	triangleArray.push( triangle );
}

function make3DCenter ( x, y, z, o)
{
	var point = new Object();
	point.x = x;
	point.y = y;
	point.z = z;
	point.o = o;
	centerPointsArray.push(point);
	return point;
};

function make3DPoint ( x, y, z, o)
{
	var point = new Object();
	point.ox = x;
	point.x = x;
	point.oy = y;
	point.y = y;
	point.oz = z;
	point.z = z;
	point.o = o;
	allPointsArray.push(point);
	return point;
};

function make2DPoint (x,y, depth, scaleFactor)
{
	var point = new Object();
	point.x = x;
	point.y = y;
	point.depth = depth;
	point.scaleFactor = scaleFactor;
	return point;
};

function get3DPoints ( object )
{
	var sx = Math.sin(object.rot.x);
	var cx = Math.cos(object.rot.x);
	var sy = Math.sin(object.rot.y);
	var cy = Math.cos(object.rot.y);
	var sz = Math.sin(object.rot.z);
	var cz = Math.cos(object.rot.z);
	var x,y,z, xy,xz, yx,yz, zx,zy;
	var i = object.pointsArray.length;
	while (i--){
		x = object.pointsArray[i].ox;
		y = object.pointsArray[i].oy;
		z = object.pointsArray[i].oz;

		xy = cx*y - sx*z;
		xz = sx*y + cx*z;
		yz = cy*xz - sy*x;
		yx = sy*xz + cy*x;
		zx = cz*yx - sz*xy;
		zy = sz*yx + cz*xy;

		object.pointsArray[i].x = zx + object.center.x;
		object.pointsArray[i].y = zy + object.center.y;
		object.pointsArray[i].z = yz + object.center.z;
	}
}

function Transform3DPointsTo2DPoints ( points, axisRotations )
{
	var TransformedPointsArray = [];
	var sx = Math.sin(axisRotations.x);
	var cx = Math.cos(axisRotations.x);
	var sy = Math.sin(axisRotations.y);
	var cy = Math.cos(axisRotations.y);
	var sz = Math.sin(axisRotations.z);
	var cz = Math.cos(axisRotations.z);
	var x,y,z, xy,xz, yx,yz, zx,zy, scaleFactor;

	var i = points.length;
	while (i--){

		x = points[i].x;
		y = points[i].y;
		z = points[i].z;

		xy = cx*y - sx*z;
		xz = sx*y + cx*z;
		yz = cy*xz - sy*x;
		yx = sy*xz + cy*x;
		zx = cz*yx - sz*xy;
		zy = sz*yx + cz*xy;

		scaleFactor = focalLength/(focalLength + yz);

		x = zx*scaleFactor;
		y = zy*scaleFactor;
		z = yz;

		TransformedPointsArray[i] = make2DPoint(x, y, -z, scaleFactor);
	}
	return TransformedPointsArray;
};

var ballArray:Array = new Array();

for ( var i:int = 0; i < allPointsArray.length; i++){
	var ball:MovieClip = new MovieClip();
	var colors = [ 0xffffff, 0x990000 ];
	var fillType:String = GradientType.RADIAL;
	var alphas:Array = [1, 1];
	var ratios:Array = [0x00, 0xff];
	var matr:Matrix = new Matrix();
	matr.createGradientBox(-20*0.4, -20*0.4, 0, 0, 0);
	var spreadMethod:String = SpreadMethod.PAD;
	var interpolationMethod:String = InterpolationMethod.RGB;
	var focal:Number = -0.1;
	with(ball.graphics)
	{
		lineStyle( 1, 0x330000 );
		beginGradientFill( fillType, colors, alphas, ratios, matr, spreadMethod, interpolationMethod, focal );
		drawCircle(0,0,3);
		endFill();
	}
	world.addChild(ball);
	ballArray.push(ball);
}

var cubeAxisRotations = make3DCenter(0,0,0, world);

this.addEventListener( Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler( event:Event )
{
	cubeAxisRotations.z += 0.5*Math.PI/180;
	cubeAxisRotations.y = - Math.sin( -cubeAxisRotations.z );
	cubeAxisRotations.x = - Math.cos( -cubeAxisRotations.z );

	object1.center.newX = object1.center.x + object1.vx;
	object1.center.newY = object1.center.y + object1.vy;

	var rz = Math.atan2(object1.vy, object1.vx);
	object1.rot.z = rz;

	if ( object1.center.newX < 200 &#038;&#038; object1.center.newX > -200 )
	{
		object1.center.x = object1.center.newX;
	}
	else
	{
		object1.vx*=-1;
	}
	if ( object1.center.newY < 200 &#038;&#038; object1.center.newY > -200 )
	{
		object1.center.y = object1.center.newY;
	}
	else
	{
		object1.vy*=-1;
	}

	get3DPoints(plane);

	get3DPoints(object1);
	get3DPoints(object2);

	var screenPoints = Transform3DPointsTo2DPoints(allPointsArray, cubeAxisRotations);
	screenPoints.sortOn("depth");
	for (i=0; i < screenPoints.length; i++)
	{
		var currBall = ballArray[i];
		currBall.x = screenPoints[i].x;
		currBall.y = screenPoints[i].y;
		currBall.scaleX = currBall.scaleY = screenPoints[i].scaleFactor;
		world.addChild(currBall);
	}
	world.graphics.clear();
	world.graphics.lineStyle(0,0x000000);
	for each ( var tri in triangleArray )
	{
		screenPoints = Transform3DPointsTo2DPoints(tri.points, cubeAxisRotations);

		if (
			( screenPoints[2].x - screenPoints[0].x ) * ( screenPoints[1].y - screenPoints[2].y ) >
			( screenPoints[2].y - screenPoints[0].y ) * ( screenPoints[1].x - screenPoints[2].x )
			)
		{
			with(world.graphics)
			{
				beginFill(tri.col, 0.75);
				moveTo(screenPoints[0].x, screenPoints[0].y);
				lineTo(screenPoints[1].x, screenPoints[1].y);
				lineTo(screenPoints[2].x, screenPoints[2].y);
				lineTo(screenPoints[0].x, screenPoints[0].y);
				endFill();
			}
		}
	}
}
</pre>
<p>Now, with a little sterring behaviour and terrain this could be really nice. Looking at the (to be released) <a href="http://labs.adobe.com/technologies/flash/molehill/">Molehill API</a> and the triangle methods in CS4 it may be not worth the effort, but it still is interesting.</p>
<p>Yoho!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2010/11/28/3d-movement-in-a-moving-3d-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What?: 3D and CS3 and spam comments&#8230;</title>
		<link>http://www.yarrcade.com/2010/11/26/what-3d-and-cs3-and-spam-comments-and-programming-drunk/</link>
		<comments>http://www.yarrcade.com/2010/11/26/what-3d-and-cs3-and-spam-comments-and-programming-drunk/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 18:04:45 +0000</pubDate>
		<dc:creator>kegogrog</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[mochiads]]></category>
		<category><![CDATA[xperiment]]></category>

		<guid isPermaLink="false">http://www.yarrcade.com/?p=1524</guid>
		<description><![CDATA[Good Morning! It took a while to write that. Why the rum? Long story as a link: I saw that and liked it. Copy, paste, trace out all compile fails and rewrite and present! The (re-coded) code: var theScene:MovieClip = &#8230; <a href="http://www.yarrcade.com/2010/11/26/what-3d-and-cs3-and-spam-comments-and-programming-drunk/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="contentthumb"><img src="http://www.yarrcade.com/wp-content/uploads/2010/11/drunk.png" alt="AS3 CS3 3DBalls moving" title="AS3 CS3 3DBalls moving" width="100" height="100"></div>
<p>Good Morning!</p>
<p>It took a while to write that. Why the rum? Long story as a link: I saw <a href="http://www.kirupa.com/developer/actionscript/rotation_center.htm">that</a> and liked it. Copy, paste, trace out all compile fails and rewrite and present!</p>
<p><span id="more-1524"></span></p>
<div class="centerswf">
<embed src="http://www.yarrcade.com/wp-content/uploads/2010/11/drunk.swf" width="550" height="400"></embed>
</div>
<p>The (re-coded) code:</p>
<pre>
var theScene:MovieClip = new MovieClip();
theScene.x = stage.stageWidth*0.5;
theScene.y = stage.stageHeight*0.5;
addChild( theScene );

var focalLength:Number = 300;

function make3DPoint ( x, y, z)
{
	var point = new Object();
	point.x = x;
	point.y = y;
	point.z = z;
	return point;
};

function make2DPoint (x,y, depth, scaleFactor)
{
	var point = new Object();
	point.x = x;
	point.y = y;
	point.depth = depth;
	point.scaleFactor = scaleFactor;
	return point;
};

function Transform3DPointsTo2DPoints (points, axisRotations)
{
	var TransformedPointsArray = [];
	var sx = Math.sin(axisRotations.x);
	var cx = Math.cos(axisRotations.x);
	var sy = Math.sin(axisRotations.y);
	var cy = Math.cos(axisRotations.y);
	var sz = Math.sin(axisRotations.z);
	var cz = Math.cos(axisRotations.z);
	var x,y,z, xy,xz, yx,yz, zx,zy, scaleFactor;

	var i = points.length;
	while (i--){
		x = points[i].x;
		y = points[i].y;
		z = points[i].z;

		// rotation around x
		xy = cx*y - sx*z;
		xz = sx*y + cx*z;
		// rotation around y
		yz = cy*xz - sy*x;
		yx = sy*xz + cy*x;
		// rotation around z
		zx = cz*yx - sz*xy;
		zy = sz*yx + cz*xy;

		scaleFactor = focalLength/(focalLength + yz);
		x = zx*scaleFactor;
		y = zy*scaleFactor;
		z = yz;

		TransformedPointsArray[i] = make2DPoint(x, y, -z, scaleFactor);
	}
	return TransformedPointsArray;
};

var pointsArray:Array = [
	make3DPoint(-50,-50,-50),
	make3DPoint(50,-50,-50),
	make3DPoint(50,-50,50),
	make3DPoint(-50,-50,50),
	make3DPoint(-50,50,-50),
	make3DPoint(50,50,-50),
	make3DPoint(50,50,50),
	make3DPoint(-50,50,50)
];

var ballArray:Array = new Array();

for ( var i:int = 0; i < pointsArray.length; i++){
	var ball:MovieClip = new MovieClip();
	var colors = [ 0xffffff, 0x990000 ];
	var fillType:String = GradientType.RADIAL;
	var alphas:Array = [1, 1];
	var ratios:Array = [0x00, 0xff];
	var matr:Matrix = new Matrix();
	matr.createGradientBox(-40*0.4, -40*0.4, 0, 0, 0);
	var spreadMethod:String = SpreadMethod.PAD;
	var interpolationMethod:String = InterpolationMethod.RGB;
	var focal:Number = -0.1;
	with(ball.graphics)
	{
		beginGradientFill( fillType, colors, alphas, ratios, matr, spreadMethod, interpolationMethod, focal );
		drawCircle(0,0,20);
		endFill();
	}
	theScene.addChild(ball);
	ballArray.push(ball);
}

var cubeAxisRotations = make3DPoint(0,0,0);

theScene.addEventListener( Event.ENTER_FRAME, enterFrameHandler );

function enterFrameHandler( event:Event )
{
	cubeAxisRotations.y -= 5*Math.PI/180;
	cubeAxisRotations.x += 5*Math.PI/180;
	var screenPoints = Transform3DPointsTo2DPoints(pointsArray, cubeAxisRotations);
	for (i=0; i < pointsArray.length; i++){
		var currBall = ballArray[i];
		currBall.x = screenPoints[i].x;
		currBall.y = screenPoints[i].y;
		currBall.xscale = currBall.yscale = 100 * screenPoints[i].scaleRatio;
		//currBall.swapDepths(screenPoints[i].depth);
	}
}
</pre>
<p>Just don't ask. Yo... -ho!</p>
<p>EDIT: The spam comments, I forgot them. I don't like them. Like: I DON'T LIKE THEM!</p>
<p>EDIT_2: And: Creating the thumbnail was time consuming. More than writing...</p>
<p>EDIT_3: I forgot to include the depths.</p>
<pre>
function enterFrameHandler( event:Event )
{
	cubeAxisRotations.y -= 2*Math.PI/180;
	cubeAxisRotations.x += 2*Math.PI/180;
	var screenPoints = Transform3DPointsTo2DPoints(pointsArray, cubeAxisRotations);
	<span class="altcode">screenPoints.sortOn("depth");</span>
	for (i=0; i < screenPoints.length; i++){
		var currBall = ballArray[i];
		currBall.x = screenPoints[i].x;
		currBall.y = screenPoints[i].y;
		currBall.xscale = currBall.yscale = 100 * screenPoints[i].scaleRatio;
		<span class="altcode">theScene.addChild(currBall);</span>
	}
}
</pre>
<div class="centerswf">
<embed src="http://www.yarrcade.com/wp-content/uploads/2010/11/drunk2.swf" width="550" height="400"></embed>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.yarrcade.com/2010/11/26/what-3d-and-cs3-and-spam-comments-and-programming-drunk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

