From 12f00b73c5f4d0a05a023c9b75a305475d545d32 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: Sun, 2 Dec 2018 15:18:37 +0900 Subject: [PATCH] Fix: speed up --- src/game/mouse/dodge/alien.js | 68 ++++++++++++++++++++++++----------- src/game/mouse/dodge/game.js | 40 ++++++++++++++++++--- 2 files changed, 84 insertions(+), 24 deletions(-) diff --git a/src/game/mouse/dodge/alien.js b/src/game/mouse/dodge/alien.js index 5b91188..4e0ef06 100644 --- a/src/game/mouse/dodge/alien.js +++ b/src/game/mouse/dodge/alien.js @@ -5,9 +5,12 @@ function Alien(spaceship) { this.spaceship = spaceship; this.isActivated = false; + this.responCount = 0; this.speed = Alien.DEFAULT_SPEED_DOT_PER_SEC; + this.boostSpeed = Alien.DEFAULT_SPEED_DOT_PER_SEC / 10; this.angleFromSpaceship = 0; this.angleFromAlien = 0; + this.responRadius = 0; Phaser.Sprite.call(this, game, 0, 0, 'alien_normal'); this.anchor.set(0.5); @@ -27,9 +30,9 @@ Alien.prototype.moveRandomPosition = function() { var radians = this.angleFromAlien * Math.PI / 180; - var radious = Alien.START_RADIOUS_PX * ( ( (100 + game.rnd.integerInRange(0, Alien.START_RANDOM_RADIOUS_PERCENT) ) / 100) ); - var posX = Math.sin(radians) * radious; - var posY = Math.cos(radians) * radious; + this.responRadius = Alien.START_Radius_PX * ( ( (100 + game.rnd.integerInRange(0, Alien.START_RANDOM_Radius_PERCENT) ) / 100) ); + var posX = Math.sin(radians) * this.responRadius; + var posY = Math.cos(radians) * this.responRadius; this.x = game.world.centerX + posX; this.y = game.world.centerY + posY; @@ -42,7 +45,9 @@ Alien.prototype.moveRandomPosition = function() { this.angleFromAlien = alienAngle; - // this.angle = this.getSpriteAngle(this.angleFromAlien); + this.responCount++; + console.log(this.responCount); + this.speedUp(this.responCount); } Alien.prototype.update = function() { @@ -61,7 +66,7 @@ Alien.prototype.update = function() { var distanceX = this.x - game.world.centerX; var distanceY = this.y - game.world.centerY; var distanceFromCenter = Math.sqrt(Math.abs(distanceX * distanceX) + Math.abs(distanceY * distanceY)); - if(distanceFromCenter > Alien.START_RADIOUS_PX) + if(distanceFromCenter > this.responRadius) this.moveRandomPosition(); } @@ -91,27 +96,50 @@ Alien.prototype.getAngle = function (x1, y1, x2, y2){ return degree; } -Alien.prototype.goRandomPosition = function() { - // set random position - var SPAWN_BOX_LEFT = 80; - var SPAWN_BOX_WIDTH = game.world.width - 160; - var SPAWN_BOX_TOP = 280; - var SPAWN_BOX_HEIGHT = game.world.height - 400; +Alien.prototype.speedUp = function(responCount) { + var boostLevel = 0; - this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH; - this.y = SPAWN_BOX_TOP + Math.random() * SPAWN_BOX_HEIGHT; + if(responCount == 2) + boostLevel = 1; + else if(responCount == 4) + boostLevel = 2; + else if(responCount == 6) + boostLevel = 3; + else if(responCount == 8) + boostLevel = 4; + else if(responCount == 10) + boostLevel = 5; - // if(isDebugMode()) { - // this.game.add.graphics() - // .beginFill(0xffffff, 0.1) - // .drawRect(SPAWN_BOX_LEFT, SPAWN_BOX_TOP, SPAWN_BOX_WIDTH, SPAWN_BOX_HEIGHT); - // } + if(boostLevel > 5) + boostLevel = 5; + switch(boostLevel) { + case 1: + this.tint = 0xffffff; + break; + + case 2: + this.tint = 0xff0000; + break; + + case 3: + this.tint = 0x00ff00; + break; + + case 4: + this.tint = 0x0000ff; + break; + + case 5: + this.tint = 0x888888; + break; + } + this.speed = Alien.DEFAULT_SPEED_DOT_PER_SEC + (this.boostSpeed * boostLevel); } Alien.DEFAULT_SPEED_DOT_PER_SEC = 100; -Alien.START_RADIOUS_PX = 600; -Alien.START_RANDOM_RADIOUS_PERCENT = 40; +Alien.START_Radius_PX = 600; +Alien.START_RANDOM_Radius_PERCENT = 40; diff --git a/src/game/mouse/dodge/game.js b/src/game/mouse/dodge/game.js index 90c321f..5b18c7d 100644 --- a/src/game/mouse/dodge/game.js +++ b/src/game/mouse/dodge/game.js @@ -112,6 +112,42 @@ var Game = { */ startGame: function() { + this.ellapsedTime = 0; + this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this); + }, + + updateTimer: function() { + this.ellapsedTime += 1; + // console.log(this.ellapsedTime); + + if(this.ellapsedTime == 1) { + for(var i = 0; i < 20; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 3) { + for(var i = 20; i < 30; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 5) { + for(var i = 30; i < 40; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 7) { + for(var i = 40; i < 50; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 9) { + for(var i = 50; i < 60; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 9) { + for(var i = 60; i < 70; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 9) { + for(var i = 70; i < 80; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 9) { + for(var i = 80; i < 90; i++) + this.aliens[i].setActive(true); + } else if(this.ellapsedTime == 9) { + for(var i = 90; i < 100; i++) + this.aliens[i].setActive(true); + } }, gameOver: function() { @@ -128,10 +164,6 @@ var Game = { return (this.alienTimer.activatedAlienIndex) * 2; }, - onAlienEscaped: function() { - this.heartManager.breakHearts(1); - } - } Game.GAME_OVER_WAIT_TIME_MS = 2000; \ No newline at end of file