How to Make a Vertical Shooter in AS2 – Part 1

Part 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.
My character
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!

Spread the Knowledge

  • Print
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Twitter
  • Google Bookmarks
  • Design Float
  • DZone
  • Yahoo! Buzz
  • PDF
  • Reddit
  • RSS
  • Technorati

Preview

Download Source
(Requires Flash 8 or above)

Subscribe!

Subscribe!
Enter your email address:  

Awesome Tutorials