Skip to content

Commit

Permalink
Added audio through mp3
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Aug 17, 2020
1 parent 3355b3d commit 99dbef2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ const ctrl = ( function() {
const dvAnswer = getHtmlPart( "dvAnswer", "missing input div" );
const dvDesc = getHtmlPart( "dvDesc", "missing desc div" );
const dvId = getHtmlPart( "dvId", "missing id div" );
var dvPic = getHtmlPart( "dvPic", "missing pic div" );
let dvPic = getHtmlPart( "dvPic", "missing pic div" );

if ( arguments.length < 2 ) {
pic = null;
Expand All @@ -1272,18 +1272,21 @@ const ctrl = ( function() {

// Hide the old picture and display the new one
dvPic.style.display = "none";
dvPic = document.createElement( "div" );
dvPic.setAttribute( "id", "dvPic" );
dvPic = document.createElement( "div" );
dvPic.id = "dvPic";
dvDesc.appendChild( dvPic );
dvPic.style.display = "none";

if ( pic != null ) {
const pImg = document.createElement( "p" );
const img = document.createElement( "img" );

pImg.align = "center";
pImg.style.width = "100%";
img.style = "width: auto; height: auto; max-width: 70%";
img.src = pic;
img.alt = img.title = "game over";

pImg.setAttribute( "align", "center" );
img.setAttribute( "src", pic );
img.setAttribute( "alt", "game over" );
pImg.appendChild( img );
dvPic.appendChild( pImg );
dvPic.style.display = "block";
Expand Down Expand Up @@ -1668,7 +1671,12 @@ const ctrl = ( function() {
function setVolume(v)
{
if ( playing != null ) {

if ( arguments.length == 0
|| v == null )
{
v = .5;
}

v = parseFloat( v );
if ( isNaN( v ) ) {
v = 0;
Expand All @@ -1679,10 +1687,14 @@ const ctrl = ( function() {

return;
}

function setInfo(audioInfo)
{
set( audioInfo.src, audioInfo.volume, audioInfo.loop );
}

function set(src, v, loop)
{
/*
stop();
playing = new Audio( src );
setVolume( v );
Expand All @@ -1695,7 +1707,6 @@ const ctrl = ( function() {
}

play();
*/
}

return {
Expand All @@ -1709,6 +1720,7 @@ const ctrl = ( function() {
"setVolume": setVolume,
"ponVolumen": setVolume,
"set": set,
"setInfo": set,
};
})();

Expand Down
Binary file added lib/res/goteo_agua.mp3
Binary file not shown.
Binary file added lib/res/murcielagos.mp3
Binary file not shown.
Binary file added lib/res/tension.mp3
Binary file not shown.
7 changes: 7 additions & 0 deletions lib/vampiro.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const locElFinal = ctrl.lugares.creaLoc(
<br>Salidas visibles: ${este, este}."
);
locElFinal.pic = "res/final.jpg";
locElFinal.audio.src = "res/tension.mp3";
locElFinal.audio.loop = true;

const locEscaleras = ctrl.lugares.creaLoc(
"Escaleras",
Expand Down Expand Up @@ -136,6 +138,8 @@ const locSotano = ctrl.lugares.creaLoc(
${arriba, arriba}.\n"
);
locSotano.pic = "res/sotano.jpg";
locSotano.audio.src = "res/goteo_agua.mp3";
locSotano.audio.loop = true;

const locVestibulo = ctrl.lugares.creaLoc(
"Vest&iacute;bulo",
Expand Down Expand Up @@ -697,6 +701,8 @@ murcielagos.daemon = function() {
if ( ctrl.getTurns() % 7 == 0 ) {
if ( ctrl.lugares.getCurrentLoc() == murcielagos.owner ) {
ctrl.print( "Unos murci&eacute;lagos se alborotan un tanto, chillando entre ellos..." );

ctrl.audio.set( "res/murcielagos.mp3" );
} else {
ctrl.print( "Ahogados, d&eacute;biles chillidos provienen de alguna parte..." );
}
Expand All @@ -708,6 +714,7 @@ ctrl.ponAlarma( 3, function() {

if ( ctrl.lugares.devLocActual() == murcielagos.owner ) {
ctrl.print( "Despertados por tu presencia, los murci&eacute;lagos chillan como comenzando a desperezarse..." );
ctrl.audio.set( "res/murcielagos.mp3" );
} else {
ctrl.print( "Unos lejanos chillidos llegan a ti de forma apagada..." );
}
Expand Down

0 comments on commit 99dbef2

Please sign in to comment.