By Matt Fussell
I will be using Adobe Flash CS 4 for this tutorial but you can use any version of Adobe Flash that supports Action Script 2.0. (The video tutorial is further down this page.)
We will be creating a shooter style video game with a hero, three enemies, a score keeper, and a title screen. I will provide all of the code for you. You just need to follow directions and be creative.
Step 1-Getting Started
Open up a new Flash file and select Action Script 2.0. Make sure that your document is set on the default size which is 550 px by 400 px. Make sure that your frame rate (fps) is between 15 and 24. Open up your library (under "Window" at the top). Right click inside of your library and select "new symbol". Make sure that your new symbol is a "movie clip". Name the new symbol "SpaceShip". Be sure to name exactly the same way I have here. If you don't, your code will not work correctly. Draw your hero on the screen. This can be a space ship, or whatever you want. Be creative here. You can always go back and change it later though. Align your registration, the "+" in the middle, with were you will want your bullets to come out. If your hero has a gun, be sure to put the end of the gun in the crosshairs of the registration.
Step 2-Add Your Hero
Go back to the main timeline. Click and drag your space ship (hero) to the stage. Where you place your hero will determine where he will start in the game. Give it an instance name of "Ship". Again, we need to be very specific with this. It needs to be spelled exactly the same way that I have it here with the capital "S".
Step 3- Add Some Code
Copy and paste the following code into the actions panel of the first frame of your main timeline...
var timer = 8; for (i = 1; i < nrEnemies; i++) var i = 0; Ship._x += 10; _root.attachMovie("Bullet", "Bullet" + i, _root.getNextHighestDepth()); } |
Now test your game by hitting "control + enter". Your ship (hero) should move around the stage by pressing the arrow keys. It should stay on the stage and not disappear off of the edges.
Step 4- Create Some Bullets
Right click again in your library. Create a "new symbol" again and be sure that it is a movie clip. Name it "Bullet". Be sure to click the "export for action script" radio button. If you don't see it, click the advanced button to see the option. In the bullet symbol, draw your bullet. Be creative, it can be whatever. Be sure to line up your bullet with the right side of the registration mark.
Add the following code to the actions panel of the first frame of the "Bullet" symbol timeline...
this.onEnterFrame = function() this._x += 12; } |
Now test your movie. Your hero (Ship) should move around and shoot your bullets when you hit the space bar. Pretty cool, eh? Now let's add some bad guys.
Step 5- Add Some Bad Guys
Right click in your library and create a new symbol. Again, this should be a movie clip. Name your new symbol "Enemy". Now , draw what you want your enemy to look like. Once your enemy is drawn, go back to your main timeline and drag your enemy to the stage. Give you first enemy an instance name (under properties) of "Enemy0", your second enemy should have an instance name of "Enemy1" and the third should have the instance name on "Enemy2". Add the following code to each instance on the stage. To do this, right click on each enemy, select "actions" and copy and paste the following code...
onClipEvent(load) |
Now test the movie again. You can fly around and kill enemies, but your hero doesn't die when it gets hit.
Step 6- Code Your Hero (Ship)
Now your ready to add code to the instance of the ship on the stage of the main timeline.
Right click on the instance of the ship on the main timeline, select actions, and add the following code...
onClipEvent(load) reset() |
Now test your movie. Your enemies will die when you shoot them, and they'll kill you when they hit you. In part two, we'll animate our characters.
Here's a video tutorial of Part 1 of How to Create a Shooter Video Game in Adobe Flash.
Continue to Part Two of How to Create a Shooter Video Game
Here are some more art lessons that you may like...