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.getRandomSpeechText = function(grade) { var donenessNoneTextArray = [ "날고기\n안먹어!!!", "구워서\n줘야지!!!" ]; var donenessRareTextArray = [ "덜 익었는데???", "좀 질기네.", "좀 더 익혀줘!" ]; var donenessWelldoneTextArray = [ "맛있어!\n^o^", "이 맛이지!\n^o^", "고마워!\n^o^", "꿀맛이야!\n^o^", ]; var donenessBurnBlackTextArray = [ "탄고기\n안먹어!!!", "탄고기는\n쓰레기통으로!", "태우면\n어떡해!!!" ]; var speechText = ""; var randomIndex = 0; switch(grade) { case MeatBase.DONENESS_NONE: randomIndex = Math.floor(Math.random() * donenessNoneTextArray.length); speechText = donenessNoneTextArray[randomIndex]; break; case MeatBase.DONENESS_RARE: randomIndex = Math.floor(Math.random() * donenessRareTextArray.length); speechText = donenessRareTextArray[randomIndex]; break; case MeatBase.DONENESS_WELLDONE: randomIndex = Math.floor(Math.random() * donenessWelldoneTextArray.length); speechText = donenessWelldoneTextArray[randomIndex]; break; case MeatBase.DONENESS_BURN_BLACK: randomIndex = Math.floor(Math.random() * donenessBurnBlackTextArray.length); speechText = donenessBurnBlackTextArray[randomIndex]; break; } return speechText; } God.prototype.animateHappy = function() { var speechText = this.getRandomSpeechText(MeatBase.DONENESS_WELLDONE); this.speechBubble.animateRoundSpeech(God.SPEECH_X, God.SPEECH_Y, speechText); 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() { var speechText = this.getRandomSpeechText(MeatBase.DONENESS_RARE); this.speechBubble.animateRectSpeech(God.SPEECH_X, God.SPEECH_Y, speechText); 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() { var speechText = this.getRandomSpeechText(MeatBase.DONENESS_NONE); this.speechBubble.animateStarSpeech(God.SPEECH_X, God.SPEECH_Y, speechText); 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() { var speechText = this.getRandomSpeechText(MeatBase.DONENESS_BURN_BLACK); this.speechBubble.animateDoubleStarSpeech(God.SPEECH_X, God.SPEECH_Y, speechText); 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 * 3 / 4, 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;