Bonus: Keeping Score
This is already a pretty impressive game. It looks cool and it’s challenging. So this is a fine stopping point. But if you’d like to add a bit more, here are some bonus features to add.
Time-Based Scoring
Let’s calculate the score like this: you get more points the quicker you finish, and you get bonus points if you can finish really quick. We can do this by adding another check in checkForGameOver().
| function checkForGameOver() { |
| if (raft.position.z > 9.8) { |
| gameOver = true; |
| scoreboard.stopTimer(); |
| scoreboard.message("You made it!"); |
| } |
| |
| if (scoreboard.getTime() > 60) { |
| gameOver = true; |
| scoreboard.stopTimer(); |
| scoreboard.message("Time's up. Too slow :("); |
| } |
| |
» | if (gameOver) { |
» | var |
Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.