From 668dfd49fac6ae93e36d9caee9de86c142221b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Fri, 10 May 2019 09:11:30 +0900 Subject: [PATCH] Add: God's next chocoball --- src/game/mouse/one_to_fifty/chocoball.js | 11 +++-- src/game/mouse/one_to_fifty/game.js | 55 ++++++++++++++++++++---- src/game/mouse/one_to_fifty/god.js | 26 ++++++++--- src/game/mouse/one_to_fifty/loading.js | 1 + 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/game/mouse/one_to_fifty/chocoball.js b/src/game/mouse/one_to_fifty/chocoball.js index 67c4372..5ffd9f2 100644 --- a/src/game/mouse/one_to_fifty/chocoball.js +++ b/src/game/mouse/one_to_fifty/chocoball.js @@ -3,9 +3,6 @@ Chocoball.constructor = Chocoball; function Chocoball(index, onClickHandler) { this.index = index; - this.row = Math.floor(index / 5); - this.col = index % 5; - this.onClickHandler = onClickHandler; this.initVariables(); @@ -17,6 +14,14 @@ function Chocoball(index, onClickHandler) { Chocoball.prototype.initVariables = function(textContent) { this.isActivated = false; this.number = 0; + + if(this.index == 100) { + this.col = 6.4; + this.row = 1; + } else { + this.row = Math.floor(this.index / 5); + this.col = this.index % 5; + } } Chocoball.prototype.drawChocoball = function() { diff --git a/src/game/mouse/one_to_fifty/game.js b/src/game/mouse/one_to_fifty/game.js index ee1e6da..21e7bb9 100644 --- a/src/game/mouse/one_to_fifty/game.js +++ b/src/game/mouse/one_to_fifty/game.js @@ -32,6 +32,7 @@ var Game = { // init game elements this.initVariables(); + this.drawObjects(); // bottom ui @@ -46,9 +47,13 @@ var Game = { }, initVariables: function() { + this.nextNumber = 1; + this.firstChocoballArray = this.makeChocoballArray(1, 25); this.secondChocoballArray = this.makeChocoballArray(26, 50); + }, + drawObjects: function() { this.chocoballs = new Array(); for(var i = 0; i < 25; i++) { var chocoball = new Chocoball( @@ -59,9 +64,39 @@ var Game = { this.chocoballs.push(chocoball); } - this.god = new God(game.world.width - 120, Game.GOD_POSITION_Y + 100, this); + var graphics = game.add.graphics(0, 0); + var triangleStartX = God.POSITION_X; + var triangleStartY = God.POSITION_Y - 220; + var triangleHalfWidth = 20; + var triangleHeight = 40; + graphics.beginFill(0xFFFFFF); + graphics.lineStyle(20, 0x000000); + graphics.moveTo(triangleStartX, triangleStartY); + graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - triangleHeight); + graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - triangleHeight); + graphics.lineTo(triangleStartX, triangleStartY); + graphics.endFill(); - this.nextNumber = 1; + graphics.lineStyle(10, 0x000000); + graphics.beginFill(0xFFFFFF); + graphics.drawCircle(God.POSITION_X, God.POSITION_Y - 340, 200); + graphics.endFill(); + + graphics.beginFill(0xFFFFFF); + graphics.lineStyle(0); + graphics.moveTo(triangleStartX, triangleStartY); + graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - triangleHeight); + graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - triangleHeight); + graphics.lineTo(triangleStartX, triangleStartY); + graphics.endFill(); + + this.nextChocoball = new Chocoball( + 100, + (function(chocoball) { console.log("no event") }).bind(this) + ); + this.nextChocoball.setNumber(this.nextNumber); + + this.god = new God(God.POSITION_X, God.POSITION_Y, this); }, makeChocoballArray(firstNumber, lastNumber) { @@ -87,17 +122,21 @@ var Game = { if(chocoball.number == 1) this.stopWatch.start(); - if(chocoball.number != this.nextNumber) { - console.log("wrong"); - return; - } else { + if(chocoball.number == this.nextNumber) { this.nextNumber++; + this.god.animateHappy(); + } else { + console.log("wrong"); + this.god.animateAngry(); + return; } - if(chocoball.number < 25) + if(chocoball.number < 25) { chocoball.setNumber(this.secondChocoballArray[chocoball.index]); - else + this.nextChocoball.setNumber(this.nextNumber); + } else { chocoball.setActive(false); + } if(chocoball.number == 50) { console.log("game clear"); diff --git a/src/game/mouse/one_to_fifty/god.js b/src/game/mouse/one_to_fifty/god.js index 41fe21a..5d39fac 100644 --- a/src/game/mouse/one_to_fifty/god.js +++ b/src/game/mouse/one_to_fifty/god.js @@ -3,6 +3,7 @@ God = function(x, y, mainGame) { this.isActivated = true; Phaser.Sprite.call(this, game, x, y, 'god_angry'); + // this.anchor.setTo(0.5, 1); this.anchor.setTo(0.5, 1); this.scale.set(0.5); @@ -11,6 +12,8 @@ God = function(x, y, mainGame) { // this.events.onInputDown.add(this.onDown, this); game.add.existing(this); + + this.smileAgain(); } God.prototype = Object.create(Phaser.Sprite.prototype); @@ -40,10 +43,10 @@ God.prototype.setScale = function(size) { God.prototype.animateHappy = function(type) { this.loadTexture('god_happy'); - this.mainGame.speechBubble.showSpeechBubble(type); + // this.mainGame.speechBubble.showSpeechBubble(type); 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.6, y:0.6}, 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); @@ -52,10 +55,12 @@ God.prototype.animateHappy = function(type) { God.prototype.animateAngry = function(type) { this.loadTexture('god_angry'); - this.mainGame.speechBubble.showSpeechBubble(type); + // this.mainGame.speechBubble.showSpeechBubble(type); 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}, 1000, Phaser.Easing.Quadratic.In, true, 0); + tween.to({x:0.6}, 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); @@ -65,4 +70,15 @@ God.prototype.animateAngry = function(type) { God.prototype.smileAgain = function() { this.scale.set(0.5); this.loadTexture('god_smile'); -} \ No newline at end of file +} + + +God.loadResources = function() { + game.load.image('god_angry', '../../../resources/image/character/god/god_hungry.png'); + game.load.image('god_smile', '../../../resources/image/character/god/god_smile.png'); + game.load.image('god_happy', '../../../resources/image/character/god/god_happy.png'); + +} + +God.POSITION_X = 840; +God.POSITION_Y = 640; \ No newline at end of file diff --git a/src/game/mouse/one_to_fifty/loading.js b/src/game/mouse/one_to_fifty/loading.js index 56a90d8..9750c8a 100644 --- a/src/game/mouse/one_to_fifty/loading.js +++ b/src/game/mouse/one_to_fifty/loading.js @@ -35,6 +35,7 @@ var Loading = { game.load.image('card_edge', '../../../resources/image/ui/card_selected.png'); Chocoball.loadResources(); + God.loadResources(); // game.load.image('a', '../../../resources/image/icon/fullscreen_white.png'); // game.load.image('b', '../../../resources/image/icon/fullscreen_white.png');