
Level: Beginner / Intermediate
Flash Version: MX, MX 2004
Total Time: 1 & 1/2 Hours
Description: This is a "time trial" racing game tutorial. After completing it, you will be able to make your own racing game with custom tracks and cars, smooth collisions, lap records and more.
Next Below: In step 3 the game becomes more dynamic and interactive.
We add laps, best lap time and total time for 10 laps.
Download racing_part1_step3.fla
1. Up to now we have a 100% functional game engine but no game. We don't have a goal. So we'll have to add one and because this tutorial is about a time trial racing game we will add laps and timers.2. Open the racing_part1_step3.fla file provided with this tutorial.
3. You notice that I added two frames on every layer and I labeled them "ready set", "go" and "finish". In the first frame a movie clip will play saying "ready, set, go". When "go" is displayed _root will move to the frame labeled "go" where the car can move.
Why the car will not move in the first frame? Well, that's because the "stepper" movieClip only exists in the second frame, so that's where the "step" function will be executed.
On the second frame of the "actions" layer you will also find two new variables. Those variables will be used to store the exact time when the race started (initialTime|) and the exact time when the current lap started (lapTime).
When the game is over, after the player finishes ten laps, _root will move to the "finish" frame where an information movieClip will be displayed.
3. OK! What we need to do next is determine whether the player has finished a lap or not, so we will add two movieClip (the red line on the right side) and check if the car "touched" this movieClip, and if it did, than you know that a lap is finished... hmm... not really :)
First of all the car will "touch" this movieClip for more than one frame. Maybe for two, maybe for ten, maybe for one hundred frames, you cannot determine this number because it depends on the car's speed. And instead of increasing the number of laps with one, you will increase it with two, ten or one hundred laps, so the race will be ready quite fast.
The second problem, assuming that you solved the first one is that one player will go past the finish line (the red line on the right) and then return immediately to the same line and "touch" it again, increasing the number of laps even though the lap is not completed. This problem can be solved in a few ways but we will chose the solution that fixes both our problems: we will add a checkpoint (the red line to the left). This checkpoint will be placed somewhere around the middle of the race so that the player will lose more time returning to the finish line than he will lose by completing the lap. Of course if you want a more secured race you will add more than one checkpoint. You will be able to easily add more checkpoints after finishing this tutorial.
4. Open the actions window for the first frame of the "actions" layer. We have to new functions both related to timing the race - setTimes (calculates and sets the total race time) and setBestLap (calculates and sets the best lap time). We'll take them one at a time and see what they do.
5. And now one more time (I promise this is the last time) back to the "step" function and let's analyze the new lines.
6. That's it :) Now let's move on to the final graphic touches and see our completed game.
© Witchhut LLC All Rights Reserved