<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Flash Games Classroom</title>
	
	<link>http://www.flashgamesclassroom.com/classroom</link>
	<description>Flash and actionscript game tutorials and news</description>
	<lastBuildDate>Sun, 18 Sep 2011 14:32:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/FlashGamesClassroom" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="flashgamesclassroom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Rapid Development with FlashPunk Framework</title>
		<link>http://www.flashgamesclassroom.com/classroom/actionscript/rapid-development-with-flashpunk-framework/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/actionscript/rapid-development-with-flashpunk-framework/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 14:32:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[AS3 Framework]]></category>
		<category><![CDATA[FlashPunk]]></category>
		<category><![CDATA[Flixel]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=264</guid>
		<description><![CDATA[In over 9 years of web game development I&#8217;d never used a third party framework until recently, preferring to code everything up from scratch. Both Flixel and FlashPunk had caught my eye though and for the past year or so I&#8217;d been meaning to try one or the other.
Well, a few months ago the opportunity [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Frapid-development-with-flashpunk-framework%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Frapid-development-with-flashpunk-framework%2F" height="61" width="51" /></a></div><p>In over 9 years of web game development I&#8217;d never used a third party framework until recently, preferring to code everything up from scratch. Both <a href="http://flixel.org/">Flixel</a> and <a href="http://flashpunk.net">FlashPunk</a> had caught my eye though and for the past year or so I&#8217;d been meaning to try one or the other.</p>
<p>Well, a few months ago the opportunity presented itself.  Hasbro hired us to develop a multi-world game to promote their new Kre-o range of toys and I decided it was the perfect project to test these frameworks with.<span id="more-264"></span></p>
<h2>Actionscript Game Engine</h2>
<p>A framework, or game engine, is essentially a group of libraries.  The libraries typically cover functionality shared by many games, such as collision detection, tile mapping and blitting (see Craig Beswetherick&#8217;s article in <a href="http://ffdmag.com/">FFD</a> July 2011 for a great intro to Blitting)</p>
<p>With this core functionality readily available, use of a game engine allows for rapid development.  In fact, I&#8217;ve seen a number of quite playable little games on some of the development forums recently which people have put together in a single day!</p>
<h2>Flixel or FlashPunk</h2>
<p>Both Flixel and FlashPunk are open source, AS3 game engines, and in general both do the same job.  Flixel is the more mature project, and has been used on quite a number of popular games including the popular Canabalt.  It was for that reason I decided to test Flixel first, and while it was certainly robust there were a few small issues I had with it, especially with the apparent lack of control over the way collisions worked.</p>
<p>FlashPunk on the other hand is a newer project, but which is rapidly expanding.  There is a very active user community on the forums at FlashPunk.net and lots of great tutorials for learning the basics of the framework.</p>
<p>While the 2 engines are very similar, I instantly felt more at home with the FlashPunk code, which I felt to be less restrictive.  The collision detection issues I had with Flixel were easy to solve with FlashPunk and in less than a week I had made the decision to build the Hasbro game (named <a href="http://www.kernowweb.co.uk/portfolio/kreon-chaos/">Kreon Chaos</a>) using FlashPunk as the basis.</p>
<p><img class="alignnone" title="Kreon Chaos" src="http://www.flashgamesclassroom.com/images/kreon_screen.jpg" alt="" width="580" height="377" /></p>
<h2>Building Kreon Chaos</h2>
<p>The reason for wanting to use a third party game engine for Kreon Chaos, was because we wanted to focus on the gameplay and level design without spending too much of our allocated timeframe on low level code.  The brief from Hasbro was to create a game which focused on the Kreons &#8211; mini figs (like Lego men) of the Transformers characters.  They wanted the player to be able to control any of the Kreons, and for them to each have their own abilities, so we decided on a 2D side scrolling platform/puzzle game.</p>
<p>Taking inspiration from a 1990&#8217;s SNES game called &#8220;The Lost Vikings&#8221; we decided that each level would be designed such that the only way to complete it was for the Kreons to work as a team.  For example, we gave Bumblebee the ability to hack computer terminals to turn elevators on, or turn of laser hazards.  We gave Sentinel Prime the ability to hold his shield up above his head so that other Kreons could jump on him to access hard to reach areas.</p>
<p>Using the FlashPunk engine as the basis for the game freed us up to spend the time necessary to work on these design aspects, rather than writing code to handle the tilesheets or collisions.  It was a real joy to work with and I only wish I&#8217;d made the step a long time ago.  One thing&#8217;s for sure &#8211; I&#8217;ll certainly be using FlashPunk again for future projects.</p>
<h2>The Flashpunk Framework</h2>
<p>FlashPunk games are built around 2 basic constructs &#8211; Worlds and Entities.  A FlashPunk World is an organisational class which will typically be a level or a menu.  A game can have menu Worlds, but only one of them is active at any one time.  So for example, when you select &#8220;Level 1&#8243; on a level select screen the game will change from the &#8220;Level Select&#8221; World to the &#8220;Level 1&#8243; World.</p>
<p>Worlds can contain any number of entities, and have a controllable camera which makes scrolling and panning super easy.  Entities are the objects which populate a world, like characters, enemies, cars or platforms.  Entities can interact with one another, move around the World and be controlled by the player.</p>
<p>Worlds and Entities can be extended and are super easy to imp0lement and adapt.  There&#8217;s little point in reinventing the wheel by putting example code up here when there are some excellent <a href="http://flashpunk.net/tutorials/">beginner&#8217;s tutorials</a> at the FlashPunk site.  It will only take you an hour or so to go through the beginners tutorials there, and you&#8217;ll see just how quick and easy it is to get a simple game off the ground.</p>
<h2>FlashPunk iOS game development</h2>
<p>What I found REALLY exciting with FlashPunk was the performance achieved.  Even with hunderds of entities animated on screen I was able to achieve fantastic framerates.  In fact the performance was so good I decided that maybe it was worth going back and testing the performance on the iPhone.</p>
<p>I spent some time testing the idea of developing for iPhone/iPad with Actionscript a while ago but the results were disappointing (FPS was less than 10 even with just a single sprite on screen!) but since I was seeing such good performance with FlashPunk on the desktop I thought it was worth a shot &#8211; and the results were superb!</p>
<p>I was able to get a simple arcade game running on an iPhone at around 25 FPS &#8211; good enough to be playable, and releasable.</p>
<p><img class="alignnone" title="Deer Hunter AS3 game on iPhone" src="http://www.flashgamesclassroom.com/images/deer_hunter_screenshot.png" alt="" width="400" height="210" /></p>
<p>I&#8217;ve been turning that initial demo into a full game and will be submitting it to the App Store within the next 7 &#8211; 10 days, and once it&#8217;s on there I&#8217;ll write a detailed post about how I did it.  Basically though, with the combination of the FlashPunk and targeting AIR 2.6 it is possible to develop AS3 based games for iOS devices &#8211; something I had previously thought was not possible!  Check back for a tutorial on the build process soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/actionscript/rapid-development-with-flashpunk-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back in the game</title>
		<link>http://www.flashgamesclassroom.com/classroom/news/back-in-the-game/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/news/back-in-the-game/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 19:41:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=256</guid>
		<description><![CDATA[Well I need to apologise, it&#8217;s been a looooooong time since my last post here!
I know a bunch of you have been wondering if and when the Flash Games Classroom course is coming out, and thanks to everyone who has been filling in the survey so here&#8217;s a quick update.
The short answer is yes, there [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fnews%2Fback-in-the-game%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fnews%2Fback-in-the-game%2F" height="61" width="51" /></a></div><p>Well I need to apologise, it&#8217;s been a looooooong time since my last post here!</p>
<p>I know a bunch of you have been wondering if and when the Flash Games Classroom course is coming out, and thanks to everyone who has been filling in the <a href="http://flashgamesclassroom.com/kg/">survey</a> so here&#8217;s a quick update.</p>
<p>The short answer is yes, there is a course in the pipeline, but it&#8217;s probably NOT going to be the &#8220;complete guide to developing Flash games&#8221; that we originally intended.  From the feedback we&#8217;ve been getting there are several specific key areas that lots of people want info on, so that&#8217;s where we&#8217;ll be focussing and so the course will be a number of key &#8220;modules&#8221; covering those topics.</p>
<p>Some of the tutorials have already been written, and we&#8217;re looking at a probably launch in November, so watch this space and make sure you are on the newsletter mailing list to be kept up to date.  I promise you won&#8217;t have to wait too long for details this time!</p>
<p><strong>So what&#8217;s with the huge delay?</strong></p>
<p>Well, sometimes life just gets in the way!  I&#8217;ve been super busy working on a ton of games for clients.  I was trying to reduce my workload to concentrate more on the course, but when clients like <a href="http://www.kernowweb.co.uk/portfolio/bop-it-game/">Hasbro</a> and <a href="http://www.kernowweb.co.uk/portfolio/star-wars-jedi-attack/">Lucasarts</a> are asking for games it&#8217;s hard to turn them down!</p>
<p>I&#8217;m 80% through a BIG game for Hasbro at the moment which is due to launch next month,  and from then on I&#8217;ll be a lot more focussed on this!</p>
<p>At the same time, I&#8217;ve been working on some <a href="http://www.frostypixel.com/">iPhone game development</a>.  In fact, that has been going so well that I&#8217;m planning a series of Flash for iPhone development tutorials to post here, and an iPhone module in the classroom</p>
<p>(and for those of you saying &#8220;you can&#8217;t run Flash on iPhone&#8221; or &#8220;iPhone games compiled for iOS are poor performance&#8221; I have news for you &#8211; you CAN develop high speed, efficient game code for the iPhone using Actionscript, and I&#8217;ll be showing you some examples here real soon!)</p>
<p>Finally, there is a complete new <a href="http://www.viralflashgames.com">Viral Flash Games</a> package in the works, so if you&#8217;re interested in getting your hands on a whole load of new games, all written in OOP AS3 and all with complete source code keep at eye on that site for an announcement in a few weeks (plus a fire sale of the last few AS2 packs at a crazy end of line price!)</p>
<p>So there we go, that&#8217;s the score and hope that all the col stuff coming helps to make up for the massive sabatical!</p>
<p><center><div class="wp-caption aligncenter" style="width: 410px"><img src="http://www.frostypixel.com/images/sheeperoids_screenshot.png" alt="Yes, you really can develop fast and playable iPhone games in Flash, watch this space for examples and tutorials very soon!" width="400" height="210" /><p class="wp-caption-text">Yes, you really can develop fast and playable iPhone games in Flash, watch this space for examples and tutorials very soon!</p></div></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/news/back-in-the-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Submitting Flash Games For More Exposure</title>
		<link>http://www.flashgamesclassroom.com/classroom/resources/submitting-flash-games-for-more-exposure/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/resources/submitting-flash-games-for-more-exposure/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 12:59:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[promotion]]></category>
		<category><![CDATA[submit games]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=253</guid>
		<description><![CDATA[As games developers we all have one thing in common.  Whether we&#8217;re creating games for fun or profit, we want more people to play our games, and that means we need to do a little promotion!
The average Flash games developer tends to pop their new creation on their own sites or blog, upload to the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fresources%2Fsubmitting-flash-games-for-more-exposure%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fresources%2Fsubmitting-flash-games-for-more-exposure%2F" height="61" width="51" /></a></div><p>As games developers we all have one thing in common.  Whether we&#8217;re creating games for fun or profit, we want more people to play our games, and that means we need to do a little promotion!</p>
<p>The average Flash games developer tends to pop their new creation on their own sites or blog, upload to the Mochimedia network, and hope that the game is good enough to go viral.  While that&#8217;s a great start, we can do better!</p>
<p>There are literally thousands of games sites out there which you can submit your games to, but a relatively small number of them will be worth the effort.  The biggest obstacle in getting your game out there is finding exactly which sites to submit to, so we&#8217;ve done the hard work for you and written a free report listing hundreds of the top games sites that you can submit to, and get a huge amount of exposure!   Many of the larger sites also offer sponsorship deals too, so use this list to allow your game to get the attention it deserves!</p>
<p>The free report is in PDF format with clickable links, so download it, and go through it at your own pace.  It starts off with some of the &#8220;big guns&#8221; like Kongregate and NewGrounds, but quickly moves into hundreds of smaller, but still very popular sites, many of which you might not have heard of.</p>
<p>If submitting your game to hundreds of sites sounds like a daunting task, check out the final page of the report which has some tips of making it an easier task!</p>
<p style="text-align: center;">Download <a title="Where to get Flash games" href="http://www.flashgamesclassroom.com/resources/Game-submission-list.pdf">Where To Submit Flash games</a> here!</p>
<p style="text-align: center;"><a href="http://www.flashgamesclassroom.com/resources/Game-submission-list.pdf"><img style="border: none;" title="Flash games submissions list" src="http://www.flashgamesclassroom.com/images/wheretosubmitflashgames.jpg" alt="" width="250" height="306" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/resources/submitting-flash-games-for-more-exposure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Most Popular Browser Game Genres</title>
		<link>http://www.flashgamesclassroom.com/classroom/actionscript/the-most-popular-browser-game-genres/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/actionscript/the-most-popular-browser-game-genres/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 14:53:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=248</guid>
		<description><![CDATA[Browsing through the new releases on MochiMedia these days, you'd be forgiven for thinking that the most popular games genres are tower defence, "dress up" girl games and side scrolling, monster truck "stunt" driving games! Just because that's what hundreds of newbie developers seem to be releasing doesn't mean that's what people want to play though!]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Fthe-most-popular-browser-game-genres%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Fthe-most-popular-browser-game-genres%2F" height="61" width="51" /></a></div><p>Browsing through the new releases on MochiMedia these days, you&#8217;d be forgiven for thinking that the most popular games genres are tower defence, &#8220;dress up&#8221; girl games and side scrolling, monster truck &#8220;stunt&#8221; driving games!  Just because that&#8217;s what hundreds of newbie developers seem to be releasing doesn&#8217;t mean that&#8217;s what people want to play though!</p>
<p>Tower Defence I can understand, in fact some of the better tower defence games (such as <a href="http://www.kwikgames.com/games/bloons-tower-defense-4/">Bloons Tower Defence</a> or <a href="http://armorgames.com/play/1128/desktop-tower-defense-15">Desktop Tower Defence</a>) are very popular at the moment, but there are 3 genres of browser games that are hugely popular, year after year.  These types of games might not be groundbreaking, sexy or exciting, but they get hordes of players, and when well designed they tend to be guaranteed hits!</p>
<p>Last year MochiMedia ran a survey that showed the average casual gamer to be 43 years of age, and that 55% of players are female which goes some way to explain why arcade and strategy games don&#8217;t feature here.  So, what are the 3 most popular genres&#8230;</p>
<p><strong>Word Games</strong></p>
<p><img style="float:right; padding-left:10px;" title="Word Games" src="http://www.flashgamesclassroom.com/images/wordgame.jpg" alt="" width="200" height="133" />From the humble crossword to games like <a href="http://www.kwikgames.com/games/word-reactor/">Word Reactor</a>, words games are always popular, particularly with female players, and the older generations, word games attract large numbers of players and can be single or multi-player.</p>
<p>Since word games, in general, tend to be relatively simple to develop and with low overheads in terms of performance they are ideally suited to the Flash platform.</p>
<p><strong>Card/Casino Games</strong></p>
<p><img style="float:right; padding-left:10px;" title="Flash Poker" src="http://www.flashgamesclassroom.com/images/zyngapoker.jpg" alt="" width="200" height="167" />Texas Hold&#8217;em on Facebook regularly attracts 15 million or more player per day! From Windows Solitaire to multi-player card games, this is an evergreen genre which always attracts players. The rules to many card and casino games are already well defined so you can spend less time tweaking and deciding on gameplay, and more time creating a polished experience.</p>
<p>Again since there is little in the way of graphical overhead these games are ideal for Flash, and work extremely well as browser based games.</p>
<p><strong>Puzzle Games</strong></p>
<p><img style="float:right; padding-left:10px;" title="Bejewelled" src="http://www.flashgamesclassroom.com/images/bejewelled.jpg" alt="" width="200" height="152" />Since Tetris is one of the best selling games of all time, it should come as no surprise that puzzle games are extremely popular online and attract huge numbers of players. Bejewelled, from PopCap games, has apparently been downloaded over 150 million times, and has sold over 35 million paid versions!  Again, with a few exceptions, they tend not to be processor hungry and so are well suited to the Flash platform. While the term &#8220;Puzzle game&#8221; can encompass a wide range of game styles, generally they are 2 dimensional, and relatively simple both in terms of gameplay and development.</p>
<p>So, the next time you&#8217;re deciding on the next game you want to create, ask yourself what you want to achieve.  If you want to push the boundaries, and create a new, funky arcade game great &#8211; but realise that while a word or puzzle game might not be as interesting to develop, it could end up being way more successful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/actionscript/the-most-popular-browser-game-genres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bargain Flash Books</title>
		<link>http://www.flashgamesclassroom.com/classroom/news/bargain-flash-books/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/news/bargain-flash-books/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 09:59:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=245</guid>
		<description><![CDATA[With the release of CS5 imminent (the official release date is 10th April - just a few days away) online bookstores such as Amazon and Barnes &#038; Noble are slashing the price of CS4 titles.  If you're looking for some solid introductions to Flash and Actionscript there are some real bargains to be had.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fnews%2Fbargain-flash-books%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fnews%2Fbargain-flash-books%2F" height="61" width="51" /></a></div><p>With the release of CS5 imminent (the official release date is 10th April &#8211; just a few days away) online bookstores such as <a href="http://www.amazon.com">Amazon</a> and <a href="http://www.barnesandnoble.com/">Barnes &#038; Noble</a> are slashing the price of CS4 titles.  If you&#8217;re looking for some solid introductions to Flash and Actionscript there are some real bargains to be had.</p>
<p>Books like Flash CS4: The Missing Manual, Adobe Flash CS4 Classroom In A Book and Learning Flash CS4 Professional are being knocked out at way under half price in some places, so grab a bargain while you can!  In fact, if you&#8217;re in the UK you can get an even better deal in the current Amazon &#8220;50% off selected computing and internet books&#8221; sale where several Flash titles are reduced even further.</p>
<p>Of course, the bargains won&#8217;t stop at just books.  I suspect that after April 10th there will be plenty of opportunities to grab bargain bin versions of Flash CS4, so if you&#8217;re still using an old and weary installation of MX2004 and looking to get up to date without splashing out on the latest upgrade to CS5 when it&#8217;s released, keep your eyes open for the next few weeks as I&#8217;m sure you&#8217;ll be able to grab a real bargain!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/news/bargain-flash-books/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript for Multiplayer Games and Virtual Worlds Review</title>
		<link>http://www.flashgamesclassroom.com/classroom/resources/actionscript-for-multiplayer-games-and-virtual-worlds-review/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/resources/actionscript-for-multiplayer-games-and-virtual-worlds-review/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 14:30:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Resources]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=239</guid>
		<description><![CDATA[I first heard of ElectroServer in Jobe Makar's first book Flash MX Game Design Demystified.  From the title you'll immediately realise that book is quite a few years old, writted back when Flash was still a Macromedia technology.  In fact, that book was published in 1993 right about the time I was first getting into Flash.  It was actually March 2003 when I uploaded my first Flash games to a website and saw the incredible potential for the technology - and a good portion of my knowledge at the time came from that book.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fresources%2Factionscript-for-multiplayer-games-and-virtual-worlds-review%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fresources%2Factionscript-for-multiplayer-games-and-virtual-worlds-review%2F" height="61" width="51" /></a></div><p><img style="float:right; padding-left:10px" title="Actionscript for Multiplayer games and virtual worlds" src="http://www.flashgamesclassroom.com/images/multiplayerworlds.jpg" alt="" width="194" height="240" />Well first of all apologies to everyone for the lack of posts this month, if you follow me on Twitter you&#8217;ll know I&#8217;m extremely busy with a couple of big games for clients so I&#8217;ve had very little time for blogging!</p>
<p>Anyway, one of the projects we&#8217;re currently in the early stages of is a multi-player game for the Facebook platform.  I&#8217;ve done some multiplayer games in the past, quizes and simple heads up puzzle games, but nothing this big or complex.  In the past I&#8217;ve used both <a href="http://www.smartfoxserver.com/">SmartFox</a> server, and an early version or <a href="http://www.electro-server.com/">ElectroServer</a>, but since I&#8217;ve not done any multiplayer games for a while I&#8217;ve been researching which would be best to use for this project.  As part of that reserach I picked up a copy of <a href="http://jobemakar.blogspot.com/">Jobe Makar</a>&#8217;s latest book <a href="http://rcm.amazon.com/e/cm?t=onlibusilogi-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0321643364&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr">Actionscript for Multiplayer Games and Virtual Worlds</a> and I thought I would post a quick review here.  (By the way &#8211; I&#8217;m now 99% decided on Electroserver for a number of reasons, so expect a tutorial on that in the near future once we have the first demos completed!)</p>
<h2>Actionscript for Multiplayer Games and Virtual Worlds</h2>
<p>I first heard of ElectroServer in Jobe Makar&#8217;s first book Flash MX Game Design Demystified.  From the title you&#8217;ll immediately realise that book is quite a few years old, writted back when Flash was still a Macromedia technology.  In fact, that book was published in 1993 right about the time I was first getting into Flash.  It was actually March 2003 when I uploaded my first Flash games to a website and saw the incredible potential for the technology &#8211; and a good portion of my knowledge at the time came from that book.</p>
<p>Well, fast forward 7 years and what does Jobe&#8217;s latest offering bring to the table?  Well as you&#8217;ll gather from the name, the book is about multi-player game development, and specifically about building multi-player Flash games in AS3 using the ElectroServer socket server.  In the second chapter Jobe does talk about different technologies, and briefly mentions alternatives to ElectroServer, but then moves swiftly on and focusses on ElectroServer for the rest of the book.  Now, I should mention that there&#8217;s a good reason for that &#8211; Jobe is one of the co-founders of ElectroTank, the makers of ElectroServer and so has a vested interest in promoting the software.  Having said that, I&#8217;ve spent quite a bit of time investigating and testing alternatives, particularly the big rival SmartFox, and in my opinion ElectroServer is the best choice for most applications.</p>
<p>The early sections of the book focus on server technologies, concepts and security issues before an installation guide for Windows, Linux/Unix and Mac.  Then he dives into the ElectroServer API with the obligetory Hello World example.  The rest of the book then teaches one concept at a time using real world examples.   Chapter 5 looks at chating, how chats are made available to users and how to set that up using ElectroServer.  Chapters 6 through 8 look at more basic concepts such as the difference between client and server code, movement and lobbies and finally in chapter 9 Jobe gives the first full game example &#8211; he takes you through the process of building a real-time tank game, and by the end of that chapter he has covered a lot of really useful concepts, from collision detection to path finding and even spatial audio (something very few authors seem to touch on).</p>
<p>Chapter 10 looks at tile based worlds, discusses their advantages and looks at the logic behind a tile based engine, and a good explaination of the a* pathfinding algorithm.  That is then built on in chapter 11 with a look at building a co-operative 2 player game.  Chapter 12 is where things start to get really interesting with a look at the isometric viewpoint and how that can be used effectively in building virtual worlds.</p>
<p>The rest of the book I&#8217;ve only skim read so far, and it covers a number of useful topics such as player avatars, buddies nd virtual worlds, and finally the appendix offers a guide to setting up the sample extension which can be downloaded from the website.</p>
<p>Here&#8217;s a breakdown of the chapters in details:</p>
<p><span style="font-family: verdana,arial; font-size: 13px;"><strong>Chapter 1. Web Game Landscape<br />
</strong>Client-side Technology<br />
Where Multiplayer Fits In</span></p>
<p><strong>Chapter 2. Connecting Users<br />
</strong>Connection Techniques<br />
Socket Server Choices&lt;</p>
<p><strong>Chapter 3. Security: You vs. Everyone Else<br />
</strong>Logical Security<br />
Physical Security</p>
<p><strong>Chapter 4. Introducing ElectroServer<br />
</strong>Server Concepts<br />
Installation<br />
Hello World<br />
Administration Panel</p>
<p><strong>Chapter 5. Chat<br />
</strong>Overview<br />
Simple Chat Room</p>
<p><strong>Chapter 6. Where Decisions Are Made<br />
</strong>New Concepts<br />
ElectroServer Plugin Concepts<br />
Installing the Extension<br />
Dig Game</p>
<p><strong>Chapter 7. Real-time Movement<br />
</strong>Responsive Controls<br />
Path Types<br />
Frame-based Movement<br />
Latency and Clock Synchronization<br />
Time-based Movement</p>
<p><strong>Chapter 8. Lobby System<br />
</strong>Common Features<br />
Game Flow<br />
Dig Game 2</p>
<p><strong>Chapter 9. Real-time Tank Game<br />
</strong>Game Overview<br />
Authority and Prediction<br />
Line of Sight<br />
Game Messaging<br />
Mini-map<br />
Message Aggregation<br />
Level Editor<br />
Spatial Audio</p>
<p><strong>Chapter 10. Tile-based Games<br />
</strong>Tile-based vs. Art-based Levels<br />
Other Tile-based Benefits<br />
A* Pathfinding</p>
<p><strong>Chapter 11. Cooperative Game Play<br />
</strong>Types and styles of Cooperative Game Play<br />
The Game: Super Blob Brothers<br />
Server vs. Client: Who&#8217;s the Boss?<br />
Game Messaging<br />
Client-side Details</p>
<p><strong>Chapter 12. Isometric View<br />
</strong>Basics and Benefits of Isometrics<br />
A Technical Look<br />
Sorting Algorithm</p>
<p><strong>Chapter 13. Avatars<br />
</strong>Meet the Avatars<br />
Rendering Approaches<br />
Sprite Sheets<br />
Avatar Creation and Customization</p>
<p><strong><img style="float:right;" title="Buy at Amazon" src="http://www.flashgamesclassroom.com/images/multiplayergamesbook.jpg" alt="" width="131" height="252" />Chapter 14. Virtual Worlds<br />
</strong>Common Features<br />
Old World<br />
Map Files<br />
Map Rendering<br />
The World</p>
<p><strong>Chapter 15. Buddies<br />
</strong>Relationships<br />
Buddies in Old World</p>
<p><strong>Chapter 16. User Homes<br />
</strong>&#8220;Open House&#8221;<br />
User Homes in Old World</p>
<p><strong>Appendix: Setting Up the Sample Extension<br />
</strong>Server-Level Components<br />
Old World<br />
Configuring the Logging<br />
Setting up the Server-side Development Environment</p>
<h2>Conclusion</h2>
<p><span style="font-family: verdana,arial; font-size: 13px;">I&#8217;ve not had time to go through all of the examples yet, but those I have gone through have been excellent.  Jobe is a great writer and is able to get the concepts across easily making the book quite an easy read despite the technical content.  It&#8217;s also well laid out and edited so you&#8217;re overwhelmed with pages crammed full of code. In fact, when I first picked the book up I was a little dissapointed as it&#8217;s quite small and I wrongly assumed it was light on content, but quite the contrary &#8211; in fact it&#8217;s amazing how much solid content Jobe manages to cram into such a small package of less than 300 pages.</span></p>
<p><span style="font-family: verdana,arial; font-size: 13px;">Personally I can&#8217;t wait for the designs for my project to get approved by my client so I can dive into the development work, and many of the concepts taught in this book will be cornerstones of my approach to the new game.  If you&#8217;re at all interested in building robust multiplayer games in Flash then you really do need this book, and you can certainly expect one or more tutorials on the subject posted here at some point in the future!</span></p>
<p><a href="http://rcm.amazon.com/e/cm?t=onlibusilogi-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0321643364&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr"><span style="font-family: verdana,arial; font-size: 13px;">Buy </span>Actionscript for Multiplayer Games and Virtual Worlds <span style="font-family: verdana,arial; font-size: 13px;">on Amazon</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/resources/actionscript-for-multiplayer-games-and-virtual-worlds-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Profits from Flash games?</title>
		<link>http://www.flashgamesclassroom.com/classroom/game-design/profits-from-flash-games/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/game-design/profits-from-flash-games/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 14:35:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=237</guid>
		<description><![CDATA[I had an interesting conversation with one of my pupils over the weekend about whether Flash games development was commercially worth the effort.  His concern was that while he wanted to learn game development for personal reasons, he felt that commercial web design might be a better direction to focus in as it would be easier to get a job, or start a successful business in that field.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fgame-design%2Fprofits-from-flash-games%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fgame-design%2Fprofits-from-flash-games%2F" height="61" width="51" /></a></div><p><img style="float:right; padding-left:10px;" title="Monetise your Flash games" src="http://www.flashgamesclassroom.com/images/dollar.jpg" alt="" width="200" height="142" />I had an interesting conversation with one of my pupils over the weekend about whether Flash games development was commercially worth the effort.  His concern was that while he wanted to learn game development for personal reasons, he felt that commercial web design might be a better direction to focus in as it would be easier to get a job, or start a successful business in that field.</p>
<p>My answer was quite simple &#8211; there are thousands of very talented web designers out there, and very few good games developers!  Add to that the fact that casual gaming is definitely on the rise, and there are more and more posts on the freelance sites looking for developers every month and it&#8217;s clear that this is a growing industry and a better one to be involved in than web design in my opinion.  And I&#8217;d like to think that my opinion counts on this matter, since I&#8217;ve been a commercial web designer and Flash games developer for the past 8 years!</p>
<p>Anyway, we discussed several different approaches to making an income with Flash game development, many of which my pupil hadn&#8217;t considered, so here they are in the hope that more people find inspiration&#8230;</p>
<h3>6 ways to monetize Flash games development (without getting a job!)</h3>
<p>Developing games for clients might be the most obvious way of earning money as a developer, but it&#8217;s surprising how few companies offer the service.  I&#8217;ve been developing games for over 8 years now, and I&#8217;m constantly asked to work on new projects.  There are lots of companies out there ready and waiting to pay you money to design and develop games for their marketing campaigns.</p>
<p>If you don&#8217;t want the obligation and deadlines of working for clients, sponsorship mighht suit you better.  This allows you to develop a game at your own pace, and once completed your sponsor pays you to embed their branding and links into the game.  The amount you&#8217;ll earn will vary, depending on the company which is sponsoring you, and the quality of the game.</p>
<p>Taking it one step further, you can monetise your own games without needing a client or a sponsor.  Networks such as Mochiads allow you to embed adverts into your games, and publish your games on their network which gets you both revenue and exposure at the same time.</p>
<p>You can also monetise your games by simply hosting them yourself, and displaying adverts on the same page.  Banner adverts, Adsense blocks or affiliate promotions are all viable ways of monetising the traffic that a good Flash game will generate.</p>
<p>A very recent, and rapidly growing technology allows for in game currencies.  While this is quite new there are already 2 networks offering the service and I&#8217;m sure this will grow tremendously in the coming months and years.</p>
<p>Finally, perhaps the most obvious, and certainly the most glamorous way to capitalize on the success of a good Flash game is to release a commercial version.  Whether it&#8217;s a downloadable PC game or a port to an entirely new platform, such as the Nintendo DS, the Xbox Live network or the iPhone, a well designed unique game with the right marketing can be a real success, and open the doors into the mainstream gaming industry.</p>
<p>So there you go, six different ways to generate an income from your Flash games development.  In fact, why not start right now.  You could take the <a href="http://www.flashgamesclassroom.com/classroom/actionscript/creating-an-asteroids-arcade-game-in-flash/">Flash Asteroids Tutorial</a> I posted recently, modify that with your own ideas and pop it on your own website with some Adsense ads! Or how about grabbing some <a href="http://www.viralflashgames.com">Flash Games source code</a>, using some of what you&#8217;ve learned here to add new levels, change the graphics and put your own features in and submit them to Mochiads?  The opportunities are all there, you just need to pick an idea and run with it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/game-design/profits-from-flash-games/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flash Game Development Workflow</title>
		<link>http://www.flashgamesclassroom.com/classroom/game-design/flash-game-development-workflow/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/game-design/flash-game-development-workflow/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 15:08:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=235</guid>
		<description><![CDATA[I wanted to write a real quick post today about the basic methodology of developing Flash games.  I&#8217;ve had a couple of people email me recently after filling in the survey about whether the Flash Games Classroom course will cover subjects like design, planning and asset management and the answer is yes it will!  In [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fgame-design%2Fflash-game-development-workflow%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Fgame-design%2Fflash-game-development-workflow%2F" height="61" width="51" /></a></div><p><img style="float:right; padding-left:10px;" title="game development" src="http://www.kernowweb.co.uk/images/alice_dev.jpg" alt="" width="300" height="216" />I wanted to write a real quick post today about the basic methodology of developing Flash games.  I&#8217;ve had a couple of people email me recently after filling in the survey about whether the Flash Games Classroom course will cover subjects like design, planning and asset management and the answer is yes it will!  In this post today though I just want to give a really brief into and explain why just sitting down at Flash and starting to code isn&#8217;t a great idea!</p>
<p>A good developer needs to be competent in Flash and Actionscript with solid programming practices, graphical skills, audio skills, a methodical and analytical approach, and the patience of a saint.  Here is a guide to how the average developer tackles a games project.   Video games are complex beasts.  Even a game as simple as Pacman has quite a number of routines, such as controlling the ghosts, taking user input, checking collisions, keeping score, and generating levels, not to mention non-game screens and functions like pre-loaders and splash screens.For this reason, a methodical approach to game development is essential, otherwise the project becomes chaotic, over budget and a nightmare to work on.</p>
<p>The first thing to do is to draw up a solid design, away from Flash, and include complete lists of assets such as graphics and audio.  Only then can you begin to develop the game in Flash.  The first step once the design is completed it to create a mock-up &#8211; an outline demo in Flash using placeholder graphics, which can be used to test and develop the game logic.  Once that is nearing completion you can begin to start adding graphical assets and audio.  It&#8217;s a good idea to leave out all extras at this stage however.  Things like splash screens and mid-level animations can slow testing down considerably, so leave them for the beta version.</p>
<p>Once the game reaches the later stages of development, when the game engine is mostly complete and tested, the final touches can be added.  Introductions, help screens, preloaders and game over screens should all be added at this point.  Leaving these until now means that testing is quicker, with less clicks, keypresses or waiting is required to restart levels or replay the game.</p>
<p>Then finally you&#8217;ll have a completed game, ready for final beta testing.  Even though we started with a complex project, by breaking the design and development process down into bite sized chunks it became manageable.  If you&#8217;re thinking of getting started in Flash game development then it&#8217;s a really good idea to <a href="http://www.viralflashgames.com">edit an existing game or two first</a>.  Making changes to an existing game, such as adding new levels or power-ups, can be a far less daunting task than building a whole game from scratch.  You can even take the source code for an existing game and turn it into a new game entirely.  Then once you&#8217;ve gained more experience you&#8217;ll be in a better position to start building your own games from scratch.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/game-design/flash-game-development-workflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading Asteroids – audio and improvements</title>
		<link>http://www.flashgamesclassroom.com/classroom/actionscript/upgrading-asteroids-audio-and-improvements/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/actionscript/upgrading-asteroids-audio-and-improvements/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 15:09:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=225</guid>
		<description><![CDATA[This is a follow-up to the main tutorial from last week, How to write the arcade classic Asteroids in Flash, which originally appeared in the January edition of Flash and Flex Developer&#8217;s Magazine which can be found at FFDmag.com
In the tutorial we built a fully working, but rather basic version of Asteroids and today we&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Fupgrading-asteroids-audio-and-improvements%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Fupgrading-asteroids-audio-and-improvements%2F" height="61" width="51" /></a></div><p>This is a follow-up to the main tutorial from last week, <a href="http://www.flashgamesclassroom.com/classroom/actionscript/creating-an-asteroids-arcade-game-in-flash/">How to write the arcade classic Asteroids in Flash</a>, which originally appeared in the January edition of Flash and Flex Developer&#8217;s Magazine which can be found at <a href="http://ffdmag.com/magazine/991-flash-and-mobile-apps-iphone-and-ipod-touch">FFDmag.com</a></p>
<p>In the tutorial we built a fully working, but rather basic version of Asteroids and today we&#8217;re going to add a couple of improvements.  I&#8217;ll leave features like power-ups and shields for a future post, but there is one gameplay tweak which is quit important.  In our original game we had no maximum speed on our spaceship, which meant that if the player held the thrust (UP) key down the ship would continue to accelerate ad infinitum.</p>
<p>That&#8217;s all well and good, but apart from looking glitchy one the ship starts travelling too far on screen each frame, if the ship is allowed to accelerate too much it could interfere with the collision detection, as it would effectively &#8220;jump&#8221; over an asteroid.  So today we&#8217;re going to fix that, and also add some simple audio so that it starts to feel like a real game.  Here&#8217;s an example of the updated game in action&#8230;</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="580" height="435" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.flashgamesclassroom.com/swf/space_debris_2.swf" /><param name="quality" value="high" /><embed type="application/x-shockwave-flash" width="580" height="435" src="http://www.flashgamesclassroom.com/swf/space_debris_2.swf" quality="high"></embed></object></p>
<h3>Setting a maximum speed</h3>
<p style="text-align: left;">Our ship&#8217;s velocity is a vector, meaning it has both magnitude and direction.  That means we can&#8217;t simply check the current speed against a maximum speed and prevent further thrusting if it&#8217;s too high &#8211; that would prevent the player from turning, and thrusting away in a different direction.</p>
<p style="text-align: left;">There are several solutions to this, but since it&#8217;s such a simple game and we&#8217;re not interested in real-world simulations we&#8217;ll go with a nice simple one.  Effectively we&#8217;ll check both the X and Y velocity of the ship after the thrust key is hit, if the extra thrust would push either the X or Y velocity over the limit we won&#8217;t apply it!</p>
<p style="text-align: left;">This means our ship will have a higher maximum velocity if travelling diagonally on the screen than if it&#8217;s going straight up/down or left/right, but for our purposes that&#8217;s not much of an issue.</p>
<h3>Coding the change</h3>
<p style="text-align: left;">We&#8217;ll need one new class variable:</p>
<p style="text-align: left;">Then we need to make a change to the moveSpaceship() method.  Replace these lines:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>thrust<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
shipDX <span style="color: #000066; font-weight: bold;">+</span>= <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">*</span>spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">/</span>180<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>thrustAmt<span style="color: #000066; font-weight: bold;">;</span><br />
shipDY <span style="color: #000066; font-weight: bold;">-</span>= <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">*</span>spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">/</span>180<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>thrustAmt<span style="color: #000066; font-weight: bold;">;</span><br />
spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">gotoAndStop</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;thrust&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>with this&#8230;</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>thrust<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<span style="color: #009900; font-style: italic;">// Check if adding thrusting would exceed max speed, if not then thrust...</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> tempDX<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> tempDY<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
tempDX = shipDX<span style="color: #000066; font-weight: bold;">;</span><br />
tempDY = shipDY<span style="color: #000066; font-weight: bold;">;</span><br />
tempDX <span style="color: #000066; font-weight: bold;">+</span>= <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">*</span>spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">/</span>180<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>thrustAmt<span style="color: #000066; font-weight: bold;">;</span><br />
tempDY <span style="color: #000066; font-weight: bold;">-</span>= <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">*</span>spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">/</span>180<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>thrustAmt<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>tempDX <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> shipMaxSpeed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
shipDX = tempDX<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>tempDY <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> shipMaxSpeed<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> &nbsp;&nbsp; &nbsp; shipDY = tempDY<span style="color: #000066; font-weight: bold;">;</span> &nbsp; &nbsp;<span style="color: #000000;">&#125;</span> &nbsp; spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">gotoAndStop</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;thrust&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>As you can see, we&#8217;ve calculated the new thrust values for a pair of temporary variables, then we compare the new velocities based on these values, and only if they are below the maximums do we apply them to the actual ship velocities shipDX and shipDY.</p>
<h3>Adding audio</h3>
<p>No game is complete without sound effects, so take a look at a couple of ways of adding them to a game.  I won&#8217;t go into detail here about using sound channels and transforms to allow for mute controls etc, that can be another post another time, for now let&#8217;s just get some simple sound effects into the game. First we&#8217;ll need some sounds.  Flash will support Wav or MP3 format audio and there are loads of sites online where you can download free (or cheap) sound effects in those formats.  If necessary you can trim or edit them using something like <a href="http://www.online-business-logic.com/tools-resources/content-creation-part-4-audio-using-audacity/">Audacity</a> and then you want to import them into our FLA file.  Go <em>File </em>&gt; <em>Import to Library</em> and select all of the sounds you want to import.  I&#8217;ve imported 4, one for the ship exploding, one for the ship firing, one for hitting an asteroid, and one for end of level/game.</p>
<p>The simplest way to add a sound is on the timeline.  Open up the <em>ship </em>movieclip and add a new level called audio.  Add a new keyframe (<strong>F6</strong>) on frame 3 (the same frame that the explosion animation starts) and on the properties panel, click on the Sound dropdown and select the sound you want to play when the ship explodes.  You&#8217;ll notice a waveform for the sound shown on the timeline, as shown below.</p>
<div class="wp-caption aligncenter" style="width: 482px"><img title="Adding sound to the timeline" src="http://www.flashgamesclassroom.com/images/timelineaudio.jpg" alt="Adding sound to the timeline" width="472" height="165" /><p class="wp-caption-text">Adding sound to the timeline</p></div>
<p>You can do the same thing in the <em>messages </em>movieclip to add the end of level, and end of game audio.</p>
<p>Now the asteroid getting hit, and the ship firing can&#8217;t be done in this way since they don&#8217;t have animations, but that&#8217;s good because it gives us a good reason for using Actionscript to play the audio.  Controlling sound with Actionscript is much more powerful than using the timeline as it gives loads of extra control, and allows us to do things dynamically (it&#8217;s also how we would add a mute or volume control to the game!)</p>
<p>First of all we need to right-click on each of the audio assets we intend to control in the library, check the &#8220;<em>Export for Actionscript</em>&#8221; setting and give them an appropriate class name:</p>
<div class="wp-caption aligncenter" style="width: 457px"><img title="Actionscript audio" src="http://www.flashgamesclassroom.com/images/linkage.jpg" alt="Check Export for Actionscript and give it a class name" width="447" height="232" /><p class="wp-caption-text">Check &quot;Export for Actionscript&quot; and give it a class name</p></div>
<p>To use simple sound we need to add one new import to our AS file:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.media</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=sound%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sound.html"><span style="color: #004993;">Sound</span></a><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>Then we need to declare a class variable for each sound we want to use:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> thisExplode<span style="color: #000066; font-weight: bold;">:</span>Explode = <span style="color: #0033ff; font-weight: bold;">new</span> Explode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> thisShot<span style="color: #000066; font-weight: bold;">:</span>Shot = <span style="color: #0033ff; font-weight: bold;">new</span> Shot<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>The type is whatever class name we gave that sound when we set the linkage (and is case sensitive!)</p>
<p>Then we simply use Sound.play() to play those sounds at the correct moment.  So add this line to the fireBullet() method right after adding the bullet to the bullets array:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">thisShot<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>And add this line to the removeAsteroids() method, right after splicing the asteroids array:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">thisExplode<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s all there is to it.  We now have basic, but fully working audio in our game!</p>
<p>As usual, comments or questions are very welcome.  I&#8217;ll come back to this again in a week or so and we&#8217;ll add some other gameplay features such as powerups!</p>
<p>(If you want to see the original Asteroids tutorial, and download the source files <a href="http://www.flashgamesclassroom.com/classroom/actionscript/creating-an-asteroids-arcade-game-in-flash/">click here</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/actionscript/upgrading-asteroids-audio-and-improvements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating an “Asteroids” arcade game in Flash</title>
		<link>http://www.flashgamesclassroom.com/classroom/actionscript/creating-an-asteroids-arcade-game-in-flash/</link>
		<comments>http://www.flashgamesclassroom.com/classroom/actionscript/creating-an-asteroids-arcade-game-in-flash/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 15:16:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.flashgamesclassroom.com/classroom/?p=206</guid>
		<description><![CDATA[Those of you who read Flash and Flex Developer&#8217;s Magazine might have already read my Asteroids tutorial in the January edition.  If not, you can grab yourself a copy over at FFDmag.com
The tutorial shows you how to create a simple arcade game from scratch, based on the classic arcade hit Asteroids.  Rather than completely rehash [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Fcreating-an-asteroids-arcade-game-in-flash%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flashgamesclassroom.com%2Fclassroom%2Factionscript%2Fcreating-an-asteroids-arcade-game-in-flash%2F" height="61" width="51" /></a></div><p><img style="float:right; padding-left:10px;" title="Asteroids Flash game" src="http://www.flashgamesclassroom.com/images/asteroids_screen.jpg" alt="" width="250" height="201" />Those of you who read Flash and Flex Developer&#8217;s Magazine might have already read my Asteroids tutorial in the January edition.  If not, you can grab yourself a copy over at <a href="http://ffdmag.com/magazine/991-flash-and-mobile-apps-iphone-and-ipod-touch">FFDmag.com</a></p>
<p>The tutorial shows you how to create a simple arcade game from scratch, based on the classic arcade hit Asteroids.  Rather than completely rehash the entire article here, what I wanted to do was back the article up with a little more info, show some of the setup in a more visual manner (with a short video) and then show how the game in the tutorial could be extended with extra features like audio, powerups and other game extensions.</p>
<p>In today&#8217;s post I&#8217;ll show you how to set up the Flash file, and go over how I designed and built the basic game.  Then I&#8217;ll follow up in a few days with a second post showing how to add extra functionality to the game, and get it to a level where it could be published online.  First of all, let&#8217;s take a look at the game&#8230; (note this is scaled down from full size of 800&#215;600 px)</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="580" height="435" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.flashgamesclassroom.com/swf/space_debris.swf" /><param name="quality" value="high" /><embed type="application/x-shockwave-flash" width="580" height="435" src="http://www.flashgamesclassroom.com/swf/space_debris.swf" quality="high"></embed></object></p>
<p>I&#8217;ve named it &#8220;Space Debris&#8221; but essentially it&#8217;s the same gameplay as the old Atari classic.  You move a small spaceship around the screen by rotating (cursors LEFT/RIGHT) thrusting (cursor UP) and firing bullets (X) in an attempt to destroy the asteroids.  Shoot a large asteroid and it becomes 2 smaller asteroids, they in turn become 2 yet smaller asteroids, and finally the smallest ones are removed when hit.  Clear the screen and you&#8217;ll have to face a larger, harder wave.</p>
<p>The player begins with 3 lives, they lose one if they crash into an asteroid, and the game is over when all lives are lost.  Pretty basic stuff right?</p>
<p>OK so the game will be written in a single class named Asteroids.as and we&#8217;ll also use a Flash file which will handle the intro/outro screens and hold our graphical assets etc.  In this video I&#8217;ll quickly show you how to set it up and then I&#8217;ll move on to actually coding the game, or simply <a href="http://www.flashgamesclassroom.com/classroom/about/free-asteroids-game-tutorial-and-source-files/">click here</a> to download all the source files.</p>
<p><strong>Setting up the Asteroids game file</strong></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="580" height="360" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/B9MmV2RcYnA&amp;hl=en_GB&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6&amp;border=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="580" height="360" src="http://www.youtube.com/v/B9MmV2RcYnA&amp;hl=en_GB&amp;fs=1&amp;color1=0x006699&amp;color2=0x54abd6&amp;border=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Writing the Asteroids game class</strong></p>
<p><em><span style="color: #800000;">The following is taken from my article in Flash and Flex Developer&#8217;s Magazine January 2010 edition, reformatted slight for this blog but it is LONG!  I would highly recommend grabbing the FFDMag January edition and reading from that instead, which also includes full setup details for the Flash file!  Then just skip to the end of this post to grab the FLA and AS3 source files&#8230;</span><br />
</em></p>
<p style="margin-bottom: 0cm; font-style: normal;">First create a new actionscript file and save it as Asteroids.as</p>
<p style="margin-bottom: 0cm; font-style: normal;">Listing 1 (please download the AS files at the bottom of this page) shows the Asteroids class which extends MovieClip.  It uses 4 imports, and has quite a number of class variables.  Most of these are self explanatory such as lives or score.  Some however need a little explanation.</p>
<p style="margin-bottom: 0cm; font-style: normal;">We use 2 eponymous arrays to keep track of all the asteroids and bullets currently on screen, and we use a movieclip called <em>gameField</em> which will contain all the game objects (spaceship, asteroids, bullets).</p>
<p style="margin-bottom: 0cm; font-style: normal;">The variable <em>oldTime</em> is used with our timer to calculate the new positions of each object on every frame, depending on their current speed and how long since the last frame.</p>
<p style="margin-bottom: 0cm; font-style: normal;">The three booleans simply keep track of whether the ship is currently turning or thrusting, and then we have variables for all of the ship parameters, from how fast it rotates, to the maximum number of bullets it can fire.</p>
<p style="margin-bottom: 0cm; font-style: normal;">Finally we declare 4 points, and another boolean.  The points are the co-ordinates of the outer extremities of our ship and will be used when we write our collision detection function to see if the ship has crashed.  The boolean simply tracks whether the game is currently playing (and the ship hasn&#8217;t already crashed!)</p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Beginning our game</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">You&#8217;ll notice that there is no constructor method.  That is because we don&#8217;t want the game to start automatically, so instead we write a method called <em>startGame()</em> which we call  frame 2 of our FLA file.</p>
<p style="margin-bottom: 0cm; font-style: normal;">The <em>startGame()</em> method sets up our game by resetting variables such as <em>level</em> and <em>score</em>, creating new arrays to keep track of the asteroids and bullets, and creating our <em>gameField</em> movieclip which we move behind our control panel with the <em>addChildIndex</em> method.</p>
<p style="margin-bottom: 0cm; font-style: normal;">We add 3 event listeners – one for ENTER_FRAME, which is our main game loop, and 2 for user input (KEY_DOWN and KEY_UP).  We also call a method called <em>addShip()</em> which, as the name suggests, creates our ship object.  We could also call <em>nextLevel()</em> from here to generate the first asteroid field, but instead we play the message movie clip, and add a listener which will call <em>messageHandler()</em> on each frame.  The <em>messageHandler()</em> method in turn will call <em>nextLevel()</em> once the message “Get Ready&#8230;” has been shown on screen.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Main game loop</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">Asteroids in an action based game.  Unlike a puzzle game or turn based game like Tic Tac Toe, or Sudoku, an action game has things happening all the time, on every frame, whether there is input from the user or not.  To handle this we create a method called <em><span style="font-weight: normal;">gameLoop()</span></em> which is called every frame from the listener we declared above.</p>
<p style="margin-bottom: 0cm; font-style: normal;">This <em>gameLoop()</em> method calculates the position of every object on screen, based on its velocity, and the time passed since the previous frame (see <a href="http://www.flashgamesclassroom.com/classroom/actionscript/frame-based-vs-time-based-animation/">Time based animation</a> post for more details).  It does this by first getting the time in milliseconds since the game started and subtracting from that the time of the previous frame.  This gives us the exact number of milliseconds since the last time the screen updated which is then passed to a number of methods to calculate the new positions of the ship, bullets and asteroids.</p>
<p style="margin-bottom: 0cm; font-style: normal;">We also check for collisions (to see if an asteroid has been shot, or has crashed into the ship) and finally we update the text field for the score.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Game objects</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">We have 3 different types of game objects – our spaceship, the bullets it fires, and the asteroids.  Each type of object has a method to create it, a method to move it (i.e. update its position on screen) and a method to remove it.  Let&#8217;s look at each object type in turn.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Spaceship</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">Firstly the spaceship.  This is what the user controls via keyboard inputs.  It starts in the middle of the screen and there it remains until we give it some input.  The <em>addShip()</em> method is very simple – it creates a new <em>SpaceShip</em> object, sets its position to the center of the screen, adds it as a child of the <em>gameField</em> object and sets the <em>inGame</em> variable to true.</p>
<p style="margin-bottom: 0cm; font-style: normal;">The <em>moveSpaceship()</em> method is quite simple too, but involves just a little maths  First it deals with the user input.  If <em>turnLeft</em> or <em>turnRight</em> are true (set when the left/right cursor keys are pressed) then the rotation of the ship is either increased or decreased by the rotation speed.</p>
<p style="margin-bottom: 0cm; font-style: normal;">If the <em>thrust</em> variable is set however there is a little more going on.  We need to convert the thrust force into cartesian values for x and y.  This is done with basic trigonometry  If you think back to your trigonometry lessons from school you&#8217;ll remember that the x or y value can be found by using sine or cosine of the angle (rotation of the ship) multiplied by the hypotenuse (thrustAmt).  We&#8217;re working in radians (rather than degrees) so we find the increase or decrease in x and y velocities like this:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">shipDX <span style="color: #000066; font-weight: bold;">+</span>= <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">*</span>spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">/</span>180<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>thrustAmt<span style="color: #000066; font-weight: bold;">;</span><br />
shipDY <span style="color: #000066; font-weight: bold;">-</span>= <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">*</span>spaceship<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>thrustAmt</div></td></tr></tbody></table></div>
<p style="margin-bottom: 0cm; font-style: normal;">Now that we know the velocities we can update the position of the ship by simply adding the new velocity values to the x and y co-ordinates of the ship.  We also show frame 2 (the thrust frame) of the ship movie clip if thrusting, or frame 1 if not.</p>
<p style="margin-bottom: 0cm; font-style: normal;">The last part of the <em>moveSpaceship()</em> method handles the edge of the screen.  In Asteroids, the spaceship and asteroids “wrap” from one side of the screen to the other, and from top to bottom.  To handle this we simply check to see if the ship&#8217;s position is outside of those boundaries, and if it is we wrap it to the opposite edge (with a little overlap of 20 pixels, roughly the width of the ship, which makes the transition look smooth!)</p>
<p style="margin-bottom: 0cm; font-style: normal;">Removing the spaceship is actually handled by 2 methods – firstly we call <em>explodeSpaceship()</em> which sets <em>inGame</em> to false, moves the spaceship to the top of the <em>gameField</em> display list (to make sure it&#8217;s in front of the other graphics), and then plays the explode animation.  We also take a life off at this point and update the <em>lives</em> field on the control panel.</p>
<p style="margin-bottom: 0cm; font-style: normal;">An event listener is added which calls <em>removeSpaceship()</em> once the explode animation is completed.  This removes the spaceship movie clip, then either calls <em>addShip()</em>, or if there are no lives remaining ends the game by playing the <em>gameover</em> frame in the messages clip.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Asteroids</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">At this point we have a spaceship flying around the screen, but that&#8217;s not much of a game on its own so lets add some asteroids!  Again, we have methods to add, move, and remove, but we also have a method called <em>nextLevel()</em> which generates the entire asteroid field for the level.</p>
<p style="margin-bottom: 0cm;"><span style="font-style: normal;">Let&#8217;s begin with the </span><em>addAsteroid()</em><span style="font-style: normal;"> method.  It accepts 3 parameters – </span><em>asteroidType</em><span style="font-style: normal;"> which is a string (</span><em>big</em><span style="font-style: normal;">, </span><em>medium</em><span style="font-style: normal;"> or </span><em>small</em><span style="font-style: normal;">) along with x and y co-ordinates.  We declare a new MovieClip variable called </span><em>newAsteroid</em><span style="font-style: normal;">, and depending on the </span><em>asteroidType</em><span style="font-style: normal;"> parameter we create a new big, medium or small asteroid object.  We also give the new asteroid a random vertical and horizontal speed within certain limits (the smaller asteroids can move faster than the big ones!)</span></p>
<p style="margin-bottom: 0cm; font-style: normal;">We then position the asteroid according to the x and y parameters, rotate it to a random angle and finally add it to both the <em>asteroids</em> array and the <em>gameField</em> movie clip.</p>
<p style="margin-bottom: 0cm; font-style: normal;">Responsible for generating the asteroid field, and passing the parameters to <em>addAsteroid</em> is the <em>nextLevel()</em> method.  It begins by incrementing the <em>level</em> variable (which we initially set to 0 in the <em>startGame() </em>method.  We generate a number of asteroids, equal to the level number plus one so we open a for loop, and then create asteroids in random positions on the screen.</p>
<p style="margin-bottom: 0cm; font-style: normal;">We don&#8217;t want asteroids to appear in the center (that&#8217;s where our ship is) or too close to the edges (otherwise they may instantly wrap which will cause a flicker) so we split the game field up into 4 quadrants.  We randomly choose a quadrant, and then randomly generate a position within that quadrant to place the asteroid.  That position, along with the size is passed to the <em>addAsteroid()</em> method to generate the asteroid field for the level.</p>
<p style="margin-bottom: 0cm; font-style: normal;">Moving the asteroids is simpler than the ship since there is no user input to worry about, except that this time we loop through each asteroid in the <em>asteroids</em> array one by one.  We again use the <em>timeFrame</em> parameter generated in <em>gameLoop()</em> but this time we simply move the asteroid based on its horizontal and vertical speed.  We rotate it based on the difference between those 2 speeds (saves having to generate another random number, but keeps them all rotating differently) and we wrap at the edges just as we did with the spaceship.</p>
<p style="margin-bottom: 0cm; font-style: normal;">While moving the asteroids is simpler than the spaceship, removing them is very slightly more complex.  If it&#8217;s a small asteroid we can simply remove it, and increase the score.  If it&#8217;s medium or large however we need to split it into 2 smaller asteroids.  We do that by first checking the the type, and then calling <em>addAsteroid()</em> twice for the next size down.  We also increase the score here, based on the size of asteroid hit, and finally we remove the asteroid both from the array and the game field.</p>
<p style="margin-bottom: 0cm; font-style: normal;">At this point we also check the asteroids array to see if there are any remaining asteroids.  If there are none then the level is over, and we play the <em>messages</em> clip from the “next level” frame, and add a listener which calls <em>messageHandler()</em> (and in turn <em>the nextLevel() </em>method) when the message finishes.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Bullets</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">Bullets are actually very simple since they don&#8217;t rotate, and they don&#8217;t wrap (we&#8217;ll remove them when they reach the edge of the screen).  First we create a new bullet with the <em>fireBullet()</em> method which takes no parameters.  It is called when the player hits the X key to shoot, and creates a new <em>Bullet</em> object.  We calculate the new bullet&#8217;s velocity based on the current rotation of the ship in the same way we calculate the ship&#8217;s velocity.  We then position the bullet just in front of the ship, add it to the <em>gameField</em> and the <em>bullets</em> array.</p>
<p style="margin-bottom: 0cm; font-style: normal;">Moving the bullets is just like moving the asteroids in that we loop through the <em>bullets</em> array one by one.  For each bullet we move it based on its velocity (multiplied by <em>bulletSpeed</em>) and we then check it against the edges of the gameField.  Once the bullet goes beyond the edge of the screen we call removeBullet.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><em>removeBullet() </em>method accepts a single parameter, which is the index of the bullet in the <em>bullets</em> array.  This method simply removes the bullet from the game field, and from the array.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Pulling it all together</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">OK so we now have a spaceship flying around the screen under the player&#8217;s control, we have asteroids floating through space, and we are able to shoot but there is one big element yet to code – the collision detection!</p>
<p style="margin-bottom: 0cm; font-style: normal;">At the moment our spaceship is invincible, and our bullets pass right through the asteroids without making a dent.  What we need is a final method added to our game loop which checks for collisions between the asteroids, and our ship and bullets.</p>
<p style="margin-bottom: 0cm; font-style: normal;"><img style="float:right; title=" src="http://www.flashgamesclassroom.com/images/colision_points.jpg" alt="" width="250" height="158" />So the <em>checkColisions()</em> method actually handles 2 different types of collision – asteroid/ship and asteroid/bullet.  Let&#8217;s take a look at the ship collisions first.</p>
<p style="margin-bottom: 0cm; font-style: normal;">First we check the <em>inGame</em> variable to ensure that the ship is still in play.  If it is then we loop through the <em>asteroids</em> array and check each asteroid&#8217;s <em>hit</em> clip against each of the collision points on the ship using <em>hitTestPoint</em> with the <em>shapeFlag</em> parameter set to true (see collision detection box).  The <em>localToGlobal</em> method is used to convert the collision points (which are relative to the ship) to global co-ordinates.  If there is a match (i.e. if one of the collision points is within the boundary of an asteroid&#8217;s hit clip then there has been a crash and <em>explodeSpaceship()</em> is called.</p>
<p style="margin-bottom: 0cm;"><span style="font-style: normal;">For the bullet collisions we loop through the </span><em>asteroids</em><span style="font-style: normal;"> array, and for each asteroid we loop through the </span><em>bullets</em><span style="font-style: normal;"> array.  Using </span><em>hitTestPoint</em><span style="font-style: normal;"> again, this time we simply check the bullet&#8217;s x and y co-ordinates against the asteroid&#8217;s </span><em>hit</em><span style="font-style: normal;"> clip.  If there is a collision we call both </span><em>removeAsteroid()</em><span style="font-style: normal;"> and </span><em>removeBullet()</em><span style="font-style: normal;">.  We then break out of the inner for loop, using </span><span style="font-family: Courier New,monospace;"><span style="font-style: normal;">continue loopAsteroids; </span></span><span style="font-style: normal;">to prevent checking another bullet against the asteroid which has just been removed.</span></p>
<p style="margin-bottom: 0cm; font-style: normal;"><strong>Finishing and running the game</strong></p>
<p style="margin-bottom: 0cm; font-style: normal;">The final methods, <em>showScores()</em>, <em>restartGame()</em>, <em>keyIsDown()</em> and <em>keyIsUp()</em> are self explanatory, and if you&#8217;ve followed the tutorial this far you should now have a simple but working game.</p>
<p style="margin-bottom: 0cm; font-style: normal;">While this works as a great example for learning some of the fundamental principles of game development, and a few years ago it probably would have been enough to compete with many other Flash games on the web, these days players want something a little more refined.</p>
<p><span style="color: #800000;"><em>{ End of magazine tutorial&#8230; }<br />
</em></span></p>
<p>Whew &#8211; I told you that was long!  OK, so rather than list all the actionscript here too I&#8217;ve put all the source files together in a zip which you can download <a href="http://www.flashgamesclassroom.com/classroom/about/free-asteroids-game-tutorial-and-source-files/">here</a>.</p>
<p>I really hope you enjoy tinkering with the game, and you learn a ton from it.  Please do give me some feedback, just leave a comment with any questions or suggestions and I will read them and resond.  Next week I&#8217;ll post a <a href="http://www.flashgamesclassroom.com/classroom/actionscript/upgrading-asteroids-audio-and-improvements/">follow-up article</a> which will extend the game, and audio and some other functionality, and basically turn it into a usable web game, so if you want to see specific features added do let me know!</p>
<p>In the meantime, have fun playing with it <img src='http://www.flashgamesclassroom.com/classroom/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p style="text-align: right;"><a href="http://www.flashgamesclassroom.com/classroom/about/free-asteroids-game-tutorial-and-source-files/"><img src="http://www.flashgamesclassroom.com/images/projectfiles.jpg" border="0" alt="Download Flash Social Media Buttons" align="middle" /><br />
Download the Flash social media buttons components</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgamesclassroom.com/classroom/actionscript/creating-an-asteroids-arcade-game-in-flash/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

