Merge pull request #17 from rsninja722/breathing-sounds
Add coughing and breaths
This commit is contained in:
commit
f2112645b4
@ -37,7 +37,8 @@ var constants = {
|
|||||||
},
|
},
|
||||||
lifeFuncs:{
|
lifeFuncs:{
|
||||||
breath:{
|
breath:{
|
||||||
fullBreath: 200
|
fullBreath: 200,
|
||||||
|
cough_interval_secs: 4.0
|
||||||
},
|
},
|
||||||
cardio:{
|
cardio:{
|
||||||
optimalPressure: 50
|
optimalPressure: 50
|
||||||
|
@ -19,8 +19,14 @@ let justBlinked = false;
|
|||||||
function updateLife() {
|
function updateLife() {
|
||||||
|
|
||||||
if(keyDown[k.x]) {
|
if(keyDown[k.x]) {
|
||||||
if(breath === 0) currentBreathMode = breathMode.inhale;
|
if (breath === 0) {
|
||||||
else if(breath === constants.lifeFuncs.breath.fullBreath) currentBreathMode = breathMode.exhale;
|
soundAssets.inhale.play();
|
||||||
|
currentBreathMode = breathMode.inhale;
|
||||||
|
}
|
||||||
|
else if (breath === constants.lifeFuncs.breath.fullBreath) {
|
||||||
|
soundAssets.exhale.play();
|
||||||
|
currentBreathMode = breathMode.exhale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
breathe();
|
breathe();
|
||||||
@ -50,6 +56,7 @@ function breathe() {
|
|||||||
fullBreathTimer++;
|
fullBreathTimer++;
|
||||||
if(fullBreathTimer >= 600) {
|
if(fullBreathTimer >= 600) {
|
||||||
//cough and lose breath or something
|
//cough and lose breath or something
|
||||||
|
handleCough();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fullBreathTimer = 0;
|
fullBreathTimer = 0;
|
||||||
@ -62,6 +69,7 @@ function breathe() {
|
|||||||
noBreathTimer++;
|
noBreathTimer++;
|
||||||
if(noBreathTimer >= 300) {
|
if(noBreathTimer >= 300) {
|
||||||
//cough and lose breath or something
|
//cough and lose breath or something
|
||||||
|
handleCough();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
noBreathTimer = 0;
|
noBreathTimer = 0;
|
||||||
@ -70,6 +78,27 @@ function breathe() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Tracker for if we are currently coughing
|
||||||
|
let _nextCoughAllowedTime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle player coughing without spamming the sound buffer
|
||||||
|
*/
|
||||||
|
function handleCough() {
|
||||||
|
|
||||||
|
// Only cough if we are past the cough time
|
||||||
|
if (getCurrentTimeSeconds() >= _nextCoughAllowedTime) {
|
||||||
|
|
||||||
|
console.log("[LifeFunctions] Coughing")
|
||||||
|
|
||||||
|
// Set the next allowed cough time
|
||||||
|
_nextCoughAllowedTime = getCurrentTimeSeconds() + constants.lifeFuncs.breath.cough_interval_secs;
|
||||||
|
|
||||||
|
// Play the cough audio
|
||||||
|
soundAssets.cough.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function heartbeat() {
|
function heartbeat() {
|
||||||
pressure+=10;
|
pressure+=10;
|
||||||
if(pressure>=100){
|
if(pressure>=100){
|
||||||
|
@ -13,13 +13,16 @@
|
|||||||
// This exists to give nicer names to files
|
// This exists to give nicer names to files
|
||||||
let soundAssetMap = {
|
let soundAssetMap = {
|
||||||
"debug-ding": "./assets/sounds/debug-ding.mp3",
|
"debug-ding": "./assets/sounds/debug-ding.mp3",
|
||||||
"footstep1":"./assets/sounds/footsteps/footstep1.mp3",
|
"footstep1": "./assets/sounds/footsteps/footstep1.mp3",
|
||||||
"footstep2":"./assets/sounds/footsteps/footstep2.mp3",
|
"footstep2": "./assets/sounds/footsteps/footstep2.mp3",
|
||||||
"footstep3":"./assets/sounds/footsteps/footstep3.mp3",
|
"footstep3": "./assets/sounds/footsteps/footstep3.mp3",
|
||||||
"footstep4":"./assets/sounds/footsteps/footstep4.mp3",
|
"footstep4": "./assets/sounds/footsteps/footstep4.mp3",
|
||||||
"footstep5":"./assets/sounds/footsteps/footstep5.mp3",
|
"footstep5": "./assets/sounds/footsteps/footstep5.mp3",
|
||||||
"footstep6":"./assets/sounds/footsteps/footstep6.mp3",
|
"footstep6": "./assets/sounds/footsteps/footstep6.mp3",
|
||||||
"heartbeat":"./assets/sounds/heartbeat.mp3"
|
"heartbeat": "./assets/sounds/heartbeat.mp3",
|
||||||
|
"inhale": "./assets/sounds/breathing/inhale.mp3",
|
||||||
|
"exhale": "./assets/sounds/breathing/exhale.mp3",
|
||||||
|
"cough":"./assets/sounds/cough.mp3"
|
||||||
}
|
}
|
||||||
|
|
||||||
// All available sounds
|
// All available sounds
|
||||||
@ -31,7 +34,10 @@ let soundAssets = {
|
|||||||
footstep4: new SoundSnippet("footstep4", audioAssetType.sfx),
|
footstep4: new SoundSnippet("footstep4", audioAssetType.sfx),
|
||||||
footstep5: new SoundSnippet("footstep5", audioAssetType.sfx),
|
footstep5: new SoundSnippet("footstep5", audioAssetType.sfx),
|
||||||
footstep6: new SoundSnippet("footstep6", audioAssetType.sfx),
|
footstep6: new SoundSnippet("footstep6", audioAssetType.sfx),
|
||||||
heartbeat: new SoundSnippet("heartbeat", audioAssetType.sfx)
|
heartbeat: new SoundSnippet("heartbeat", audioAssetType.sfx),
|
||||||
|
inhale: new SoundSnippet("inhale", audioAssetType.sfx),
|
||||||
|
exhale: new SoundSnippet("exhale", audioAssetType.sfx),
|
||||||
|
cough: new SoundSnippet("cough", audioAssetType.sfx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,10 @@ function clamp(value, min, max) {
|
|||||||
return Math.min(max, Math.max(min, value));
|
return Math.min(max, Math.max(min, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentTimeSeconds() {
|
||||||
|
return new Date().getTime() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
// linear interpolation towards somewhere
|
// linear interpolation towards somewhere
|
||||||
function lerp(start, end, amt) { return (1 - amt) * start + amt * end; }
|
function lerp(start, end, amt) { return (1 - amt) * start + amt * end; }
|
||||||
|
|
||||||
|
BIN
docs/assets/sounds/breathing/exhale.mp3
Normal file
BIN
docs/assets/sounds/breathing/exhale.mp3
Normal file
Binary file not shown.
BIN
docs/assets/sounds/breathing/inhale.mp3
Normal file
BIN
docs/assets/sounds/breathing/inhale.mp3
Normal file
Binary file not shown.
BIN
docs/assets/sounds/cough.mp3
Normal file
BIN
docs/assets/sounds/cough.mp3
Normal file
Binary file not shown.
Reference in New Issue
Block a user