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