Article
Build a Shoot-em-up Game in Flash MX
Build the Flash Movie
Launch Flash MX and, if you've not already done so, open a new file. Click on Save, and name your Movie (you could be original and call it shootemup.fla).
Now, name your layer 'Targets', and in frame 1, import your target image to the stage.
File-import or (ctrl+R [pc])–[Browse for image]-Open
With your target on the main stage, make sure it is selected and make it into an individual movie clip (F8 [pc]). When the 'Create Symbol' dialog box appears, name the movie clip (MC) 'target', and make sure the 'Movie Clip' radio button is selected. In the 'Property Inspector', name the instance 'target1'. While you're at it, drag another two instances of the TargetMC onto the stage and give them instance names of 'target2' and 'target3' respectively. Click on frame 2 and press (F5) to copy the frame over. We'll stick with three static targets for now – though, beyond this tutorial, how many targets you add and how they move is completely up to you.
Create another layer, name it 'Text', and in frame 1, use the text tool, setting the option to 'Dynamic Text', to create 2 boxes of about 30 characters in size along the top of the screen. Font size and colour are up to you. You may also want to spend some time sizing and aligning.
Select the 'single line' and 'border around text' options from the Property inspector. In the properties instance field, name these 'hits' and 'info' respectively. Move to frame2 on the timeline, and create a new keyframe (F6) Then, in an appropriate bit of white space on the stage, add some text along the lines of 'GAME OVER'.
Create another layer and name it 'Actions'. Open up the panel (Window Menu-Actions or (F9 [PC]) and copy the following code into frame 1:
(ActionScript (AS) for frame 1)
stop();
//Set global highScore variables
highScore = 0;
//Set the properties for the game elements
_root.lastFrame = false; //Stop bullets
//See AS for bullet MC for details
setProperty(_root.crosshair, _visible, true);
SetProperty(_root.bullet, _visible, false); //
//Individual destroyed target images hidden until needed
setProperty(_root.target1d, _visible, false);
setProperty(_root.target2d, _visible, false);
setProperty(_root.target3d, _visible, false);
//As above. Individual highlighted target images hidden until needed
setProperty(_root.target1Image, _visible, false);
setProperty(_root.target2Image, _visible, false);
setProperty(_root.target3Image, _visible, false);
mouse.hide(); //hide mouse to use cross-hairs
//select a target to shoot at random then add that target
//to the array of selected targets so that it isn't used
//again in this game.
//When the number of direct hits against the selected
//target has been reached. Find another random target.
//Check whether it exists in the array. If yes, select
//again. If no, make visible.
_root.targets = new Array(); //create array on the main
//timeline so that it is
//easily accessed by all MCs
_root.targets[0] = "target1";
_root.targets[1] = "target2";
_root.targets[2] = "target3"; //3 targets we are using in
//tutorial
n = _root.targets.length; //get length of array
ran = random(n); //get random number location to select from array
target = _root.targets[ran]; //show random array location
_root.activeTarget = target; //create target variable
setProperty("_root."+target+"Image", _visible, true); //show target
_root.targets.splice(ran, 1); //remove the random element
//from the array. splice
//the random number found and
//to the depth of one so only
//one element is removed.
//-------------------------------------------------------//
(AS for Actions frame 2)
Click on frame 2 in the Actions layer and create a blank keyframe (F7). Then, enter the following code into the actions panel:
stop();
_root.lastFrame = true; //Stop bullets
//See AS for bullet MC for details
mouse.show(); //reshow mouse
setProperty(_root.crosshair, _visible, false); //Hide cross hair
target1Hits = 0; //reset the hits for each target in case another
//game is played.
target2Hits = 0;
target3Hits = 0;
//-------------------------------------------------------//