Fix: alien ES5 bug
This commit is contained in:
@@ -1,93 +1,90 @@
|
||||
class AlienTimer {
|
||||
function AlienTimer(aliens) {
|
||||
this.aliens = aliens;
|
||||
this.activatedAlienIndex = 0;
|
||||
|
||||
constructor(aliens) {
|
||||
this.aliens = aliens;
|
||||
this.activatedAlienIndex = 0;
|
||||
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);
|
||||
|
||||
let posX = this.aliens[0].x;
|
||||
let 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);
|
||||
|
||||
var grd = this.timerText.context.createLinearGradient(0, 0, 0, this.timerText.height);
|
||||
grd.addColorStop(0, '#FFD68E');
|
||||
grd.addColorStop(1, '#B34C00');
|
||||
this.timerText.fill = grd;
|
||||
// this.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
this.timerText.stroke = '#000';
|
||||
this.timerText.strokeThickness = 5;
|
||||
|
||||
this.timerEvent = null;
|
||||
this.timeInterval = AlienTimer.DEFAULT_TIME_GAP_SEC;
|
||||
this.timeLeft = this.timeInterval;
|
||||
}
|
||||
|
||||
start() {
|
||||
this.enableTimerOn(this.getActivatedAlien());
|
||||
// this.getActivatedAlien().setActive(true);
|
||||
this.timerText.text = this.timeLeft.toString();
|
||||
if(this.timerEvent === null)
|
||||
this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this);
|
||||
}
|
||||
|
||||
pause() {
|
||||
}
|
||||
|
||||
stop() {
|
||||
if(this.timerEvent)
|
||||
this.removeTimer();
|
||||
this.timerText.text = "";
|
||||
|
||||
for(let i = 0; i < this.aliens.length; i++)
|
||||
this.aliens[i].stop();
|
||||
}
|
||||
|
||||
next() {
|
||||
this.timeLeft = this.timeInterval;
|
||||
this.timerText.text = this.timeLeft.toString();
|
||||
|
||||
this.activatedAlienIndex++;
|
||||
if(this.activatedAlienIndex >= this.aliens.length) {
|
||||
this.timerText.text = "";
|
||||
this.removeTimer();
|
||||
return null;
|
||||
}
|
||||
|
||||
this.enableTimerOn(this.getActivatedAlien());
|
||||
}
|
||||
|
||||
getActivatedAlien() {
|
||||
return this.aliens[this.activatedAlienIndex];
|
||||
}
|
||||
|
||||
enableTimerOn(alien) {
|
||||
alien.setActive(true);
|
||||
this.timerText.x = alien.x;
|
||||
}
|
||||
|
||||
disableTimerOn(alien) {
|
||||
alien.setActive(false);
|
||||
this.timerText.text = "";
|
||||
}
|
||||
|
||||
updateTimer() {
|
||||
this.timeLeft--;
|
||||
if(this.timeLeft == 0) {
|
||||
this.timeLeft = this.timeInterval;
|
||||
|
||||
this.getActivatedAlien().goOnstage();
|
||||
} else {
|
||||
this.timerText.text = this.timeLeft.toString();
|
||||
}
|
||||
}
|
||||
|
||||
removeTimer() {
|
||||
game.time.events.remove(this.timerEvent);
|
||||
this.timerEvent = null;
|
||||
}
|
||||
var grd = this.timerText.context.createLinearGradient(0, 0, 0, this.timerText.height);
|
||||
grd.addColorStop(0, '#FFD68E');
|
||||
grd.addColorStop(1, '#B34C00');
|
||||
this.timerText.fill = grd;
|
||||
// this.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
this.timerText.stroke = '#000';
|
||||
this.timerText.strokeThickness = 5;
|
||||
|
||||
this.timerEvent = null;
|
||||
this.timeInterval = AlienTimer.DEFAULT_TIME_GAP_SEC;
|
||||
this.timeLeft = this.timeInterval;
|
||||
}
|
||||
|
||||
AlienTimer.prototype.start = function() {
|
||||
this.enableTimerOn(this.getActivatedAlien());
|
||||
// this.getActivatedAlien().setActive(true);
|
||||
this.timerText.text = this.timeLeft.toString();
|
||||
if(this.timerEvent === null)
|
||||
this.timerEvent = game.time.events.loop(Phaser.Timer.SECOND, this.updateTimer, this);
|
||||
}
|
||||
|
||||
AlienTimer.prototype.pause = function() {
|
||||
}
|
||||
|
||||
AlienTimer.prototype.stop = function() {
|
||||
if(this.timerEvent)
|
||||
this.removeTimer();
|
||||
this.timerText.text = "";
|
||||
|
||||
for(var i = 0; i < this.aliens.length; i++)
|
||||
this.aliens[i].stop();
|
||||
}
|
||||
|
||||
AlienTimer.prototype.next = function() {
|
||||
this.timeLeft = this.timeInterval;
|
||||
this.timerText.text = this.timeLeft.toString();
|
||||
|
||||
this.activatedAlienIndex++;
|
||||
if(this.activatedAlienIndex >= this.aliens.length) {
|
||||
this.timerText.text = "";
|
||||
this.removeTimer();
|
||||
return null;
|
||||
}
|
||||
|
||||
this.enableTimerOn(this.getActivatedAlien());
|
||||
}
|
||||
|
||||
AlienTimer.prototype.getActivatedAlien = function() {
|
||||
return this.aliens[this.activatedAlienIndex];
|
||||
}
|
||||
|
||||
AlienTimer.prototype.enableTimerOn = function(alien) {
|
||||
alien.setActive(true);
|
||||
this.timerText.x = alien.x;
|
||||
}
|
||||
|
||||
AlienTimer.prototype.disableTimerOn = function(alien) {
|
||||
alien.setActive(false);
|
||||
this.timerText.text = "";
|
||||
}
|
||||
|
||||
AlienTimer.prototype.updateTimer = function() {
|
||||
this.timeLeft--;
|
||||
if(this.timeLeft == 0) {
|
||||
this.timeLeft = this.timeInterval;
|
||||
|
||||
this.getActivatedAlien().goOnstage();
|
||||
} else {
|
||||
this.timerText.text = this.timeLeft.toString();
|
||||
}
|
||||
}
|
||||
|
||||
AlienTimer.prototype.removeTimer = function() {
|
||||
game.time.events.remove(this.timerEvent);
|
||||
this.timerEvent = null;
|
||||
}
|
||||
|
||||
|
||||
AlienTimer.DEFAULT_TEXT_FONT = {
|
||||
font: "bold 30px Arial",
|
||||
boundsAlignH: "center", // left, center. right
|
||||
|
||||
Reference in New Issue
Block a user