Refactored states + "battle" message on fight start
This commit is contained in:
parent
b1999822f0
commit
6700685062
28
src/app/view/BaseView.ts
Normal file
28
src/app/view/BaseView.ts
Normal file
|
@ -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 = <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");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
/// <reference path="../BaseView.ts"/>
|
||||
|
||||
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
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
/// <reference path="../BaseView.ts"/>
|
||||
|
||||
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
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
/// <reference path="../BaseView.ts"/>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue