3D Game Programming

(C. Jardin) #1
boundary.position.y = -100;
boundary.rotation.x = -Math.PI/2;
trunk.add(boundary);

not_allowed.push(boundary);

trunk.position.set(x, -75, z);
scene.add(trunk);
// ... but add the following line to the end:
returntop;
}

functionshakeTree() {
tree_with_treasure = Math.floor(Math.random() * trees.length);

newTWEEN
.Tween({x: 0})
.to({x: 2*Math.PI}, 200)
.repeat(20)
.onUpdate(function() {
trees[tree_with_treasure].position.x = 75 * Math.sin(this.x);
})
.start();

setTimeout(shakeTree, 12*1000);
}
shakeTree();

// Now, animate what the camera sees on the screen:
varclock =newTHREE.Clock(true);
functionanimate() {
requestAnimationFrame(animate);
TWEEN.update();
walk();
turn();
acrobatics();
renderer.render(scene, camera);
}
animate();

functionwalk() {
if(!isWalking())return;
varposition = Math.sin(clock.getElapsedTime()*5) * 50;
right_hand.position.z = position;
left_hand.position.z = -position;
right_foot.position.z = -position;
left_foot.position.z = position;
}

functionturn() {

Appendix 1. Project Code • 236


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf