Fix: alien ES5 bug
This commit is contained in:
@@ -1,155 +1,155 @@
|
||||
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;
|
||||
this.speedGrowing = Alien.DEFAULT_SPEED_SEC;
|
||||
this.isActivated = false;
|
||||
this.isOnWaitingRoom = true;
|
||||
this.speedGrowing = Alien.DEFAULT_SPEED_SEC;
|
||||
|
||||
this.initialX = initialX;
|
||||
this.initialY = initialY;
|
||||
this.initialX = initialX;
|
||||
this.initialY = initialY;
|
||||
|
||||
this.tweenScaleUp = null;
|
||||
this.tweenScaleDown = null;
|
||||
this.tweenScaleUp = null;
|
||||
this.tweenScaleDown = null;
|
||||
|
||||
this.onGoOnstageFunction = onGoOnstageFunction;
|
||||
this.onFiredFunction = onFiredFunction;
|
||||
this.onEscapedFunction = onEscapedFunction;
|
||||
this.onGoOnstageFunction = onGoOnstageFunction;
|
||||
this.onFiredFunction = onFiredFunction;
|
||||
this.onEscapedFunction = onEscapedFunction;
|
||||
|
||||
Phaser.Sprite.call(this, game, this.initialX, this.initialY, 'alien_normal');
|
||||
this.anchor.set(0.5);
|
||||
this.goWaitingRoom();
|
||||
Phaser.Sprite.call(this, game, this.initialX, this.initialY, 'alien_normal');
|
||||
this.anchor.set(0.5);
|
||||
this.goWaitingRoom();
|
||||
|
||||
|
||||
this.inputEnabled = true;
|
||||
this.events.onInputOut.add(this.onOut, this);
|
||||
this.events.onInputOver.add(this.onOver, this);
|
||||
this.events.onInputDown.add(this.onDown, this);
|
||||
|
||||
game.add.existing(this);
|
||||
}
|
||||
|
||||
onOut() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
this.tint = 0xffffff;
|
||||
}
|
||||
|
||||
onOver() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
this.tint = 0xffaaaa;
|
||||
}
|
||||
|
||||
onDown() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
if(this.isOnWaitingRoom) {
|
||||
this.goOnstage();
|
||||
return;
|
||||
} else {
|
||||
this.onFired();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stop() {
|
||||
this.setActive(false);
|
||||
this.removeTween();
|
||||
|
||||
// if(this.isOnWaitingRoom !== true)
|
||||
// this.scale.set(0);
|
||||
}
|
||||
|
||||
setActive(isActivated) {
|
||||
this.isActivated = isActivated;
|
||||
|
||||
if(this.isActivated) {
|
||||
this.tint = 0xffffff;
|
||||
} else {
|
||||
this.tint = 0x555555;
|
||||
}
|
||||
}
|
||||
|
||||
removeTween() {
|
||||
if(this.tweenScaleUp !== null) {
|
||||
this.tweenScaleUp.stop();
|
||||
this.tweenScaleUp = null;
|
||||
}
|
||||
if(this.tweenScaleDown !== null) {
|
||||
this.tweenScaleDown.stop();
|
||||
this.tweenScaleDown = null;
|
||||
}
|
||||
}
|
||||
|
||||
goWaitingRoom() {
|
||||
this.isOnWaitingRoom = true;
|
||||
|
||||
this.x = this.initialX;
|
||||
this.y = this.initialY;
|
||||
this.scale.set(Alien.WAITING_SCALE);
|
||||
}
|
||||
|
||||
goOnstage() {
|
||||
this.isOnWaitingRoom = false;
|
||||
this.goRandomPosition();
|
||||
|
||||
if(typeof this.onGoOnstageFunction !== "undefined")
|
||||
this.onGoOnstageFunction();
|
||||
}
|
||||
|
||||
onFired() {
|
||||
if(typeof this.onFiredFunction !== "undefined")
|
||||
this.onFiredFunction(this);
|
||||
|
||||
this.goRandomPosition();
|
||||
}
|
||||
|
||||
goRandomPosition() {
|
||||
// set random position
|
||||
const SPAWN_BOX_LEFT = 80;
|
||||
const SPAWN_BOX_WIDTH = game.world.width - 160;
|
||||
const SPAWN_BOX_TOP = 280;
|
||||
const SPAWN_BOX_HEIGHT = game.world.height - 400;
|
||||
|
||||
this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH;
|
||||
this.y = SPAWN_BOX_TOP + Math.random() * SPAWN_BOX_HEIGHT;
|
||||
|
||||
// if(isDebugMode()) {
|
||||
// this.game.add.graphics()
|
||||
// .beginFill(0xffffff, 0.1)
|
||||
// .drawRect(SPAWN_BOX_LEFT, SPAWN_BOX_TOP, SPAWN_BOX_WIDTH, SPAWN_BOX_HEIGHT);
|
||||
// }
|
||||
|
||||
this.tint = 0xffffff;
|
||||
this.scale.set(Alien.ONSTAGE_MIN_SCALE);
|
||||
|
||||
// start scale tween animation
|
||||
this.removeTween();
|
||||
|
||||
this.tweenScaleUp = game.add.tween(this.scale)
|
||||
.to( { x: Alien.ONSTAGE_MAX_SCALE, y: Alien.ONSTAGE_MAX_SCALE }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||
this.tweenScaleDown = game.add.tween(this.scale)
|
||||
.to( { x: 0, y: 0 }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||
this.tweenScaleUp.chain(this.tweenScaleDown);
|
||||
this.tweenScaleDown.onComplete.addOnce(this.onEscaped, this);
|
||||
this.tweenScaleUp.start();
|
||||
}
|
||||
|
||||
onEscaped() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
if(typeof this.onEscapedFunction !== "undefined")
|
||||
this.onEscapedFunction();
|
||||
}
|
||||
this.inputEnabled = true;
|
||||
this.events.onInputOut.add(this.onOut, this);
|
||||
this.events.onInputOver.add(this.onOver, this);
|
||||
this.events.onInputDown.add(this.onDown, this);
|
||||
|
||||
game.add.existing(this);
|
||||
}
|
||||
|
||||
Alien.prototype.onOut = function() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
this.tint = 0xffffff;
|
||||
}
|
||||
|
||||
Alien.prototype.onOver = function() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
this.tint = 0xffaaaa;
|
||||
}
|
||||
|
||||
Alien.prototype.onDown = function() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
if(this.isOnWaitingRoom) {
|
||||
this.goOnstage();
|
||||
return;
|
||||
} else {
|
||||
this.onFired();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Alien.prototype.stop = function() {
|
||||
this.setActive(false);
|
||||
this.removeTween();
|
||||
|
||||
// if(this.isOnWaitingRoom !== true)
|
||||
// this.scale.set(0);
|
||||
}
|
||||
|
||||
Alien.prototype.setActive = function(isActivated) {
|
||||
this.isActivated = isActivated;
|
||||
|
||||
if(this.isActivated) {
|
||||
this.tint = 0xffffff;
|
||||
} else {
|
||||
this.tint = 0x555555;
|
||||
}
|
||||
}
|
||||
|
||||
Alien.prototype.removeTween = function() {
|
||||
if(this.tweenScaleUp !== null) {
|
||||
this.tweenScaleUp.stop();
|
||||
this.tweenScaleUp = null;
|
||||
}
|
||||
if(this.tweenScaleDown !== null) {
|
||||
this.tweenScaleDown.stop();
|
||||
this.tweenScaleDown = null;
|
||||
}
|
||||
}
|
||||
|
||||
Alien.prototype.goWaitingRoom = function() {
|
||||
this.isOnWaitingRoom = true;
|
||||
|
||||
this.x = this.initialX;
|
||||
this.y = this.initialY;
|
||||
this.scale.set(Alien.WAITING_SCALE);
|
||||
}
|
||||
|
||||
Alien.prototype.goOnstage = function() {
|
||||
this.isOnWaitingRoom = false;
|
||||
this.goRandomPosition();
|
||||
|
||||
if(typeof this.onGoOnstageFunction !== "undefined")
|
||||
this.onGoOnstageFunction();
|
||||
}
|
||||
|
||||
Alien.prototype.onFired = function() {
|
||||
if(typeof this.onFiredFunction !== "undefined")
|
||||
this.onFiredFunction(this);
|
||||
|
||||
this.goRandomPosition();
|
||||
}
|
||||
|
||||
Alien.prototype.goRandomPosition = function() {
|
||||
// set random position
|
||||
const SPAWN_BOX_LEFT = 80;
|
||||
const SPAWN_BOX_WIDTH = game.world.width - 160;
|
||||
const SPAWN_BOX_TOP = 280;
|
||||
const SPAWN_BOX_HEIGHT = game.world.height - 400;
|
||||
|
||||
this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH;
|
||||
this.y = SPAWN_BOX_TOP + Math.random() * SPAWN_BOX_HEIGHT;
|
||||
|
||||
// if(isDebugMode()) {
|
||||
// this.game.add.graphics()
|
||||
// .beginFill(0xffffff, 0.1)
|
||||
// .drawRect(SPAWN_BOX_LEFT, SPAWN_BOX_TOP, SPAWN_BOX_WIDTH, SPAWN_BOX_HEIGHT);
|
||||
// }
|
||||
|
||||
this.tint = 0xffffff;
|
||||
this.scale.set(Alien.ONSTAGE_MIN_SCALE);
|
||||
|
||||
// start scale tween animation
|
||||
this.removeTween();
|
||||
|
||||
this.tweenScaleUp = game.add.tween(this.scale)
|
||||
.to( { x: Alien.ONSTAGE_MAX_SCALE, y: Alien.ONSTAGE_MAX_SCALE }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||
this.tweenScaleDown = game.add.tween(this.scale)
|
||||
.to( { x: 0, y: 0 }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||
this.tweenScaleUp.chain(this.tweenScaleDown);
|
||||
this.tweenScaleDown.onComplete.addOnce(this.onEscaped, this);
|
||||
this.tweenScaleUp.start();
|
||||
}
|
||||
|
||||
Alien.prototype.onEscaped = function() {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
if(typeof this.onEscapedFunction !== "undefined")
|
||||
this.onEscapedFunction();
|
||||
}
|
||||
|
||||
|
||||
Alien.DEFAULT_SPEED_SEC = 3000;
|
||||
Alien.WAITING_SCALE = 2;
|
||||
Alien.ONSTAGE_MIN_SCALE = 0.1;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user