mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 16:21:53 +08:00
We have audio! Thanks @orsi!
This commit is contained in:
+236
@@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -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',
|
||||
};
|
||||
+82
-6
@@ -75,7 +75,7 @@
|
||||
debug: false,
|
||||
log: false,
|
||||
dropbox: false,
|
||||
doubleTime: false
|
||||
doubleTime: true
|
||||
},
|
||||
|
||||
init: function(options) {
|
||||
@@ -104,6 +104,15 @@
|
||||
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');
|
||||
|
||||
var menu = $('<div>')
|
||||
@@ -133,6 +142,12 @@
|
||||
});
|
||||
}
|
||||
|
||||
$('<span>')
|
||||
.addClass('volume menuBtn')
|
||||
.text(_('sound on.'))
|
||||
.click(() => Engine.toggleVolume())
|
||||
.appendTo(menu);
|
||||
|
||||
$('<span>')
|
||||
.addClass('appStore menuBtn')
|
||||
.text(_('get the app.'))
|
||||
@@ -200,10 +215,12 @@
|
||||
$.Dispatch('stateUpdate').subscribe(Engine.handleStateUpdates);
|
||||
|
||||
$SM.init();
|
||||
AudioEngine.init();
|
||||
Notifications.init();
|
||||
Events.init();
|
||||
Room.init();
|
||||
|
||||
|
||||
if(typeof $SM.get('stores.wood') != 'undefined') {
|
||||
Outside.init();
|
||||
}
|
||||
@@ -215,18 +232,32 @@
|
||||
}
|
||||
|
||||
if($SM.get('config.lightsOff', true)){
|
||||
Engine.turnLightsOff();
|
||||
Engine.turnLightsOff();
|
||||
}
|
||||
|
||||
if($SM.get('config.hyperMode', true)){
|
||||
Engine.triggerHyperMode();
|
||||
Engine.triggerHyperMode();
|
||||
}
|
||||
|
||||
Engine.toggleVolume(Boolean($SM.get('config.soundOn')));
|
||||
if(!AudioEngine.isAudioContextRunning()){
|
||||
document.addEventListener('click', Engine.resumeAudioContext, true);
|
||||
}
|
||||
|
||||
Engine.saveLanguage();
|
||||
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() {
|
||||
return ( location.search.indexOf( 'ignorebrowser=true' ) >= 0 || ( typeof Storage != 'undefined' && !oldIE ) );
|
||||
},
|
||||
@@ -596,7 +627,6 @@
|
||||
Engine.activeModule = module;
|
||||
module.onArrival(diff);
|
||||
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){
|
||||
if( Engine.options.doubleTime && !skipDouble ){
|
||||
Engine.log('Double time, cutting interval in half');
|
||||
@@ -802,7 +847,6 @@
|
||||
return setTimeout(callback, timeout);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function eventNullifier(e) {
|
||||
@@ -813,6 +857,38 @@
|
||||
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){
|
||||
|
||||
+54
-6
@@ -11,7 +11,6 @@ var Events = {
|
||||
_LEAVE_COOLDOWN: 1,
|
||||
STUN_DURATION: 4000,
|
||||
BLINK_INTERVAL: false,
|
||||
|
||||
init: function(options) {
|
||||
this.options = $.extend(
|
||||
this.options,
|
||||
@@ -135,7 +134,7 @@ var Events = {
|
||||
}
|
||||
$('<div>').addClass('clear').appendTo(healBtns);
|
||||
Events.setHeal(healBtns);
|
||||
|
||||
|
||||
// Set up the enemy attack timer
|
||||
Events._enemyAttackTimer = Engine.setInterval(Events.enemyAttack, scene.attackDelay * 1000);
|
||||
},
|
||||
@@ -340,10 +339,12 @@ var Events = {
|
||||
|
||||
eatMeat: function(btn) {
|
||||
Events.doHeal('cured meat', World.meatHeal(), btn);
|
||||
AudioEngine.playSound(AudioLibrary.EAT_MEAT);
|
||||
},
|
||||
|
||||
useMeds: function(btn) {
|
||||
Events.doHeal('medicine', World.medsHeal(), btn);
|
||||
AudioEngine.playSound(AudioLibrary.USE_MEDS);
|
||||
},
|
||||
|
||||
useWeapon: function(btn) {
|
||||
@@ -416,8 +417,23 @@ var Events = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
if($('#enemy').data('hp') <= 0 && !Events.won) {
|
||||
// Success!
|
||||
@@ -427,7 +443,7 @@ var Events = {
|
||||
}
|
||||
},
|
||||
|
||||
damage: function(fighter, enemy, dmg) {
|
||||
damage: function(fighter, enemy, dmg, type) {
|
||||
var enemyHp = enemy.data('hp');
|
||||
var msg = "";
|
||||
if(typeof dmg == 'number') {
|
||||
@@ -443,6 +459,20 @@ var Events = {
|
||||
Events.setHeal();
|
||||
}
|
||||
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 {
|
||||
if(dmg == 'stun') {
|
||||
@@ -468,7 +498,7 @@ var Events = {
|
||||
|
||||
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);
|
||||
});
|
||||
@@ -489,7 +519,7 @@ var Events = {
|
||||
$('<div>').css(start).addClass('bullet').text('o').appendTo('#description')
|
||||
.animate(end, Events._FIGHT_SPEED * 2, 'linear', function() {
|
||||
|
||||
Events.damage(fighter, enemy, dmg);
|
||||
Events.damage(fighter, enemy, dmg, 'ranged');
|
||||
|
||||
$(this).remove();
|
||||
if(typeof callback == 'function') {
|
||||
@@ -519,6 +549,7 @@ var Events = {
|
||||
clearTimeout(Events._enemyAttackTimer);
|
||||
Events.endEvent();
|
||||
World.die();
|
||||
AudioEngine.playSound(AudioLibrary.LOSE_FIGHT);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -536,6 +567,7 @@ var Events = {
|
||||
return;
|
||||
}
|
||||
Events.endFight();
|
||||
// AudioEngine.playSound(AudioLibrary.WIN_FIGHT);
|
||||
$('#enemy').animate({opacity: 0}, 300, 'linear', function() {
|
||||
Engine.setTimeout(function() {
|
||||
var scene = Events.activeEvent().scenes[Events.activeScene];
|
||||
@@ -1018,6 +1050,7 @@ var Events = {
|
||||
} else {
|
||||
var r = Math.floor(Math.random()*(possibleEvents.length));
|
||||
Events.startEvent(possibleEvents[r]);
|
||||
AudioEngine.playEventMusic(possibleEvents[r].audio);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1035,6 +1068,20 @@ var Events = {
|
||||
|
||||
var r = Math.floor(Math.random()*(possibleFights.length));
|
||||
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() {
|
||||
@@ -1080,6 +1127,7 @@ var Events = {
|
||||
},
|
||||
|
||||
endEvent: function() {
|
||||
AudioEngine.stopEventMusic();
|
||||
Events.eventPanel().animate({opacity:0}, Events._PANEL_FADE, 'linear', function() {
|
||||
Events.eventPanel().remove();
|
||||
Events.activeEvent().eventPanel = null;
|
||||
|
||||
@@ -61,6 +61,7 @@ Events.Global = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_THIEF
|
||||
}
|
||||
];
|
||||
|
||||
@@ -63,7 +63,8 @@ Events.Outside = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_RUINED_TRAP
|
||||
},
|
||||
{ /* Hut fire */
|
||||
title: _('Fire'),
|
||||
@@ -89,7 +90,8 @@ Events.Outside = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_HUT_FIRE
|
||||
},
|
||||
{ /* Sickness */
|
||||
title: _('Sickness'),
|
||||
@@ -146,7 +148,8 @@ Events.Outside = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_SICKNESS
|
||||
},
|
||||
|
||||
{ /* Plague */
|
||||
@@ -217,7 +220,8 @@ Events.Outside = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_PLAGUE
|
||||
},
|
||||
|
||||
{ /* Beast attack */
|
||||
@@ -251,7 +255,8 @@ Events.Outside = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_BEAST_ATTACK
|
||||
},
|
||||
|
||||
{ /* Soldier attack */
|
||||
@@ -285,7 +290,8 @@ Events.Outside = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_SOLDIER_ATTACK
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
+20
-10
@@ -47,7 +47,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_NOMAD
|
||||
},
|
||||
{ /* Noises Outside -- gain wood/fur */
|
||||
title: _('Noises'),
|
||||
@@ -98,7 +99,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_NOISES_OUTSIDE
|
||||
},
|
||||
{ /* Noises Inside -- trade wood for better good */
|
||||
title: _('Noises'),
|
||||
@@ -184,7 +186,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_NOISES_INSIDE
|
||||
},
|
||||
{ /* The Beggar -- trade fur for better good */
|
||||
title: _('The Beggar'),
|
||||
@@ -255,7 +258,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_BEGGAR
|
||||
},
|
||||
{/* The Shady Builder */
|
||||
title: _('The Shady Builder'),
|
||||
@@ -311,7 +315,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_SHADY_BUILDER
|
||||
},
|
||||
|
||||
{ /* Mysterious Wanderer -- wood gambling */
|
||||
@@ -390,7 +395,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_MYSTERIOUS_WANDERER
|
||||
},
|
||||
|
||||
{ /* Mysterious Wanderer -- fur gambling */
|
||||
@@ -469,7 +475,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_MYSTERIOUS_WANDERER
|
||||
},
|
||||
|
||||
{ /* The Scout -- Map Merchant */
|
||||
@@ -511,7 +518,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_SCOUT
|
||||
},
|
||||
|
||||
{ /* The Wandering Master */
|
||||
@@ -584,7 +592,8 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_WANDERING_MASTER
|
||||
},
|
||||
|
||||
{ /* The Sick Man */
|
||||
@@ -672,6 +681,7 @@ Events.Room = [
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.EVENT_SICK_MAN
|
||||
}
|
||||
];
|
||||
|
||||
+26
-13
@@ -28,7 +28,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_FRIENDLY_OUTPOST
|
||||
},
|
||||
"swamp": { /* Swamp */
|
||||
title: _('A Murky Swamp'),
|
||||
@@ -85,7 +86,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_SWAMP
|
||||
},
|
||||
"cave": { /* Cave */
|
||||
title: _('A Damp Cave'),
|
||||
@@ -516,7 +518,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_CAVE
|
||||
},
|
||||
"town": { /* Town */
|
||||
title: _('A Deserted Town'),
|
||||
@@ -1233,7 +1236,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_TOWN
|
||||
},
|
||||
"city": { /* City */
|
||||
title: _('A Ruined City'),
|
||||
@@ -2928,7 +2932,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_CITY
|
||||
},
|
||||
"house": { /* Abandoned House */
|
||||
title: _('An Old House'),
|
||||
@@ -3045,7 +3050,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_HOUSE
|
||||
},
|
||||
"battlefield": { /* Discovering an old battlefield */
|
||||
title: _('A Forgotten Battlefield'),
|
||||
@@ -3098,7 +3104,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_BATTLEFIELD
|
||||
},
|
||||
"borehole": { /* Admiring a huge borehole */
|
||||
title: _('A Huge Borehole'),
|
||||
@@ -3127,7 +3134,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_BOREHOLE
|
||||
},
|
||||
"ship": { /* Finding a way off this rock */
|
||||
title: _('A Crashed Ship'),
|
||||
@@ -3150,7 +3158,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_CRASHED_SHIP
|
||||
},
|
||||
"sulphurmine": { /* Clearing the Sulphur Mine */
|
||||
title: _('The Sulphur Mine'),
|
||||
@@ -3299,7 +3308,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_SULPHUR_MINE
|
||||
},
|
||||
"coalmine": { /* Clearing the Coal Mine */
|
||||
title: _('The Coal Mine'),
|
||||
@@ -3441,7 +3451,8 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_COAL_MINE
|
||||
},
|
||||
"ironmine": { /* Clearing 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 */
|
||||
@@ -3569,6 +3581,7 @@ Events.Setpieces = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
audio: AudioLibrary.LANDMARK_DESTROYED_VILLAGE
|
||||
}
|
||||
};
|
||||
|
||||
+18
-1
@@ -94,7 +94,6 @@ var Outside = {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
TrapDrops: [
|
||||
{
|
||||
rollUnder: 0.5,
|
||||
@@ -588,12 +587,29 @@ var Outside = {
|
||||
Outside.updateVillage(true);
|
||||
|
||||
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() {
|
||||
Notifications.notify(Outside, _("dry brush and dead branches litter the forest floor"));
|
||||
var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10;
|
||||
$SM.add('stores.wood', gatherAmt);
|
||||
AudioEngine.playSound(AudioLibrary.GATHER_WOOD);
|
||||
},
|
||||
|
||||
checkTraps: function() {
|
||||
@@ -634,6 +650,7 @@ var Outside = {
|
||||
|
||||
Notifications.notify(Outside, s);
|
||||
$SM.addM('stores', drops);
|
||||
AudioEngine.playSound(AudioLibrary.CHECK_TRAPS);
|
||||
},
|
||||
|
||||
handleStateUpdates: function(e){
|
||||
|
||||
+3
-1
@@ -1,5 +1,4 @@
|
||||
var Path = {
|
||||
|
||||
DEFAULT_BAG_SPACE: 10,
|
||||
_STORES_OFFSET: 0,
|
||||
// Everything not in this list weighs 1
|
||||
@@ -304,6 +303,8 @@ var Path = {
|
||||
Path.setTitle();
|
||||
Path.updateOutfitting();
|
||||
Path.updatePerks(true);
|
||||
|
||||
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_DUSTY_PATH);
|
||||
|
||||
Engine.moveStoresView($('#perks'), transition_diff);
|
||||
},
|
||||
@@ -319,6 +320,7 @@ var Path = {
|
||||
World.onArrival();
|
||||
$('#outerSlider').animate({left: '-700px'}, 300);
|
||||
Engine.activeModule = World;
|
||||
AudioEngine.playSound(AudioLibrary.EMBARK);
|
||||
},
|
||||
|
||||
handleStateUpdates: function(e){
|
||||
|
||||
+432
-351
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -7,7 +7,6 @@ var Ship = {
|
||||
ALLOY_PER_THRUSTER: 1,
|
||||
BASE_HULL: 0,
|
||||
BASE_THRUSTERS: 1,
|
||||
|
||||
name: _("Ship"),
|
||||
init: function(options) {
|
||||
this.options = $.extend(
|
||||
@@ -91,6 +90,7 @@ var Ship = {
|
||||
Notifications.notify(Ship, _('somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.'));
|
||||
$SM.set('game.spaceShip.seenShip', true);
|
||||
}
|
||||
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_SHIP);
|
||||
|
||||
Engine.moveStoresView(null, transition_diff);
|
||||
},
|
||||
@@ -112,6 +112,7 @@ var Ship = {
|
||||
Button.setDisabled($('#liftoffButton', Ship.panel), false);
|
||||
}
|
||||
$('#hullRow .row_val', Ship.panel).text($SM.get('game.spaceShip.hull'));
|
||||
AudioEngine.playSound(AudioLibrary.REINFORCE_HULL);
|
||||
},
|
||||
|
||||
upgradeEngine: function() {
|
||||
@@ -122,6 +123,7 @@ var Ship = {
|
||||
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_THRUSTER);
|
||||
$SM.add('game.spaceShip.thrusters', 1);
|
||||
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
|
||||
AudioEngine.playSound(AudioLibrary.UPGRADE_ENGINE);
|
||||
},
|
||||
|
||||
getMaxHull: function() {
|
||||
@@ -166,6 +168,7 @@ var Ship = {
|
||||
$('#outerSlider').animate({top: '700px'}, 300);
|
||||
Space.onArrival();
|
||||
Engine.activeModule = Space;
|
||||
AudioEngine.playSound(AudioLibrary.LIFT_OFF);
|
||||
},
|
||||
|
||||
handleStateUpdates: function(e){
|
||||
|
||||
+33
-2
@@ -11,7 +11,6 @@ var Space = {
|
||||
NUM_STARS: 200,
|
||||
STAR_SPEED: 60000,
|
||||
FRAME_DELAY: 100,
|
||||
|
||||
stars: null,
|
||||
backStars: null,
|
||||
ship: null,
|
||||
@@ -54,6 +53,7 @@ var Space = {
|
||||
Space.hull = Ship.getMaxHull();
|
||||
Space.altitude = 0;
|
||||
Space.setTitle();
|
||||
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_SPACE);
|
||||
Space.updateHull();
|
||||
|
||||
Space.up =
|
||||
@@ -67,6 +67,8 @@ var Space = {
|
||||
});
|
||||
Space.startAscent();
|
||||
Space._shipTimer = setInterval(Space.moveShip, 33);
|
||||
Space._volumeTimer = setInterval(Space.lowerVolume, 1000);
|
||||
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_SPACE);
|
||||
},
|
||||
|
||||
setTitle: function() {
|
||||
@@ -136,6 +138,21 @@ var Space = {
|
||||
t.remove();
|
||||
Space.hull--;
|
||||
Space.updateHull();
|
||||
|
||||
// play audio on asteroid hit
|
||||
// higher altitudes play higher frequency hits
|
||||
var r = Math.floor(Math.random() * 2);
|
||||
if(Space.altitude > 40) {
|
||||
r += 6;
|
||||
AudioEngine.playSound(AudioLibrary['ASTEROID_HIT_' + r]);
|
||||
} else if(Space.altitude > 20) {
|
||||
r += 4;
|
||||
AudioEngine.playSound(AudioLibrary['ASTEROID_HIT_' + r]);
|
||||
} else {
|
||||
r += 1;
|
||||
AudioEngine.playSound(AudioLibrary['ASTEROID_HIT_' + r]);
|
||||
}
|
||||
|
||||
if(Space.hull === 0) {
|
||||
Space.crash();
|
||||
}
|
||||
@@ -221,7 +238,7 @@ var Space = {
|
||||
left: x + 'px',
|
||||
top: y + 'px'
|
||||
});
|
||||
|
||||
|
||||
Space.lastMove = Date.now();
|
||||
},
|
||||
|
||||
@@ -325,6 +342,7 @@ var Space = {
|
||||
Space.done = true;
|
||||
clearInterval(Space._timer);
|
||||
clearInterval(Space._shipTimer);
|
||||
clearInterval(Space._volumeTimer);
|
||||
clearTimeout(Space._panelTimeout);
|
||||
var body_color;
|
||||
if (Engine.isLightsOff())
|
||||
@@ -358,6 +376,7 @@ var Space = {
|
||||
Ship.onArrival();
|
||||
Button.cooldown($('#liftoffButton'));
|
||||
Engine.event('progress', 'crash');
|
||||
AudioEngine.playSound(AudioLibrary.CRASH);
|
||||
},
|
||||
|
||||
endGame: function() {
|
||||
@@ -366,6 +385,7 @@ var Space = {
|
||||
Space.done = true;
|
||||
clearInterval(Space._timer);
|
||||
clearInterval(Space._shipTimer);
|
||||
clearInterval(Space._volumeTimer);
|
||||
clearTimeout(Engine._saveTimer);
|
||||
clearTimeout(Outside._popTimeout);
|
||||
clearTimeout(Engine._incomeTimeout);
|
||||
@@ -380,6 +400,8 @@ var Space = {
|
||||
}
|
||||
delete Outside._popTimeout;
|
||||
|
||||
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_ENDING);
|
||||
|
||||
$('#hullRemaining', Space.panel).animate({opacity: 0}, 500, 'linear');
|
||||
Space.ship.animate({
|
||||
top: '350px',
|
||||
@@ -532,5 +554,14 @@ var Space = {
|
||||
|
||||
handleStateUpdates: function(e){
|
||||
|
||||
},
|
||||
|
||||
lowerVolume: function () {
|
||||
if (Space.done) return;
|
||||
|
||||
// lower audio as ship gets further into space
|
||||
var progress = Space.altitude / 60;
|
||||
var newVolume = 1.0 - progress;
|
||||
AudioEngine.setBackgroundMusicVolume(newVolume, 0.3);
|
||||
}
|
||||
};
|
||||
|
||||
+8
-1
@@ -1,5 +1,4 @@
|
||||
var World = {
|
||||
|
||||
RADIUS: 30,
|
||||
VILLAGE_POS: [30, 30],
|
||||
TILE: {
|
||||
@@ -347,6 +346,11 @@ var World = {
|
||||
World.lightMap(World.curPos[0], World.curPos[1], World.state.mask);
|
||||
World.drawMap();
|
||||
World.doSpace();
|
||||
|
||||
// play random footstep
|
||||
var randomFootstep = Math.floor(Math.random() * 5) + 1;
|
||||
AudioEngine.playSound(AudioLibrary['FOOTSTEPS_' + randomFootstep]);
|
||||
|
||||
if(World.checkDanger()) {
|
||||
if(World.danger) {
|
||||
Notifications.notify(World, _('dangerous to be this far from the village without proper protection'));
|
||||
@@ -534,6 +538,7 @@ var World = {
|
||||
} else if(typeof World.LANDMARKS[curTile] != 'undefined') {
|
||||
if(curTile != World.TILE.OUTPOST || !World.outpostUsed()) {
|
||||
Events.startEvent(Events.Setpieces[World.LANDMARKS[curTile].scene]);
|
||||
AudioEngine.playEventMusic(Events.Setpieces[World.LANDMARKS[curTile].scene].audio);
|
||||
}
|
||||
} else {
|
||||
if(World.useSupplies()) {
|
||||
@@ -883,6 +888,7 @@ var World = {
|
||||
World.state = null;
|
||||
Path.outfit = {};
|
||||
$SM.remove('outfit');
|
||||
AudioEngine.playSound(AudioLibrary.DEATH);
|
||||
$('#outerSlider').animate({opacity: '0'}, 600, 'linear', function() {
|
||||
$('#outerSlider').css('left', '0px');
|
||||
$('#locationSlider').css('left', '0px');
|
||||
@@ -1006,6 +1012,7 @@ var World = {
|
||||
World.curPos = World.copyPos(World.VILLAGE_POS);
|
||||
World.drawMap();
|
||||
World.setTitle();
|
||||
AudioEngine.playBackgroundMusic(AudioLibrary.MUSIC_WORLD);
|
||||
World.dead = false;
|
||||
$('div#bagspace-world > div').empty();
|
||||
World.updateSupplies();
|
||||
|
||||
Reference in New Issue
Block a user