Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Music
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranayub committed Aug 23, 2015
1 parent 9170f07 commit c74ebca
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 26 deletions.
3 changes: 3 additions & 0 deletions game/blood.ts
Expand Up @@ -6,6 +6,7 @@ class Blood extends ex.Actor {
private _emitters: IBloodEmitter[] = [];
public static BloodPixel: ex.Sprite;
public static BloodPixelGreen: ex.Sprite;
private _sprayEmitter: ex.ParticleEmitter;

constructor() {
super(0, 0);
Expand All @@ -17,6 +18,8 @@ class Blood extends ex.Actor {
this._sctx.globalCompositeOperation = 'source-over';

this.traits.length = 0;
this._sprayEmitter = new ex.ParticleEmitter(0, 0, 100, 100);

}

public onInitialize() {
Expand Down
47 changes: 34 additions & 13 deletions game/game.js
Expand Up @@ -44,6 +44,8 @@ var Resources = {
AxeSwing: new ex.Sound('sounds/axe-swing.wav'),
AxeSwingHit: new ex.Sound('sounds/axe-swing-hit.wav'),
BloodSpatter: new ex.Sound('sounds/blood-splatter-1.wav'),
AnnouncerDefend: new ex.Sound('sounds/defend.wav'),
SoundMusic: new ex.Sound('sounds/music.mp3'),
TextureHero: new ex.Texture("images/hero.png"),
TextureHeroLootIndicator: new ex.Texture("images/loot-indicator.png"),
TextureMonsterDown: new ex.Texture("images/minotaurv2.png"),
Expand Down Expand Up @@ -86,12 +88,8 @@ var Map = (function (_super) {
this._map.anchor.setTo(0, 0);
this._map.addDrawing(Resources.TextureMap);
this.add(this._map);
// make sure volume is set for sounds
_.forIn(Resources, function (resource) {
if (resource instanceof ex.Sound) {
resource.setVolume(1);
}
});
// start sounds
SoundManager.start();
// Initialize blood
this.add(blood);
this.buildWalls();
Expand Down Expand Up @@ -214,12 +212,7 @@ var Map = (function (_super) {
game.goToScene('gameover');
};
Map.prototype.onDeactivate = function () {
_.forIn(Resources, function (resource) {
if (resource instanceof ex.Sound) {
resource.setVolume(0);
}
});
//TODO clean up hero generation
SoundManager.stop();
};
Map.CellSize = 24;
return Map;
Expand All @@ -236,6 +229,7 @@ var Blood = (function (_super) {
this._sctx = this._scvs.getContext('2d');
this._sctx.globalCompositeOperation = 'source-over';
this.traits.length = 0;
this._sprayEmitter = new ex.ParticleEmitter(0, 0, 100, 100);
}
Blood.prototype.onInitialize = function () {
Blood.BloodPixel = Resources.TextureBloodPixel.asSprite();
Expand Down Expand Up @@ -826,6 +820,29 @@ var GameOver = (function (_super) {
};
return GameOver;
})(ex.Scene);
var SoundManager = (function () {
function SoundManager() {
}
SoundManager.start = function () {
// make sure volume is set for sounds
_.forIn(Resources, function (resource) {
if (resource instanceof ex.Sound) {
resource.setVolume(1);
}
});
Resources.SoundMusic.setVolume(0.05);
Resources.SoundMusic.play();
};
SoundManager.stop = function () {
// make sure volume is set for sounds
_.forIn(Resources, function (resource) {
if (resource instanceof ex.Sound) {
resource.setVolume(0);
}
});
};
return SoundManager;
})();
/// <reference path="config.ts" />
/// <reference path="resources.ts" />
/// <reference path="util.ts" />
Expand All @@ -836,6 +853,7 @@ var GameOver = (function (_super) {
/// <reference path="treasure.ts" />
/// <reference path="stats.ts" />
/// <reference path="gameover.ts" />
/// <reference path="soundmanager.ts" />
var game = new ex.Engine({
canvasElementId: "game",
width: 960,
Expand Down Expand Up @@ -869,7 +887,10 @@ game.start(loader).then(function () {
defendIntro.previousOpacity = 0;
game.add(defendIntro);
// fade don't work
defendIntro.delay(1000).callMethod(function () { return defendIntro.opacity = 1; }).delay(2000).callMethod(function () { return defendIntro.kill(); });
defendIntro.delay(1000).callMethod(function () {
defendIntro.opacity = 1;
Resources.AnnouncerDefend.play();
}).delay(2000).callMethod(function () { return defendIntro.kill(); });
var heroTimer = new ex.Timer(function () { return HeroSpawner.spawnHero(); }, Config.HeroSpawnInterval, true);
game.add(heroTimer);
HeroSpawner.spawnHero();
Expand Down
7 changes: 6 additions & 1 deletion game/game.ts
Expand Up @@ -8,6 +8,7 @@
/// <reference path="treasure.ts" />
/// <reference path="stats.ts" />
/// <reference path="gameover.ts" />
/// <reference path="soundmanager.ts" />

var game = new ex.Engine({
canvasElementId: "game",
Expand Down Expand Up @@ -50,7 +51,11 @@ game.start(loader).then(() => {
defendIntro.previousOpacity = 0;
game.add(defendIntro);
// fade don't work
defendIntro.delay(1000).callMethod(() => defendIntro.opacity = 1).delay(2000).callMethod(() => defendIntro.kill());
defendIntro.delay(1000).callMethod(() => {
defendIntro.opacity = 1;
Resources.AnnouncerDefend.play();
}).delay(2000).callMethod(() => defendIntro.kill());


var heroTimer = new ex.Timer(() => HeroSpawner.spawnHero(), Config.HeroSpawnInterval, true);
game.add(heroTimer);
Expand Down
15 changes: 3 additions & 12 deletions game/map.ts
Expand Up @@ -20,12 +20,8 @@ class Map extends ex.Scene {
this._map.addDrawing(Resources.TextureMap);
this.add(this._map);

// make sure volume is set for sounds
_.forIn(Resources, (resource) => {
if (resource instanceof ex.Sound) {
resource.setVolume(1);
}
});
// start sounds
SoundManager.start();

// Initialize blood
this.add(blood);
Expand Down Expand Up @@ -187,11 +183,6 @@ class Map extends ex.Scene {
}

public onDeactivate() {
_.forIn(Resources, (resource) => {
if (resource instanceof ex.Sound) {
resource.setVolume(0);
}
});
//TODO clean up hero generation
SoundManager.stop();
}
}
3 changes: 3 additions & 0 deletions game/resources.ts
Expand Up @@ -3,6 +3,9 @@ var Resources = {
AxeSwing: new ex.Sound('sounds/axe-swing.wav'),
AxeSwingHit: new ex.Sound('sounds/axe-swing-hit.wav'),
BloodSpatter: new ex.Sound('sounds/blood-splatter-1.wav'),
AnnouncerDefend: new ex.Sound('sounds/defend.wav'),

SoundMusic: new ex.Sound('sounds/music.mp3'),

TextureHero: new ex.Texture("images/hero.png"),
TextureHeroLootIndicator: new ex.Texture("images/loot-indicator.png"),
Expand Down
25 changes: 25 additions & 0 deletions game/soundmanager.ts
@@ -0,0 +1,25 @@
class SoundManager {

public static start() {
// make sure volume is set for sounds
_.forIn(Resources, (resource) => {
if (resource instanceof ex.Sound) {
(<ex.Sound>resource).setVolume(1);
}
});

Resources.SoundMusic.setVolume(0.05);
Resources.SoundMusic.play();
}

public static stop() {
// make sure volume is set for sounds
_.forIn(Resources, (resource) => {
if (resource instanceof ex.Sound) {
(<ex.Sound>resource).setVolume(0);
}
});
}

// todo save/restore settings
}
Binary file added sounds/music.mp3
Binary file not shown.

0 comments on commit c74ebca

Please sign in to comment.