1
0
Fork 0
Michaël Lemaire 2015-04-22 23:42:40 +02:00
parent b60cd52510
commit 2e962ca301
12 changed files with 86 additions and 19 deletions

View file

@ -11,8 +11,13 @@ module SpaceTac {
// Current focused star system
star: Game.Star;
constructor() {
super(1280, 720, Phaser.AUTO, '-space-tac');
// Audio manager
audio: View.Audio;
constructor(headless: boolean = false) {
super(1280, 720, headless ? Phaser.HEADLESS : Phaser.AUTO, '-space-tac');
this.audio = new View.Audio(this);
this.session = new Game.GameSession();
this.star = null;

View file

@ -43,6 +43,10 @@ module SpaceTac.View {
this.gameui.loadGame();
this.game.state.start("router");
});
var key_m = this.input.keyboard.addKey(Phaser.Keyboard.M);
key_m.onUp.add(() => {
this.gameui.audio.toggleMute();
});
}
}
}

View file

@ -66,6 +66,10 @@ module SpaceTac.View {
// Load sounds
this.loadSound("battle/ship-change.wav");
this.loadSound("battle/weapon-bullets.wav");
// Load musics
this.loadSound("music/walking-along.mp3");
this.loadSound("music/full-on.mp3");
}
create() {
@ -77,7 +81,7 @@ module SpaceTac.View {
}
private loadSound(path: string) {
var key = path.replace(/\//g, "-").replace(".wav", "");
var key = path.replace(/\//g, "-").replace(".wav", "").replace(".mp3", "");
this.load.audio(key, "assets/sounds/" + path);
}
}

View file

@ -120,7 +120,7 @@ module SpaceTac.View {
}
this.playing = arena_ship;
Sound.playOnce(this.game, "battle-ship-change");
this.battleview.gameui.audio.playOnce("battle-ship-change");
}
}
}

View file

@ -110,6 +110,9 @@ module SpaceTac.View {
// "Battle" animation
this.displayFightMessage();
// BGM
this.gameui.audio.startMusic("full-on");
// Key mapping
var key_space = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
key_space.onUp.add(this.onSpaceKeyPressed, this);

View file

@ -0,0 +1,61 @@
module SpaceTac.View {
"use strict";
// Utility functions for sounds
export class Audio {
private game: Phaser.Game;
private music: Phaser.Sound;
constructor(game: Phaser.Game) {
this.game = game;
this.music = null;
}
// Check if the sound system is up and running
isActive(): boolean {
return this.game.sound.context ? true : false;
}
// Play a ponctual sound
playOnce(key: string): void {
if (this.isActive()) {
this.game.sound.play(key);
}
}
// Start a background music
startMusic(key: string): void {
if (this.isActive()) {
if (this.music && this.music.key !== key) {
this.stopMusic();
}
if (!this.music) {
this.music = this.game.sound.play("music-" + key, 1, true);
}
}
}
// Stop currently playing background music
stopMusic(): void {
if (this.isActive()) {
if (this.music) {
this.music.stop();
this.music = null;
}
}
}
// Toggle the mute status of the sound system
toggleMute(): void {
if (this.isActive()) {
if (this.game.sound.volume > 0) {
this.game.sound.volume = 0;
} else {
this.game.sound.volume = 1;
}
}
}
}
}

View file

@ -1,14 +0,0 @@
module SpaceTac.View {
"use strict";
// Utility functions for sounds
export class Sound {
// Play a ponctual sound
static playOnce(game: Phaser.Game, key: string): void {
if (game.sound.context) {
game.sound.play("battle-ship-change");
}
}
}
}

View file

@ -50,6 +50,8 @@ module SpaceTac.View {
this.button_jump.visible = false;
this.drawAll();
this.gameui.audio.startMusic("walking-along");
}
// Leaving the view, unbind and destroy

View file

@ -40,6 +40,8 @@ module SpaceTac.View {
this.drawAll();
this.gameui.audio.startMusic("walking-along");
// Inputs
this.input.keyboard.addKey(Phaser.Keyboard.R).onUp.addOnce(this.revealAll, this);
}

View file

@ -11,7 +11,7 @@ module SpaceTac.View.Specs {
spyOn(console, "log").and.stub();
spyOn(console, "warn").and.stub();
var game = new Phaser.Game(500, 500, Phaser.HEADLESS);
var game = new GameUI(true);
if (!state) {
state = new Phaser.State();

Binary file not shown.

Binary file not shown.