// Cloned by MENGTE ZHU on 29 Nov 2022 from World "Pacman (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 = 90;
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()
// --- some useful random functions -------------------------------------------
function World() {
var LEVEL = [
'# # # # # # # # # # # # # # # # # # # #', // 1
'# . . . # . . . . . # . . . . . . . . #', // 2
'# . # # # . . # . # # . . . . # . . . #', // 3
'# # . . . . . . . . . . . . . # . . - #', // 4
'# . # # . . . # # # # . # # # # . # . #', // 5
'# . # # . . . . . . . . . . . . . # . #', // 6
'# . # # . . # . . . # . # # . # . . . #', // 7
'# . . # . . # . . . . . . # . . . # . #', // 8
'# . . . . . . . . . # . # # . . . . . #', // 9
'# . # # # . . . . . # . . # . . # . . #', // 10
'# . # . # . . . . # # . . . . . # # # #', // 11
'# . . . . . . . - . . . . . . . . . . #', // 12
'# # . # # # . . . . # # . # # . . . . #', // 13
'# . . . . . . . . # # . . . . . # . . #', // 14
'# . # . . . . . . . . . . . . . . . . #', // 15
'# # . . . . . . . # . . # . . # . . - #', // 16
'# . # . . # # # . # . . # . . # . . . #', // 17
'# # # . . . # . . # . . # . # # . . . #', // 18
'# / . . # . . . . . . . . . . . . . . #', // 19
'# # # # # # # # # # # # # # # # # # # #' // 20
];//地图初始化
var numPellets = 0; // counts the number of pellet objects on the screen, used for removal of pellets
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
function initGrid()
{
for (var i = 0; i < gridsize ; i++) {
GRID[i] = new Array(gridsize); // each element is an array
for (var j = 0; j < gridsize ; j++) {
GRID[i][j] = GRID_BLANK ;
}
}
}
function occupied ( i, j ){ // is this square occupie
if ( GRID[i][j] == GRID_WALL ) return true; // fixed objects, walls and stones
if ( GRID[i][j] == GRID_MAZE ) return true;
return false;
}
function occupiedByPellet(i, j) {
if (isSpecialPellet(i, j)) { // start of ghost killer mode if true
ghostKiller = true;
playIntermissionSound();
threeworld.scene.remove(GRID[i][j]);
GRID[i][j] = GRID_BLANK;
numPellets--;
window.setTimeout(slowAlert, 5000); // after 5 seconds pacman can no longer kill ghosts
}
}
}