Fix: alien ES5 bug

This commit is contained in:
2018-09-14 22:47:54 +09:00
parent 6568eb5292
commit 9d1a57a997
3 changed files with 233 additions and 242 deletions
+15 -15
View File
@@ -1,7 +1,8 @@
class Alien extends Phaser.Sprite {
Alien.prototype = Object.create(Phaser.Sprite.prototype);
Alien.constructor = Alien;
constructor(initialX, initialY, onGoOnstageFunction, onFiredFunction, onEscapedFunction) {
super();
function Alien(initialX, initialY, onGoOnstageFunction, onFiredFunction, onEscapedFunction) {
// super();
this.isActivated = false;
this.isOnWaitingRoom = true;
@@ -30,21 +31,21 @@ class Alien extends Phaser.Sprite {
game.add.existing(this);
}
onOut() {
Alien.prototype.onOut = function() {
if(!this.isActivated)
return;
this.tint = 0xffffff;
}
onOver() {
Alien.prototype.onOver = function() {
if(!this.isActivated)
return;
this.tint = 0xffaaaa;
}
onDown() {
Alien.prototype.onDown = function() {
if(!this.isActivated)
return;
@@ -57,7 +58,7 @@ class Alien extends Phaser.Sprite {
}
stop() {
Alien.prototype.stop = function() {
this.setActive(false);
this.removeTween();
@@ -65,7 +66,7 @@ class Alien extends Phaser.Sprite {
// this.scale.set(0);
}
setActive(isActivated) {
Alien.prototype.setActive = function(isActivated) {
this.isActivated = isActivated;
if(this.isActivated) {
@@ -75,7 +76,7 @@ class Alien extends Phaser.Sprite {
}
}
removeTween() {
Alien.prototype.removeTween = function() {
if(this.tweenScaleUp !== null) {
this.tweenScaleUp.stop();
this.tweenScaleUp = null;
@@ -86,7 +87,7 @@ class Alien extends Phaser.Sprite {
}
}
goWaitingRoom() {
Alien.prototype.goWaitingRoom = function() {
this.isOnWaitingRoom = true;
this.x = this.initialX;
@@ -94,7 +95,7 @@ class Alien extends Phaser.Sprite {
this.scale.set(Alien.WAITING_SCALE);
}
goOnstage() {
Alien.prototype.goOnstage = function() {
this.isOnWaitingRoom = false;
this.goRandomPosition();
@@ -102,14 +103,14 @@ class Alien extends Phaser.Sprite {
this.onGoOnstageFunction();
}
onFired() {
Alien.prototype.onFired = function() {
if(typeof this.onFiredFunction !== "undefined")
this.onFiredFunction(this);
this.goRandomPosition();
}
goRandomPosition() {
Alien.prototype.goRandomPosition = function() {
// set random position
const SPAWN_BOX_LEFT = 80;
const SPAWN_BOX_WIDTH = game.world.width - 160;
@@ -140,7 +141,7 @@ class Alien extends Phaser.Sprite {
this.tweenScaleUp.start();
}
onEscaped() {
Alien.prototype.onEscaped = function() {
if(!this.isActivated)
return;
@@ -148,7 +149,6 @@ class Alien extends Phaser.Sprite {
this.onEscapedFunction();
}
}
Alien.DEFAULT_SPEED_SEC = 3000;
Alien.WAITING_SCALE = 2;
+13 -16
View File
@@ -1,11 +1,9 @@
class AlienTimer {
constructor(aliens) {
function AlienTimer(aliens) {
this.aliens = aliens;
this.activatedAlienIndex = 0;
let posX = this.aliens[0].x;
let posY = this.aliens[0].y - AlienTimer.MOVE_UP_AMOUNT_PX;
var posX = this.aliens[0].x;
var posY = this.aliens[0].y - AlienTimer.MOVE_UP_AMOUNT_PX;
this.timerText = game.add.text(posX, posY, "30", AlienTimer.DEFAULT_TEXT_FONT);
this.timerText.anchor.set(0.5);
@@ -22,7 +20,7 @@ class AlienTimer {
this.timeLeft = this.timeInterval;
}
start() {
AlienTimer.prototype.start = function() {
this.enableTimerOn(this.getActivatedAlien());
// this.getActivatedAlien().setActive(true);
this.timerText.text = this.timeLeft.toString();
@@ -30,19 +28,19 @@ class AlienTimer {
this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this);
}
pause() {
AlienTimer.prototype.pause = function() {
}
stop() {
AlienTimer.prototype.stop = function() {
if(this.timerEvent)
this.removeTimer();
this.timerText.text = "";
for(let i = 0; i < this.aliens.length; i++)
for(var i = 0; i < this.aliens.length; i++)
this.aliens[i].stop();
}
next() {
AlienTimer.prototype.next = function() {
this.timeLeft = this.timeInterval;
this.timerText.text = this.timeLeft.toString();
@@ -56,21 +54,21 @@ class AlienTimer {
this.enableTimerOn(this.getActivatedAlien());
}
getActivatedAlien() {
AlienTimer.prototype.getActivatedAlien = function() {
return this.aliens[this.activatedAlienIndex];
}
enableTimerOn(alien) {
AlienTimer.prototype.enableTimerOn = function(alien) {
alien.setActive(true);
this.timerText.x = alien.x;
}
disableTimerOn(alien) {
AlienTimer.prototype.disableTimerOn = function(alien) {
alien.setActive(false);
this.timerText.text = "";
}
updateTimer() {
AlienTimer.prototype.updateTimer = function() {
this.timeLeft--;
if(this.timeLeft == 0) {
this.timeLeft = this.timeInterval;
@@ -81,12 +79,11 @@ class AlienTimer {
}
}
removeTimer() {
AlienTimer.prototype.removeTimer = function() {
game.time.events.remove(this.timerEvent);
this.timerEvent = null;
}
}
AlienTimer.DEFAULT_TEXT_FONT = {
font: "bold 30px Arial",
+10 -16
View File
@@ -1,16 +1,10 @@
/////////////////////////////
// Loading
var Loading = {
// var x = 32;
// var y = 80;
class Loading {
preload() {
preload: function() {
// this.game.load.image('loadingbar', './image/phaser.png');
}
},
create() {
create: function() {
// let userID = sessionStorage.getItem("UserID");
// console.log("userID : " + userID);
@@ -30,9 +24,9 @@ class Loading {
this.game.load.onLoadComplete.add(this.loadComplete, this);
this.startLoading();
}
},
startLoading() {
startLoading: function() {
this.game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
this.game.load.image('star', '../../../resources/image/background/star_7x7.png');
@@ -64,9 +58,9 @@ class Loading {
// this.game.load.image('medal_bronze', './image/medal_bronze.png');
this.game.load.start();
}
},
fileComplete(progress, cacheKey, success, totalLoaded, totalFiles) {
fileComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) {
// this.preloadBar.alpha = progress / 100;
// console.log('progress : ' + progress);
@@ -82,9 +76,9 @@ class Loading {
// x = 32;
// y += 332;
// }
}
},
loadComplete(progress, cacheKey, success, totalLoaded, totalFiles) {
loadComplete: function(progress, cacheKey, success, totalLoaded, totalFiles) {
// this.preloadBar.alpha = 1;
if(isDebugMode()) {