var EHDI = EHDI || Object.create(null); EHDI.scene = EHDI.scene || Object.create(null); EHDI.scene.GameScene = function (){ PIXI.Container.call(this); this.gameLayer = new EHDI.aka.Container(); this.gridLayer = new EHDI.aka.Container(); this.guiLayer = new EHDI.aka.Container(); this.addChild(this.gameLayer); this.addChild(this.guiLayer); EHDI.GAME.gameScene = this; } 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["gizmo_bg"]); this.gameLayer.addChild(this.bg); } EHDI.scene.GameScene.prototype.screenDidAppear = function() { //this.setupPauseButton(); var pauseButton = new EHDI.components.pauseButton(); this.guiLayer.addChild(pauseButton); this.createDragonBones(); this.gizmoShadow = new EHDI.aka.Sprite(EHDI.Assets.images["patternpanic_shadow"]); this.gizmoShadow.anchor.set(0.5, 0.5); this.gizmoShadow.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.925); this.gameLayer.addChild(this.gizmoShadow); EHDI.GAME.gizmoArmature = EHDI.GAME.dbFactory.buildArmature("ppgizmo"); EHDI.GAME.gizmoArmature.animation.gotoAndPlay("open", -1, -1, 1); EHDI.GAME.gizmoArmature.addEventListener(dragonBones.AnimationEvent.COMPLETE, this.continueIntro.bind(this)); EHDI.GAME.gizmo = EHDI.GAME.gizmoArmature.getDisplay(); EHDI.GAME.gizmo.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.95); this.gameLayer.addChild(EHDI.GAME.gizmo); this.backGlow = new EHDI.aka.Sprite(EHDI.Assets.images["patternpanic_holo2"]); this.backGlow.anchor.x = 0.5; this.backGlow.anchor.y = 0.5; this.backGlow.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.6); this.gameLayer.addChild(this.backGlow); this.glow = new EHDI.aka.Sprite(EHDI.Assets.images["patternpanic_holo1"]); this.glow.anchor.x = 0.5; this.glow.anchor.y = 0.5; this.glow.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.6); this.gameLayer.addChild(this.glow); this.hologram = new EHDI.aka.Sprite(EHDI.Assets.images["patternpanic_hologram"]); this.hologram.anchor.x = 0.5; this.hologram.anchor.y = 0.5; this.hologram.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.65); this.gameLayer.addChild(this.hologram); this.borderLeft = new EHDI.aka.Sprite(EHDI.Assets.images["patternpanic_border1"]); this.borderLeft.anchor.set(0.5, 0.5); this.borderLeft.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.45, EHDI.GAME.sceneManager.getStageHeight() * 0.55); this.gameLayer.addChild(this.borderLeft); this.borderRight = new EHDI.aka.Sprite(EHDI.Assets.images["patternpanic_border1"]); this.borderRight.anchor.set(0.5, 0.5); this.borderRight.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.55, EHDI.GAME.sceneManager.getStageHeight() * 0.55); this.gameLayer.addChild(this.borderRight); this.gameLayer.addChild(this.gridLayer); this.borderRight.scale.set(-1, 0); this.borderLeft.scale.set(1, 0); this.glow.scale.set(0, 0); this.backGlow.scale.set(0, 0); this.hologram.scale.set(0, 1); EHDI.GAME.patternManager = new EHDI.components.PatternManager(this.gridLayer); 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.updateFunction = this.updateGlowRotation.bind(this); EHDI.GAME.updateManager.addFrameListener(this.updateFunction); this.introTimeline = new TimelineMax(); this.introTimeline.from(EHDI.GAME.gizmo, 0.1, {y : EHDI.GAME.sceneManager.getStageHeight() * 0.8}); this.introTimeline.to(EHDI.GAME.gizmo.scale, 0.1, {y : 0.8, x : 1.2, ease : Power0.easeNone}); this.introTimeline.to(EHDI.GAME.gizmo.scale, 0.1, {y : 1, x : 1, ease : Power0.easeNone}); this.introTimeline.add(function() { dragonBones.WorldClock.clock.add(EHDI.GAME.gizmoArmature); }); this.patternTimeline = new TimelineMax({repeat : -1}) this.patternTimeline.to(this.gridLayer, 1, {y: this.gridLayer.y + 2, ease: Power0.easeNone}); this.patternTimeline.to(this.gridLayer, 2, {y: this.gridLayer.y - 4, ease: Power0.easeNone}); this.patternTimeline.to(this.gridLayer, 1, {y: this.gridLayer.y, ease: Power0.easeNone}); this.startAmbientTimeline(); EHDI.GAME.soundManager.playSFX("ambient01"); }; EHDI.scene.GameScene.prototype.startAmbientTimeline = function() { if(this.ambientTimeline) this.ambientTimeline.kill(); this.ambientTimeline = new TimelineMax(); this.ambientTimeline.add(this.playAmbientSFX, "+=" + EHDI.NumberUtil.randomRange(5, 10)); this.ambientTimeline.add(this.startAmbientTimeline.bind(this), "+=1"); }; EHDI.scene.GameScene.prototype.playAmbientSFX = function() { EHDI.GAME.soundManager.playSFX("ambient0" + Math.floor(EHDI.NumberUtil.randomRange(2, 5))); } EHDI.scene.GameScene.prototype.createDragonBones = function() { EHDI.GAME.dbFactory = new dragonBones.PixiFactory(); var textureImage = EHDI.Assets.images["gizmoanim_tex"].baseTexture.source; var textureData = EHDI.Assets.cjAssets.getResult("gizmoanim_tex"); EHDI.GAME.dbFactory.addTextureAtlas(new dragonBones.TextureAtlas(textureImage, textureData)); var skeleton = EHDI.Assets.cjAssets.getResult("gizmoanim_ske"); EHDI.GAME.dbFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(skeleton)); textureImage = EHDI.Assets.images["patternpanic_fx_an_tex"].baseTexture.source; textureData = EHDI.Assets.cjAssets.getResult("patternpanic_fx_an_tex"); EHDI.GAME.dbFactory.addTextureAtlas(new dragonBones.TextureAtlas(textureImage, textureData)); skeleton = EHDI.Assets.cjAssets.getResult("patternpanic_fx_an_ske"); EHDI.GAME.dbFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(skeleton)); EHDI.GAME.updateManager.addFrameListener(this.animateAnimations); var cache = EHDI.GAME.saveData; 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.animateAnimations = function(dt) { if(EHDI.GAME.pauseButton.isPaused) return; dragonBones.WorldClock.clock.advanceTime(dt * 0.001) }; EHDI.scene.GameScene.prototype.error = function() { this.borderLeft.texture = EHDI.Assets.images["patternpanic_border1_red"]; this.borderRight.texture = EHDI.Assets.images["patternpanic_border1_red"]; this.hologram.texture = EHDI.Assets.images["patternpanic_hologram_red"]; this.holoTimeLine.kill(); this.patternTimeline.kill(); var holoX = this.hologram.x, leftX = this.borderLeft.x, rightX = this.borderRight.x; this.holoTimeline = new TimelineMax({repeat : 3}); this.holoTimeline.to(this.hologram, 0.075, {x : holoX + EHDI.GAME.sceneManager.getStageWidth() * 0.008}); this.holoTimeline.to(this.borderLeft, 0.075, {x : leftX + EHDI.GAME.sceneManager.getStageWidth() * 0.008}, 0); this.holoTimeline.to(this.borderRight, 0.075, {x : rightX + EHDI.GAME.sceneManager.getStageWidth() * 0.008}, 0); this.holoTimeline.to(this.hologram, 0.0375, {x : holoX - EHDI.GAME.sceneManager.getStageWidth() * 0.008}); this.holoTimeline.to(this.borderLeft, 0.0375, {x : leftX - EHDI.GAME.sceneManager.getStageWidth() * 0.008}, "-=0.05"); this.holoTimeline.to(this.borderRight, 0.0375, {x : rightX - EHDI.GAME.sceneManager.getStageWidth() * 0.008}, "-=0.05"); this.holoTimeline.to(this.hologram, 0.075, {x : holoX}); this.holoTimeline.to(this.borderLeft, 0.075, {x : leftX}, "-=0.1"); this.holoTimeline.to(this.borderRight, 0.075, {x : rightX}, "-=0.1"); }; EHDI.scene.GameScene.prototype.setupPauseButton = function() { this.pauseButton = new EHDI.displays.Button(EHDI.Assets.images["pause-button-fs8"], EHDI.Assets.images["pause-button-on-hit-fs8"]); this.pauseButton.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.9, EHDI.GAME.sceneManager.getStageHeight() * 0.15); this.guiLayer.addChild(this.pauseButton); this.pauseButton.setOnClickFunction(this.onPauseClick.bind(this)); }; EHDI.scene.GameScene.prototype.updateGlowRotation = function(dt) { if(EHDI.GAME.pauseButton.isPaused) return; this.glow.rotation += 1.5708 * dt / 3600; this.backGlow.rotation += 1.5708 * dt / 3600; }; EHDI.scene.GameScene.prototype.screenDidDisappear = function() { EHDI.GAME.pauseButton.endGame(); EHDI.GAME.updateManager.removeFrameListener(this.updateFunction); EHDI.GAME.updateManager.removeFrameListener(this.animateAnimations); this.ambientTimeline.kill(); dragonBones.WorldClock.clock.clear(); this.glow.destroy(); delete this.glow; this.hologram.destroy(); delete this.hologram; this.gameLayer.destroy(); delete this.gameLayer; this.guiLayer.destroy(); delete this.guiLayer; EHDI.GAME.gizmo.destroy(); delete EHDI.GAME.gizmo; delete EHDI.GAME.patternManager; this.destroy({children : true}); }; EHDI.scene.GameScene.prototype.continueIntro = function(event) { if(event.animationName === "open") { EHDI.GAME.gizmoArmature.animation.gotoAndPlay("idle", -1, -1, 0); this.introTimeline.to(this.glow.scale, 0.15, {x : 1, y : 1}); this.introTimeline.to(this.backGlow.scale, 0.15, {x : 1, y : 1}, "-=0.15"); this.introTimeline.to(this.borderLeft.scale, 0.15, {y : 1}, "-=0.15"); this.introTimeline.to(this.borderRight.scale, 0.15, {y : 1}, "-=0.15"); this.introTimeline.to(this.borderLeft, 0.15, {x : EHDI.GAME.sceneManager.getStageWidth() * 0.1}); this.introTimeline.to(this.borderRight, 0.15, {x : EHDI.GAME.sceneManager.getStageWidth() * 0.9}, "-=0.15"); this.introTimeline.to(this.hologram.scale, 0.15, {x : 1}, "-=0.15"); this.introTimeline.add(EHDI.GAME.patternManager.createPattern.bind(EHDI.GAME.patternManager)); } else if(event.animationName ==="close") { EHDI.GAME.patternManager.goToPostGame(); } else if(event.animationName === "correct") { EHDI.GAME.patternManager.nextRound(); } } EHDI.scene.GameScene.prototype.popUpDidAppear = function() { if(this.holoTimeLine) this.holoTimeLine.pause(); if(this.introTimeline) this.introTimeline.pause(); if(this.outroTimeline) this.outroTimeline.pause(); if(this.patternTimeline) this.patternTimeline.pause(); EHDI.GAME.patternManager.pauseAnimations(); // EHDI.GAME.soundManager.pauseBGM(); }; EHDI.scene.GameScene.prototype.popUpDidDisappear = function() { if(!EHDI.GAME.pauseButton.isEndGame) { EHDI.GAME.patternManager.resumeAnimations(); if(this.holoTimeline) this.holoTimeLine.play(); if(this.introTimeline) this.introTimeline.play(); if(this.outroTimeline) this.outroTimeline.play(); if(this.patternTimeline) this.patternTimeline.play(); EHDI.GAME.soundManager.resumeBGM(); } }; EHDI.scene.GameScene.prototype.lowerGlowIntensity = function() { if(this.holoTimeLine) this.holoTimeLine.kill(); this.holoTimeLine = new TimelineMax(); this.holoTimeLine.to(this.hologram, 0.25, {alpha : 0.7}); this.holoTimeLine.to(this.glow.scale, 0.25, {x : 0.75, y : 0.75}, "-=0.25"); this.holoTimeLine.to(this.backGlow.scale, 0.25, {x : 0.75, y : 0.75}, "-=0.25"); this.holoTimeLine.to(this.glow, 0.25, {alpha : 0.8}, "-=0.25"); this.holoTimeLine.to(this.backGlow, 0.25, {alpha : 0}, "-=0.25"); this.holoTimeLine.add(this.animateGlow.bind(this)); }; EHDI.scene.GameScene.prototype.animateGlow = function() { if(this.holoTimeLine) this.holoTimeLine.kill(); this.holoTimeLine = new TimelineMax({repeat : -1, yoyo : true}); this.holoTimeLine.to(this.hologram, 1.5, {alpha : 0.4}); this.holoTimeLine.to(this.backGlow, 1.5, {alpha : 0.8}, 0); this.holoTimeLine.to(this.glow, 1.5, {alpha : 0.8}, 0); this.holoTimeLine.to(this.hologram, 1, {alpha : 0.7}, 1.5); this.holoTimeLine.to(this.backGlow, 1, {alpha : 0}, 1.5); this.holoTimeLine.to(this.glow, 1, {alpha : 0.5}, 1.5); }; EHDI.scene.GameScene.prototype.higherGlowIntensity = function() { if(this.holoTimeLine) this.holoTimeLine.kill(); this.holoTimeLine = new TimelineMax(); this.holoTimeLine.to(this.hologram, 0.25, {alpha : 1}); this.holoTimeLine.to(this.glow.scale, 0.25, {x : 1, y : 1}, "-=0.25"); this.holoTimeLine.to(this.backGlow.scale, 0.25, {x : 1, y : 1}, "-=0.25"); this.holoTimeLine.to(this.glow, 0.25, {alpha : 1}, "-=0.25"); this.holoTimeLine.to(this.backGlow, 0.25, {alpha : 0}, "-=0.25"); this.holoTimeLine.add(EHDI.GAME.patternManager.createPattern.bind(EHDI.GAME.patternManager)); }; EHDI.scene.GameScene.prototype.playOutro = function() { this.outroTimeline = new TimelineMax(); this.outroTimeline.add(EHDI.GAME.patternManager.hideAllPatterns.bind(EHDI.GAME.patternManager)); this.outroTimeline.to(this.hologram.scale, 0.15, {x : 0}, "+=0.3 "); this.outroTimeline.to(this.borderLeft, 0.15, {x : EHDI.GAME.sceneManager.getStageWidth() * 0.45}, "-=0.15"); this.outroTimeline.to(this.borderRight, 0.15, {x : EHDI.GAME.sceneManager.getStageWidth() * 0.55}, "-=0.15"); this.outroTimeline.to(this.glow.scale, 0.15, {x : 0, y : 0}); this.outroTimeline.to(this.backGlow.scale, 0.15, {x : 0, y : 0}, "-=0.15"); this.outroTimeline.to(this.borderLeft.scale, 0.15, {y : 0}, "-=0.15"); this.outroTimeline.to(this.borderRight.scale, 0.15, {y : 0}, "-=0.15"); this.outroTimeline.add(function() { EHDI.GAME.gizmoArmature.animation.gotoAndPlay("close", -1, -1, 1); }, "+=0.1"); }; EHDI.scene.GameScene.prototype.onPauseClick = function() { EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.PauseScene(), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(),0), duration : 0.2}); };