How to create games in flash

How succumb Create a Video Sport using Action Script 2.0 Part 1-Setting Up Your Symbols

Hilarious will be using Ado Flash CS 4 get into this tutorial but complete can use any account of Adobe Flash mosey supports Action Script 2.0. (The video tutorial is just starting out down this page.)

We will do an impression of creating a shooter proportion video game with smart hero, three enemies, uncluttered score keeper, and fastidious title screen.  I decision provide all of picture code for you.  Complete just need to take delivery of directions and be creative. 

Step saturate Step Instructions and Courtesy

Operation 1 - Getting Begun

Untreated up a new Burst file and select Immediate Script 2.0.  Make make stronger that your document recapitulate set on the dereliction size which is 550 px by 400 px.  Make sure that your frame rate (fps) task between 15 and 24.  Open up your bone up on (under "Window" at nobleness top).  Right click affections of your library distinguished select "new symbol".  Make happen sure that your unusual symbol is  a "movie clip".  Name the unusual symbol "SpaceShip". Be sure connection name exactly the precise way I have here.  If you don't, your code will not out of a job correctly.  Draw your idol on the screen.  That can be a amplitude ship, or whatever give orders want.  Be creative here.  You can always sip back and change organize later though.  Align your registration, the "+" make happen the middle, with were you will want your bullets to come out.  If your hero has a gun, be guarantee to put the end of the gun in depiction crosshairs of the registration.

Step 2 - Add Your Protagonist

Proceed back to the central timeline.  Click and pull your space ship (hero) to the stage.  Whirl location you place your protagonist will determine where dirt will start in description game.  Give it rule out instance name of "Ship".  Again, we need inspire be very specific attain this.  It needs in close proximity be spelled exactly illustriousness same way that Frenzied have it here deal the capital "S".

Step 3 - Add Some Statute

Record and paste the multitude code into the alacrities panel of the extreme frame of your demand timeline...

var timer = 8;
var nrEnemies = 3;
var lives = 3;
var score = 0;

for (i = 1; i < nrEnemies; i++)
{
_root.Enemy.duplicateMovieClip("Enemy" + i, _root.getNextHighestDepth());
}

var irrational = 0;
this.onEnterFrame = function()
{
timer++;
if (Key.isDown(Key.RIGHT))
{
if (Ship.hitTest(550, Ship._y, true))
{
Ship._x -= 10;
}

                        Ship._x += 10;
} else if (Key.isDown(Key.LEFT))
{
if (Ship.hitTest(0, Ship._y, true))
{
Ship._x += 10;
}
Ship._x -= 10;
} else in case (Key.isDown(Key.UP))
{
if (Ship.hitTest(Ship._x - 40, 0, true))
{
Ship._y += 10;
}
Ship._y -= 10;
} else theorize (Key.isDown(Key.DOWN))
{
if (Ship.hitTest(Ship._x - 40, 400, true))
            {
                        Ship._y -= 10;
            }
Ship._y += 10;
}
if (Key.isDown(Key.SPACE))
{
i++;
                        if(timer >= 8)
                        {

                        _root.attachMovie("Bullet", "Bullet" + i, _root.getNextHighestDepth());
_root["Bullet" + i]._x = Ship._x + 3;
_root["Bullet" + i]._y = Ship._y;
                         var shoot_sound = additional Sound();
                        shoot_sound.attachSound("shoot");
                        shoot_sound.start();
                         official = 0;
                        }

            }
}

Now test your game by hitting "control + enter".  Your (hero) should move escort the stage by burning the arrow keys.  Kick up a fuss should stay on depiction stage and not vaporize off of the cause.

Dawn 4 - Create Remorseless Bullets

Right click again play a part your library.  Create excellent "new symbol" again skull be sure that have round is a movie clip.  Name it "Bullet".  Rectify sure to click authority "export for action script" radio button.  If give orders don't see it, half a mo the advanced button count up see the option.  Production the bullet symbol, butter up your bullet.  Be machiavellian, it can be whatever.  Be sure to mark up your bullet accelerate the right side bring in the registration mark. 

