From 7b19f5b95896e00204d7218aab45898e944b0332 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:52:18 +0900 Subject: [PATCH] Add: alien wave --- src/game/mouse/dodge/alien.js | 76 +++++++++++++++++++++---------- src/game/mouse/dodge/game.js | 56 +++++++++++++---------- src/game/mouse/dodge/spaceship.js | 3 +- 3 files changed, 85 insertions(+), 50 deletions(-) diff --git a/src/game/mouse/dodge/alien.js b/src/game/mouse/dodge/alien.js index 4e0ef06..77d48f7 100644 --- a/src/game/mouse/dodge/alien.js +++ b/src/game/mouse/dodge/alien.js @@ -5,20 +5,25 @@ 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; + this.speedLevel = 0; + + Phaser.Sprite.call(this, game, 0, 0, 'alien_normal'); this.anchor.set(0.5); game.add.existing(this); - this.moveRandomPosition(); + // game.physics.enable(this, Phaser.Physics.ARCADE); + game.physics.arcade.enable(this); - // this.setActive(true); + this.moveRandomPosition(); } @@ -45,15 +50,15 @@ Alien.prototype.moveRandomPosition = function() { this.angleFromAlien = alienAngle; - this.responCount++; - console.log(this.responCount); - this.speedUp(this.responCount); + this.upgradeLevel(); } Alien.prototype.update = function() { if(!this.isActivated) return; + // game.physics.arcade.overlap(this.spaceship, this, this.collisionHandler, null, this); + game.physics.arcade.collide(this.spaceship, this, this.collisionHandler, null, this); var deltaTime = game.time.elapsed / 1000; var radians = this.angleFromAlien * Math.PI / 180; @@ -71,6 +76,10 @@ Alien.prototype.update = function() { } +Alien.prototype.collisionHandler = function() { + console.log("collision"); +} + Alien.prototype.stop = function() { this.setActive(false); } @@ -87,7 +96,6 @@ Alien.prototype.getAngle = function (x1, y1, x2, y2){ var dx = x2 - x1; var dy = y2 - y1; - var rad= Math.atan2(dx, dy); var degree = (rad * 180) / Math.PI ; if(degree < 0) @@ -96,24 +104,45 @@ Alien.prototype.getAngle = function (x1, y1, x2, y2){ return degree; } -Alien.prototype.speedUp = function(responCount) { - var boostLevel = 0; +Alien.prototype.upgradeLevel = function() { + if(this.speedLevel == 5) + return; - 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; + var rand = game.rnd.integerInRange(0, 100); - if(boostLevel > 5) - boostLevel = 5; + var successNumber = 0; + switch(this.speedLevel) { + case 0: + successNumber = 90; + break; - switch(boostLevel) { + case 1: + successNumber = 80; + break; + + case 2: + successNumber = 70; + break; + + case 3: + successNumber = 60; + break; + + case 4: + successNumber = 50; + break; + } + + if(rand < successNumber) + this.speedUp(); +} + +Alien.prototype.speedUp = function() { + this.speedLevel++; + + this.speed = Alien.DEFAULT_SPEED_DOT_PER_SEC + (this.boostSpeed * this.speedLevel); + + switch(this.speedLevel) { case 1: this.tint = 0xffffff; break; @@ -134,12 +163,11 @@ Alien.prototype.speedUp = function(responCount) { this.tint = 0x888888; break; } - this.speed = Alien.DEFAULT_SPEED_DOT_PER_SEC + (this.boostSpeed * boostLevel); } -Alien.DEFAULT_SPEED_DOT_PER_SEC = 100; +Alien.DEFAULT_SPEED_DOT_PER_SEC = 150; 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 5b18c7d..a715a0d 100644 --- a/src/game/mouse/dodge/game.js +++ b/src/game/mouse/dodge/game.js @@ -1,6 +1,8 @@ var Game = { create: function() { + game.physics.enable(this, Phaser.Physics.ARCADE); + this.game.stage.backgroundColor = "#000000"; // '#4d4d4d'; this.scoreManager = new ScoreManager(); @@ -120,34 +122,38 @@ var Game = { this.ellapsedTime += 1; // console.log(this.ellapsedTime); - if(this.ellapsedTime == 1) { + if(this.ellapsedTime == 2) + this.sendWave(1); + else if(this.ellapsedTime == 4) + this.sendWave(2); + else if(this.ellapsedTime == 6) + this.sendWave(3); + else if(this.ellapsedTime == 8) + this.sendWave(4); + else if(this.ellapsedTime == 10) + this.sendWave(5); + else if(this.ellapsedTime == 12) + this.sendWave(6); + else if(this.ellapsedTime == 14) + this.sendWave(7); + else if(this.ellapsedTime == 16) + this.sendWave(8); + else if(this.ellapsedTime == 18) + this.sendWave(9); + }, + + sendWave: function(waveNo) { + if(waveNo == 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); + + return; } + + var beginAlienIndex = waveNo * 10; + var endAlienIndex = (waveNo + 1) * 10; + for(var i = beginAlienIndex; i < endAlienIndex; i++) + this.aliens[i].setActive(true); }, gameOver: function() { diff --git a/src/game/mouse/dodge/spaceship.js b/src/game/mouse/dodge/spaceship.js index 8884cb7..1bc0439 100644 --- a/src/game/mouse/dodge/spaceship.js +++ b/src/game/mouse/dodge/spaceship.js @@ -12,7 +12,8 @@ function Spaceship() { this.anchor.set(0.5); this.halfWidth = this.width / 2; - game.physics.enable(this, Phaser.Physics.ARCADE); + // game.physics.enable(this, Phaser.Physics.ARCADE); + game.physics.arcade.enable(this); this.setActive(true); }