var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.PatternObject = function(assetName, column, row, shouldClick) { EHDI.aka.Container.call(this); 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); //this.displaySprite = EHDI.displays.FillRectangle(0x808080, x, y, width, height); this.assetName = assetName; this.shouldClick = shouldClick; if(this.shouldClick) this.displaySprite = new EHDI.aka.Sprite(EHDI.Assets.images[assetName + 1]); else { this.displaySprite = new EHDI.aka.Sprite(EHDI.Assets.images[assetName + 2]); this.lightningSpriteLeft = new EHDI.aka.Sprite(EHDI.Assets.images["lightning"]); this.lightningSpriteRight = new EHDI.aka.Sprite(EHDI.Assets.images["lightning2"]); this.lightningSpriteLeft.scale.x = 0.7; this.lightningSpriteLeft.scale.y = 0.7; this.lightningSpriteLeft.anchor.x = 0.5; this.lightningSpriteLeft.anchor.y = 0.5; this.lightningSpriteRight.scale.x = 0.7; this.lightningSpriteRight.scale.y = 0.7; this.lightningSpriteRight.anchor.x = 0.5; this.lightningSpriteRight.anchor.y = 0.5; this.lightningSpriteRight.alpha = 0; //this.lightningSpriteLeft.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.6); this.displaySprite.addChild(this.lightningSpriteLeft); this.displaySprite.addChild(this.lightningSpriteRight); this.sparkTimeline = new TimelineMax({repeat : -1}); this.sparkTimeline.to(this.lightningSpriteLeft, 0, {alpha : 1}); this.sparkTimeline.to(this.lightningSpriteLeft.scale, 0.3, {x : 1, y : 1, ease : Power0.easeNone}); this.sparkTimeline.to(this.lightningSpriteLeft, 0, {alpha : 0}, 0.05); this.sparkTimeline.to(this.lightningSpriteLeft, 0, {alpha : 1}, 0.1); this.sparkTimeline.to(this.lightningSpriteLeft, 0, {alpha : 0}, 0.2); this.sparkTimeline.to(this.lightningSpriteLeft, 0, {alpha : 1}, 0.25); this.sparkTimeline.to(this.lightningSpriteLeft, 0, {alpha : 0}, 0.3); this.sparkTimeline.to(this.lightningSpriteRight, 0, {alpha : 1}, 0.3); this.sparkTimeline.to(this.lightningSpriteRight.scale, 0.75, {x : 1, y : 1, ease: Power0.easeNone}, 0.3); this.sparkTimeline.to(this.lightningSpriteRight, 0, {alpha : 0}, 0.35); this.sparkTimeline.to(this.lightningSpriteRight, 0, {alpha : 1}, 0.4); this.sparkTimeline.to(this.lightningSpriteRight, 0, {alpha : 0}, 0.5); this.sparkTimeline.to(this.lightningSpriteRight, 0, {alpha : 1}, 0.55); this.sparkTimeline.to(this.lightningSpriteRight, 0, {alpha : 0}, 0.6); } this.displaySprite.scale.x = 0; this.displaySprite.scale.y = 0; this.displaySprite.anchor.x = 0.5; this.displaySprite.anchor.y = 0.5; this.displaySprite.alpha = 0.6; this.displaySprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.5, EHDI.GAME.sceneManager.getStageHeight() * 0.6); this.addChild(this.displaySprite); 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.PatternObject.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.PatternObject.prototype.touchstart = function(touchData) { this.onClickFunction(); }; EHDI.components.PatternObject.prototype.mousedown = function(touchData) { this.onClickFunction(); }; EHDI.components.PatternObject.prototype.onClickFunction = function() { if(EHDI.GAME.patternManager.processInput(this)) { 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.PatternObject.prototype.hideObject = function(explode, hide) { this.interactive = false; this.displaySprite.texture = EHDI.Assets.images[this.assetName + 3]; this.hideTimeline = new TimelineMax(); if(hide) this.hideTimeline.to(this.displaySprite.scale, 0.3, {x : 0, y : 0, ease : Back.easeIn}); if(explode) { this.fx.position.set(this.displaySprite.x, this.displaySprite.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(this.sparkTimeline) this.sparkTimeline.kill(); }; EHDI.components.PatternObject.prototype.hideFX = function() { this.fx.visible = false; } EHDI.components.PatternObject.prototype.pauseTimeline = function() { if(this.sparkTimeline) this.sparkTimeline.pause(); if(this.hideTimeline) this.hideTimeline.pause(); }; EHDI.components.PatternObject.prototype.resumeTimeline = function() { if(this.sparkTimeline) this.sparkTimeline.play(); if(this.hideTimeline) this.hideTimeline.play(); } EHDI.components.PatternObject.prototype.break = function() { this.displaySprite.texture = EHDI.Assets.images[this.assetName + 2]; }