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');
|
Phaser.Sprite.call(this, game, this.initialX, this.initialY, 'alien_normal');
|
||||||
this.anchor.set(0.5);
|
this.anchor.set(0.5);
|
||||||
// this.scale.set(Alien.MAX_SCALE);
|
this.goWaitingRoom();
|
||||||
this.setOnInitialPosition();
|
|
||||||
|
|
||||||
|
|
||||||
this.inputEnabled = true;
|
this.inputEnabled = true;
|
||||||
@@ -41,6 +40,12 @@ class Alien extends Phaser.Sprite {
|
|||||||
if(!this.isActivated)
|
if(!this.isActivated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(!this.isOnstage) {
|
||||||
|
this.isOnstage = true;
|
||||||
|
this.goOnstage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(typeof this.onFiredFunction !== "undefined")
|
if(typeof this.onFiredFunction !== "undefined")
|
||||||
this.onFiredFunction(this);
|
this.onFiredFunction(this);
|
||||||
}
|
}
|
||||||
@@ -68,27 +73,35 @@ class Alien extends Phaser.Sprite {
|
|||||||
this.scale.set(0);
|
this.scale.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
setOnInitialPosition() {
|
goWaitingRoom() {
|
||||||
|
this.isOnstage = false;
|
||||||
|
|
||||||
this.x = this.initialX;
|
this.x = this.initialX;
|
||||||
this.y = this.initialY;
|
this.y = this.initialY;
|
||||||
this.scale.set(Alien.MAX_SCALE);
|
this.scale.set(Alien.WAITING_SCALE);
|
||||||
}
|
}
|
||||||
|
|
||||||
goOnstage() {
|
goOnstage() {
|
||||||
// set random position
|
// set random position
|
||||||
let SPAWN_BOX_LEFT = 100;
|
const SPAWN_BOX_LEFT = 50;
|
||||||
let SPAWN_BOX_WIDTH = game.world.width - 200;
|
const SPAWN_BOX_WIDTH = game.world.width - 100;
|
||||||
let SPAWN_BOX_TOP = 300;
|
const SPAWN_BOX_TOP = 250;
|
||||||
let SPAWN_BOX_HEIGHT = game.world.height - 400;
|
const SPAWN_BOX_HEIGHT = game.world.height - 340;
|
||||||
|
|
||||||
this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH;
|
this.x = SPAWN_BOX_LEFT + Math.random() * SPAWN_BOX_WIDTH;
|
||||||
this.y = SPAWN_BOX_TOP + Math.random() * SPAWN_BOX_HEIGHT;
|
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
|
// start scale tween animation
|
||||||
this.shutdown();
|
this.shutdown();
|
||||||
|
|
||||||
this.tweenScaleUp = game.add.tween(this.scale)
|
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)
|
this.tweenScaleDown = game.add.tween(this.scale)
|
||||||
.to( { x: 0, y: 0 }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
.to( { x: 0, y: 0 }, Alien.DEFAULT_SPEED_SEC, Phaser.Easing.Linear.None, false);
|
||||||
this.tweenScaleUp.chain(this.tweenScaleDown);
|
this.tweenScaleUp.chain(this.tweenScaleDown);
|
||||||
@@ -107,4 +120,5 @@ class Alien extends Phaser.Sprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Alien.DEFAULT_SPEED_SEC = 3000;
|
Alien.DEFAULT_SPEED_SEC = 3000;
|
||||||
Alien.MAX_SCALE = 3;
|
Alien.WAITING_SCALE = 2;
|
||||||
|
Alien.ONSTAGE_MAX_SCALE = 3;
|
||||||
|
|||||||
@@ -4,11 +4,7 @@
|
|||||||
class Game {
|
class Game {
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
// this.historyRecordManager = new HistoryRecordManager();
|
|
||||||
|
|
||||||
this.game.stage.backgroundColor = '#4d4d4d';
|
this.game.stage.backgroundColor = '#4d4d4d';
|
||||||
// this.chartGraphics = game.add.graphics(100, game.world.height - 120);
|
|
||||||
|
|
||||||
|
|
||||||
// top
|
// top
|
||||||
let backButton = new BackButton( () => {
|
let backButton = new BackButton( () => {
|
||||||
@@ -18,13 +14,18 @@ class Game {
|
|||||||
let fullscreenButton = new FullscreenButton(this.game);
|
let fullscreenButton = new FullscreenButton(this.game);
|
||||||
|
|
||||||
|
|
||||||
|
// waiting room
|
||||||
|
this.game.add.graphics()
|
||||||
|
.beginFill(0xffffff, 0.1)
|
||||||
|
.drawRect(0, 100, game.world.width, 100);
|
||||||
|
|
||||||
|
|
||||||
// contents
|
// contents
|
||||||
let alien = new Alien(
|
let alien = new Alien(100, 150, this.onAlienFired, this.onAlienEscaped);
|
||||||
this.game.world.width / 2, this.game.world.height / 2,
|
alien.goWaitingRoom();
|
||||||
this.onAlienFired, this.onAlienEscaped
|
|
||||||
);
|
// activate first alien
|
||||||
alien.setActive(true);
|
alien.setActive(true);
|
||||||
alien.goOnstage();
|
|
||||||
|
|
||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
@@ -81,7 +82,6 @@ class Game {
|
|||||||
|
|
||||||
onAlienEscaped(sprite) {
|
onAlienEscaped(sprite) {
|
||||||
console.log("onAlienEscaped");
|
console.log("onAlienEscaped");
|
||||||
// sprite.goOnstage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user