// Cloned by Colin Ekedigwe on 30 Nov 2022 from World "Tower Builder" by Joseph Adedayo
// Please leave this clone trail here.
// online sockets
//test
// clean + submit
// Intro in game
AB.newSplash (" <H2> PRESS SPACE TO START GAME ! </H2>");
// 3D world
const SKYBOX_ARRAY = [
"/uploads/starter/dawnmountain-xpos.png",
"/uploads/starter/dawnmountain-xneg.png",
"/uploads/starter/dawnmountain-ypos.png",
"/uploads/starter/dawnmountain-yneg.png",
"/uploads/starter/dawnmountain-zpos.png",
"/uploads/starter/dawnmountain-zneg.png"
];
const boxcolor = 'red';
const objectsize = 5; // size of object
const startRadius = 400; // distance from centre we start the camera at
const maxRadius = startRadius * 10; // maximum distance from camera we render things
var timer = true;
// the object is a cube (each dimension equal):
// count score + increment box height + h2 opponent
var higher = 0;
var higher2 = 0;
// Define what the World does at the start of a run:
AB.world.newRun = function()
{
// start a 3D scene:
ABWorld.init3d ( startRadius, maxRadius);
// add the object to the scene:
AB.msg ( `<H2> PRESS SPACE TO START GAME ! </H2>` );
//function definition - end of game + message
function codingCourse() {
console.log("TIME IS UP !");
AB.msg ( `<H1> Your Score: ${higher} </H1> <H1> Opponent Score: ${higher2} </H1> <H1> TIME IS UP ! </H1>` );
timer = false;
}
// random sphere colours selected
let items = ["black", "yellow", "green", "red", "pink", "purple", "orange"];
// Checks if space is selecetd by user and if timer still runnning = count points
document.body.onkeyup = function(e) {
if ( ((e.key == " " || e.code == "Space" || e.keyCode == 32 ) && timer)
) {
// Gets a random sphere + increment by 5 to count score + sphere height
var boxcolor = items[Math.floor(Math.random()*items.length)];
higher = higher + 5;
var shape = new THREE.SphereGeometry ( objectsize, objectsize, objectsize );
var material = new THREE.MeshBasicMaterial ( { color: boxcolor.toLowerCase() } );
var theobject = new THREE.Mesh ( shape, material );
theobject.position.y = higher;
// Shows current score until time is up
AB.msg ( `<H1> Your Score: ${higher} </H1> <H1> Opponent Score: ${higher2} </H1>` );
if (higher >= 5)
{
// start timer and remove intro screen when user press space
setTimeout(codingCourse, 5000);
AB.removeSplash();
}
// Build tower
ABWorld.scene.add ( theobject );
}
}
ABWorld.scene.background = new THREE.CubeTextureLoader().load ( SKYBOX_ARRAY, function()
{
ABWorld.render();
AB.removeLoading();
AB.runReady = true;
});
};
//Hand up a short report (under 5 pages) explaining the project.
//Your report will highlight what is special about your project. Highlight functionality that is not obvious.
//Explain some of the code that is not obvious.
//Document can have screenshots, snippets of code.
//No need for document to include all your code because I can see your code.
//Submit it to me through this form. Password will be given out to the class. Use the form to tell me the URL. Only one submission needed per team.
//Use your proper name (no nicknames) on Ancient Brain, or your work may not be properly credited to you.
/*Our project is a game called 'Tower builder' it is a multiplayer game and the aim of it is to outbuild your opponent to see who can build the tallest tower within the invisible time given.
*/