var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.Customer = function(bread,fish,rotate, bonus) { EHDI.aka.Container.call(this); this.number = Math.floor(EHDI.NumberUtil.randomRange(2, 6)); if(bonus) { this.number = 1; this.hourglass = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_hourglass"]); this.hourglass.anchor.x = 0.5; this.hourglass.anchor.y = 0.5; this.hourglass.visible = false; } this.customer = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_p" + this.number + "_default"]); this.customer.anchor.x = 0.5; this.customer.anchor.y = 1; this.addChild(this.customer); if(this.hourglass) { this.hourglass.position.x = this.customer.width * 0.55; this.hourglass.position.y = -this.customer.height * 0.75; this.addChild(this.hourglass); } this.breadSprite = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_bread"]); this.breadSprite.anchor.x = 0.5; this.breadSprite.anchor.y = 0.5; this.addChild(this.breadSprite); this.fishSprite = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_fish"]); this.fishSprite.anchor.x = 0.5; this.fishSprite.anchor.y = 0.5; this.bread = bread; this.fish = fish; if(rotate) { this.breadSprite.position.set(-30, -135); this.fishSprite.position.set(25, -150); this.addChild(this.fishSprite); this.addChild(this.breadSprite); } else { this.breadSprite.position.set(30, -150); this.fishSprite.position.set(-30, -130); this.addChild(this.breadSprite); this.addChild(this.fishSprite); } this.breadSprite.visible = this.bread; this.fishSprite.visible = this.fish; //this.interactive = true; }; EHDI.components.Customer.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.Customer.prototype.fishToggle = function() { this.fish = !this.fish; this.fishSprite.visible = this.fish; }; EHDI.components.Customer.prototype.breadToggle = function() { this.bread = !this.bread; this.breadSprite.visible = this.bread; }; EHDI.components.Customer.prototype.happy = function() { this.customer.texture = EHDI.Assets.images["fishbread_p" + this.number + "_correct"]; }; EHDI.components.Customer.prototype.sad = function() { this.customer.texture = EHDI.Assets.images["fishbread_p" + this.number + "_wrong"]; } EHDI.components.Customer.prototype.normal = function() { this.customer.texture = EHDI.Assets.images["fishbread_p" + this.number + "_default"]; EHDI.GAME.customerSpawner.toggleInteraction(); } EHDI.components.Customer.prototype.mousedown = function() { this.processCustomer(); }; EHDI.components.Customer.prototype.touchstart = function () { this.processCustomer(); }; EHDI.components.Customer.prototype.processCustomer = function() { if(!EHDI.GAME.customerSpawner.interaction) return; if(this.reactionTimeline) this.reactionTimeline.kill(); if(this.fish && this.bread) { this.interactive = false; this.reactionTimeline = new TimelineMax({repeat : 1, yoyo : true, onComplete: EHDI.GAME.customerSpawner.moveCustomer.bind(EHDI.GAME.customerSpawner)}); this.reactionTimeline.addCallback(this.happy.bind(this)); this.reactionTimeline.to(this, 0.125, {y : this.y - EHDI.GAME.sceneManager.getStageHeight() * 0.05}); EHDI.GAME.customerSpawner.interaction = false; EHDI.GAME.scoreManager.addScore(10); if(this.number === 1) { this.hourglass.visible = true; //EHDI.GAME.timer.addTime(); } } else { EHDI.GAME.customerSpawner.interaction = false; this.reactionTimeline = new TimelineMax({repeat : 5, yoyo : true, onComplete : this.normal.bind(this)}); this.reactionTimeline.addCallback(this.sad.bind(this)); this.reactionTimeline.to(this, 0.125, {y : this.y - EHDI.GAME.sceneManager.getStageHeight() * 0.05}); } };