# Create a Flash game like Metro Siberia Underground – Part 4

Multipart tutorial: available parts 1, 2, 3, 4 ,5

In this 4th part I’ll cover the code written in 3rd part. You should read parts 1 and 2 too, because I will comment only the new code.

For a better understanding, I’ll re-publish the code

Lines 5-7: New filters used for the rock object (the white square), the fuel object (the blue circle) and the score written at the upper left corner. Since there isn’t any tunnel in this example, you can remove line 4 if you want

Line 15: You can remove this line too if you want

Line 16: A variable that determines the fuel spawn frequency. Higher value means higher freq

Line 17: This is the amount of gasoline in your ship

Line 18: A variable that determines the rock spawn frequency… same thing as the fuel one seen at line 16

Line 21: Creating a new movieclip to host all fuel cans.

Line 22: New movieclip to host all rocks

Line 23: Attaching the score movieclip

Line 25: Applying the filter to score movieclip

Line 27: Showing distance traveled and remaining fuel

Line 28: As you can see in the `if` statement, now you must have gasoline in order to give thrust to your spaceship

Line 31: Obviously giving thrust will cost you some gasoline…

Line 33: Checking if it’s time to spawn a can of gasoline

Line 34: if true, then attach a fuel movieclip in the game at a random position

Line 35: Applying the filter to fuel movieclip

Line 36: Function to be executed by the fuel tank at every frame

Line 37: Moving the fuel tank according to ship’s speed. Notice that there is a 1.2 multiplier to make the fuel move faster than rocks

Lines 38-40: Calculating the distance from the head of the spaceship and the centre of the fuel tank using trigonometry. More information about trigonometry at Create a flash draw game like Line Rider or others – part 3. I want the gasoline to be collected only with the head of the ship, to give the game some kind of “realism”

Lines 41-44: If the distance is less than 10 (the radius of the gasoline tank), then add 100 units of gasoline and remove the fuel tank

Lines 45-47: If the fuel tank leaves the game to the left, then remove it

Line 50: Checking if it’s time to spawn an asteroid (a rock)

Line 51: if true, then attach a rock movieclip in the game at a random position wiht a random rotation

Line 52: Applying the filter to rock movieclip

Line 53: Function to be executed by the rock at every frame

Lines 54-57: Moving the rock according to ship’s speed. If the rock leaves the game to the left, then remove it

Lines 80-89: Checking if the ship hits the rocks or goes too high or too low… if true, resetting the game

That’s all…

Multipart tutorial: available parts 1, 2, 3, 4 ,5

• Wait, so this is all the code for for parts 1-3?
does this have any different code from part 3?

• Lol what was the point in part 3 then?

• Goinginsane

No offense Emanuele. Most of your tutorials have helped me immensly. But this one doesnt seem to meet the par. It is more suited for those of more expeience with flash. What about us? The noobs. What happened to the step by step instructions that helped me out so much on other tutorials. I am sorry if that seemed a bit harsh….I have been working on this game with no avail for several weaks.

• Gabriel

I agree with goinginsane (lol?)… IÂºll do a game with that…

• robby

emanuele will you make a tutorial on how to make a game like coolio niato’s Rhythm Fireworks one of these days? http://www.kongregate.com/games/Coolio_Niato/rhythm-fireworks-2

I really want to try and make a music game :)thanxs

• Colin

sorry if it seems like a bit of a stupid question Emanuele but what does the original movie clip for the distance and the gasoline consist of? would it just be a movie clip of the number 0 or a movie clip of numbers counting which then gets loaded throughout the game?

Thanks for any help.

• Colin

Ed and Xavi this is exactly the same code as part three just with comments underneath explaining what all the code does and how it works as explanations were not included in part three.

• Hey, Emanuele. Great tut. The only problem I am having is I can’t get the score to show up. I made the score movieclip, but I can’t get it to display.

Any help would be appreciated.

• Thanks a lot for this tutorial Emanuele. I love this site so much.

http://zawa.blogsome.com

• lemonsrock

gr8 tutorial,like most others. Except when i tried tower defence part 2 it didnt work plz help me out.
Thanks :)