We have audio! Thanks @orsi!

This commit is contained in:
jorsi
2020-05-28 19:10:09 -04:00
committed by Michael Townsend
parent d6d1c1b987
commit a601473645
106 changed files with 1415 additions and 399 deletions
Vendored
BIN
View File
Binary file not shown.
+1
View File
@@ -5,3 +5,4 @@
.idea .idea
lang/.DS_Store lang/.DS_Store
.DS_Store .DS_Store
node_modules
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+8
View File
@@ -0,0 +1,8 @@
import express from 'express';
const PORT = 8080;
const app = express();
app.use(express.static('.'));
app.listen(PORT, () => console.log(`Listening on port ${PORT}`));
+2
View File
@@ -48,6 +48,8 @@
</script> </script>
<script src="script/Button.js"></script> <script src="script/Button.js"></script>
<script src="script/audioLibrary.js"></script>
<script src="script/audio.js"></script>
<script src="script/engine.js"></script> <script src="script/engine.js"></script>
<script src="script/state_manager.js"></script> <script src="script/state_manager.js"></script>
<script src="script/header.js"></script> <script src="script/header.js"></script>
+15
View File
@@ -0,0 +1,15 @@
{
"name": "adarkroom",
"type": "module",
"version": "1.0.0",
"private": true,
"repository": "git@github.com:doublespeakgames/adarkroom.git",
"author": "Michael Townsend <michael@doublespeakgames.com>",
"license": "MPL-2.0",
"scripts": {
"start": "node dev-server.js"
},
"dependencies": {
"express": "^4.17.1"
}
}
+236
View File
@@ -0,0 +1,236 @@
/**
* Module that takes care of audio playback
*/
var AudioEngine = {
FADE_TIME: 1,
AUDIO_BUFFER_CACHE: {},
_audioContext: null,
_master: null,
_currentBackgroundMusic: null,
_currentEventAudio: null,
_currentSoundEffectAudio: null,
init: function () {
AudioEngine._initAudioContext();
},
_initAudioContext: function () {
AudioEngine._audioContext = new (window.AudioContext || window.webkitAudioContext);
AudioEngine._createMasterChannel();
},
_createMasterChannel: function () {
// create master
AudioEngine._master = AudioEngine._audioContext.createGain();
AudioEngine._master.gain.setValueAtTime(1.0, AudioEngine._audioContext.currentTime);
AudioEngine._master.connect(AudioEngine._audioContext.destination);
},
_getMissingAudioBuffer: function () {
// plays beeping sound to indicate missing audio
var buffer = AudioEngine._audioContext.createBuffer(
1,
AudioEngine._audioContext.sampleRate,
AudioEngine._audioContext.sampleRate
);
// Fill the buffer
var bufferData = buffer.getChannelData(0);
for (var i = 0; i < buffer.length / 2; i++) {
bufferData[i] = Math.sin(i * 0.05) / 4; // max .25 gain value
}
return buffer;
},
_playSound: function (buffer) {
if (AudioEngine._currentSoundEffectAudio &&
AudioEngine._currentSoundEffectAudio.source.buffer == buffer) {
return;
}
var source = AudioEngine._audioContext.createBufferSource();
source.buffer = buffer;
source.onended = function(event) {
// dereference current sound effect when finished
if (AudioEngine._currentSoundEffectAudio &&
AudioEngine._currentSoundEffectAudio.source.buffer == buffer) {
AudioEngine._currentSoundEffectAudio = null;
}
};
source.connect(AudioEngine._master);
source.start();
AudioEngine._currentSoundEffectAudio = {
source: source
};
},
_playBackgroundMusic: function (buffer) {
var source = AudioEngine._audioContext.createBufferSource();
source.buffer = buffer;
source.loop = true;
var envelope = AudioEngine._audioContext.createGain();
envelope.gain.setValueAtTime(0.0, AudioEngine._audioContext.currentTime);
var fadeTime = AudioEngine._audioContext.currentTime + AudioEngine.FADE_TIME;
// fade out current background music
if (AudioEngine._currentBackgroundMusic &&
AudioEngine._currentBackgroundMusic.source &&
AudioEngine._currentBackgroundMusic.source.playbackState !== 0) {
var currentBackgroundGainValue = AudioEngine._currentBackgroundMusic.envelope.gain.value;
AudioEngine._currentBackgroundMusic.envelope.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.setValueAtTime(currentBackgroundGainValue, AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.linearRampToValueAtTime(0.0, fadeTime);
AudioEngine._currentBackgroundMusic.source.stop(fadeTime + 0.3); // make sure fade has completed
}
// fade in new backgorund music
source.connect(envelope);
envelope.connect(AudioEngine._master);
source.start();
envelope.gain.linearRampToValueAtTime(1.0, fadeTime);
// update current background music
AudioEngine._currentBackgroundMusic = {
source: source,
envelope: envelope
};
},
_playEventMusic: function (buffer) {
var source = AudioEngine._audioContext.createBufferSource();
source.buffer = buffer;
source.loop = true;
var envelope = AudioEngine._audioContext.createGain();
envelope.gain.setValueAtTime(0.0, AudioEngine._audioContext.currentTime);
var fadeTime = AudioEngine._audioContext.currentTime + AudioEngine.FADE_TIME * 2;
// turn down current background music
if (AudioEngine._currentBackgroundMusic != null) {
var currentBackgroundGainValue = AudioEngine._currentBackgroundMusic.envelope.gain.value;
AudioEngine._currentBackgroundMusic.envelope.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.setValueAtTime(currentBackgroundGainValue, AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.linearRampToValueAtTime(0.2, fadeTime);
}
// fade in event music
source.connect(envelope);
envelope.connect(AudioEngine._master);
source.start();
envelope.gain.linearRampToValueAtTime(1.0, fadeTime);
// update reference
AudioEngine._currentEventAudio = {
source: source,
envelope: envelope
};
},
_stopEventMusic: function () {
var fadeTime = AudioEngine._audioContext.currentTime + AudioEngine.FADE_TIME * 2;
// fade out event music and stop
if (AudioEngine._currentEventAudio) {
var currentEventGainValue = AudioEngine._currentEventAudio.envelope.gain.value;
AudioEngine._currentEventAudio.envelope.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
AudioEngine._currentEventAudio.envelope.gain.setValueAtTime(currentEventGainValue, AudioEngine._audioContext.currentTime);
AudioEngine._currentEventAudio.envelope.gain.linearRampToValueAtTime(0.0, fadeTime);
AudioEngine._currentEventAudio.source.stop(fadeTime + 1); // make sure fade has completed
AudioEngine._currentEventAudio = null;
}
// turn up background music
if (AudioEngine._currentBackgroundMusic) {
var currentBackgroundGainValue = AudioEngine._currentBackgroundMusic.envelope.gain.value;
AudioEngine._currentBackgroundMusic.envelope.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.setValueAtTime(currentBackgroundGainValue, AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.linearRampToValueAtTime(1.0, fadeTime);
}
},
isAudioContextRunning: function () {
return AudioEngine._audioContext.state !== 'suspended';
},
tryResumingAudioContext: function() {
if (AudioEngine._audioContext.state === 'suspended') {
AudioEngine._audioContext.resume();
}
},
playBackgroundMusic: function (src) {
AudioEngine.loadAudioFile(src)
.then(function (buffer) {
AudioEngine._playBackgroundMusic(buffer);
});
},
playEventMusic: function (src) {
AudioEngine.loadAudioFile(src)
.then(function (buffer) {
AudioEngine._playEventMusic(buffer);
});
},
stopEventMusic: function () {
AudioEngine._stopEventMusic();
},
playSound: function (src) {
AudioEngine.loadAudioFile(src)
.then(function (buffer) {
AudioEngine._playSound(buffer);
});
},
loadAudioFile: function (src) {
if (src.indexOf('http') === -1) {
src = window.location + src;
}
if (AudioEngine.AUDIO_BUFFER_CACHE[src]) {
return new Promise(function (resolve, reject) {
resolve(AudioEngine.AUDIO_BUFFER_CACHE[src]);
});
} else {
var request = new Request(src);
return fetch(request).then(function (response) {
return response.arrayBuffer();
}).then(function (buffer) {
if (buffer.byteLength === 0) {
console.error('cannot load audio from ' + src);
return AudioEngine._getMissingAudioBuffer();
}
return AudioEngine._audioContext.decodeAudioData(buffer, function (decodedData) {
AudioEngine.AUDIO_BUFFER_CACHE[src] = decodedData;
return AudioEngine.AUDIO_BUFFER_CACHE[src];
});
});
}
},
setBackgroundMusicVolume: function (volume, s) {
if (AudioEngine._master == null) return; // master may not be ready yet
if (volume === undefined) {
volume = 1.0;
}
if (s === undefined) {
s = 1.0;
}
// cancel any current schedules and then ramp
var currentBackgroundGainValue = AudioEngine._currentBackgroundMusic.envelope.gain.value;
AudioEngine._currentBackgroundMusic.envelope.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.setValueAtTime(currentBackgroundGainValue, AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.linearRampToValueAtTime(
volume,
AudioEngine._audioContext.currentTime + s
);
},
setMasterVolume: function (volume, s) {
if (AudioEngine._master == null) return; // master may not be ready yet
if (volume === undefined) {
volume = 1.0;
}
if (s === undefined) {
s = 1.0;
}
// cancel any current schedules and then ramp
var currentGainValue = AudioEngine._master.gain.value;
AudioEngine._master.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
AudioEngine._master.gain.setValueAtTime(currentGainValue, AudioEngine._audioContext.currentTime);
AudioEngine._master.gain.linearRampToValueAtTime(
volume,
AudioEngine._audioContext.currentTime + s
);
}
};
+91
View File
@@ -0,0 +1,91 @@
/**
* Module that defines all audio files
*/
var AudioLibrary = {
MUSIC_DUSTY_PATH: 'audio/dusty-path.flac',
MUSIC_SILENT_FOREST: 'audio/silent-forest.flac',
MUSIC_LONELY_HUT: 'audio/lonely-hut.flac',
MUSIC_TINY_VILLAGE: 'audio/tiny-village.flac',
MUSIC_MODEST_VILLAGE: 'audio/modest-village.flac',
MUSIC_LARGE_VILLAGE: 'audio/large-village.flac',
MUSIC_RAUCOUS_VILLAGE: 'audio/raucous-village.flac',
MUSIC_FIRE_DEAD: 'audio/fire-dead.flac',
MUSIC_FIRE_SMOLDERING: 'audio/fire-smoldering.flac',
MUSIC_FIRE_FLICKERING: 'audio/fire-flickering.flac',
MUSIC_FIRE_BURNING: 'audio/fire-burning.flac',
MUSIC_FIRE_ROARING: 'audio/fire-roaring.flac',
MUSIC_WORLD: 'audio/world.flac',
MUSIC_SPACE: 'audio/space.flac',
MUSIC_ENDING: 'audio/ending.flac',
MUSIC_SHIP: 'audio/ship.flac',
EVENT_NOMAD: 'audio/event-nomad.flac',
EVENT_NOISES_OUTSIDE: 'audio/event-noises-outside.flac',
EVENT_NOISES_INSIDE: 'audio/event-noises-inside.flac',
EVENT_BEGGAR: 'audio/event-beggar.flac',
EVENT_SHADY_BUILDER: 'audio/event-shady-builder.flac',
EVENT_MYSTERIOUS_WANDERER: 'audio/event-mysterious-wanderer.flac',
EVENT_SCOUT: 'audio/event-scout.flac',
EVENT_WANDERING_MASTER: 'audio/event-wandering-master.flac',
EVENT_SICK_MAN: 'audio/event-sick-man.flac',
EVENT_RUINED_TRAP: 'audio/event-ruined-trap.flac',
EVENT_HUT_FIRE: 'audio/event-hut-fire.flac',
EVENT_SICKNESS: 'audio/event-sickness.flac',
EVENT_PLAGUE: 'audio/event-plague.flac',
EVENT_BEAST_ATTACK: 'audio/event-beast-attack.flac',
EVENT_SOLDIER_ATTACK: 'audio/event-soldier-attack.flac',
EVENT_THIEF: 'audio/event-thief.flac',
LANDMARK_FRIENDLY_OUTPOST: 'audio/landmark-friendly-outpost.flac',
LANDMARK_SWAMP: 'audio/landmark-swamp.flac',
LANDMARK_CAVE: 'audio/landmark-cave.flac',
LANDMARK_TOWN: 'audio/landmark-town.flac',
LANDMARK_CITY: 'audio/landmark-city.flac',
LANDMARK_HOUSE: 'audio/landmark-house.flac',
LANDMARK_BATTLEFIELD: 'audio/landmark-battlefield.flac',
LANDMARK_BOREHOLE: 'audio/landmark-borehole.flac',
LANDMARK_CRASHED_SHIP: 'audio/landmark-crashed-ship.flac',
LANDMARK_SULPHUR_MINE: 'audio/landmark-sulphurmine.flac',
LANDMARK_COAL_MINE: 'audio/landmark-coalmine.flac',
LANDMARK_IRON_MINE: 'audio/landmark-ironmine.flac',
LANDMARK_DESTROYED_VILLAGE: 'audio/landmark-destroyed-village.flac',
ENCOUNTER_TIER_1: 'audio/encounter-tier-1.flac',
ENCOUNTER_TIER_2: 'audio/encounter-tier-2.flac',
ENCOUNTER_TIER_3: 'audio/encounter-tier-3.flac',
LIGHT_FIRE: 'audio/light-fire.flac',
STOKE_FIRE: 'audio/stoke-fire.flac',
BUILD: 'audio/build.flac',
CRAFT: 'audio/craft.flac',
BUY: 'audio/buy.flac',
GATHER_WOOD: 'audio/gather-wood.flac',
CHECK_TRAPS: 'audio/check-traps.flac',
EMBARK: 'audio/embark.flac',
FOOTSTEPS_1: 'audio/footsteps-1.flac',
FOOTSTEPS_2: 'audio/footsteps-2.flac',
FOOTSTEPS_3: 'audio/footsteps-3.flac',
FOOTSTEPS_4: 'audio/footsteps-4.flac',
FOOTSTEPS_5: 'audio/footsteps-5.flac',
FOOTSTEPS_6: 'audio/footsteps-6.flac',
EAT_MEAT: 'audio/eat-meat.flac',
USE_MEDS: 'audio/use-meds.flac',
WEAPON_UNARMED_1: 'audio/weapon-unarmed-1.flac',
WEAPON_UNARMED_2: 'audio/weapon-unarmed-2.flac',
WEAPON_UNARMED_3: 'audio/weapon-unarmed-3.flac',
WEAPON_MELEE_1: 'audio/weapon-melee-1.flac',
WEAPON_MELEE_2: 'audio/weapon-melee-2.flac',
WEAPON_MELEE_3: 'audio/weapon-melee-3.flac',
WEAPON_RANGED_1: 'audio/weapon-ranged-1.flac',
WEAPON_RANGED_2: 'audio/weapon-ranged-2.flac',
WEAPON_RANGED_3: 'audio/weapon-ranged-3.flac',
DEATH: 'audio/death.flac',
REINFORCE_HULL: 'audio/reinforce-hull.flac',
UPGRADE_ENGINE: 'audio/upgrade-engine.flac',
LIFT_OFF: 'audio/lift-off.flac',
ASTEROID_HIT_1: 'audio/asteroid-hit-1.flac',
ASTEROID_HIT_2: 'audio/asteroid-hit-2.flac',
ASTEROID_HIT_3: 'audio/asteroid-hit-3.flac',
ASTEROID_HIT_4: 'audio/asteroid-hit-4.flac',
ASTEROID_HIT_5: 'audio/asteroid-hit-5.flac',
ASTEROID_HIT_6: 'audio/asteroid-hit-6.flac',
ASTEROID_HIT_7: 'audio/asteroid-hit-7.flac',
ASTEROID_HIT_8: 'audio/asteroid-hit-8.flac',
CRASH: 'audio/crash.flac',
};
+80 -4
View File
@@ -75,7 +75,7 @@
debug: false, debug: false,
log: false, log: false,
dropbox: false, dropbox: false,
doubleTime: false doubleTime: true
}, },
init: function(options) { init: function(options) {
@@ -104,6 +104,15 @@
Engine.loadGame(); Engine.loadGame();
} }
// start loading music and events early
for (var key in AudioLibrary) {
if (
key.toString().indexOf('MUSIC_') > -1 ||
key.toString().indexOf('EVENT_') > -1) {
AudioEngine.loadAudioFile(AudioLibrary[key]);
}
}
$('<div>').attr('id', 'locationSlider').appendTo('#main'); $('<div>').attr('id', 'locationSlider').appendTo('#main');
var menu = $('<div>') var menu = $('<div>')
@@ -133,6 +142,12 @@
}); });
} }
$('<span>')
.addClass('volume menuBtn')
.text(_('sound on.'))
.click(() => Engine.toggleVolume())
.appendTo(menu);
$('<span>') $('<span>')
.addClass('appStore menuBtn') .addClass('appStore menuBtn')
.text(_('get the app.')) .text(_('get the app.'))
@@ -200,10 +215,12 @@
$.Dispatch('stateUpdate').subscribe(Engine.handleStateUpdates); $.Dispatch('stateUpdate').subscribe(Engine.handleStateUpdates);
$SM.init(); $SM.init();
AudioEngine.init();
Notifications.init(); Notifications.init();
Events.init(); Events.init();
Room.init(); Room.init();
if(typeof $SM.get('stores.wood') != 'undefined') { if(typeof $SM.get('stores.wood') != 'undefined') {
Outside.init(); Outside.init();
} }
@@ -222,11 +239,25 @@
Engine.triggerHyperMode(); Engine.triggerHyperMode();
} }
Engine.toggleVolume(Boolean($SM.get('config.soundOn')));
if(!AudioEngine.isAudioContextRunning()){
document.addEventListener('click', Engine.resumeAudioContext, true);
}
Engine.saveLanguage(); Engine.saveLanguage();
Engine.travelTo(Room); Engine.travelTo(Room);
}, setTimeout(notifyAboutSound, 3000);
},
resumeAudioContext: function () {
AudioEngine.tryResumingAudioContext();
// turn on music!
AudioEngine.setMasterVolume($SM.get('config.soundOn') ? 1.0 : 0.0, 0);
document.removeEventListener('click', Engine.resumeAudioContext);
},
browserValid: function() { browserValid: function() {
return ( location.search.indexOf( 'ignorebrowser=true' ) >= 0 || ( typeof Storage != 'undefined' && !oldIE ) ); return ( location.search.indexOf( 'ignorebrowser=true' ) >= 0 || ( typeof Storage != 'undefined' && !oldIE ) );
}, },
@@ -596,7 +627,6 @@
Engine.activeModule = module; Engine.activeModule = module;
module.onArrival(diff); module.onArrival(diff);
Notifications.printQueue(module); Notifications.printQueue(module);
} }
}, },
@@ -782,6 +812,21 @@
} }
}, },
toggleVolume: function(enabled /* optional */) {
if (enabled == null) {
enabled = !$SM.get('config.soundOn');
}
if (!enabled) {
$('.volume').text(_('sound on.'));
$SM.set('config.soundOn', false);
AudioEngine.setMasterVolume(0.0);
} else {
$('.volume').text(_('sound off.'));
$SM.set('config.soundOn', true);
AudioEngine.setMasterVolume(1.0);
}
},
setInterval: function(callback, interval, skipDouble){ setInterval: function(callback, interval, skipDouble){
if( Engine.options.doubleTime && !skipDouble ){ if( Engine.options.doubleTime && !skipDouble ){
Engine.log('Double time, cutting interval in half'); Engine.log('Double time, cutting interval in half');
@@ -802,7 +847,6 @@
return setTimeout(callback, timeout); return setTimeout(callback, timeout);
} }
}; };
function eventNullifier(e) { function eventNullifier(e) {
@@ -813,6 +857,38 @@
return true; return true;
} }
function notifyAboutSound() {
if ($SM.get('playStats.audioAlertShown')) {
return;
}
// Tell new users that there's sound now!
$SM.set('playStats.audioAlertShown', true);
Events.startEvent({
title: _('Sound Available!'),
scenes: {
start: {
text: [
_('ears flooded with new sensations.'),
_('perhaps silence is safer?')
],
buttons: {
'yes': {
text: _('enable audio'),
nextScene: 'end',
onChoose: () => Engine.toggleVolume(true)
},
'no': {
text: _('disable audio'),
nextScene: 'end',
onChoose: () => Engine.toggleVolume(false)
}
}
}
}
});
}
})(); })();
function inView(dir, elem){ function inView(dir, elem){
+52 -4
View File
@@ -11,7 +11,6 @@ var Events = {
_LEAVE_COOLDOWN: 1, _LEAVE_COOLDOWN: 1,
STUN_DURATION: 4000, STUN_DURATION: 4000,
BLINK_INTERVAL: false, BLINK_INTERVAL: false,
init: function(options) { init: function(options) {
this.options = $.extend( this.options = $.extend(
this.options, this.options,
@@ -340,10 +339,12 @@ var Events = {
eatMeat: function(btn) { eatMeat: function(btn) {
Events.doHeal('cured meat', World.meatHeal(), btn); Events.doHeal('cured meat', World.meatHeal(), btn);
AudioEngine.playSound(AudioLibrary.EAT_MEAT);
}, },
useMeds: function(btn) { useMeds: function(btn) {
Events.doHeal('medicine', World.medsHeal(), btn); Events.doHeal('medicine', World.medsHeal(), btn);
AudioEngine.playSound(AudioLibrary.USE_MEDS);
}, },
useWeapon: function(btn) { useWeapon: function(btn) {
@@ -418,6 +419,21 @@ var Events = {
} }
var attackFn = weapon.type == 'ranged' ? Events.animateRanged : Events.animateMelee; var attackFn = weapon.type == 'ranged' ? Events.animateRanged : Events.animateMelee;
// play variation audio for weapon type
var r = Math.floor(Math.random() * 2) + 1;
switch (weapon.type) {
case 'unarmed':
AudioEngine.playSound(AudioLibrary['WEAPON_UNARMED_' + r]);
break;
case 'melee':
AudioEngine.playSound(AudioLibrary['WEAPON_MELEE_' + r]);
break;
case 'ranged':
AudioEngine.playSound(AudioLibrary['WEAPON_RANGED_' + r]);
break;
}
attackFn($('#wanderer'), dmg, function() { attackFn($('#wanderer'), dmg, function() {
if($('#enemy').data('hp') <= 0 && !Events.won) { if($('#enemy').data('hp') <= 0 && !Events.won) {
// Success! // Success!
@@ -427,7 +443,7 @@ var Events = {
} }
}, },
damage: function(fighter, enemy, dmg) { damage: function(fighter, enemy, dmg, type) {
var enemyHp = enemy.data('hp'); var enemyHp = enemy.data('hp');
var msg = ""; var msg = "";
if(typeof dmg == 'number') { if(typeof dmg == 'number') {
@@ -443,6 +459,20 @@ var Events = {
Events.setHeal(); Events.setHeal();
} }
Events.updateFighterDiv(enemy); Events.updateFighterDiv(enemy);
// play variation audio for weapon type
var r = Math.floor(Math.random() * 2) + 1;
switch (type) {
case 'unarmed':
AudioEngine.playSound(AudioLibrary['WEAPON_UNARMED_' + r]);
break;
case 'melee':
AudioEngine.playSound(AudioLibrary['WEAPON_MELEE_' + r]);
break;
case 'ranged':
AudioEngine.playSound(AudioLibrary['WEAPON_RANGED_' + r]);
break;
}
} }
} else { } else {
if(dmg == 'stun') { if(dmg == 'stun') {
@@ -468,7 +498,7 @@ var Events = {
fighter.stop(true, true).animate(start, Events._FIGHT_SPEED, function() { fighter.stop(true, true).animate(start, Events._FIGHT_SPEED, function() {
Events.damage(fighter, enemy, dmg); Events.damage(fighter, enemy, dmg, 'melee');
$(this).animate(end, Events._FIGHT_SPEED, callback); $(this).animate(end, Events._FIGHT_SPEED, callback);
}); });
@@ -489,7 +519,7 @@ var Events = {
$('<div>').css(start).addClass('bullet').text('o').appendTo('#description') $('<div>').css(start).addClass('bullet').text('o').appendTo('#description')
.animate(end, Events._FIGHT_SPEED * 2, 'linear', function() { .animate(end, Events._FIGHT_SPEED * 2, 'linear', function() {
Events.damage(fighter, enemy, dmg); Events.damage(fighter, enemy, dmg, 'ranged');
$(this).remove(); $(this).remove();
if(typeof callback == 'function') { if(typeof callback == 'function') {
@@ -519,6 +549,7 @@ var Events = {
clearTimeout(Events._enemyAttackTimer); clearTimeout(Events._enemyAttackTimer);
Events.endEvent(); Events.endEvent();
World.die(); World.die();
AudioEngine.playSound(AudioLibrary.LOSE_FIGHT);
} }
}); });
} }
@@ -536,6 +567,7 @@ var Events = {
return; return;
} }
Events.endFight(); Events.endFight();
// AudioEngine.playSound(AudioLibrary.WIN_FIGHT);
$('#enemy').animate({opacity: 0}, 300, 'linear', function() { $('#enemy').animate({opacity: 0}, 300, 'linear', function() {
Engine.setTimeout(function() { Engine.setTimeout(function() {
var scene = Events.activeEvent().scenes[Events.activeScene]; var scene = Events.activeEvent().scenes[Events.activeScene];
@@ -1018,6 +1050,7 @@ var Events = {
} else { } else {
var r = Math.floor(Math.random()*(possibleEvents.length)); var r = Math.floor(Math.random()*(possibleEvents.length));
Events.startEvent(possibleEvents[r]); Events.startEvent(possibleEvents[r]);
AudioEngine.playEventMusic(possibleEvents[r].audio);
} }
} }
@@ -1035,6 +1068,20 @@ var Events = {
var r = Math.floor(Math.random()*(possibleFights.length)); var r = Math.floor(Math.random()*(possibleFights.length));
Events.startEvent(possibleFights[r]); Events.startEvent(possibleFights[r]);
// play audio only when fight is possible
if (possibleFights.length > 0) {
if (World.getDistance() > 20) {
// Tier 3
AudioEngine.playEventMusic(AudioLibrary.ENCOUNTER_TIER_3);
} else if (World.getDistance() > 10) {
// Tier 2
AudioEngine.playEventMusic(AudioLibrary.ENCOUNTER_TIER_2);
} else {
// Tier 1
AudioEngine.playEventMusic(AudioLibrary.ENCOUNTER_TIER_1);
}
}
}, },
activeEvent: function() { activeEvent: function() {
@@ -1080,6 +1127,7 @@ var Events = {
}, },
endEvent: function() { endEvent: function() {
AudioEngine.stopEventMusic();
Events.eventPanel().animate({opacity:0}, Events._PANEL_FADE, 'linear', function() { Events.eventPanel().animate({opacity:0}, Events._PANEL_FADE, 'linear', function() {
Events.eventPanel().remove(); Events.eventPanel().remove();
Events.activeEvent().eventPanel = null; Events.activeEvent().eventPanel = null;
+2 -1
View File
@@ -61,6 +61,7 @@ Events.Global = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_THIEF
} }
]; ];
+12 -6
View File
@@ -63,7 +63,8 @@ Events.Outside = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_RUINED_TRAP
}, },
{ /* Hut fire */ { /* Hut fire */
title: _('Fire'), title: _('Fire'),
@@ -89,7 +90,8 @@ Events.Outside = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_HUT_FIRE
}, },
{ /* Sickness */ { /* Sickness */
title: _('Sickness'), title: _('Sickness'),
@@ -146,7 +148,8 @@ Events.Outside = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_SICKNESS
}, },
{ /* Plague */ { /* Plague */
@@ -217,7 +220,8 @@ Events.Outside = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_PLAGUE
}, },
{ /* Beast attack */ { /* Beast attack */
@@ -251,7 +255,8 @@ Events.Outside = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_BEAST_ATTACK
}, },
{ /* Soldier attack */ { /* Soldier attack */
@@ -285,7 +290,8 @@ Events.Outside = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_SOLDIER_ATTACK
} }
]; ];
+20 -10
View File
@@ -47,7 +47,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_NOMAD
}, },
{ /* Noises Outside -- gain wood/fur */ { /* Noises Outside -- gain wood/fur */
title: _('Noises'), title: _('Noises'),
@@ -98,7 +99,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_NOISES_OUTSIDE
}, },
{ /* Noises Inside -- trade wood for better good */ { /* Noises Inside -- trade wood for better good */
title: _('Noises'), title: _('Noises'),
@@ -184,7 +186,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_NOISES_INSIDE
}, },
{ /* The Beggar -- trade fur for better good */ { /* The Beggar -- trade fur for better good */
title: _('The Beggar'), title: _('The Beggar'),
@@ -255,7 +258,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_BEGGAR
}, },
{/* The Shady Builder */ {/* The Shady Builder */
title: _('The Shady Builder'), title: _('The Shady Builder'),
@@ -311,7 +315,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_SHADY_BUILDER
}, },
{ /* Mysterious Wanderer -- wood gambling */ { /* Mysterious Wanderer -- wood gambling */
@@ -390,7 +395,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_MYSTERIOUS_WANDERER
}, },
{ /* Mysterious Wanderer -- fur gambling */ { /* Mysterious Wanderer -- fur gambling */
@@ -469,7 +475,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_MYSTERIOUS_WANDERER
}, },
{ /* The Scout -- Map Merchant */ { /* The Scout -- Map Merchant */
@@ -511,7 +518,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_SCOUT
}, },
{ /* The Wandering Master */ { /* The Wandering Master */
@@ -584,7 +592,8 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_WANDERING_MASTER
}, },
{ /* The Sick Man */ { /* The Sick Man */
@@ -672,6 +681,7 @@ Events.Room = [
} }
} }
} }
} },
audio: AudioLibrary.EVENT_SICK_MAN
} }
]; ];
+26 -13
View File
@@ -28,7 +28,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_FRIENDLY_OUTPOST
}, },
"swamp": { /* Swamp */ "swamp": { /* Swamp */
title: _('A Murky Swamp'), title: _('A Murky Swamp'),
@@ -85,7 +86,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_SWAMP
}, },
"cave": { /* Cave */ "cave": { /* Cave */
title: _('A Damp Cave'), title: _('A Damp Cave'),
@@ -516,7 +518,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_CAVE
}, },
"town": { /* Town */ "town": { /* Town */
title: _('A Deserted Town'), title: _('A Deserted Town'),
@@ -1233,7 +1236,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_TOWN
}, },
"city": { /* City */ "city": { /* City */
title: _('A Ruined City'), title: _('A Ruined City'),
@@ -2928,7 +2932,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_CITY
}, },
"house": { /* Abandoned House */ "house": { /* Abandoned House */
title: _('An Old House'), title: _('An Old House'),
@@ -3045,7 +3050,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_HOUSE
}, },
"battlefield": { /* Discovering an old battlefield */ "battlefield": { /* Discovering an old battlefield */
title: _('A Forgotten Battlefield'), title: _('A Forgotten Battlefield'),
@@ -3098,7 +3104,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_BATTLEFIELD
}, },
"borehole": { /* Admiring a huge borehole */ "borehole": { /* Admiring a huge borehole */
title: _('A Huge Borehole'), title: _('A Huge Borehole'),
@@ -3127,7 +3134,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_BOREHOLE
}, },
"ship": { /* Finding a way off this rock */ "ship": { /* Finding a way off this rock */
title: _('A Crashed Ship'), title: _('A Crashed Ship'),
@@ -3150,7 +3158,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_CRASHED_SHIP
}, },
"sulphurmine": { /* Clearing the Sulphur Mine */ "sulphurmine": { /* Clearing the Sulphur Mine */
title: _('The Sulphur Mine'), title: _('The Sulphur Mine'),
@@ -3299,7 +3308,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_SULPHUR_MINE
}, },
"coalmine": { /* Clearing the Coal Mine */ "coalmine": { /* Clearing the Coal Mine */
title: _('The Coal Mine'), title: _('The Coal Mine'),
@@ -3441,7 +3451,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_COAL_MINE
}, },
"ironmine": { /* Clearing the Iron Mine */ "ironmine": { /* Clearing the Iron Mine */
title: _('The Iron Mine'), title: _('The Iron Mine'),
@@ -3517,7 +3528,8 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_IRON_MINE
}, },
"cache": { /* Cache - contains some of supplies from previous game */ "cache": { /* Cache - contains some of supplies from previous game */
@@ -3569,6 +3581,7 @@ Events.Setpieces = {
} }
} }
} }
} },
audio: AudioLibrary.LANDMARK_DESTROYED_VILLAGE
} }
}; };
+18 -1
View File
@@ -94,7 +94,6 @@ var Outside = {
} }
} }
}, },
TrapDrops: [ TrapDrops: [
{ {
rollUnder: 0.5, rollUnder: 0.5,
@@ -588,12 +587,29 @@ var Outside = {
Outside.updateVillage(true); Outside.updateVillage(true);
Engine.moveStoresView($('#village'), transition_diff); Engine.moveStoresView($('#village'), transition_diff);
// set music
var numberOfHuts = $SM.get('game.buildings["hut"]', true);
if(numberOfHuts === 0) {
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_SILENT_FOREST);
} else if(numberOfHuts == 1) {
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_LONELY_HUT);
} else if(numberOfHuts <= 4) {
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_TINY_VILLAGE);
} else if(numberOfHuts <= 8) {
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_MODEST_VILLAGE);
} else if(numberOfHuts <= 14) {
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_LARGE_VILLAGE);
} else {
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_RAUCOUS_VILLAGE);
}
}, },
gatherWood: function() { gatherWood: function() {
Notifications.notify(Outside, _("dry brush and dead branches litter the forest floor")); Notifications.notify(Outside, _("dry brush and dead branches litter the forest floor"));
var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10; var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10;
$SM.add('stores.wood', gatherAmt); $SM.add('stores.wood', gatherAmt);
AudioEngine.playSound(AudioLibrary.GATHER_WOOD);
}, },
checkTraps: function() { checkTraps: function() {
@@ -634,6 +650,7 @@ var Outside = {
Notifications.notify(Outside, s); Notifications.notify(Outside, s);
$SM.addM('stores', drops); $SM.addM('stores', drops);
AudioEngine.playSound(AudioLibrary.CHECK_TRAPS);
}, },
handleStateUpdates: function(e){ handleStateUpdates: function(e){

Some files were not shown because too many files have changed in this diff Show More