<?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>Malefic Games &#187; juakob</title>
	<atom:link href="http://maleficgames.com/wp/?author=1&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://maleficgames.com/wp</link>
	<description>Malefic Games, independent game developer</description>
	<lastBuildDate>Sat, 06 Dec 2014 01:09:25 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.24</generator>
	<item>
		<title>Sequential programming</title>
		<link>http://maleficgames.com/wp/?p=13</link>
		<comments>http://maleficgames.com/wp/?p=13#comments</comments>
		<pubDate>Fri, 05 Dec 2014 23:26:00 +0000</pubDate>
		<dc:creator><![CDATA[juakob]]></dc:creator>
				<category><![CDATA[haxe]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sequential programming]]></category>

		<guid isPermaLink="false">http://maleficgames.com/wp/?p=13</guid>
		<description><![CDATA[If you program games or real time simulation you probably found yourself trying to achieve sequential executions(do this, then this, wait to finish this&#8230;) in the step/update function of your code. How many times have you write code that checked if you are at the end of an animation to do something else after that? <a class="read-more" href="http://maleficgames.com/wp/?p=13">&#8230;&#160;<span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you program games or real time simulation you probably found yourself trying to achieve sequential executions(do this, then this, wait to finish this&#8230;) in the step/update function of your code. How many times have you write code that checked if you are at the end of an animation to do something else after that? You can overcome this problem using ifs and flags, if your list of things to do sequentially is short. But we all know that short term solutions can turn into horrible nightmares if the extrapolate the same pattern of adding more ifs and variables.</p>
<p>THE PROBLEM</p>
<p>Generate an easy way to execute functions sequentially. Execute one function, wait until it&#8217;s done, execute the next function until there are no more functions to execute.</p>
<p>PROPOSE SOLUTION(for haxe/as3)</p>
<p>Generate a class that handles the problem! So my solution is quite simple, just create a class that store the functions to be executed and execute them one at a time.<br />
The first thing we need to know is when a function has finish. To do this we simply return a bool in all the functions. If we finish doing what we needed to do in the function we return true, if not we return false.</p>
<p>Here an example how to manually loop an animation using the SequenceCode class</p>
<pre class="brush: as3; title: ; notranslate">
var mSequencer:SequenceCode=new SequenceCode();
mSequencer.addFunction(loop);

public function update(aDt:Float):Void
{
mSequencer.update(aDt);
}
</pre>
<p>and here  the functions&#8230;</p>
<pre class="brush: as3; title: ; notranslate">
private function loop(aDt:Float):Bool
{
  mSequencer.addFunction(resetAnimation);
  mSequencer.addFunction(animationFinish);
  mSequencer.addFunction(loop);
}
private function animationFinish(aDt:Float):Bool
{
  return mCurrentAnimation.totalFrames==mCurrentAnimation.currentFrame;
}
private function resetAnimation(aDt:Float):Bool
{
  mCurrentAnimation.goToAndPlay(0);
return true;
}
</pre>
<p>You can even create simple animations sequences with a variable target and a function moveToTarget(aDt) that returns true once it reach the target. </p>
<p>You can use it to create simple AI :</p>
<pre class="brush: as3; title: ; notranslate">
private think(aDt:Float):Boolean
{
if(player is far away)
{
 mSequence.addWhile(notNear,follow);
 mSequence.addFunction(think);
}else{
 mSequence.addWait(1);
 mSequence.addFunction(attackSequence);
 mSequence.addFunction(think);
}
 return true;
}
</pre>
<p>The logic code gets far more readable using this approach vs the ifs and the flags.</p>
<p>The full code of the SequenceCode class can be found here <a href="https://github.com/juakob/SequenceCode/tree/master/utils" title="https://github.com/juakob/SequenceCode/tree/master/utils" target="_blank">https://github.com/juakob/SequenceCode/tree/master/utils</a></p>
<p>Fell free to write me back =)</p>
<p>In my next post I will show you how to use my implementation of a behavior tree <a href="https://github.com/juakob/BehaviorTreeHaxe" title="https://github.com/juakob/BehaviorTreeHaxe">https://github.com/juakob/BehaviorTreeHaxe</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maleficgames.com/wp/?feed=rss2&#038;p=13</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>First post!</title>
		<link>http://maleficgames.com/wp/?p=7</link>
		<comments>http://maleficgames.com/wp/?p=7#comments</comments>
		<pubDate>Fri, 07 Nov 2014 21:21:22 +0000</pubDate>
		<dc:creator><![CDATA[juakob]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://maleficgames.com/wp/?p=7</guid>
		<description><![CDATA[Hi all! my name is Joaquin Bello, I live in Uruguay  and I don&#8217;t like boring post so here are two timelapse of  enemies from my next game =) &#160; &#160;]]></description>
				<content:encoded><![CDATA[<p>Hi all! my name is Joaquin Bello, I live in Uruguay  and I don&#8217;t like boring post so here are two timelapse of  enemies from my next game =)</p>
<p>&nbsp;</p>
<p><iframe width="500" height="281" src="https://www.youtube.com/embed/2UFsbGzAUNA?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p><iframe width="500" height="281" src="https://www.youtube.com/embed/0pWO6nJw0ck?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://maleficgames.com/wp/?feed=rss2&#038;p=7</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
