Added music to map and arena stages
For future credits : http://incompetech.com/music/royalty-free/index.html?isrc=USUAN1300005 http://incompetech.com/music/royalty-free/index.html?isrc=USUAN1100020
This commit is contained in:
parent
b60cd52510
commit
2e962ca301
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
61
src/app/view/common/Audio.ts
Normal file
61
src/app/view/common/Audio.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
BIN
src/assets/sounds/music/full-on.mp3
Normal file
BIN
src/assets/sounds/music/full-on.mp3
Normal file
Binary file not shown.
BIN
src/assets/sounds/music/walking-along.mp3
Normal file
BIN
src/assets/sounds/music/walking-along.mp3
Normal file
Binary file not shown.
Loading…
Reference in a new issue