// //---- global constants: -------------------------------------------------------
// const show3d = true; // Switch between 3d and 2d view (both using Three.js)
// // following textures from: Freepik.com
// // const TEXTURE_WALL = '/uploads/nithinsai/ancient_wall.jpg';
// const TEXTURE_WALL = '/uploads/nithinsai/minecraft_brick.jpg';
// const TEXTURE_MAZE = '/uploads/nithinsai/minecraft_brick.jpg';
// const TEXTURE_AGENT = '/uploads/nithinsai/crying.png';
// const TEXTURE_ENEMY = '/uploads/nithinsai/rick.jpg';
// const TEXTURE_FLOOR = '/uploads/nithinsai/grass_texture.jpg';
// const MUSIC_BACK = '/uploads/nithinsai/winning-elevation.mp3';
// const SOUND_ALARM = '/uploads/starter/air.horn.mp3';
// // credits:
// // https://pixabay.com/music/main-title-winning-elevation-111355/
// // http://soundbible.com/1542-Air-Horn.html
// var PATH_COLOR = 0x000000; // color of the path
// const gridsize = 40; // number of squares along side of world
// const HEURISTIC_APPROACH_TYPE = 2;
// /*
// HEURISTIC APPROACH TYPE
// 0 = high constant heuristic of 1000
// 1 = breadth first search heuristic of 0
// 2 = an A* heuristic of Manhattan distance
// 3 = an A* heuristic of Euclidean distance
// 4 = an A* heuristic of Chebyshev distance
// */
// const NOBOXES = Math.trunc((gridsize * gridsize) / 4); // 5
// // density of maze - number of internal boxes
// // (bug) use trunc or can get a non-integer
// const squaresize = 20; // size of square in pixels
// const MAXPOS = gridsize * squaresize; // length of one side in pixels
// const SKYCOLOR = 0x000000; // a number, not a string
// const DARK_GAME = false; // enable to test a dark game
// const startRadiusConst = MAXPOS * 0.8; // distance from centre to start the camera at
// const maxRadiusConst = MAXPOS * 10; // maximum distance from camera we will render things
// //--- change ABWorld defaults: -------------------------------
// ABHandler.MAXCAMERAPOS = maxRadiusConst;
// ABHandler.GROUNDZERO = true; // "ground" exists at altitude zero
// //--- skybox: -------------------------------
// // Image from: https://www.cleanpng.com/png-skybox-multiplication-sign-android-multiplication-1687670
// const SKYBOX_ARRAY = [
// "/uploads/nithinsai/neg_x_dark.png",
// "/uploads/nithinsai/pos_x_dark.png",
// "/uploads/nithinsai/pos_y_darkk.png",
// "/uploads/nithinsai/neg_y_dark.png",
// "/uploads/nithinsai/pos_z_dark.png",
// "/uploads/nithinsai/neg_z_dark.png"
// ];
// // ===================================================================================================================
// // === End of tweaker's box ==========================================================================================
// // ===================================================================================================================
// // You will need to be some sort of JavaScript programmer to change things below the tweaker's box.
// //--- Mind can pick one of these actions -----------------
// const ACTION_LEFT = 0;
// const ACTION_RIGHT = 1;
// const ACTION_UP = 2;
// const ACTION_DOWN = 3;
// const ACTION_STAYSTILL = 4;
// // in initial view, (smaller-larger) on i axis is aligned with (left-right)
// // in initial view, (smaller-larger) on j axis is aligned with (away from you - towards you)
// // contents of a grid square
// const GRID_BLANK = 0;
// const GRID_WALL = 1;
// const GRID_MAZE = 2;
// var totalStatesExplored = 0; // global variable to keep track of the total states explored
// var totalPossibleSteps = 0; // global variable to keep track of the total possible steps
// var BOXHEIGHT; // 3d or 2d box height
// var GRID = new Array(gridsize); // can query GRID about whether squares are occupied, will in fact be initialised as a 2D array
// var theagent, theenemy;
// var wall_texture, agent_texture, enemy_texture, maze_texture, floor_texture;
// // enemy and agent position on squares
// var ei, ej, ai, aj;
// var badsteps;
// var goodsteps;
// function loadResources() // asynchronous file loads - call initScene() when all finished
// {
// var loader1 = new THREE.TextureLoader();
// var loader2 = new THREE.TextureLoader();
// var loader3 = new THREE.TextureLoader();
// var loader4 = new THREE.TextureLoader();
// var loader5 = new THREE.TextureLoader();
// loader1.load(TEXTURE_WALL, function (thetexture) {
// thetexture.minFilter = THREE.LinearFilter;
// wall_texture = thetexture;
// if (asynchFinished()) initScene(); // if all file loads have returned
// });
// loader2.load(TEXTURE_AGENT, function (thetexture) {
// thetexture.minFilter = THREE.LinearFilter;
// agent_texture = thetexture;
// if (asynchFinished()) initScene();
// });
// loader3.load(TEXTURE_ENEMY, function (thetexture) {
// thetexture.minFilter = THREE.LinearFilter;
// enemy_texture = thetexture;
// if (asynchFinished()) initScene();
// });
// loader4.load(TEXTURE_MAZE, function (thetexture) {
// thetexture.minFilter = THREE.LinearFilter;
// maze_texture = thetexture;
// if (asynchFinished()) initScene();
// });
// // code by Nithin Sai Kirumani Jagadish - added floor texture
// loader5.load(TEXTURE_FLOOR, function (thetexture) {
// thetexture.minFilter = THREE.LinearFilter;
// floor_texture = thetexture;
// if (asynchFinished()) initScene();
// });
// // end code by Nithin Sai Kirumani Jagadish - added floor texture
// }
// function asynchFinished() // all file loads returned
// {
// if (wall_texture && agent_texture && enemy_texture && maze_texture && floor_texture) return true;
// else return false;
// }
// function initScene()
// {
// var i, j, shape, thecube;
// var edgesMaterial = new THREE.LineBasicMaterial({ color: 0x000000 });
// // set up GRID as 2D array
// for (i = 0; i < gridsize; i++)
// GRID[i] = new Array(gridsize);
// // set up walls
// // code edit by Nithin Sai - small edits to add an alternate version of game
// var wallMaterial;
// if (DARK_GAME) {
// wallMaterial = new THREE.MeshBasicMaterial({ color: 0x000000 });
// }
// else {
// wallMaterial = new THREE.MeshBasicMaterial({ map: wall_texture });
// wallMaterial.color.set(0x765656);
// }
// for (i = 0; i < gridsize; i++) {
// for (j = 0; j < gridsize; j++) {
// if ((i === 0) || (i == gridsize - 1) || (j === 0) || (j == gridsize - 1)) {
// GRID[i][j] = GRID_WALL;
// shape = new THREE.BoxGeometry(squaresize, BOXHEIGHT, squaresize);
// thecube = new THREE.Mesh(shape);
// let edgesMaterial = new THREE.LineBasicMaterial({ color: 0xffffff });
// var edges = new THREE.EdgesGeometry(shape);
// if (DARK_GAME) {
// var edgesMesh = new THREE.LineSegments(edges, edgesMaterial);
// thecube.add(edgesMesh);
// }
// thecube.material = wallMaterial;
// // thecube.position.copy(translate(i, j)); // translate my (i,j) grid coordinates to three.js (x,y,z) coordinates
// ABWorld.scene.add(thecube);
// }
// else {
// GRID[i][j] = GRID_BLANK;
// }
// }
// }
// // set up maze
// var mazeMaterial;
// if (DARK_GAME) {
// mazeMaterial = new THREE.MeshBasicMaterial({ color: 0x555555 });
// }
// else {
// mazeMaterial = new THREE.MeshBasicMaterial({ map: maze_texture });
// mazeMaterial.color.set(0xaaaaaa);
// }
// for (var c = 1; c <= NOBOXES; c++) {
// i = AB.randomIntAtoB(1, gridsize - 2); // inner squares are 1 to gridsize-2
// j = AB.randomIntAtoB(1, gridsize - 2);
// GRID[i][j] = GRID_MAZE;
// shape = new THREE.BoxGeometry(squaresize, BOXHEIGHT, squaresize);
// thecube = new THREE.Mesh(shape);
// let edges = new THREE.EdgesGeometry(shape);
// if (DARK_GAME) {
// let edgesMesh = new THREE.LineSegments(edges, edgesMaterial);
// thecube.add(edgesMesh);
// }
// thecube.material = mazeMaterial;
// // translate my (i,j) grid coordinates to three.js (x,y,z) coordinates
// ABWorld.scene.add(thecube);
// }
// // total number of places on the GRID that are vacant
// totalPossibleSteps = GRID.flat().filter(cell => cell === GRID_BLANK).length;
// // set up enemy
// // start in random location
// // do {
// // i = AB.randomIntAtoB(1, gridsize - 2);
// // j = AB.randomIntAtoB(1, gridsize - 2);
// // }
// // while (occupied(i, j)); // search for empty square
// ei = i;
// ej = j;
// shape = new THREE.BoxGeometry(squaresize, BOXHEIGHT, squaresize);
// theenemy = new THREE.Mesh(shape);
// if (DARK_GAME) {
// theenemy.material = new THREE.MeshBasicMaterial({ color: 0xffffff });
// let edgesMesh = new THREE.LineSegments(edges, edgesMaterial);
// theenemy.add(edgesMesh);
// } else {
// theenemy.material = new THREE.MeshBasicMaterial({ map: enemy_texture });
// }
// ABWorld.scene.add(theenemy);
// // drawEnemy();
// // set up agent
// // start in random location
// // do {
// // i = AB.randomIntAtoB(1, gridsize - 2);
// // j = AB.randomIntAtoB(1, gridsize - 2);
// // }
// // while (occupied(i, j)); // search for empty square
// ai = i;
// aj = j;
// shape = new THREE.BoxGeometry(squaresize, BOXHEIGHT, squaresize);
// shapeCircle = new THREE.SphereGeometry(squaresize / 2, squaresize / 2, squaresize / 2);
// theagent = new THREE.Mesh(shape);
// if(DARK_GAME) {
// theagent.material = new THREE.MeshBasicMaterial({ color: 0x000000 });
// } else {
// theagent.material = new THREE.MeshBasicMaterial({ map: agent_texture });
// }
// ABWorld.scene.add(theagent);
// // drawAgent();
// // end code edit by Nithin Sai - small edits to add an alternate version of game
// // set up the floor
// // code by Nithin Sai Kirumani Jagadish - added floor to the game
// var floorGrid = new Array(gridsize);
// for (i = 0; i < gridsize; i++) {
// floorGrid[i] = new Array(gridsize);
// }
// var floorMaterial;
// if (DARK_GAME) {
// floorMaterial = new THREE.MeshBasicMaterial({ color: 0xbbbbbb });
// }
// else {
// floorMaterial = new THREE.MeshBasicMaterial({ map: floor_texture });
// floorMaterial.color.set(0x77aa88);
// }
// for (i = 0; i < gridsize; i++) {
// for (j = 0; j < gridsize; j++) {
// shape = new THREE.BoxGeometry(squaresize, BOXHEIGHT, squaresize);
// thecube = new THREE.Mesh(shape);
// let edges = new THREE.EdgesGeometry(shape);
// if (DARK_GAME) {
// let edgesMesh = new THREE.LineSegments(edges, edgesMaterial);
// thecube.add(edgesMesh);
// }
// thecube.material = floorMaterial;
// // thecube.position.copy(translate(i, j));
// thecube.position.y = -BOXHEIGHT;
// ABWorld.scene.add(thecube);
// floorGrid[i][j] = thecube;
// }
// }
// // end code by Nithin Sai Kirumani Jagadish - added floor to the game
// // finally skybox
// // setting up skybox is simple
// // just pass it array of 6 URLs and it does the asych load
// ABWorld.scene.background = new THREE.CubeTextureLoader().load(SKYBOX_ARRAY, function () {
// ABWorld.render();
// var scaleFactor = 0.5;
// ABWorld.camera.scale.set(scaleFactor, scaleFactor, scaleFactor);
// AB.removeLoading();
// AB.runReady = true; // start the run loop
// });
// }
// AB.world.newRun = function () {
// AB.loadingScreen();
// AB.runReady = false;
// badsteps = 0;
// goodsteps = 0;
// if (show3d) {
// BOXHEIGHT = squaresize;
// ABWorld.init3d(startRadiusConst, maxRadiusConst, SKYCOLOR);
// }
// else {
// BOXHEIGHT = 1;
// ABWorld.init2d(startRadiusConst, maxRadiusConst, SKYCOLOR);
// }
// loadResources();
// };
// Create a scene
var scene = new THREE.Scene();
// Create a camera
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
// Create a renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Create a cube and add it to the scene
var cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
var cubeMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
scene.add(cube);
// Load the skybox texture
var skyboxTexture = new THREE.CubeTextureLoader().load(
"/uploads/nithinsai/neg_x_dark.png",
"/uploads/nithinsai/pos_x_dark.png",
"/uploads/nithinsai/pos_y_darkk.png",
"/uploads/nithinsai/neg_y_dark.png",
"/uploads/nithinsai/pos_z_dark.png",
"/uploads/nithinsai/neg_z_dark.png"
);
scene.background = skyboxTexture;
// Set up a resize listener
window.addEventListener('resize', function () {
var newWidth = window.innerWidth;
var newHeight = window.innerHeight;
camera.aspect = newWidth / newHeight;
camera.updateProjectionMatrix();
renderer.setSize(newWidth, newHeight);
});
// Render the scene
function animate() {
requestAnimationFrame(animate);
// Add animation or other updates here
renderer.render(scene, camera);
}
animate();