// Cloned by Zak Smith on 30 Nov 2022 from World "Cubeland" by Senan Warnock
// Please leave this clone trail here.
const skycolor = 'lightblue';
const boxcolor = 'maroon';
// Background
const scene = new THREE.Scene();
const loader = new THREE.TextureLoader();
const bgTexture = loader.load('/uploads/zak86/istockphoto-1238079801-170667a.jpg');
scene.background = bgTexture;
const objectsize = 300; // size of object
const startRadius = 1000; // distance from centre we start the camera at
const maxRadius = startRadius * 10; // maximum distance from camera we render things
/*
-----------------------------------------------------------------------------------
Objects in the game
-----------------------------------------------------------------------------------
TODO:
loading screen for player to join?
change camera perspective on load.
add multiplayer functionality / load new player when connected.
function to create a new player?
make function to create bullets on the spot and set location to player location
make objects for background design and platform etc
collision detection
implement lives and score mechanics.
add sound design.
collision detection:
need to know coords of bullet and player, if at the same spot
record death
*/
var shape = new THREE.BoxGeometry ( objectsize, objectsize, objectsize );
var material = new THREE.MeshBasicMaterial ( { color: boxcolor.toLowerCase() } );
var theobject = new THREE.Mesh ( shape, material,);
var obj2 = new THREE.Mesh(shape, material);
obj2.position.x += 5000;
var bulletShape = new THREE.SphereGeometry(100, 100, 100);
var bullet = new THREE.Mesh(bulletShape, material);
bullet.position = theobject.position;
/*
---------------------------------------------------------
Mobility functions
---------------------------------------------------------
*/
function movePlayerUp() {
theobject.position.x += 100;
}
function movePlayerDown() {
theobject.position.x -= 100;
}
function movePlayerRight() {
theobject.position.z += 100;
}
function movePlayerLeft() {
theobject.position.z -= 100;
}
function moveBullet() {
// edit this to move continuously
// delete bullet on collision
bullet.position.x += 100;
}
function shootBullet() {
ABWorld.scene.add(bullet);
moveBullet();
}
function keyHandler(e)
// user control
// Note that this.takeAction(a) is constantly running at same time, redrawing the screen.
{
if (e.keyCode == 37) movePlayerLeft();
if (e.keyCode == 38) movePlayerUp();
if (e.keyCode == 39) movePlayerRight();
if (e.keyCode == 40) movePlayerDown();
if (e.keyCode == 32) shootBullet();
}
// Define what the World does at the start of a run:
AB.world.newRun = function()
{
// start a 3D scene:
ABWorld.init3d ( startRadius, maxRadius, bgTexture);
// add the object to the scene:
ABWorld.scene.add ( theobject );
ABWorld.scene.add(obj2);
};
AB.world.nextStep = function() {
document.onkeydown = keyHandler;
}