God.prototype = Object.create(Phaser.Sprite.prototype); God.prototype.constructor = God; function God(mainGame) { this.mainGame = mainGame; this.isActivated = true; Phaser.Sprite.call(this, game, God.POSITION_X, God.POSITION_Y, 'god_angry'); this.anchor.setTo(0.5, 1); this.scale.set(0.5); this.inputEnabled = false; // this.input.enableDrag(false); // this.events.onInputDown.add(this.onDown, this); game.add.existing(this); this.speechBubble = new SpeechBubble(); this.speechBubble.hide(); this.makeParticles(); } God.prototype.makeParticles = function() { game.physics.startSystem(Phaser.Physics.ARCADE); this.fullHeartEmitter = game.add.emitter(God.POSITION_X, God.POSITION_Y - 170, 20); this.fullHeartEmitter.makeParticles("heart_full"); // this.fullHeartEmitter.minParticleScale = 0.5; // this.fullHeartEmitter.maxParticleScale = 0.7; // this.fullHeartEmitter.minParticleSpeed.setTo(-150, -700); // this.fullHeartEmitter.maxParticleSpeed.setTo(150, -500); // this.fullHeartEmitter.gravity = 1500; this.fullHeartEmitter.width = God.HEAD_WIDTH; this.fullHeartEmitter.height = God.HEAD_HEIGHT; this.fullHeartEmitter.setRotation(-180, 180); // this.fullHeartEmitter.setAlpha(0.1, 0.3); // this.fullHeartEmitter.setScale(0.2, 0.2); // this.fullHeartEmitter.minParticleScale = 0.4; // this.fullHeartEmitter.maxParticleScale = 0.5; this.fullHeartEmitter.minParticleSpeed.setTo(-10, -200); this.fullHeartEmitter.maxParticleSpeed.setTo(10, -100); // this.fullHeartEmitter.gravity = 3000; this.fullHeartEmitter.setAlpha( 1.0, 0.0, God.EFFECT_LIFE_TIME_MS, Phaser.Easing.Bounce.In, false ); this.fullHeartEmitter.setScale( 0.4, 0.6, 0.4, 0.6, God.EFFECT_LIFE_TIME_MS, Phaser.Easing.Quadratic.Out, false ); this.emptyHeartEmitter = game.add.emitter(God.POSITION_X, God.POSITION_Y - 150, 20); this.emptyHeartEmitter.makeParticles("heart_empty"); this.emptyHeartEmitter.minParticleScale = 0.5; this.emptyHeartEmitter.maxParticleScale = 0.7; this.emptyHeartEmitter.minParticleSpeed.setTo(-150, -700); this.emptyHeartEmitter.maxParticleSpeed.setTo(150, -500); this.emptyHeartEmitter.gravity = 1500; this.angryEmitter = game.add.emitter(God.POSITION_X, God.POSITION_Y - 200, 20); this.angryEmitter.makeParticles("smoke"); this.angryEmitter.width = God.HEAD_WIDTH; this.angryEmitter.height = God.HEAD_HEIGHT; this.angryEmitter.setRotation(-90, 90); this.angryEmitter.setAlpha( 0.2, 0.0, God.EFFECT_LIFE_TIME_MS, Phaser.Easing.Bounce.In, false ); // this.angryEmitter.setAlpha(0.1, 0.3); // this.angryEmitter.setScale(0.2, 0.2); this.angryEmitter.minParticleScale = 0.5; this.angryEmitter.maxParticleScale = 1; this.angryEmitter.gravity = -300; this.angryEmitter.forEach( function(particle) { // particle.tint = 0xf0f0f0; particle.tint = 0xa08080; } ); } God.prototype.update = function() { } God.prototype.onDown = function(sprite, pointer) { console.log("onDown : " + pointer.x + ", " + pointer.y); this.animateAngry(); } God.prototype.isInRect = function(x, y) { return true; } God.prototype.onDragStop = function(sprite, pointer) { console.log("onDragStop : " + pointer.x + ", " + pointer.y); } God.prototype.setScale = function(size) { this.scale.set(size); this.backupScale = size; } God.prototype.animateHappy = function(meat) { this.speechBubble.showSpeechBubble(meat); this.loadTexture('god_happy'); var tween = game.add.tween(this.scale); tween.to({x:0.7, y:0.7}, 500, Phaser.Easing.Quadratic.Out, true, 0); // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); tween.onComplete.add(this.smileAgain, this); tween.start(); this.particleBurst(God.REACTION_HAPPY); } God.prototype.animateAngryWithRare = function(meat) { this.speechBubble.showSpeechBubble(meat); this.loadTexture('god_angry'); var tween = game.add.tween(this.scale); tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Bounce.Out, true, 0); // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); tween.onComplete.add(this.smileAgain, this); tween.start(); if(meat.getTotalCookingTime() == 0) this.particleBurst(God.REACTION_ANGRY); } God.prototype.animateAngryWithBurnBlack = function(meat) { this.speechBubble.showSpeechBubble(meat); this.loadTexture('god_angry'); var tween = game.add.tween(this.scale); tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Bounce.Out, true, 0); // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Elastic.InOut, true, 0, 2, true); // tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Linear.None, true, 0); tween.onComplete.add(this.smileAgain, this); tween.start(); this.particleBurst(God.REACTION_ANGRY); } God.prototype.smileAgain = function() { this.scale.set(0.5); this.loadTexture('god_smile'); } God.prototype.particleBurst = function(reaction) { // if(this.fullHeartEmitter.on) // this.fullHeartEmitter.on = false; // if(this.emptyHeartEmitter.on) // this.emptyHeartEmitter.on = false; switch(reaction) { case God.REACTION_HAPPY: this.fullHeartEmitter.start(true, God.EFFECT_LIFE_TIME_MS, 100, 10, true); break; case God.REACTION_SMILE: this.emptyHeartEmitter.start(true, God.EFFECT_LIFE_TIME_MS, 100, 15, true); break; case God.REACTION_ANGRY: this.angryEmitter.start(true, God.EFFECT_LIFE_TIME_MS, 100, 20, true); break; } } God.POSITION_X = GAME_SCREEN_SIZE.x - 120; God.POSITION_Y = 340; God.HEAD_WIDTH = 80; God.HEAD_HEIGHT = 30; God.EFFECT_LIFE_TIME_MS = 1200; God.REACTION_HAPPY = 0; God.REACTION_SMILE = 1; God.REACTION_ANGRY = 2;