StoveDial.prototype = Object.create(Phaser.Sprite.prototype); StoveDial.prototype.constructor = StoveDial; function StoveDial(x, y) { Phaser.Sprite.call(this, game, x, y, 'stove_dial'); this.anchor.set(0.5); this.scale.set(1.3); this.smoothed = false; this.inputEnabled = true; game.add.existing(this); this.events.onInputDown.add( (function() { this.onDown(); }).bind(this), this ); this.addDotSprite(); this.burnLevel = HeatPlate.BURN_LEVEL_WEAK; this.setDialLevel(); } StoveDial.prototype.addDotSprite = function() { this.dot = game.make.sprite(0, -27, "stove_dial_dot"); this.dot.anchor.set(0.5); this.dot.smoothed = false; this.dot.tint = 0xff0000; this.addChild(this.dot); } StoveDial.prototype.onDown = function() { switch(this.burnLevel) { case HeatPlate.BURN_LEVEL_WEAK: this.burnLevel = HeatPlate.BURN_LEVEL_NORMAL; break; case HeatPlate.BURN_LEVEL_NORMAL: this.burnLevel = HeatPlate.BURN_LEVEL_STRONG; break; case HeatPlate.BURN_LEVEL_STRONG: this.burnLevel = HeatPlate.BURN_LEVEL_WEAK; break; } this.setDialLevel(); this.onChangeDialLevel(this.burnLevel); } StoveDial.prototype.setOnChangeDialLevelHandler = function(eventHandler) { this.onChangeDialLevel = eventHandler; } StoveDial.prototype.setDialLevel = function() { switch(this.burnLevel) { case HeatPlate.BURN_LEVEL_WEAK: this.angle = 30; this.dot.tint = StoveDial.BURN_COLOR_WEAK; break; case HeatPlate.BURN_LEVEL_NORMAL: this.angle = 60; this.dot.tint = StoveDial.BURN_COLOR_NORMAL; break; case HeatPlate.BURN_LEVEL_STRONG: this.angle = 90; this.dot.tint = StoveDial.BURN_COLOR_STRONG; break; } } StoveDial.BURN_COLOR_WEAK = 0xf7d708; StoveDial.BURN_COLOR_NORMAL = 0xbd5915; StoveDial.BURN_COLOR_STRONG = 0xcd0030;