3D Game Programming

(C. Jardin) #1
if (game_over) {
game_over = false;
animate();
gameStep();
}
}
</script>

A1.16Code: Tilt-a-Board


This is the final version of the game code from Chapter 16, Project: Tilt-a-
Board, on page 145.

<body></body>
<script src="http://gamingJS.com/Three.js"></script>
<script src="http://gamingJS.com/physi.js"></script>
<script src="http://gamingJS.com/ChromeFixes.js"></script>
<script>
// Physics settings
Physijs.scripts.ammo ='http://gamingJS.com/ammo.js';
Physijs.scripts.worker ='http://gamingJS.com/physijs_worker.js';

// This is where stuff in our game will happen:
varscene =newPhysijs.Scene({ fixedTimeStep: 2 / 60 });
scene.setGravity(newTHREE.Vector3( 0, -50, 0 ));

// This is what sees the stuff:
varaspect_ratio = window.innerWidth / window.innerHeight;
varcamera =newTHREE.PerspectiveCamera(75, aspect_ratio, 1, 10000);
camera.position.set(0, 100, 200);
camera.rotation.x = -Math.PI/8;
scene.add(camera);

// This will draw what the camera sees onto the screen:
varrenderer =newTHREE.WebGLRenderer();
renderer.shadowMapEnabled = true;
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// ******** START CODING ON THE NEXT LINE ********
addLights();

varball = addBall();
varboard = addBoard();

addControls();
addGoal();
addBackground();

animate();

report erratum • discuss

Code: Tilt-a-Board • 249


Prepared exclusively for Michael Powell

Free download pdf