diff --git a/src/game/mouse/space_invaders/alien.js b/src/game/mouse/space_invaders/alien.js index 41e2419..55f5a38 100644 --- a/src/game/mouse/space_invaders/alien.js +++ b/src/game/mouse/space_invaders/alien.js @@ -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; diff --git a/src/game/mouse/space_invaders/game.js b/src/game/mouse/space_invaders/game.js index bc55688..a81b915 100644 --- a/src/game/mouse/space_invaders/game.js +++ b/src/game/mouse/space_invaders/game.js @@ -4,11 +4,7 @@ class Game { create() { - // this.historyRecordManager = new HistoryRecordManager(); - this.game.stage.backgroundColor = '#4d4d4d'; - // this.chartGraphics = game.add.graphics(100, game.world.height - 120); - // top let backButton = new BackButton( () => { @@ -18,13 +14,18 @@ class 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 - let alien = new Alien( - this.game.world.width / 2, this.game.world.height / 2, - this.onAlienFired, this.onAlienEscaped - ); + let alien = new Alien(100, 150, this.onAlienFired, this.onAlienEscaped); + alien.goWaitingRoom(); + + // activate first alien alien.setActive(true); - alien.goOnstage(); // bottom @@ -81,7 +82,6 @@ class Game { onAlienEscaped(sprite) { console.log("onAlienEscaped"); - // sprite.goOnstage(); } } \ No newline at end of file