Flash dodge ball game part 6 killing counter


In this tutorial we will add a counter to our flash game, to tell us how many lifes we have left and control when then game is over (when we have 0 lifes left).


1.
Now first of all we will make a score board or just some place to contain the counter.
So I made a square with soft edges and a gradient color as shown in the image below.
Then on top of it put in some text fields on static containing "life:" and one dynamic containing the number 3 (as in 3 lifes).
Select the dynamic text box and in the properties panel name it life_text

Photoshop Tutorial thumb picture


2.
Drag and select the two text fields and the graphic we just made, right click and convert it to a movie clip.
In the properties panel name the new movie clip board

3.
Now in the timeline right click at frame 2 and create a empty keyframe, (here you can make a button that goes back to frame 1 using gotoAndPlay(1);

In frame 1 go to the actionscript panel and type in stop(); do the same at frame 2.

4.
Now we are ready to code.

select the ball we made in the last lesson, and go to the actionscript panel, again we will use the hit test to determinate if the ball has hit our character, so type in the following.

if (hitTest(_root.joe)==true)
{
if (_root.board.life_text.text < 1) {
_root.gotoAndStop(2);
}
else {
_root.board.life_text.text -= 1
}

what this does is if the ball hits joe then it will check if the life counter is more then 0 life left, if that is true then subtract 1 life, if life counter is less then 1 then the flash movie will jump to frame 2, where I placed a button called restart.

Photoshop Tutorial thumb picture


And we are done for this time, you can download the source code here.

Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7

0tutor.com rss feed