var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.AnimatedPatternObject = function() { EHDI.aka.Container.call(this); this.armature = EHDI.GAME.dbFactory.buildArmature("patternpanic_vfx"); this.armature.animation.gotoAndPlay("1_sheen", -1, -1, 1); dragonBones.WorldClock.clock.add(this.armature); this.armature.advanceTime(this.armature.animation.animationDataList[1].duration); this.sprite = this.armature.getDisplay(); this.sprite.position.set(EHDI.GAME.sceneManager.getStageWidth () * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.6); this.addChild(this.sprite); this.visible = false; this.fx = new EHDI.aka.Sprite(EHDI.Assets.images["patternpanic_fx_explode"]); this.fx.anchor.set(0.5, 0.5); this.fx.scale.set(0, 0); this.addChild(this.fx); }; EHDI.components.AnimatedPatternObject.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.AnimatedPatternObject.prototype.setPattern = function(circuitNumber, column, row, shouldClick) { var width = 126, height = 126; this.xPos = EHDI.GAME.sceneManager.getStageWidth() * 0.105 + ((width + 10) * column) + (width * 0.5); this.yPos = EHDI.GAME.sceneManager.getStageHeight() * 0.225 + ((height + 10) * row) + (height * 0.5); if(this.hideTimeline) { this.hideTimeline.kill(); this.hideTimeline = null; } var animationDataIndex = 1; if(circuitNumber === "1") animationDataIndex = shouldClick ? 1 : 0; else if(circuitNumber === "2") animationDataIndex = shouldClick ? 3 : 4; else animationDataIndex = shouldClick ? 2 : 5; this.circuitNumber = circuitNumber; this.shouldClick = shouldClick; if(this.shouldClick) this.armature.animation.gotoAndPlay(this.circuitNumber + "_sheen", -1, -1, 1); else this.armature.animation.gotoAndPlay(this.circuitNumber + "_lightning", -1, -1, 0); this.armature.advanceTime(this.armature.animation.animationDataList[animationDataIndex].duration); this.sprite.position.set(EHDI.GAME.sceneManager.getStageWidth () * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.6); this.sprite.scale.set(0, 0); this.sprite.alpha = 0.6; this.fx.scale.set(0, 0); this.visible = true; }; EHDI.components.AnimatedPatternObject.prototype.showPattern = function() { if(this.shouldClick) this.armature.animation.gotoAndPlay(this.circuitNumber + "_sheen", -1, -1, 1); else this.armature.animation.gotoAndPlay(this.circuitNumber + "_lightning", -1, -1, 0); }; EHDI.components.AnimatedPatternObject.prototype.touchstart = function(touchData) { if(EHDI.GAME.pauseButton.isPaused || EHDI.GAME.pauseButton.isEndGame) return; this.onClickFunction(); }; EHDI.components.AnimatedPatternObject.prototype.mousedown = function(touchData) { if(EHDI.GAME.pauseButton.isPaused || EHDI.GAME.pauseButton.isEndGame) return; this.onClickFunction(); }; EHDI.components.AnimatedPatternObject.prototype.onClickFunction = function() { if(EHDI.GAME.patternManager.processInput(this)) { this.fx.texture = EHDI.Assets.images["patternpanic_fx_explode"]; this.hideObject(true, true); EHDI.GAME.soundManager.playSFX("correct"); EHDI.GAME.patternManager.checkIfNextRound(); } else { this.fx.texture = EHDI.Assets.images["patternpanic_fx_explode_red"]; this.hideObject(true, false); EHDI.GAME.soundManager.playSFX("wrong"); EHDI.GAME.patternManager.endGame(); } }; EHDI.components.AnimatedPatternObject.prototype.hideFX = function() { this.fx.visible = false; }; EHDI.components.AnimatedPatternObject.prototype.hideMe = function() { this.visible = false; } EHDI.components.AnimatedPatternObject.prototype.pauseTimeline = function() { if(this.hideTimeline) this.hideTimeline.pause(); }; EHDI.components.AnimatedPatternObject.prototype.resumeTimeline = function () { if(this.hideTimeline) this.hideTimeline.play(); }; EHDI.components.AnimatedPatternObject.prototype.break = function() { this.armature.animation.gotoAndPlay(this.circuitNumber + "_lightning", -1, -1, 0); }; EHDI.components.AnimatedPatternObject.prototype.hideObject = function(explode, hide) { this.interactive = false; this.armature.animation.gotoAndPlay(this.circuitNumber + "_white", -1, -1, 0); if(explode) this.fx.alpha = 1; this.hideTimeline = new TimelineMax(); if(hide) this.hideTimeline.to(this.sprite.scale, 0.3, {x : 0, y : 0, ease : Back.easeIn}); if(explode) { this.fx.position.set(this.sprite.x, this.sprite.y); this.hideTimeline.to(this.fx.scale, 0.2, {x : 1, y : 1, ease : Power0.easeNone}, 0); this.hideTimeline.to(this.fx, 0.3, {alpha: 0, ease : Power0.easeNone}, 0.2); } if(hide && explode) { this.hideTimeline.add(this.hideMe.bind(this)); this.hideTimeline.to(this.sprite.scale, 0.1, {x : 0, y : 0, ease : Back.easeIn}); } };