var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.Hand = function() { EHDI.aka.Container.call(this); this.arm = new PIXI.extras.TilingSprite(EHDI.Assets.images["arm_upper"], 110, 22); this.addChild(this.arm); this.arm.position.set (0, EHDI.GAME.sceneManager.getStageHeight() * 0.5 - this.arm.height * 0.7); this.hand = new EHDI.aka.Sprite(EHDI.Assets.images["arm_lower1"]); this.addChild(this.hand); this.hand.anchor.y = 0.5; this.hand.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.09, EHDI.GAME.sceneManager.getStageHeight() * 0.5); this.shadow = new EHDI.aka.Sprite(EHDI.Assets.images["gizmo_hand_shadow"]); this.addChild(this.shadow); this.shadow.anchor.x = 0.76; this.shadow.anchor.y = 0.5; this.shadow.position.set(0, EHDI.GAME.sceneManager.getStageHeight() * 0.675); this.handCollider = EHDI.displays.FillRectangle(0x00AA00, EHDI.GAME.sceneManager.getStageWidth() * 0.16, EHDI.GAME.sceneManager.getStageHeight() * 0.65, 75, 40, 0); this.handCollider.anchor.x = 0.5; this.handCollider.anchor.y = 0.5; this.vy = 0; this.addChild(this.handCollider); this.zIndex = this.handCollider.y; this.updateFunction = this.moveHand.bind(this); this.handCollider.visible = false; this.moveSpeed = EHDI.GAME.sceneManager.getStageHeight() * 0.5; this.x -= this.hand.x + this.hand.width this.hint = new EHDI.aka.Container(); this.addChild(this.hint); this.hintBubble = new EHDI.aka.Sprite(EHDI.Assets.images["bubble"]); this.hintBubble.anchor.y = 1; this.hint.position.set (this.hintBubble.width * 0.1, EHDI.GAME.sceneManager.getStageHeight() * 0.45); this.hint.addChild(this.hintBubble); this.info = new EHDI.aka.Sprite(EHDI.Assets.images["bubble_exclam"]); this.hint.addChild(this.info); this.info.anchor.set(0.5, 0.5); this.info.position.set(this.hintBubble.width * 0.5, - this.hintBubble.height * 0.5); this.hint.scale.set(0, 0); this.hint.visible = false; }; EHDI.components.Hand.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.Hand.prototype.goTo = function(y) { var toTarget = y; if(y - this.hand.height * this.hand.anchor.y < 90) toTarget = 90 + this.hand.height * this.hand.anchor.y; else if(y + 105 + this.handCollider.height * this.handCollider.anchor.y > EHDI.GAME.sceneManager.getStageHeight()) toTarget = EHDI.GAME.sceneManager.getStageHeight() - 105 - this.handCollider.height * this.handCollider.anchor.y; this.targetY = toTarget; }; EHDI.components.Hand.prototype.enter = function() { this.tween = TweenLite.to(this, 0.25, {x : 0, ease: Power0.easeNone, onComplete: EHDI.GAME.gameScene.startGame.bind(EHDI.GAME.gameScene)}); }; EHDI.components.Hand.prototype.pause = function() { this.tween.pause(); }; EHDI.components.Hand.prototype.resume = function() { this.tween.play(); }; EHDI.components.Hand.prototype.moveHand = function(dt) { if(EHDI.GAME.pauseButton.isPaused) return; if(this.hand.y > this.targetY) { this.vy = -this.moveSpeed; } else if(this.hand.y < this.targetY) { this.vy = this.moveSpeed; } else if (this.hand.y === this.targetY) { this.vy = 0; } this.hand.y += this.vy * dt / 1000; this.shadow.y += this.vy * dt / 1000; this.arm.y += this.vy * dt / 1000; this.handCollider.y += this.vy * dt / 1000; this.hint.y += this.vy * dt / 1000; if(this.sheep) { this.sheep.y += this.vy * dt / 1000; } if(this.hand.y < this.targetY && this.vy === -this.moveSpeed) { this.hand.y = this.targetY; this.arm.y = this.targetY - this.arm.height * 0.7; this.shadow.y = this.targetY + 105; this.handCollider.y = this.targetY + 105; this.hint.y = this.targetY - 30; if(this.sheep) { this.sheep.y = this.targetY; } } else if(this.hand.y > this.targetY && this.vy === this.moveSpeed) { this.hand.y = this.targetY; this.arm.y = this.targetY - this.arm.height * 0.7; this.shadow.y = this.targetY + 105; this.handCollider.y = this.targetY + 105; this.hint.y = this.targetY - 30; if(this.sheep) { this.sheep.y = this.targetY; } } if(this.hand.y === 90 + this.hand.height * this.hand.anchor.y) { this.flipHint = true; this.hint.y = this.hand.y + 30; if(this.hint.scale.y === 1) { this.hint.scale.set(1, -1); this.info.scale.y = -1; } } else { this.flipHint = false; this.hint.y = this.hand.y - 30; if(this.hint.scale.y === -1) { this.hint.scale.set(1, 1); this.info.scale.y = 1; } } this.zIndex = this.handCollider.y; EHDI.GAME.gameScene.particleContainer.zIndex = this.handCollider.y; }; EHDI.components.Hand.prototype.idleHand = function() { if(!this.sheep) this.hand.texture = EHDI.Assets.images["arm_lower1"]; }; EHDI.components.Hand.prototype.grabHand = function() { if(!this.sheep) this.hand.texture = EHDI.Assets.images["arm_lower4"]; }; EHDI.components.Hand.prototype.revertHand = function () { EHDI.GAME.pauseButton.isEndGame = true; EHDI.GAME.updateManager.removeFrameListener(this.updateFunction); var offScreen = -(this.hand.x + this.hand.width + 75); TweenLite.to(this, 0.5, {x : offScreen, onComplete: EHDI.GAME.gameScene.endGame}); }; EHDI.components.Hand.prototype.destroyHand = function() { this.hand.texture = EHDI.Assets.images["arm_lower3"]; this.arm.y += this.arm.height * 0.3; } EHDI.components.Hand.prototype.moveHandPosition = function (value) { this.hand.x += value; this.arm.width += value; this.shadow.x += value; this.handCollider.x += value; this.sheep.x += value; }; EHDI.components.Hand.prototype.getSheep = function (number) { EHDI.GAME.updateManager.removeFrameListener(this.updateFunction); this.hand.texture = EHDI.Assets.images["arm_lower2"]; //this.hand.y += this.hand.height * 0.2; var color = "grey"; if(number === 2) color = "brown"; else if(number === 3) color = "white" this.sheepArmature = EHDI.GAME.dbFactory.buildArmature("lambs_2"); this.sheepArmature.animation.gotoAndPlay("lamb_" + color + "_an", -1, -1, 0); dragonBones.WorldClock.clock.add(this.sheepArmature); this.sheep = this.sheepArmature.getDisplay(); this.sheep.position.set(this.hand.x + this.hand.width * 0.7, this.hand.y); this.addChild(this.sheep); }; EHDI.components.Hand.prototype.showHint = function(obstacle) { if(this.hint.visible) return; this.toHide = false; if(this.hintTimeline) this.hintTimeline.kill(); if(obstacle) this.info.texture = EHDI.Assets.images["bubble_exclam"]; else this.info.texture = EHDI.Assets.images["bubble_gizmo"]; this.hint.scale.set(0, 0); this.hint.visible = true; this.hintTimeline = new TimelineMax(); if(this.flipHint) { this.hintTimeline.to(this.hint.scale, 0.05, {x : 1, y : -1, ease : Back.easeOut}); this.info.scale.y = -1; } else { this.hintTimeline.to(this.hint.scale, 0.05, {x : 1, y : 1, ease : Back.easeOut}); this.info.scale.y = 1; } }; EHDI.components.Hand.prototype.hideHint = function() { if(this.toHide) return; this.toHide = true; if(this.hintTimeline) this.hintTimeline.kill(); this.hintTimeline = new TimelineMax(); this.hintTimeline.to(this.hint.scale, 0.075, {x : 0, y : 0, ease : Back.easeIn}); this.hintTimeline.add(this.invisibleHint.bind(this)); }; EHDI.components.Hand.prototype.invisibleHint = function() { this.toHide = false; this.hint.visible = false; }