Code viewer for World: Maze Battlegrounds [Pick M...

// Cloned by MENGTE ZHU on 29 Nov 2022 from World "Maze Battlegrounds [Pick Mind For Gamemode] (clone by junhao zhao)" by junhao zhao 
// Please leave this clone trail here.
 

////////////////////////////////////////////////////////////////////////////////////////////////

AB.drawRunControls = false;
threeworld.drawCameraControls = false;

// World must define these:
 
const	 	CLOCKTICK 	= 100;			// speed of run - move things every n milliseconds, lower faster
const		MAXSTEPS 	= 10000;			// length of a run before final score
 
const  SCREENSHOT_STEP = 50;    


// -- constants for normal or special pellets to be added to screen
const NORMAL = true;
const SPECIAL = false;



//---- global constants: -------------------------------------------------------

const gridsize = 20;						// number of squares along side of world	   

// density of maze - number of internal boxes
// (bug) use trunc or can get a non-integer 

const squaresize = 100;					// size of square in pixels
const MAXPOS = gridsize * squaresize;		// length of one side in pixels 

const sphereRadius = 50;
const sphereHeight = 10;
const sphereWidth = 10;

const pelletRadius = 10;

const SKYCOLOR 	= 0x000000;				// a number, not a string 
const BLANKCOLOR 	= SKYCOLOR ;			// make objects this color until texture arrives (from asynchronous file read)




const show3d = true;						// Switch between 3d and 2d view (both using Three.js) 
 
 // ********** originally = 0.8 ***************//
const startRadiusConst	 	= MAXPOS * 0.8 ;		// distance from centre to start the camera at


// it's an illusion, if you zoom out you see theat the skybox is just a container and outside of that is nothing
const skyboxConst			= MAXPOS * 3 ;		// where to put skybox 
const maxRadiusConst 		= MAXPOS * 8 ;		// maximum distance from camera we will render things  





//--- 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;

 // keyword self used for a private function to call a public function self.functionName()
 

     var game = document.getElementById("game");
     var len = game.children.length; 
     for (var i = 0; i < len; i++) 
     { game.removeChild(game.children[0]); //从第一个开始,每次都删除一个子节点 } 
     }
    /*创建新的子节点*/
    winDom = document.createElement("div");//创建一个新的div块 
    winDom.setAttribute("id", "windows"); //设置background属性 
    winDom.setAttribute("class", "background");
    game.appendChild(winDom);//把background节点插入到game里面去
     //定义地图
// 列:13 行:10
    var winDom;    
    var world = new Array();  
    var map = [    
    [5, 3, 3, 1, 1, 5, 5, 5, 1, 1, 3, 3, 5],    
    [5, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 5],    
    [5, 1, 4, 1, 3, 1, 1, 1, 1, 2, 1, 1, 5],    
    [5, 1, 3, 1, 1, 1, 3, 1, 1, 1, 3, 1, 5],    
    [3, 4, 1, 2, 4, 1, 1, 1, 3, 1, 1, 4, 2],    
    [1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 1, 3],    
    [1, 3, 4, 1, 3, 1, 1, 1, 1, 1, 3, 1, 3],    
    [1, 1, 2, 1, 5, 1, 1, 1, 5, 2, 2, 1, 1],    
    [1, 3, 3, 1, 5, 2, 2, 2, 5, 1, 2, 4, 1],    
    [1, 3, 3, 5, 5, 2, 0, 2, 5, 5, 5, 1, 1]    
    ];      
    // 渲染地图    
    for(var i=0;i<map.length; i++){    
    for(var j=0; j< map[i].length; j++){    
    var cell = map[i][j]; // 1    
    var x = j * 60;    
    var y = i * 60;    
    var obj;    
    if(cell == 1){// 土墙    
    var obj = new Wall(winDom);    
    obj.setLocation(x,y);    
    }else if(cell == 2){// 钢砖    
    var obj = new SteelWall(winDom);    
    obj.setLocation(x, y);    
    }else if(cell == 3){ //草地    
    var obj = new Grass(winDom);    
    obj.setLocation(x, y);    
    }else if(cell == 4){ //水面   
    var obj = new Water(winDom);    
    obj.setLocation(x,y);    
    }else if(cell == 0){ // Boss老巢   
    var obj = new Boss(winDom);    
    obj.setLocation(x,y);    
    }    
    world.push(obj);    
    }    
    }