const OBJPATH = "/uploads/chris/"; // path of OBJ and MTL
const OBJNAME = "CastleOBJ.obj";
const MTLNAME = "CastleOBJ.mtl";
const TEXTURE_AGENT = '/uploads/starter/pacman.jpg' ;
const TEXTURE_ENEMY = '/uploads/starter/ghost.3.png' ;
const MUSIC_BACK = '/uploads/starter/Defense.Line.mp3' ;
const SKYCOLOR = 0xa9a9a9 ; // a number, not a string
const LIGHTCOLOR = 0xa9a9a9 ;
const MODELLENGTH = 6159;
const MODELWIDTH = 3791;
const SCALE_CASTLE = 0.1; // scale it by this
const SCALEDMODELLENGTH = MODELLENGTH * SCALE_CASTLE;
const SCALEDMODELWIDTH = MODELWIDTH * SCALE_CASTLE;
const startRadiusConst = SCALEDMODELLENGTH * 0.5 ;
const maxRadiusConst = SCALEDMODELLENGTH * 10 ;
function loadResources() // asynchronous file loads - call initScene when finished
{
// load castle model OBJ and materials MTL (which reference JPEGs)
var m = new THREE.MTLLoader();
m.setResourcePath ( OBJPATH );
m.setPath ( OBJPATH );
m.load ( MTLNAME, function ( materials )
{
materials.preload();
var o = new THREE.OBJLoader();
o.setMaterials ( materials );
o.setPath ( OBJPATH );
o.load ( OBJNAME, function ( object )
{
thecastle = object;
if ( asynchFinished() ) initScene();
});
});
}
function asynchFinished()
{
if ( thecastle ) return true;
else return false;
}
function initScene()
{
ABWorld.scene.add ( thecastle );
ABWorld.render();
console.log ( "Resources loaded." );
resourcesLoaded = true;
if ( resourcesLoaded && splashClicked )
AB.runReady = true; // start run loop
}
// --- score: -----------------------------------
AB.world.newRun = function()
{
badsteps = 0;
goodsteps = 0;
ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR );
// newRun can run behind splash screen
// do not start run loop until resources ready AND splash screen is dismissed
AB.runReady = false;
loadResources(); // aynch file loads
// calls initScene() when it returns
var thelight = new THREE.DirectionalLight ( 0xffffff, 0.5 );
thelight.position.set ( startRadiusConst, startRadiusConst, startRadiusConst );
ABWorld.scene.add(thelight);
};