3D Game Programming

(C. Jardin) #1
(p1.x - p2.x)*(p1.x - p2.x) +
(p1.z - p2.z)*(p1.z - p2.z)
);

if(distance < 500) {
scorePoints();
}
}

functionscorePoints() {
if(scoreboard.getTimeRemaining() === 0)return;
scoreboard.addPoints(10);
Sounds.bubble.play();
animateFruit();
}

varfruit;
functionanimateFruit() {
if(fruit)return;

fruit =newTHREE.Mesh(
newTHREE.CylinderGeometry(25, 25, 5, 25),
newTHREE.MeshBasicMaterial({color: 0xFFD700})
);
fruit.rotation.x = Math.PI/2;

marker.add(fruit);

newTWEEN.
Tween({
height: 150,
spin: 0
}).
to({
height: 250,
spin: 4
}, 500).
onUpdate(function() {
fruit.position.y = this.height;
fruit.rotation.z = this.spin;
}).
onComplete(function() {
marker.remove(fruit);
fruit = undefined;
}).
start();
}

functionanimateJump() {
newTWEEN

report erratum • discuss

Code: Fruit Hunt • 239


Prepared exclusively for Michael Powell

Free download pdf