backgound music
This commit is contained in:
parent
498ab5502a
commit
c814f7715e
5
TODO.md
5
TODO.md
@ -1,9 +1,12 @@
|
|||||||
- several correct answer
|
- finish game image
|
||||||
|
- desktop (landscape) orientation
|
||||||
|
- background music
|
||||||
- change quest animation
|
- change quest animation
|
||||||
- button hover animation
|
- button hover animation
|
||||||
- make docs/
|
- make docs/
|
||||||
|
|
||||||
## done
|
## done
|
||||||
|
- several correct answer [498ab55]
|
||||||
- loading all quest images with loading [b8aa4b6]
|
- loading all quest images with loading [b8aa4b6]
|
||||||
- splash (loading) screen [b8aa4b6]
|
- splash (loading) screen [b8aa4b6]
|
||||||
- add quest progress [aac38ec]
|
- add quest progress [aac38ec]
|
||||||
|
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
engine.js
|
engine.js
|
||||||
assets/images/*.jpg
|
assets/images/*.jpg
|
||||||
|
assets/sfx/*.mp3
|
||||||
|
@ -2,5 +2,6 @@
|
|||||||
"gameName": "quizEngine",
|
"gameName": "quizEngine",
|
||||||
"gameVersion": [0, 0, 1],
|
"gameVersion": [0, 0, 1],
|
||||||
"debug": true,
|
"debug": true,
|
||||||
"loaderWidth": 200
|
"loaderWidth": 200,
|
||||||
|
"music": "music.mp3"
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import gameData from '../app/gameData.json'; // game data
|
|||||||
|
|
||||||
import { getMousePos, isInside } from './buttons.js';
|
import { getMousePos, isInside } from './buttons.js';
|
||||||
import { clearContext, placeImage, getCenterH, getCenterV } from './draw.js';
|
import { clearContext, placeImage, getCenterH, getCenterV } from './draw.js';
|
||||||
|
import { playMusic } from './music.js';
|
||||||
import { imagePreloader, checkAnswer, shuffle, restartGame } from './game.js';
|
import { imagePreloader, checkAnswer, shuffle, restartGame } from './game.js';
|
||||||
|
|
||||||
// Engine variables -------------------------------------
|
// Engine variables -------------------------------------
|
||||||
@ -18,6 +19,7 @@ let game = {}; // main game variable
|
|||||||
let areas = { game: {}, finish: {} };
|
let areas = { game: {}, finish: {} };
|
||||||
let images = {};
|
let images = {};
|
||||||
let buttons = {};
|
let buttons = {};
|
||||||
|
let music = {};
|
||||||
|
|
||||||
// Init -------------------------------------------------
|
// Init -------------------------------------------------
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
@ -47,6 +49,9 @@ window.onload = function() {
|
|||||||
|
|
||||||
imagePreloader(questImages, function() { game.loadedState = true; });
|
imagePreloader(questImages, function() { game.loadedState = true; });
|
||||||
|
|
||||||
|
music.music = new AudioContext() || new webkitAudioContext();
|
||||||
|
playMusic(config, music.music);
|
||||||
|
|
||||||
game.loadedState = false;
|
game.loadedState = false;
|
||||||
game.finish = false;
|
game.finish = false;
|
||||||
game.currentQuest = 0;
|
game.currentQuest = 0;
|
||||||
|
19
js/music.js
Normal file
19
js/music.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export function playMusic(config, music) {
|
||||||
|
let request = new XMLHttpRequest();
|
||||||
|
|
||||||
|
request.open("GET", `assets/sfx/${config.music}`, true);
|
||||||
|
request.responseType = "arraybuffer";
|
||||||
|
request.onload = function(){
|
||||||
|
music.decodeAudioData(request.response, onDecoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDecoded(buffer) {
|
||||||
|
var bufferSource = music.createBufferSource();
|
||||||
|
bufferSource.buffer = buffer;
|
||||||
|
bufferSource.connect(music.destination);
|
||||||
|
bufferSource.loop = true;
|
||||||
|
bufferSource.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
request.send();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user