Tutorial: Make a Vertical Shooter in AS2
Categories: Flash
Table of Contents
Step 1: Programming the Character
Today, we’re going to make a classic vertical shooter game in ActionScript 2. I hope you learn from it! Let us begin.
The first thing that I’m going to do is make the background of my game black, so it looks more retro. Then, we’re going to have to make the frame rate faster, mine will be 24 fps. Also, this will be a vertical shooter, so we probably should make the playing screen more narrow. My new dimensions are at 300×400 pixels.
Next, we’re going to draw a character. Mine will be simple, just a triangle pointing upwards.
The dimensions for it are 30×35 pixels.
Then, we’re going to turn it into a symbol. After that, we’re going to give it an instance name of mcMain for main character. We will need this so we can reference the guy later. Now we’re ready to code this sucker. Make a new layer called “actions” and add the following code:
var mainSpeed:Number = 5;//how fast the main guy can move
onEnterFrame = function(){ //this function will run every frame (needed for moving the character
if(Key.isDown(37) || Key.isDown(65)){ //if the "A" key or Left Arrow Key is Down
mcMain._x -= mainSpeed;//then the move the guy left
}
if (Key.isDown(38) || Key.isDown(87)){//if the "W" key or Up Arrow Key is Down
mcMain._y -= mainSpeed; //then move the guy up
}
if(Key.isDown(39) || Key.isDown(68)){//if the "D" key or Right Arrow Key is Down
mcMain._x += mainSpeed; //then move the guy to the right
}
if(Key.isDown(40) || Key.isDown(83)){//if the "S" key or Down Arrow Key is Down
mcMain._y += mainSpeed; //then move the guy down
}
//keeping the main character within bounds
if(mcMain._x <= 0){
mcMain._x += mainSpeed;
}
if(mcMain._y <= 0){
mcMain._y += mainSpeed;
}
if(mcMain._x >= Stage.width - mcMain._width){
mcMain._x -= mainSpeed;
}
if(mcMain._y >= Stage.height - mcMain._height){
mcMain._y -= mainSpeed;
}
}
This is actually all we need for this chapter. Pretty easy, right? Next time, we’ll make him shoot!
Sorry for this stupid question but how to add a code
March 22nd, 2009 at 4:11 pm
erm….. how do u get as2???
April 12th, 2009 at 10:09 pm
umm i had a problem with the coding when it is inserted into flash its code is completely benin.
April 13th, 2009 at 11:16 am
@Dieter
First you make the thing you want to add a code to a symbol then press F9 so that the actions toolbar appears. ^_^
@perry
You dont have to get AS2, It is already built in from Flash 5 to Flash 8 i think.
May 27th, 2009 at 3:59 am
The Actionscript code is damaged, “guy” unresponsive to keystrokes
August 29th, 2009 at 4:28 pm
niggas niggas and niggas
your all niggas
September 9th, 2009 at 7:32 pm
press F9 to insert the codes
October 7th, 2009 at 9:14 am
Im having a few problems i am currently using flash mx and the code doesnt seem to work i even copyed an d pasted it in and deleted all outside text there are 2 syntax errors i fix them as directed but my charecter doesnt move please help!
November 27th, 2009 at 5:41 pm
My charecter us not moving and i have 2 syntax errors im using flash mx here is the action script onClipEvent(load){
var mainSpeed:Number = 5;
}
onEnterFrame = function(){
if(Key.isDown(37) || Key.isDown(65)){
mcMain._x -= mainSpeed;
}
if (Key.isDown(38) || Key.isDown(87)){
mcMain._y -= mainSpeed;
}
if(Key.isDown(39) || Key.isDown(68)){
mcMain._x += mainSpeed;
}
if(Key.isDown(40) || Key.isDown(83)){
mcMain._y += mainSpeed;
}
November 27th, 2009 at 6:35 pm
I have having some difficulty. “Statement block must be terminated by ‘}'”
I am using Adobe Flash CS4 and I am using Actionscript2, please help.
December 8th, 2009 at 10:55 am
Worked Great for me, keep up the good tutorials
February 25th, 2010 at 10:23 pm
What type of symbol do you convert the “character – triangle” into?
April 7th, 2010 at 11:59 pm
Hey… i got a problem with keeping a guy within bounds…
What should i do?????
April 20th, 2010 at 3:25 am
The code doesn’t work. Something is missing at the top.
April 22nd, 2010 at 9:46 am