Resetting the Game

The ground, water, scoreboard, and raft are the most important pieces in our game. So after each is added, let’s reset the game to a good starting point.

​ ​var​ ground = addGround();
​ ​var​ water = addWater();
​ ​var​ scoreboard = addScoreboard();
​ ​var​ raft = addRaft();
»reset();

Below addRaft, we add the reset() function.

​ ​function​ reset() {
​  camera.position.​set​(0,-1,2);
​  camera.lookAt(​new​ THREE.Vector3(0, 0, 0));
​  raft.add(camera);
​ 
​  scoreboard.message(​''​);
​  scoreboard.resetTimer();
​  scoreboard.score(0);
​ 
​  raft.__dirtyPosition = ​true​;
​  raft.position.​set​(0.75, 2, -9.6);
​  raft.setLinearVelocity(​new​ THREE.Vector3(0, ...

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.