};
Levels.prototype.levelUp =function() {
if(!this.hasMoreLevels())return;
this.erase();
this.current_level++;
this.draw();
this.scoreboard.resetCountdown(50 - this.current_level * 5);
};
Levels.prototype.hasMoreLevels = function() {
varlast_level = this.levels.length-1;
returnthis.current_level < last_level;
};
functionbuildObstacle(shape_name, x, y) {
varshape;
if(shape_name =='platform') {
shape =newTHREE.CubeGeometry(height/2, height/10, 10);
}else{
shape =newTHREE.CylinderGeometry(50, 2, height);
}
varmaterial = Physijs.createMaterial(
newTHREE.MeshBasicMaterial({color:0x333333}), 0.2, 1.0
);
varobstacle =newPhysijs.ConvexMesh(shape, material, 0);
obstacle.position.set(x, y, 0);
returnobstacle;
}
varlevels =newLevels(scoreboard, scene);
levels.addLevel([]);
levels.addLevel([
buildObstacle('platform', 0, 0.5 * height/2 * Math.random())
]);
levels.addLevel([
buildObstacle('platform', 0, 0.5 * height/2 * Math.random()),
buildObstacle('platform', 0, -0.5 * height/2 * Math.random())
]);
levels.addLevel([
buildObstacle('platform', 0, 0.5 * height/2 * Math.random()),
buildObstacle('platform', 0, -0.5 * height/2 * Math.random()),
buildObstacle('stalactite', -0.33 * width, height/2),
buildObstacle('stalactite', 0.33 * width, height/2)
]);
avatar.addEventListener('collision',function(object) {
if(!object.isGoal)return;
if(!levels.hasMoreLevels())returngameOver();
Appendix 1. Project Code • 264
Prepared exclusively for Michael Powell report erratum • discuss