Add: waiting room
This commit is contained in:
@@ -15,8 +15,7 @@ class Alien extends Phaser.Sprite {
|
||||
|
||||
Phaser.Sprite.call(this, game, this.initialX, this.initialY, 'alien_normal');
|
||||
this.anchor.set(0.5);
|
||||
// this.scale.set(Alien.MAX_SCALE);
|
||||
this.setOnInitialPosition();
|
||||
this.goWaitingRoom();
|
||||
|
||||
|
||||
this.inputEnabled = true;
|
||||
@@ -41,6 +40,12 @@ class Alien extends Phaser.Sprite {
|
||||
if(!this.isActivated)
|
||||
return;
|
||||
|
||||
if(!this.isOnstage) {
|
||||
this.isOnstage = true;
|
||||
this.goOnstage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof this.onFiredFunction !== "undefined")
|
||||
this.onFiredFunction(this);
|
||||
}
|
||||
@@ -68,27 +73,35 @@ class Alien extends Phaser.Sprite {
|
||||
this.scale.set(0);
|
||||
}
|
||||
|
||||
setOnInitialPosition() {
|
||||
goWaitingRoom() {
|
||||
this.isOnstage = false;
|
||||
|
||||
this.x = this.initialX;
|
||||
this.y = this.initialY;
|
||||
this.scale.set(Alien.MAX_SCALE);
|
||||
this.scale.set(Alien.WAITING_SCALE);
|
||||
}
|
||||
|
||||
goOnstage() {
|
||||
// set random position
|
||||
let SPAWN_BOX_LEFT = 100;
|
||||
let SPAWN_BOX_WIDTH = game.world.width - 200;
|
||||
let SPAWN_BOX_TOP = 300;
|
||||
let SPAWN_BOX_HEIGHT = game.world.height - 400;
|
||||
const SPAWN_BOX_LEFT = 50;
|
||||
const SPAWN_BOX_WIDTH = game.world.width - 100;
|
||||
const SPAWN_BOX_TOP = 250;
|
||||
const SPAWN_BOX_HEIGHT = game.world.height - 340;
|
||||
|
||||
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);
|
||||
// }
|
||||
|
||||
// start scale tween animation
|
||||
this.shutdown();
|
||||
|
||||
this.tweenScaleUp = game.add.tween(this.scale)
|
||||
.to( { x: Alien.MAX_SCALE, y: Alien.MAX_SCALE }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||
.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);
|
||||
@@ -107,4 +120,5 @@ class Alien extends Phaser.Sprite {
|
||||
}
|
||||
|
||||
Alien.DEFAULT_SPEED_SEC = 3000;
|
||||
Alien.MAX_SCALE = 3;
|
||||
Alien.WAITING_SCALE = 2;
|
||||
Alien.ONSTAGE_MAX_SCALE = 3;
|
||||
|
||||
Reference in New Issue
Block a user