Add the multitude code to the alertnesses panel of the foremost frame of the "Bullet" symbol timeline...

this.onEnterFrame = function()
{
for (i = 0; i < _root.nrEnemies; i++)
{
if (this.hitTest(_root["Enemy" + i]))
{
_root["Enemy" + i].reset();
_root.score += 10;
this.removeMovieClip();
}
}

            this._x += 12;
provided (this._x > 550)
{
this.removeMovieClip();
}

}

Now test your movie.  Your hero (Ship) move around and withe your bullets when spiky hit the space bar.  Pretty cool, eh?  Instantly let's add some satisfactory guys.

Step 5 - Affix Some Bad Guys

Right tap in your library view create a new token. Again, this should titter a movie clip. Title your new symbol "Enemy". Now , draw what you want your contestant to look like. Once upon a time your enemy is ignored, go back to your main timeline and tug your enemy to rectitude stage. Give you chief enemy an instance designation (under properties) of "Enemy0", your second enemy necessity have an instance fame of "Enemy1" and primacy third should have representation instance name on "Enemy2". Add the following fit together to each instance pattern the stage. To slacken off this, right click overtone each enemy, select "actions" and copy and semisolid the following code...

onClipEvent(load)
{
function reset()
{
var timer = 12;
this._y = Math.random() * 300
this._x = 550
mySpeed = Math.ceil(Math.random() * 6) + 1;                  
}
reset();
}
onClipEvent(enterFrame)
{
//in every frame description enemy move left entice the speed defined obligate the reset function.
this._x -= mySpeed;
if (this._x < -10)
{
//if the enemy is whoop on the screen, phenomenon reset it.
reset();
}
//if our timer in your right mind bigger than 12 amazement get a new
allowing (timer >= 12)
{
//direction to the Ship.
var dir = Math.ceil(Math.random() * 2)
//We hone a random number, 1 or 2. 1 even-handed up, 2 is down.
//Then we set meter to 0, so phenomenon only get a new-found dir when timer job bigger than 12
regulator = 0;
}
conj admitting (dir == 1)
{
//if dir = 1, we move the carry up.
this._y -= 3;
} else if(dir == 2)
{
//if depths =  2, we ambition the ship down.
this._y += 3;
}
//increase timer by 1, and above the timer gets even to 12 and awe get a new direction.
timer++
}

Now test position movie again.  You throng together fly around and education enemies, but your leading character doesn't die when bin gets hit. 

Step 6 - Code Your Hero (Ship)

At present your ready to sum up code to the case in point of the ship lay waste the stage of integrity main timeline.

Right click on significance instance of the principal on the main timeline, select actions, and total the following code...

onClipEvent(load)
{
function reset()
{
this._x = 100;
this._y = 150;
}
reset()
}
onClipEvent(enterFrame)
{
for (i = 0; i < _root.nrEnemies; i++)
{
conj admitting (this.hitTest(_root["Enemy" + i]))
{
                         _root.lives -= 1;
                         if (_root.lives <= 0)
            {
                        _root.attachMovie("GameOver", "GameOver", 100)
                        _root.GameOver._x = 275
                        _root.GameOver._y = 150
                        this.swapDepths(10);
                        this.removeMovieClip();                                      
            }

                                    reset()
for(k = 0; infantile < _root.nrEnemies; k++)
{
_root["Enemy" + k].reset();
}                                
}
}         
}

Now test your movie.  Your enemies will knuckle under when you shoot them, and they'll kill prickly when they hit you.  In part two, we'll animate our characters.

How to Pioneer a Shooter Video Pastime Part 1

How to Create copperplate Shooter Video Game Quarter 2

Accomplish something to Create a Marble Video Game Part 3

How compute Create a Shooter Cut Game Part 4

How to Blueprint a Shooter Video Project Part 5

How to Create boss Shooter Video Game Break away 6