Talking about Actionscript 3, Flash and Game development.
Let me guess something: when you are designing your latest game, you start with a working prototype, design a couple of levels, maybe add some cute graphics then… in most case you abandon the project.
Since it happens quite often to me, I tried to focus on what is making me drop a project.
And I found once I have an almost working game, I get bored when it’s time to add splash screen, buttons, music, level selection, third part APIs, and all that stuff which isn’t related to the game itself.
So I decided to build some kind of framework/template which will do the boring job for me, letting me focus on what’s really importat: making games.
Look at these level selection screens:
I made them in a minute, just changing some variables in my template.
Let me explain the concept: this is the class of the level selection screen itself:
package {
import flash.display.Sprite;
public class levelSelectionMc extends Sprite {
public function levelSelectionMc(beaten:int):void {
var setup:setupClass = new setupClass();
var levelSelect:levelSelectMc;
for (var i:int=0; i
As you can see, I have the amount of beaten levels as argument at line 4, then a for
loop which iterates through the entire number of levels (defined in a class called setupClass
) and constructs levelSelectMc
instances (the level thumbnail) passing as arguments the number of the level and a Boolean variable which is true
if the level has already been beaten, false
otherwise.
Then, levelSelectMc class is defined as follows:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class levelSelectMc extends Sprite {
private var level:Number;
public function levelSelectMc(n:Number,solved:Boolean):void {
level=n;
var setup:setupClass = new setupClass();
if (! solved) {
var locked:lockedMc = new lockedMc();
addChild(locked);
}
else {
addEventListener(MouseEvent.CLICK,clicked);
}
var levelWidth:Number=setup.levelsPerRow*width+(setup.levelsPerRow-1)*setup.levelsHorizontalSpacing;
var numberOfRows:Number=Math.floor(setup.totalLevels/setup.levelsPerRow);
var levelHeight:Number=numberOfRows*height+(numberOfRows-1)*setup.levelsVerticalSpacing;
var xOffset:Number=(setup.gameWidth-levelWidth)/2+setup.levelsOffsetX;
var yOffset:Number=(setup.gameHeight-levelHeight)/2+setup.levelsOffsetY;
x=n%setup.levelsPerRow*(width+setup.levelsHorizontalSpacing)+xOffset;
y= Math.floor(n/setup.levelsPerRow)*(height+setup.levelsVerticalSpacing)+yOffset;
leveltext.text=(n+1).toString();
mouseChildren=false;
buttonMode=true;
}
private function clicked(e:MouseEvent):void {
removeEventListener(MouseEvent.CLICK,clicked);
var theParent:Main=this.parent.parent as Main;
theParent.playGame(level);
}
}
}
As you can see at lines 16-23, the position of the level thumbnail varies according to the number of thumbnails per row, the horizontal and vertical spacing between thumbnails, and absolute offsets, which are also defined in setupClass
class.
So, changing some basic values in this class:
package {
public class setupClass {
// basic game info
public var gameWidth:Number=640;
public var gameHeight:Number=480;
// levels
public var totalLevels:Number=40;
public var levelsPerRow:Number=8
public var levelsHorizontalSpacing:Number=5;
public var levelsVerticalSpacing:Number=5;
public var levelsOffsetX:Number=0;
public var levelsOffsetY:Number=30;
// play game button
public var playGameButtonX:Number=320;
public var playGameButtonY:Number=230;
// back to menu button
public var homeButtonX:Number=560;
public var homeButtonY:Number=0;
// level completed
public var completedReplayButtonX:Number=320;
public var completedReplayButtonY:Number=200;
public var completedPlayNextButtonX:Number=320;
public var completedPlayNextButtonY:Number=240;
public var completedShowLevelsButtonX:Number=320;
public var completedShowLevelsButtonY:Number=280;
// level failed
public var failedReplayButtonX:Number=320;
public var failedReplayButtonY:Number=320;
public var failedShowLevelsButtonX:Number=320;
public var failedShowLevelsButtonY:Number=360;
}
}
I can create any kind of layout in a minute.
A lot of more stuff in the game is defined with the same concept, from statistics to sound button, from congratulations screen to game over... just to let me develop "plug and play" games.
Once my first couple of games will be released, I plan to give the template for free, to let you create and publish your games focusing only on game coding.
Did you already made something similar? Which stuff do you hate to insert in your game? Buttons? APIs? Let me know and I'll add them as much as I can.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.