God.prototype = Object.create(Phaser.Sprite.prototype); God.prototype.constructor = God; function God(mainGame) { this.mainGame = mainGame; Phaser.Sprite.call(this, game, God.POSITION_X, God.POSITION_Y, 'god_smile'); this.anchor.setTo(0.5, 1); this.scale.set(0.5); this.inputEnabled = false; game.add.existing(this); this.speechBubble = new SpeechBubble(); this.speechBubble.hide(); this.makeParticles(); } God.prototype.makeParticles = function() { game.physics.startSystem(Phaser.Physics.ARCADE); // full heart 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); // empty heart this.emptyHeartEmitter = game.add.emitter(God.POSITION_X, God.POSITION_Y - 150, 10); 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; // angry 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.minParticleScale = 0.5; this.angryEmitter.maxParticleScale = 1; this.angryEmitter.gravity = -1000; } God.prototype.isOver = function(x, y) { var halfWidth = (this.width - God.OUT_OF_FACE_WIDTH) / 2; var halfHeight = this.height / 2; if(x < this.x - halfWidth) return false; else if(this.x + halfWidth < x) return false; else if(y < this.y - this.height + God.OUT_OF_FACE_HEIGHT) return false; else if(this.y - God.OUT_OF_FACE_HEIGHT < y) return false; return true; } God.prototype.animateHappy = function() { this.speechBubble.animateRoundSpeech(God.SPEECH_X, God.SPEECH_Y, "맛있어. ^o^"); this.particleBurst(God.REACTION_WELLDONE); 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.onComplete.add(this.smileAgain, this); tween.start(); } God.prototype.animateSmile = function() { this.speechBubble.animateRectSpeech(God.SPEECH_X, God.SPEECH_Y, "좀 질기네. -_-"); this.particleBurst(God.REACTION_MEDIUM); this.loadTexture('god_smile'); var tween = game.add.tween(this.scale); tween.to({x:0.7, y:0.7}, 1000, Phaser.Easing.Bounce.Out, true, 0); tween.onComplete.add(this.smileAgain, this); tween.start(); } God.prototype.animateAngryWithRare = function() { this.speechBubble.animateStarSpeech(God.SPEECH_X, God.SPEECH_Y, "날고기 싫어!!!"); this.particleBurst(God.REACTION_RARE); 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.onComplete.add(this.smileAgain, this); tween.start(); } God.prototype.animateAngryWithBurnBlack = function() { this.speechBubble.animateDoubleStarSpeech(God.SPEECH_X, God.SPEECH_Y, "탄고기\n안먹어!!!"); this.particleBurst(God.REACTION_BURN_BLACK); 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.onComplete.add(this.smileAgain, this); tween.start(); } 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_WELLDONE: this.fullHeartEmitter.start(true, God.EFFECT_LIFE_TIME_MS, 100, 10, true); break; case God.REACTION_MEDIUM: this.emptyHeartEmitter.start(true, God.EFFECT_LIFE_TIME_MS / 2, 100, 15, true); break; case God.REACTION_RARE: this.angryEmitter.forEach( function(particle) { particle.tint = 0xff6060; } ); this.angryEmitter.start(true, God.EFFECT_LIFE_TIME_MS, 100, 20, true); break; case God.REACTION_BURN_BLACK: this.angryEmitter.forEach( function(particle) { particle.tint = 0x000000; } ); 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 = 120; God.HEAD_HEIGHT = 30; God.OUT_OF_FACE_WIDTH = 30; God.OUT_OF_FACE_HEIGHT = 30; God.EFFECT_LIFE_TIME_MS = 1200; God.REACTION_WELLDONE = 0; God.REACTION_MEDIUM = 1; God.REACTION_RARE = 2; God.REACTION_BURN_BLACK = 3; God.SPEECH_X = God.POSITION_X - 200; God.SPEECH_Y = God.POSITION_Y - 200;