From 3e2ebf4797fab968afbb948e5f2e6ac82a13a8ef 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 08:40:38 +0900 Subject: [PATCH] Add: onClickChocobal --- src/game/mouse/one_to_fifty/chocoball.js | 17 +++--- src/game/mouse/one_to_fifty/game.js | 53 ++++++++++++++++-- src/game/mouse/one_to_fifty/god.js | 68 ++++++++++++++++++++++++ src/web/client/onetofifty.html | 16 +++--- 4 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 src/game/mouse/one_to_fifty/god.js diff --git a/src/game/mouse/one_to_fifty/chocoball.js b/src/game/mouse/one_to_fifty/chocoball.js index 9583021..67c4372 100644 --- a/src/game/mouse/one_to_fifty/chocoball.js +++ b/src/game/mouse/one_to_fifty/chocoball.js @@ -16,6 +16,7 @@ function Chocoball(index, onClickHandler) { Chocoball.prototype.initVariables = function(textContent) { this.isActivated = false; + this.number = 0; } Chocoball.prototype.drawChocoball = function() { @@ -24,25 +25,26 @@ Chocoball.prototype.drawChocoball = function() { this.body = game.add.sprite(x, y, 'choco_body'); this.body.scale.set(1); this.body.anchor.set(0.5); - this.body.tint = 0xff0000; + this.body.tint = 0x553333; + // this.body.tint = 0xff0000; this.body.inputEnabled = true; this.body.events.onInputDown.add(this.onClick, this); - this.number = this.makeNumber("50"); - this.body.addChild(this.number); + this.numberText = this.makeNumber(""); + this.body.addChild(this.numberText); this.gloss = game.add.sprite(x, y, 'choco_gloss'); this.gloss.scale.set(1); this.gloss.anchor.set(0.5); } -Chocoball.prototype.makeNumber = function(textContent) { +Chocoball.prototype.makeNumber = function(numberText) { var width = 0; var height = this.width / 30; - var number = game.add.text(width, height, textContent, Chocoball.FONT_STYLE); + var number = game.add.text(width, height, numberText, Chocoball.FONT_STYLE); number.anchor.set(0.5); number.lineSpacing = Chocoball.DEFAULT_TEXT_LINE_SPACING_PX; @@ -50,12 +52,15 @@ Chocoball.prototype.makeNumber = function(textContent) { } Chocoball.prototype.setNumber = function(number) { - this.number.text = number; + this.number = number; + this.numberText.text = number; } Chocoball.prototype.setActive = function(isActivated) { this.isActivated = isActivated; + this.body.visible = isActivated; + this.gloss.visible = isActivated; } Chocoball.prototype.onClick = function() { diff --git a/src/game/mouse/one_to_fifty/game.js b/src/game/mouse/one_to_fifty/game.js index 4865d48..ee1e6da 100644 --- a/src/game/mouse/one_to_fifty/game.js +++ b/src/game/mouse/one_to_fifty/game.js @@ -46,12 +46,32 @@ var Game = { }, initVariables: function() { + this.firstChocoballArray = this.makeChocoballArray(1, 25); + this.secondChocoballArray = this.makeChocoballArray(26, 50); + this.chocoballs = new Array(); for(var i = 0; i < 25; i++) { - var chocoball = new Chocoball(i, this.onClickChocoball); - chocoball.setNumber(i); + var chocoball = new Chocoball( + i, + (function(chocoball) { this.onClickChocoball(chocoball); }).bind(this) + ); + chocoball.setNumber(this.firstChocoballArray[i]); this.chocoballs.push(chocoball); } + + this.god = new God(game.world.width - 120, Game.GOD_POSITION_Y + 100, this); + + this.nextNumber = 1; + }, + + makeChocoballArray(firstNumber, lastNumber) { + var numberArray = new Array(); + for(var i = firstNumber; i < lastNumber + 1; i++) { + numberArray.push(i); + } + + var randomArray = Phaser.ArrayUtils.shuffle(numberArray); + return randomArray; }, back: function() { @@ -61,12 +81,32 @@ var Game = { onClickChocoball: function(chocoball) { - console.log(chocoball.index); + // console.log(chocoball.index); + console.log(chocoball.number); + + if(chocoball.number == 1) + this.stopWatch.start(); + + if(chocoball.number != this.nextNumber) { + console.log("wrong"); + return; + } else { + this.nextNumber++; + } + + if(chocoball.number < 25) + chocoball.setNumber(this.secondChocoballArray[chocoball.index]); + else + chocoball.setActive(false); + + if(chocoball.number == 50) { + console.log("game clear"); + this.gameClear(); + } }, startGame: function() { - this.stopWatch.start(); }, gameClear: function() { @@ -75,6 +115,7 @@ var Game = { if(!isExperienceMaestroAccount()) this.updateResultRecord(); + var missionClearText = new MissionClearText(); game.time.events.add(Game.GAME_OVER_WAIT_TIME_MS, this.goResult, this); }, @@ -88,10 +129,14 @@ var Game = { if(!isExperienceMaestroAccount()) this.updateResultRecord(); + var timeOverText = new TimeOverText(); game.time.events.add(Game.GAME_OVER_WAIT_TIME_MS, this.goResult, this); }, updateResultRecord: function() { + console.log("update record : " + sessionStorageManager.getRecord()); + return; + if(sessionStorageManager.getMaestroAccountType() < 100) { // experience account this.dbConnectManager.updateResultRecord( sessionStorageManager.getMaestroID(), diff --git a/src/game/mouse/one_to_fifty/god.js b/src/game/mouse/one_to_fifty/god.js new file mode 100644 index 0000000..41fe21a --- /dev/null +++ b/src/game/mouse/one_to_fifty/god.js @@ -0,0 +1,68 @@ +God = function(x, y, mainGame) { + this.mainGame = mainGame; + this.isActivated = true; + + Phaser.Sprite.call(this, game, x, 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); +} + +God.prototype = Object.create(Phaser.Sprite.prototype); +God.prototype.constructor = God; +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(type) { + this.loadTexture('god_happy'); + 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.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(); +} + +God.prototype.animateAngry = function(type) { + this.loadTexture('god_angry'); + 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, 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(); +} + +God.prototype.smileAgain = function() { + this.scale.set(0.5); + this.loadTexture('god_smile'); +} \ No newline at end of file diff --git a/src/web/client/onetofifty.html b/src/web/client/onetofifty.html index 67491fe..441e5e3 100644 --- a/src/web/client/onetofifty.html +++ b/src/web/client/onetofifty.html @@ -39,18 +39,19 @@ - + - - - - - - + + + + + + + @@ -67,6 +68,7 @@ +