this.BD = this.BD || {}; var Const = {}; var Global = {}; Global.hiscore = 0; Global.level = 1; //------------------ for (var i in CONFIG.UI){ Global[i] = CONFIG.UI[i].max; } //--------------------- Global.GAME_ID = parseInt(getQueryVariable('id')) || 24; Global.STORAGE_ID = "LEVELUP_ENHANCE_7_"+Global.GAME_ID; var TESTING; // = parseInt(getQueryVariable('t')) ; var BASE_WIDTH = 1024; //1024; var BASE_HEIGHT = 665; ///665; BD.SCALE = 1; var root = this; var curbg, stage, renderer, page; //--------------------------- // var joystick = null, // joystick2 = null; // // var showJoystick = function () { // return CONFIG.JOYSTICK.show && (VirtualJoystick.touchScreenAvailable()) ? true : false; // || (TESTING // } // // function createJoystick(x1, y1, x2, y2){ // joystick = new VirtualJoystick({ // container : document.getElementById('left-joy'), // mouseSupport : true, // stationaryBase : true, // baseX : x1, // baseY : y1, // limitStickTravel: true, // stickRadius : 40 // }); // joystick2 = new VirtualJoystick({ // container : document.getElementById('right-joy'), // mouseSupport : true, // stationaryBase : true, // baseX : x2, // baseY : y2, // limitStickTravel: true, // stickRadius : 1 // }); // } //--------------------------- function doResize() { var FULL = 1; getScreenSize(); var x, y, w, h; if ( (BD.screenWidth/BD.screenHeight) < (BASE_WIDTH/BASE_HEIGHT) ){ w = BD.screenWidth; if (!FULL){ if (w>800) w = 800; } h = w * (BASE_HEIGHT/BASE_WIDTH); } else { h = BD.screenHeight; if (!FULL) { if (h>600) h = 600; } w = h * (BASE_WIDTH/BASE_HEIGHT) } // x = (BD.screenWidth-w)/2; // y = (BD.screenHeight-h)/2; // renderer.view.style.backgroundColour = '#ff0000'; if (FULL){ renderer.view.style.position = 'absolute'; renderer.view.style.left = '0'; renderer.view.style.top = '0'; } renderer.view.style.width = (w*1)+'px'; renderer.view.style.height = (h*1)+'px'; BD.canvasWidth = w; BD.canvasHeight = h; //COCOON - PIXI //renderer.view.style.cssText = "idtkscale:ScaleAspectFill;" updateBackgroundSize(curbg); // reposition joystick // if (showJoystick()){ // var y1 = (BD.screenHeight-90); // var yjo1 = (BD.screenHeight-90); // var x1 = (70); // var y2 = (BD.screenHeight-90); // var x2 = (BD.screenWidth-90); // try { // if (joystick){ // joystick.destroy(); // joystick = null; // } // if (joystick2){ // joystick2.destroy(); // joystick2= null; // } // createJoystick(x1, y1, x2, y2); // } catch(e){} // } }; function updateBackgroundSize(_bg, istrans) { if (!istrans){ curbg = _bg; } var w, h; if ( (BD.screenWidth/BD.screenHeight) < (BASE_WIDTH/BASE_HEIGHT) ){ w = BD.screenWidth; h = BD.screenWidth * (BASE_HEIGHT/BASE_WIDTH); } else { w = BD.screenHeight * (BASE_WIDTH/BASE_HEIGHT); h = BD.screenHeight; } if (_bg){ _bg.width = BD.screenWidth/(w/BASE_WIDTH); _bg.x = -((BD.screenWidth-w)/2)/(w/BASE_WIDTH); _bg.height = BD.screenHeight/(h/BASE_HEIGHT); _bg.y = -((BD.screenHeight-h)/2)/(h/BASE_HEIGHT); } } function getScreenSize() { BD.screenWidth = Math.floor(window.innerWidth); BD.screenHeight = Math.floor(window.innerHeight); // BD.screenWidth = window.innerWidth || document.body.clientWidth // BD.screenHeight = window.innerHeight || document.body.clientHeight; //BD.screenWidth = document.documentElement.clientWidth; //BD.screenHeight = document.documentElement.clientHeight; // alert(document.documentElement.clientWidth); //BD.screenWidth = document.documentElement.clientWidth; // BD.screenHeight = window.innerHeight; // BD.screenWidth = (BASE_WIDTH/BASE_HEIGHT)*BD.screenHeight; // // alert(BD.screenHeight); // alert(BD.screenWidth); // alert(document.body.clientWidth); }; //------------------------------ function tick(){ //requestAnimationFrame(tick); //setTimeout(tick, 10); renderer.render(stage); if (Global.gameactive && BD.physicsStep){ BD.physicsStep(); } EventDispatcher.trigger('update'); } // PAGES ------------------------------ function createSplash(){ Global.level = 1; removeAll(); page = new BD.SplashPage(); page.execute({callback:splashComplete}); } function splashComplete(){ CONFIG.INSTRUCTIONS.active ? createInstructions() : instructionsComplete(); } function createInstructions(){ removeAll(); page = new BD.InstructionsPage() page.execute({callback:instructionsComplete, config:CONFIG.INSTRUCTIONS}); } function instructionsComplete(){ CONFIG.INTRO.active ? createIntro() : introComplete(); } function createIntro(){ // create sound if (!sound){ sound = document.createElement('audio'); sound.loop = true; sound.src = 'audio/19461968_8-bit-loop_by_bright_light_preview.mp3'; sound.type = 'audio/mpeg'; sound.play(); } removeAll(); new BD.InstructionsPage().execute({callback:introComplete, config:CONFIG.INTRO}); } function introComplete(){ CONFIG.SHOW_LEVEL_SELECT ? createSelectLevel() : createGame(); } function createSelectLevel(){ removeAll(); page = new BD.SelectLevelPage(); page.execute({callback:createGame}); } function showDataCapturePage(){ removeAll(); page = new BD.DataCapturePage(); page.execute({callback:showHiScorePage}); } function showHiScorePage(){ removeAll(); page = new BD.HiscorePage(); page.execute({callback:createSplash}); } var game = null; var physics; var sound; function createGame(){ removeAll(); // var // logotexture = PIXI.Texture.fromImage('img/gameskin// logo_bg.jpg'); // PIXI.// logo = new PIXI.Sprite(// logotexture); // stage.addChild(PIXI.// logo); // // PIXI.// logo = new PIXI.Sprite(root['trundle_wheel']); // stage.addChild(PIXI.// logo); // BD.distance = 0; BD.distanceY = 0; game = new BD.Game(); game.execute({ gameovercallback:onGameOver, quitcallback:onQuitGame, gamecompletecallback:onGameComplete }); } function onGameOver(){ game.destroy(); game = null; Global.gameactive = false; removeAll(); new BD.GameOverPanel({callback:onGameOverDone}); } function onQuitGame(){ game.destroy(); game = null; Global.gameactive = false; removeAll(); createSplash(); //createSelectLevel(); } function onGameOverDone(){ // game.destroy(); // game = null; // Global.gameactive = false; // removeAll(); // CONFIG = {}; // gameid = 10; //setConfig(); //initLoader(); removeAll(); createSplash(); } function onGameComplete(){ game.destroy(); game = null; Global.gameactive = false; removeAll(); new BD.GameCompletePanel({callback:onGameOverDone}); } //------------------------------ var fontsReady = 0; // $(document).ready(onReady); // setTimeout(function(){ // setConfig(); // init_main2(); // }, 500) /* function checkFont1() { fontSpy(CONFIG.FONT, { success: checkFont2, failure: checkFont2 }); } function checkFont2() { fontSpy('SamsungSharpSansMedium', { success: checkFont3, failure: checkFont3 }); } */ // function onReady(){ // setConfig(); // checkFont(); // } // function checkFont() { // fontSpy(CONFIG.FONT, { // success: function() { // fontsReady = 1; // init_main(); // }, // failure: function() { // fontsReady = 1; // init_main(); // } // }); // } function init_main(){ // console.// log('init_main') TESTING = parseInt(getQueryVariable('t')) ; // if (fontsReady == 1){ // init_main2(); // fontsReady = 2; setConfig(); setBaseSize(); init_main2(); } //--------------------------- var graphics; var fassets; function iterateAssetData(obj) { for (var property in obj) { if (typeof obj[property] == "object") { if (obj[property]){ if (obj[property].length>0){ for (var i in obj[property]){ //if (typeof obj[property][i] == "string"){ var o = {asset:obj[property][i]}; //console.// log('>>> property ', property) //console.// log('>>> o ', o) iterateAssetData(o) //} } } else { //console.// log('>> ', obj[property]) iterateAssetData(obj[property]); } } } else { if (property == 'asset' || property == 'grid_square' || property == 'buttonasset' || property == 'logo' || property == 'icon' || property == 'sprite' || property == 'assetsLevels' || property == 'bulletasset' || property == 'splashasset' || property == 'mobile_button_left' || property == 'mobile_button_rotate_left' || property == 'mobile_button_right' || property == 'mobile_button_rotate_right' || property == 'mobile_button_up' || property == 'mobile_button_down' || property == 'mobile_button_forwards' || property == 'mobile_button_fire' ){ if (assets[obj[property]]){ fassets[obj[property]] = assets[obj[property]]; } } } } } function setBaseSize(){ if (CONFIG.FULLSCREEN){ getScreenSize(); if (BD.screenWidth>BD.screenHeight){ BD.SCALE = (BASE_HEIGHT/BD.screenHeight); BASE_WIDTH = BASE_HEIGHT*(BD.screenWidth/BD.screenHeight); //BASE_HEIGHT = BD.screenHeight; } else { //BASE_WIDTH = BD.screenWidth; BASE_HEIGHT = BASE_WIDTH*(BD.screenHeight/BD.screenWidth); } } } function init_main2() { if (TESTING) { initFPS(); } // V4 renderer = new PIXI.Application(BASE_WIDTH, BASE_HEIGHT, {backgroundColor : 0x999999}); document.getElementById('game').appendChild(renderer.view); stage = renderer.stage; renderer.view.style.border = 'solid 1px #666666'; // renderer.view.style.position = 'absolute'; // renderer.view.style.top = 0; // renderer.view.style.left = 0; // --- build STAGES --- for (var i=1;i<5;i++){ window["stage"+i] = new PIXI.Container(true); stage.addChild(window["stage"+i]); } stage = window.stage1; // V3 //Create the renderer // //renderer = PIXI.autoDetectRenderer(BASE_WIDTH, BASE_HEIGHT); // renderer = new PIXI.WebGLRenderer(BASE_WIDTH, BASE_HEIGHT); // document.body.appendChild(renderer.view); // stage = new PIXI.Container(); // renderer.render(stage); // SH renderer interface doResize(); // document.body.onresize = doResize; // window.addEventListener("orientationchange", function() { // doResize(); // }, false); // setTimeout(function(){ // doResize(); // }, 50); // setTimeout(function(){ // doResize(); // }, 1000); // doResize(); renderer.ticker.add(function(delta) { tick(); }); initLoader(); } var assetsToLoadLength = 0; function initLoader(){ fassets = {}; iterateAssetData(CONFIG) // var // logotexture = PIXI.Texture.fromImage('img/gameskin// logo_bg.jpg'); // PIXI.// logo = new PIXI.Sprite(// logotexture); // stage.addChild(PIXI.// logo); //graphics = new PIXI.Graphics(); //stage.addChild(graphics); PIXI.loadingtxt = new PIXI.Text('Loading ', {font:"28px Bungee", fill:'#FFFFFF', align:"left"}); PIXI.loadingtxt.position.x = BASE_WIDTH/2 - 90; PIXI.loadingtxt.position.y = BASE_HEIGHT - 120; stage.addChild(PIXI.loadingtxt); var loader = PIXI.loader; for (var i in fassets){ if (!this[i]){ try { loader.add(i, fassets[i]); this[i] = PIXI.Texture.fromImage(fassets[i]); assetsToLoadLength++; } catch(e){} } else { // log('[LOADER] LOADED ALREADY i '+i) } } if (assetsToLoadLength == 0){ onAssetsLoaded() } else { loader.on('progress', onAssetsProgress); loader.once('complete', onAssetsLoaded); loader.load(); } } function onAssetsProgress(e){ //log('onAssetsProgress ('+parseInt(e.progress)+') ', e); // graphics.beginFill(0xffffff); // graphics.drawRect(PIXI.loadingtxt.position.x, PIXI.loadingtxt.position.y+40, e.progress*2, 5); // graphics.endFill(); var percent = 100-Math.floor((e.progress/assetsToLoadLength)*100) if (PIXI.loadingtxt){ PIXI.loadingtxt.text = "Loading "+percent; } // log(percent) // if (PIXI.// logo){ // PIXI.// logo.position.x += 5; // } } function onAssetsLoaded(){ stage.removeChild(PIXI.loadingtxt); //stage.removeChild(PIXI.// logo); PIXI.loadingtxt = null; //PIXI.// logo = null; // log('onAssetsLoaded'); init_main3(); } function createAnim1(){ removeAll(); new BD.Anim1().execute({callback:createSplash}); } function init_main3(){ if (TESTING){ //createSplash(); //createGame(); //createSelectLevel(); //createInstructions(); if (0 && CONFIG.ANIMATIONS){ createAnim1(); } else { createGame(); // new BD.GameOverPanel({}); // createSelectLevel(); } } else { setTimeout(function(){ createSplash(); }, 1000) } } function removeAll(){ if (stage.removeAll){ // using PIXI-ISH if (stage){ stage.removeAll(); } } else { // using PIXI while(stage.children[0]){ stage.removeChild(stage.children[0]); } } document.onkeypress = null; }