Main Content

You are here:

Avoider (Part 1)

Welcome to Part One of making an Avoider type game, the second in a series of Foundation Flash classic game remakes. The game we shall be making is shown below. You are the black circle, try and get the blue squares but avoider the white, 'enemy' circles.

During this project, we will be building on the skills learned from our previous tutorials, such as Pong!. Specifically, we will also be adding the following to our ActionScripting arsenal:

Well, let's crack on. First of all, you will need to create a new project, including one .fla and one .as. Call the .as file Avoider.as (it is customary to entitle classes, and thus their .as files, with a capital letter). Save them both in the same folder. Then, in the .fla, make the document class "Avoider" (with the capital letter, see for more one of our previous tutorials). This will make sure that the Avoider class constructor is loaded as soon as the swf is compiled. Good.

Now we need to actually put some code in Avoider.as. Go to it, and type:

package{
        import flash.display.MovieClip;
        public class Avoider extends MovieClip{
                public function Avoider(){
 
                }
        }
}

This forms the bare bones of our file. You will notice it is very similar to our previous projects, and includes the MovieClip class, which we will needs, then uses that as a foundation for our new Avoider class. The other imports you will need to add are listed below:

     import flash.text.TextField;
        import flash.display.Shape;
        import flash.events.Event;

Copy and paste them into the section, under the one import we had already. The bottom two we have met before and/or are quite self explanatory. However, we don't have a textfield yet, so why do we need to have the TextField class. Go on then, create one! Go back to you .fla, add a dynamic textfield, giving it an instance name of scoretext. Yes, that will be holding our score.

While you're in you .fla, you'll need to add in the four walls. Make them quite thin, at most about 15px (or alter the later code). Give them, in clockwise order, the instance names walltop, wallright, wallbottom and wallleft. WE will be using them later for both the player and the enemies, who 'bounce' off them.

Finally for today, then, we will be adding in some variables to use later. These need to go into between the Avoider class definition line and the Avoider function definition line, and are as follows:

             public var target:MovieClip = new MovieClip;
                public var player:MovieClip = new MovieClip;
                public var score:int = 0;
                public var mouseDiffX:int = 0;
                public var mouseDiffY:int = 0;

The target will become the blue square; the player is the you, the black circle; score holds, er, the score; mouseDiff X and Y will hold how far away from the mouse you are

All this is to come of course, but I do so hope you will join me for it.

Harry.

Comments