Flash dodge ball game part 7 getting points


In this tutorial we will add a point score, move a object to random places with time sequence, pretty cool and easy features for games.


1.
Now I thought the white background was a bit boring, so I imported a grass image, placed it in a new layer beneath the other layer.

Now you see that the walls we made in lesson 4 is shown, we want to hide them, so select all the wall movie clips, right click and choose distribute to layers, and place those layers beneath the grass layer.

Photoshop Tutorial thumb picture


2.
Now we want to make some object that our character can catch to get some points, I found an image of a strawberry, converted it to a movie clip, and call it point in the properties panel.

Photoshop Tutorial thumb picture


3.
Now the trick is to make the position of the strawberry change frequently, so in frame 1 go to the action script panel and type in the following code beneath the stop(); command from lesson 6.

var dorandom = function(){
_root.point._x = random(430)
_root.point._y = random(380)
}
var intervalID = setInterval(dorandom, 5000); //repeats every 5 sec.

Now what this does is to pick a random number between 0 and 430 for the x axis and a random number between 0 and 380 for the y axis and then place the strawberry at that position every 5000 mil seconds (5 sec).

Photoshop Tutorial thumb picture


4.
Now we want to make some point for this game, so double click the board movie clip from lesson 4 and make new dynamic text field as in the image below and type in 0 for the text, (as in 0 points), then name the text field "score_text".

Photoshop Tutorial thumb picture


5.
Go back to the main stage in the flash project.
Click the strawberry, then go to the action script panel and type in the following code.

onClipEvent (enterFrame) {
if (hitTest(_root.joe)==true)
{
_root.board.score_text.text = Number(_root.board.score_text.text) + Number(1)

_root.point._x = random(450)
_root.point._y = random(400)
}
}

The onClipEvent(enterFrame) we have been using before in a previous lesson, so you should know what its function is.

Now we tell flash that if our character joe hits the strawberry then it should add 1 to the score text field (_root.board.score_text.text) and remember when adding numbers together we need to put the fields in a Number(something) field.

At last we give the strawberry a new position so we don't repeat getting points at the same spot for 5 seconds.

Finally our game is done, I know this is a very big tutorial in 7 lessons, but I did it over 7 lessons just to keep it basic so even newbies should be able to follow it.

Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7
0tutor.com rss feed