Code viewer for World: Zombie Death Baby (clone b...

// Cloned by Leigh Reilly on 1 Dec 2022 from World "Zombie Death Baby" by Starter user 
// Please leave this clone trail here.
 





 const TEXTURE_BABY 	= '/uploads/starter/baby.1.png' ;









	
	

//--- change ABWorld defaults: -------------------------------



var baby_texture;

 


	loader1.load ( TEXTURE_BABY, function ( thetexture )  
	{
		thetexture.minFilter  = THREE.LinearFilter;
		baby_texture = thetexture;
		if ( asynchFinished() )	initScene();		 
	});
	
	



function asynchFinished()		 // all file loads returned 
{
	if (  baby_texture  )  return true; 
	else return false;
}	
	
	
 

//--- grid system -------------------------------------------------------------------------------
// my numbering is 0 to gridsize-1

	


 

 
	

	 	 
   
	// set up first baby 

		BABIES[0] = newBaby();				   
	
	 
	
	// set up agent 
	// start in random location
	
	
  
 

// --- babies -----------------------------------
 
 



function moveBabies()
{ 
 for ( var c = 0; c < BABIES.length; c++ )
 { 
	var thebaby = BABIES[c][0];
	var ei 		= BABIES[c][1];
	var ej 		= BABIES[c][2];
	var i, j; 
	 
	// move towards agent 
	// put some randomness in so it won't get stuck with barriers 

	 if ( ei < ai )  i = AB.randomIntAtoB(ei, ei+1); 
	 if ( ei == ai ) i = ei; 
	 if ( ei > ai )  i = AB.randomIntAtoB(ei-1, ei); 

	 if ( ej < aj )  j = AB.randomIntAtoB(ej, ej+1); 
	 if ( ej == aj ) j = ej; 
	 if ( ej > aj )  j = AB.randomIntAtoB(ej-1, ej); 
	 
	 if ( ! occupied(i,j) )  	 	// if no obstacle then move, else just miss a turn for this baby 
	 {
		GRID[ei][ej] = GRID_BLANK;
		GRID[i][j]   = GRID_BABY;
		thebaby.position.copy ( translate(i,j) ); 		  	// translate my (i,j) grid coordinates to three.js (x,y,z) coordinates 
		BABIES[c] = new Array ( thebaby, i, j );			// update list of positions 
 	 }
 }
}





// --- agent -----------------------------------
// movement caused by user actions 



    

	

// --- score and status: -----------------------------------


function babyClose()			
// is a baby close to (within one square of) the agent
// note because of the wall, co-ordinates at +1 and -1 always exist 
{
 if ( GRID[ai-1][aj-1] == GRID_BABY ) return true;
 if ( GRID[ai-1][aj]   == GRID_BABY ) return true;
 if ( GRID[ai-1][aj+1] == GRID_BABY ) return true;

 if ( GRID[ai][aj-1]   == GRID_BABY ) return true;
 if ( GRID[ai][aj]     == GRID_BABY ) return true;
 if ( GRID[ai][aj+1]   == GRID_BABY ) return true;
 
 if ( GRID[ai+1][aj-1] == GRID_BABY ) return true;
 if ( GRID[ai+1][aj]   == GRID_BABY ) return true;
 if ( GRID[ai+1][aj+1] == GRID_BABY ) return true;
 
 return false;
}



 





// --- background music, play once ----------------------------------------

// note mute button only mutes the background music 
// would need to design my own mute button to mute the sound effects