logo

Home

tutorials

game tutorials part 1 -movement

game tutorials part 2 -pickups 

Beginners tutorial on creating a game in AS2 part 2

intro

This tutorial is a continuation of the previous tutorial so if you haven’t checked it out you might be a little lost on this one. If you have then lets continue.

What would a game be without its pickup? Kind of boring unless the game is well crafted. Pickups include health, magic, weapons, cash etc. Although generally pickups are a benefit to the user there are some pickups which can be disadvantage to the user .an example is the poisonous mushroom in Mario.

Ok then that is enough of the overview and let’s get down to the tutorial.

Step 1

In this tutorial we are going to be dealing with health so We will need to create a health bar so the player can see how the pickup reacts with the player.

Create a dynamic text box by clicking on the text tool. Then in the properties section on the bottom of the page .click on where it says static text. Then select dynamic text. Then create the text box on the stage. Then look in the properties section where it says variable. Give it the variable name “ health” without quotation marks.

Step 2

Go to main timeline and click on the frame and then add this code to it.

_root.health = 0;

 

//code explanation

This is basically setting the health variable to 0

Step 2 –create pickup

To create a pickup you will need to create a movie clip of it. So first draw what u want the pickup to look like .In this case we are going to make it a health pack. So make it look  like what u want it to do.then convert it into a movie clip.

Then add this code to it.

onClipEvent(enterFrame){

                if(this.hitTest(_root.player)){

                                                                 _root.health +=10;

                                                                  unloadMovie(this);

                                                                    }

} 

//code explanation

unloadMovie(this);

This is basically saying to remove the movie clip

_root.health+= 10;

This is increasing the health by 10.

if(this.hitTest(_root.player)){

this is saying that when the

This is saying that when the health pack touches the player.  Whatever code is in the parenthesis is executed.

 

Now if you run the movie you will notice that the health of the player goes up by 10 when he touches it.

This tutorial is the basis of most power ups, but say if you wanted to create a bad pick up. Which damages the player. The code just needs to be adjusted slightly to this.

 Example of another power up

Toxic/poison powerup

onClipEvent(enterFrame){

                if(this.hitTest(_root.player)){

                                                               _root.health -=10;

                                                                unloadMovie(this);

                                                                                }

}

As you can probably notice the only adjustment is that instead of + 10 it is -10

Next tutorial is going to cover animation or wall collisions. Whichever one is released first i guess.

Finished productThis is what you should end up with. 

 

 

 

 
gorillagames.co.uk copyright 2009