Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website.  Home Flash & Swish Flash Tutorials Space Shooter - Movie Clip and Movement

Space Shooter - Movie Clip and Movement

Browse Pages: << < 1  2  3  4  5  > >>

This is the forth part of the development of a Space Shooter game. In this tutorial we will add lives, scores and game over to our game.

Let's start with score.

Open the main timeline code and add this variable:

var score = 0;

Now open the Bullet's code and add this:

this.onEnterFrame = function() { this._x += 9; if (this._x > 550) { this.removeMovieClip(); } for (i = 0; i < _root.nrEnemies; i++) { if (this.hitTest(_root["Enemy" + i])) { _root["Enemy" + i].reset(); _root.score += 10; this.removeMovieClip(); } } }

This is the code we used before to know if a bullet hits an enemy, so we can put the score for killing an enemy there.

If you want the player to lose points for getting killed, just add _root.score -= PointsToLose to the code that checks if the player was killed.

The score is done; we just need to show the player his score.

To do that, select the Text Tool and draw it on the stage.

image 1

Write "Score:"

Now draw another Text box on the stage. Select this new Text box and change these properties:

image 2

Run the game and see how it works.

image 3

Now let's make our ship have lives. Add another variable in the main code:

var lives = 3;

And make these changes in the code that checks if the player crashed with an enemy:

if (this.hitTest(_root["Enemy" + i])) { _root.lives -= 1; reset() for(k = 0; k < _root.nrEnemies; k++) { _root["Enemy" + k].reset(); } }

Draw two text boxes again:

image 4

We can see the ship losing lives now, but nothing happens when it goes lower than zero.

To change that we tell the player when its game over. Create a new movie clip.

image 5

Write "Game Over" using the text tool and go back to the main timeline.

You will see something like this:

image 6

Add this to the Ship's code:

if (this.hitTest(_root["Enemy" + i])) { _root.lives -= 1; if (_root.lives <= 0) { _root.attachMovie("GameOver", "GameOver", 100) _root.GameOver._x = 275 _root.GameOver._y = 150 this.swapDepths(10); this.removeMovieClip(); } reset() for(k = 0; k < _root.nrEnemies; k++) { _root["Enemy" + k].reset(); } }

f the player's lives are over, we attach the "Game Over" MC and set its position.

this.swapDepths(10); this.removeMovieClip();

ere we are removing the Ship MC, but first we use the function swapDepths(depth) because we placed this MC manually on stage, so we need to set a new depth before deleting it.

Try dying now... =)

The last tutorial will be about sound effects and a pause key. Then our game is finished.



About the Author:

Webzo Studio is a web design company located in the United States. Webzo Studio was founded in August 2005. We are a small team of designers that just love our job. The love of doing what we do is what makes us not doing our job as a job, but as an enjoyment.
read more about this author

Author's URL: Webzo Studio
Browse Pages: << < 1  2  3  4  5  > >>
Final results of our readers
New!
Passed through all the steps? Share your result!
Your result will be premoderated.
Please make sure you choose the right image.
 
 



Captcha

*Required fileds
Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website. More Flash Tutorials: Featured Materials | Fresh Materials | More Flash Tutorials at FlashPerfection.com

Reader's comments
comments Joey December 07, 2011 says:
I DONT WORK. Could you please find your error in the coding?
Reply
comments MaryA2900 April 13, 2011 says:
Hi, I am confused on what replaces the word 'this' or if it stays the same.
Reply
comments Tammie October 14, 2010 says:
I can't get this page to work either. It is very confusing of where to paste the code.
Reply
comments Tommy March 24, 2010 says:
hey i got to the of this page and i cant go any further because i keep on recieving this error when i try to test my movie
it looks like this Operator '=' must be followed by an operand now this happened when i pasted the actionscript for the bullets
can you help me out?

Reply
Add comments to "Space Shooter - Movie Clip and Movement"

Captcha