function Mole(x, y, type) { if(type == Mole.TYPE_BIG_MOLE) { this.mole = game.add.image(x, y, "mole_grey"); this.mole.scale.set(BigMole.SCALE); } else { this.mole = game.add.image(x, y, "mole_grey_small"); this.mole.scale.set(KeyboardMole.SCALE); } this.posY = y; } Mole.prototype.alpha = function(value) { this.mole.alpha = value; } Mole.prototype.move = function(x, y) { this.mole.x = x; this.mole.y = y; this.posY = y; } Mole.prototype.anchor = function(x, y) { this.mole.anchor.x = x; this.mole.anchor.y = y; } Mole.prototype.showUpTween = function(showUpHeight) { this.tween = game.add.tween(this.mole) // .from( { y: BigMole.START_POS_Y }, 10 ) // .to( { y: BigMole.SHOW_UP_POS_Y }, BigMole.SHOW_UP_TIME_MS, "Quart.easeOut"); .from( { y: this.posY }, 10 ) .to( { y: (this.posY - showUpHeight) }, BigMole.SHOW_UP_TIME_MS, "Quart.easeOut"); this.tween.start(); } Mole.TYPE_BIG_MOLE = "big_mole"; Mole.TYPE_KEYBOARD_MOLE = "kebyard_mole"; // big mole BigMole.prototype = Object.create(Mole.prototype); BigMole.constructor = BigMole; function BigMole(x, y) { Mole.call(this, x, y, Mole.TYPE_BIG_MOLE); this.anchor(0.5, 0); // this.helmet = game.add.image(0, 0, "helmet"); this.helmet = new Helmet(); this.helmet.scale(BigMole.SCALE); this.helmet.anchor(0.5, 0); this.mole.addChild(this.helmet.getSprite()); } BigMole.prototype.showUp = function() { this.showUpTween(BigMole.SHOW_UP_HEIGHT); } BigMole.prototype.changeColor = function(keyID) { if(keyID == "KeyF" || keyID == "KeyJ") this.mole.loadTexture("mole_peach"); else this.mole.loadTexture("mole_grey"); } BigMole.prototype.changeHelmetColor = function(hammerType) { switch(hammerType) { case Hammer.TYPE_PPYONG: this.helmet.getSprite().tint = Hammer.COLOR_PPYONG; break; case Hammer.TYPE_WOOD: this.helmet.getSprite().tint = Hammer.COLOR_WOOD; break; case Hammer.TYPE_BRONZE: this.helmet.getSprite().tint = Hammer.COLOR_BRONZE; break; case Hammer.TYPE_SILVER: this.helmet.getSprite().tint = Hammer.COLOR_SILVER; break; case Hammer.TYPE_GOLD: this.helmet.getSprite().tint = Hammer.COLOR_GOLD; break; } } BigMole.SCALE = 1; BigMole.START_POS_Y = 200; BigMole.SHOW_UP_HEIGHT = 100; BigMole.SHOW_UP_TIME_MS = 200; // keyboard mole KeyboardMole.prototype = Object.create(Mole.prototype); KeyboardMole.constructor = KeyboardMole; function KeyboardMole(keyboard) { this.keyboard = keyboard; Mole.call(this, 0, 0, Mole.TYPE_KEYBOARD_MOLE); this.anchor(0, 0); this.hide(); } KeyboardMole.prototype.show = function() { this.alpha(1); } KeyboardMole.prototype.hide = function() { this.alpha(0); } KeyboardMole.prototype.moveToKey = function(text) { var x = this.keyboard.getKeyPosX(text) + KeyboardMole.OFFSET_X; var y = this.keyboard.getKeyPosY(text) + KeyboardMole.OFFSET_Y; this.move(x, y); } KeyboardMole.prototype.changeColor = function(keyID) { if(keyID == "KeyF" || keyID == "KeyJ") this.mole.loadTexture("mole_peach_small"); else this.mole.loadTexture("mole_grey_small"); } KeyboardMole.SCALE = 1.2; KeyboardMole.OFFSET_X = 4; KeyboardMole.OFFSET_Y = 4;