Space Shooter - Lives and Score

Category : Flash Views : 18172
Version : 8 Rating
3.4/5 (30 votes)
Type : Text Source File: space-shooter-lives-score.zip
Result: See the result


<<< PreviousIndex SeriesNext >>>

Previous | 1 | 2 | Next

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:
Free Flash Tutorials, Free Flash Game, Space Shooter Game, Lives and Score

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.
Free Flash Tutorials, Free Flash Game, Space Shooter Game, Lives and Score

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

You will see something like this: Free Flash Tutorials, Free Flash Game, Space Shooter Game, Lives and Score

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(); } }
If the player's lives are over, we attach the "Game Over" Movie Clip and set its position.

this.swapDepths(10); this.removeMovieClip();
Here we are removing the Ship Movie Clip, but first we use the function swapDepths(depth) because we placed this Movie Clip 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.


del.icio.us digg it Reddit Stumble Upon Technorati

Previous | 1 | 2 | Next

<<< PreviousIndex SeriesNext >>>




Supporters

Reseller Web Hosting