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

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

This tutorial reached the 5th part, and it’s time to add some new feature… something that wasn’t included in the original game.

Always remember to add something to a game you are about to clone, or people will get bored very soon of your game.

In this tutorial we will make the ship fire. “Oh, well”, you may say, “thanks for the millionth tutorial about firing spaceships”.

Wait… do you remember Metro Siberia Underground is a one button game? And that the one an only button you can press in this game is already used to give thrust?

That’s where my gameplay idea comes and shines… your ship is always firing… and it’s up to you firing only at the rocks, avoiding to blow off fuel tanks.

Read parts 1 to 4 before continuing, then take this actionscript:

And let’s see what do new lines make:

Line 21: Creating an empty movie clip that will represent the laser beam. It will be a simple line, but, hey, we have to use a bit of imagination…

Line 25: Attaching the `beam_spot` movieclip… it’s a red 2×2 pixels dot, and it’s the spot where you are going to fire

Lines 26-27: Attaching filters to laser beam and laser spot. I want them to have a red glow, so I am using the same filters used for the smoke

Line 80: Clearing `beam` movieclip

Line 81: Setting the drawing style for the laser beam. For more information about drawing styles refer to Create a flash draw game like Line Rider or others – part 1

Line 82: Moving the pen that will draw the laser beam in front of the spaceship using trigonometry. More information about Flash and trigonometry at Create a flash draw game like Line Rider or others – part 3

Line 83: Beginning of a loop to be executed 250 times… because my laser beam will be 250 pixels wide

Lines 84-85: Using trigonometry, I determine when will be the `x-th` pixel of the laser beam according to spaceship rotation

Lines 86-88: If the `x-th` pixel hits a rock or a fuel can, then exit the `for` loop

Line 90: Drawing the line until the pixel that gave a positive hit test with rock or fuel, or draw all 250 pixels if there wasn’t any collision. This method reminds the one to draw the cone of light in Create a survival horror game in Flash – part 1

Lines 91-92: Moving the beam red spot at the end of the laser beam.

Now I can know when the laser hits a rock or a fuel can, but I can’t determine which rock or which can did I hit…

I mean… I know that at coordinates (x,y) there is a rock or a fuel can, but now I have to see which one touches the (x,y) pixel according to its rotation, size and position.

… unless I perform an hit test between any rock (or fuel) and the beam spot… and that what I am doing at:

Line 42: Performing an hit test between the fuel can and the beam spot

Line 43: If true, then make the fuel can a bit more transparent

Lines 44-46: If the fuel can is completely transparent, then remove it from the game. BOOOM… you hitted a fuel can… you will run out of gasoline very soon if you don’t pay attention to fuel cans…
unless I perform a standard hit test between the red spot and rocks and cans.

Lines 65-70: Same thing with rocks, but they are a bit more difficult to destroy.

And here it is the result… only one button needed to play, ladies and gentlemen…

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

• David

brilliant! i already created a version of this, but using the space bar as the firing weapon!

i must say that you are a complete genius!
i can never be able to create anything like this!

keep up the good tutorials
after all, this is the only site that i have to go to now to learn about flash!

• Gabriel

very good…

• Graham Kaemmer

That’s sweet.

It would require another button, but you should show how to make a weapon that fires when you want it to.

• Graham Kaemmer

Alright, maybe I sounded really stupid, but actionscript isn’t really my strong point. I know more about web design.

What other of your tuts shows how to do the firing thing.

• Eblup

Hey can you help me make a platform version of super mario galaxy. I will send you the flash of what i have so far but i dont have youre email. PLEASE HELP ASAP!!!!!!!

• This is really a coincidence! I just finished implementing a similar feature using the spacebar to fire (just like David) and I see this tutorial!

Your code is so much cleaner than my “spaghetti code” ;)

• Suely (Snakesue)

Hi, I agree to David:keep up the good tutorials
after all, this is the better site that i have to go to now to learn about flash!
I DO NOT WANT TO BE A PROTOTYPE LIKE VISITOR COPY AND PASTE. I WANT TO BE A REGISTER MEMBER AND GAME MAKER.

• brart

weapon is kind of anoying because it also destroys the fuel things.

It’s possible to make a larger game from this. With save points and not a “see how far you come” game.

anyway nice glowfilters and good tut

• H35

Hi,
How can i make this, im totally new in action script world, but i really like to learn.
lot’s of thnx…..

• David

Can’t wait for the nect tut!!!

• I used your tutorial in a complete game… with original art, music, etc.. .check it out!

http://www.mrtiki.com/games/play/Wootropolis_Flyby.php

• I tried and failed to make the code.
Anyways gr8!

• Goinginsane

What exactly does “unexpected file format” mean
Flash mx says it everytime I try to downlod the file………

• Ahmed

that mean you must probably right ckick in the folder and extract all

• tom

great game! for what is the “tunnel” clip in the .fla file?