diff --git a/src/app/view/BaseView.ts b/src/app/view/BaseView.ts new file mode 100644 index 0000000..39595cb --- /dev/null +++ b/src/app/view/BaseView.ts @@ -0,0 +1,28 @@ +module SpaceTac.View { + "use strict"; + + // Base class for all game views + export class BaseView extends Phaser.State { + // Link to the root UI + protected gameui: GameUI; + + // Init the view + init(...args: any[]) { + this.gameui = this.game; + } + + // Create view graphics + create() { + // Key mapping + var key_s = this.input.keyboard.addKey(Phaser.Keyboard.S); + key_s.onUp.add(() => { + this.gameui.saveGame(); + }); + var key_l = this.input.keyboard.addKey(Phaser.Keyboard.L); + key_l.onUp.add(() => { + this.gameui.loadGame(); + this.game.state.start("router"); + }); + } + } +} diff --git a/src/app/view/battle/BattleView.ts b/src/app/view/battle/BattleView.ts index 2fd472e..baffb2b 100644 --- a/src/app/view/battle/BattleView.ts +++ b/src/app/view/battle/BattleView.ts @@ -1,8 +1,10 @@ +/// + module SpaceTac.View { "use strict"; // Interactive view of a Battle - export class BattleView extends Phaser.State { + export class BattleView extends BaseView { // Displayed battle battle: Game.Battle; @@ -52,6 +54,8 @@ module SpaceTac.View { // Init the view, binding it to a specific battle init(player: Game.Player, battle: Game.Battle) { + super.init(); + this.player = player; this.battle = battle; this.targetting = null; @@ -64,6 +68,8 @@ module SpaceTac.View { // Create view graphics create() { + super.create(); + var game = this.game; // Background @@ -101,6 +107,9 @@ module SpaceTac.View { // Start processing the battle log this.log_processor = new LogProcessor(this); + // "Battle" animation + this.displayFightMessage(); + // Key mapping var key_space = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); key_space.onUp.add(this.onSpaceKeyPressed, this); @@ -155,6 +164,21 @@ module SpaceTac.View { } this.battle = null; + + super.shutdown(); + } + + // Display an animated "BATTLE" text in the center of the view + displayFightMessage(): void { + var text = this.game.add.text(1280 / 2, 720 / 2, "BATTLE !", + {align: "center", font: "bold 42px Arial", fill: "#EE2233"}); + text.anchor.set(0.5, 0.5); + this.game.tweens.create(text.scale).to({x: 3, y: 3}).start(); + var text_anim = this.game.tweens.create(text).to({alpha: 0}); + text_anim.onComplete.addOnce(() => { + text.destroy(); + }); + text_anim.start(); } // Listener for space key events diff --git a/src/app/view/map/StarSystemView.ts b/src/app/view/map/StarSystemView.ts index 384eaab..2e03a66 100644 --- a/src/app/view/map/StarSystemView.ts +++ b/src/app/view/map/StarSystemView.ts @@ -1,8 +1,10 @@ +/// + module SpaceTac.View { "use strict"; // Interactive map of a star system - export class StarSystemView extends Phaser.State { + export class StarSystemView extends BaseView { // Displayed star system star: Game.Star; @@ -22,12 +24,16 @@ module SpaceTac.View { // Init the view, binding it to a universe init(star: Game.Star, player: Game.Player) { + super.init(); + this.star = star; this.player = player; } // Create view graphics create() { + super.create(); + this.locations = this.add.group(); var display_margin = 50; @@ -50,6 +56,8 @@ module SpaceTac.View { shutdown() { this.star = null; this.player = null; + + super.shutdown(); } // Redraw the view diff --git a/src/app/view/map/UniverseMapView.ts b/src/app/view/map/UniverseMapView.ts index 75e8a65..a3c777a 100644 --- a/src/app/view/map/UniverseMapView.ts +++ b/src/app/view/map/UniverseMapView.ts @@ -1,8 +1,10 @@ +/// + module SpaceTac.View { "use strict"; // Interactive map of the universe - export class UniverseMapView extends Phaser.State { + export class UniverseMapView extends BaseView { // Displayed universe universe: Game.Universe; @@ -18,12 +20,16 @@ module SpaceTac.View { // Init the view, binding it to a universe init(universe: Game.Universe, player: Game.Player) { + super.init(); + this.universe = universe; this.player = player; } // Create view graphics create() { + super.create(); + this.stars = this.add.group(); var display_margin = 50; @@ -42,6 +48,8 @@ module SpaceTac.View { shutdown() { this.universe = null; this.player = null; + + super.shutdown(); } // Redraw the whole scene