var ITW = (function(itw){ "use strict"; //AlIASES var scene, protot, _this, _super; itw.scene = itw.scene || Object.create(null); scene = itw.scene; //PRIVATES var _distanceScore; var _background, _player, _jonah, _pshadow, _pbubbles, _psplash; var _airmanager, _wavemanager, _obstaclemanager; var _score, _pause; var _elementsPaused; scene.GameScene = function(){ this.super.call(this); _this = this; _super = _this.super; ITW.GameMgr.init(); } protot = scene.GameScene.prototype = Object.create(EHDI.aka.Container.prototype); protot.super = EHDI.aka.Container; protot.mouseDown_Handler = function(){ _player.setMoveDown( true ); } protot.mouseUp_Handler = function(){ _player.setMoveDown( false ); } protot.loop = function( dt ){ if( _pause.isPaused === true ){ if( _elementsPaused === false ){ _elementsPaused = true; ITW.SoundMgr.pauseAllSFX(); _wavemanager.pauseWaves( true ); _obstaclemanager.pauseShips(); _player.pause(); } return; } else{ if( _elementsPaused === true ){ _elementsPaused = false; ITW.SoundMgr.resumeAllSFX(); _wavemanager.pauseWaves( false ); _obstaclemanager.resumeShips(); _player.resume(); } } if( ITW.GameMgr.getGameOver() === true ){ _this.endGame(); return; } dt *= 0.001; if(!!ITW.GameMgr.getLoop("bg")) _background.loop( dt ); if(!!ITW.GameMgr.getLoop("air")) _airmanager.loop( dt ); if(!!ITW.GameMgr.getLoop("obstacle")) _obstaclemanager.loop( dt ); if(!!ITW.GameMgr.getLoop("wave")) _wavemanager.loop( dt ); if(!!ITW.GameMgr.getLoop("player")){ _player.loop( dt ); if(_pshadow) _pshadow.loop(); } _distanceScore += dt * ITW.GameMgr.getSpeed(); if( _distanceScore > 200 ){ _distanceScore -= 200; _score.addScore(1); ITW.GameMgr.setScore( _score.getScore() ); if( _score.getScore() % 7 === 0 ){ ITW.GameMgr.increaseSpeed(); } } } protot.endGame = function(){ _wavemanager.pauseWaves( true ); _pause.endGame(); var stars = 0; var score = _score.getScore(); if( score >= 15 && score < 50 ) stars = 1; else if( score >= 50 && score < 100 ) stars = 2; else if( score >= 100 ) stars = 3; this.popUpDidAppear(); /* var popup = new EHDI.popup.PostGamePopUp( stars, score ); popup.x = ITW.SceneMgr.getStageWidth() * 0.5; popup.y = ITW.SceneMgr.getStageHeight() * 0.5; ITW.SceneMgr.pushPopUp( popup ); */ ITW.UpdateMgr.removeFrameListener( _this.loop ); if(score > EHDI.GAME.saveData.highScore) { EHDI.GAME.saveData.highScore = score; EHDI.sbGame.saveGameData(EHDI.GAME.saveData, "DEFAULT", function(){ console.log("data saved."); }); } EHDI.sbGame.end(score); } protot.screenWillAppear = function(){ _background = new ITW.components.Background(); _this.addChild( _background ); _player = new ITW.components.Player(); _player.setStartPos( ITW.SceneMgr.getStageWidth() * 0.2, ITW.SceneMgr.getStageHeight() * 0.315 ); _psplash = new ITW.components.PlayerSplash( _player ); _player.playSplash = _psplash.play.bind(_psplash); if(!ITW.isIP4){ _pshadow = new ITW.components.PlayerShadow( _player ); ITW.components.PlayerBubbles.setPlayerRef( _player ); _pbubbles = new ITW.components.PlayerBubbles( ); _player.playBubbles = _pbubbles.play.bind(_pbubbles); } _jonah = new ITW.components.Jonah(); _jonah.x = 5; _jonah.y = ITW.SceneMgr.getStageHeight() - _jonah.height - 10; _pause = new EHDI.components.pauseButton(); _wavemanager = new ITW.managers.WaveManager(); _wavemanager.y = ITW.SceneMgr.getStageHeight() * 0.27; _obstaclemanager = new ITW.managers.ObstacleManager( _player ); _airmanager = new ITW.managers.AirManager( _player ); _airmanager.setContainerPosition( ITW.SceneMgr.getStageWidth() * 0.02 + _airmanager.width * 1.05, ITW.SceneMgr.getStageHeight() * 0.025 ); _distanceScore = 0; _elementsPaused = false; _airmanager.jonah = _jonah; } protot.setBgInteractive = function(){ _background.interactive = true; _background.touchstart = _background.mousedown = _this.mouseDown_Handler; _background.touchend = _background.mouseup = _background.touchendoutside = _background.mouseupoutside = _this.mouseUp_Handler; ITW.UpdateMgr.addFrameListener( _this.loop ); } protot.screenDidAppear = function(){ if(_pshadow) _this.addChild( _pshadow ); _this.addChild( _psplash ); _this.addChild( _player ); if(_pbubbles)_this.addChild( _pbubbles ); _this.addChild( _obstaclemanager ); _this.addChild( _wavemanager ); _score = new EHDI.components.ScoreManager( _this ); _score.setXY( ITW.SceneMgr.getStageWidth() * 0.02, ITW.SceneMgr.getStageHeight() * 0.025 ); _this.addChild( _airmanager ); _this.addChild( _jonah ); _this.addChild( _pause ); if(EHDI.GAME.saveData.isFirstTimePlay){ var htp = new EHDI.popup.HTPPopUp(this.setBgInteractive.bind(this)); htp.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.5); EHDI.GAME.sceneManager.pushPopUp(htp, {alpha : new EHDI.scene.TransitionParameter(0, 1), duration : 0.1}); }else{ _this.setBgInteractive(); } this.sfxOcean = ITW.SoundMgr.playSFX("ocean_ambient_loop"); this.sfxOcean.stop(); this.sfxOcean.loop = -1; this.sfxOcean.volume = 0.4; this.sfxOcean.play(); } protot.screenWillDisappear = function(){ ITW.UpdateMgr.removeFrameListener( _this.loop ); _pause.endGame(); if( ITW.GameMgr.getGameOver() === false ){ ITW.GameMgr.setGameOver( true ); } } protot.screenDidDisappear = function(){ ITW.DBoneFactory.enableClock = true; _pause.dispose(); // this.sfxOcean.destroy(); ITW.SoundMgr.stopAllSFX(); _super.prototype.destroy.call(_this, {children: true}); } protot.popUpDidAppear = function(){ this.sfxOcean.paused = true; } protot.popUpDidDisappear = function(){ this.sfxOcean.paused = false; } return itw; }(ITW || Object.create(null)))