var EHDI = EHDI || Object.create(null); EHDI.scene = EHDI.scene || Object.create(null); EHDI.scene.GameScene = function (){ PIXI.Container.call(this); EHDI.GAME.gameScene = this; this.gameLayer = new EHDI.aka.Container(); this.guiLayer = new EHDI.aka.Container(); this.addChild(this.gameLayer); this.addChild(this.guiLayer); } EHDI.scene.GameScene.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.scene.GameScene.prototype.screenWillAppear = function() { this.bg = new EHDI.aka.Sprite(EHDI.Assets.images["kinnor_bg"]); this.gameLayer.addChild(this.bg); this.atmosphere = new EHDI.aka.Sprite(EHDI.Assets.images["kinnor_atmosphere"]); this.gameLayer.addChild(this.atmosphere) }; EHDI.scene.GameScene.prototype.screenDidAppear = function() { this.createDragonBones(); var pauseButton = new EHDI.components.pauseButton(); this.buttons = []; this.guiLayer.addChild(pauseButton); this.smoke = EHDI.GAME.dbFactory.buildArmature("smoke"); this.smoke.animation.gotoAndPlay("animtion0", -1, -1, 0); dragonBones.WorldClock.clock.add(this.smoke); this.smokeSprite = this.smoke.getDisplay(); this.gameLayer.addChild(this.smokeSprite); this.smoke.animation.timeScale = 0.5; this.smokeSprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.85, EHDI.GAME.sceneManager.getStageHeight() * 0.9); this.kingSaul = EHDI.GAME.dbFactory.buildArmature("Saul"); dragonBones.WorldClock.clock.add(this.kingSaul); this.kingSaul.animation.gotoAndPlay("saul_default", -1, -1, 0); this.kingSaul.animationComplete = this.handleAnimationComplete.bind(this); this.kingSaul.addEventListener(dragonBones.AnimationEvent.COMPLETE, this.kingSaul.animationComplete); this.kingSaulSprite = this.kingSaul.getDisplay(); this.kingSaulSprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.85, EHDI.GAME.sceneManager.getStageHeight() * 0.9); this.gameLayer.addChild(this.kingSaulSprite); EHDI.GAME.scoreManager = EHDI.components.ScoreManager(this.guiLayer); EHDI.GAME.scoreManager.setXY(EHDI.GAME.sceneManager.getStageWidth() * 0.025, EHDI.GAME.sceneManager.getStageHeight() * 0.015); this.song = EHDI.GAME.soundManager.playSFX("gamesong"); this.songListener = this.song.on("complete", this.endGame.bind(this)); var cache = EHDI.GAME.saveData; if(cache.isFirstTimePlay) { this.song.paused = true; } EHDI.GAME.timer = new EHDI.components.Timer(); this.arm = new EHDI.aka.Sprite(EHDI.Assets.images["kinnor_kinnor2"]); this.arm.anchor.y = 1; this.arm.position.x = EHDI.GAME.sceneManager.getStageWidth() * 0.175; this.arm.position.y = EHDI.GAME.sceneManager.getStageHeight(); this.gameLayer.addChild(this.arm); for(var i = 0; i < 4; i++) { var newButton = new EHDI.components.NoteButton(i); this.buttons.push(newButton); this.gameLayer.addChild(newButton); } this.kinnor = new EHDI.aka.Sprite(EHDI.Assets.images["kinnor_kinnor"]); this.kinnor.anchor.y = 1; this.kinnor.position.y = EHDI.GAME.sceneManager.getStageHeight(); this.gameLayer.addChild(this.kinnor); this.myMask = new EHDI.aka.Sprite(EHDI.Assets.images["kinnor_kinnor_mask"]); this.myMask.anchor.set(0.5, 1); this.myMask.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.49, EHDI.GAME.sceneManager.getStageHeight() * 0.935); this.gameLayer.addChild(this.myMask); this.noteContainer = new EHDI.aka.Container(); this.gameLayer.addChild(this.noteContainer); this.noteContainer.mask = this.myMask; this.noteManager = new EHDI.components.NoteManager(this.noteContainer); if(cache.isFirstTimePlay) { EHDI.GAME.pauseButton.isPaused = true; EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.HTPPopUp(), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(), EHDI.GAME.sceneManager.getStageHeight() * 0.5), duration : 0.25}); cache.isFirstTimePlay = false; EHDI.sbGame.saveGameData(EHDI.GAME.saveData, "DEFAULT", function(){ console.log("data saved."); }); } }; EHDI.scene.GameScene.prototype.handleAnimationComplete = function(e) { if(e.animationName === "saul_hiterror1" || e.animationName === "saul_hiterror2" || e.animationName === "saul_hiterror3") { EHDI.GAME.gameScene.kingSaul.animation.gotoAndPlay("saul_error" + this.kingSaul.number, -1, -1, 0); } } EHDI.scene.GameScene.prototype.createDragonBones = function() { EHDI.GAME.dbFactory = new dragonBones.PixiFactory(); var textureImage = EHDI.Assets.images["kinnorsfx_tex"].baseTexture.source; var textureData = EHDI.Assets.cjAssets.getResult("kinnorsfx_tex"); EHDI.GAME.dbFactory.addTextureAtlas(new dragonBones.TextureAtlas(textureImage, textureData)); var skeleton = EHDI.Assets.cjAssets.getResult("kinnorsfx_ske"); EHDI.GAME.dbFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(skeleton)); textureImage = EHDI.Assets.images["kingsaul_tex"].baseTexture.source; textureData = EHDI.Assets.cjAssets.getResult("kingsaul_tex"); EHDI.GAME.dbFactory.addTextureAtlas(new dragonBones.TextureAtlas(textureImage, textureData)); skeleton = EHDI.Assets.cjAssets.getResult("kingsaul_ske"); EHDI.GAME.dbFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(skeleton)); EHDI.GAME.updateManager.addFrameListener(this.animateAnimations); }; EHDI.scene.GameScene.prototype.endGame = function() { EHDI.GAME.pauseButton.isEndGame = true; if(this.songListener) this.song.off("complete", this.songListener); this.songListener = null; this.song = null; if(EHDI.GAME.timer) EHDI.GAME.timer.dispose(); EHDI.GAME.timer = null; this.kingSaul.animation.gotoAndPlay("saul_win", -1, -1, 0); setTimeout(this.goToEndScreen.bind(this), 500); }; EHDI.scene.GameScene.prototype.goToEndScreen = function() { var score = EHDI.GAME.scoreManager.getScore(); var stars = 1; if(score === 0) { stars--; } if(score > 175) { stars++; } if(score > 350) { stars++; } EHDI.GAME.pauseButton.isPaused = true; EHDI.GAME.pauseButton.endGame(); //EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.PostGamePopUp(stars, score), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(), EHDI.GAME.sceneManager.getStageHeight() * 0.5), duration : 0.5}); 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); } EHDI.scene.GameScene.prototype.animateAnimations = function(dt) { if(EHDI.GAME.pauseButton.isPaused) return; dragonBones.WorldClock.clock.advanceTime(dt * 0.001); }; EHDI.scene.GameScene.prototype.popUpDidAppear = function() { if(!EHDI.GAME.pauseButton.isEndGame) this.song.paused = true; }; EHDI.scene.GameScene.prototype.popUpDidDisappear = function () { if(!EHDI.GAME.pauseButton.isEndGame) this.song.paused = false; }; EHDI.scene.GameScene.prototype.screenDidDisappear = function() { if(EHDI.GAME.timer) EHDI.GAME.timer.dispose(); if(this.songListener) this.song.off("complete", this.songListener); this.song = null; this.songListener = null; EHDI.GAME.updateManager.removeFrameListener(this.animateAnimations); this.noteManager.dispose(); this.buttons.forEach(function(element) { element.dispose(); }); EHDI.GAME.pauseButton.endGame(); if(this.song) { this.song.stop(); this.song.destroy(); } };