-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0ebb21
commit 075dbb1
Showing
12 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE HTML> | ||
<html lang = "en-US"> | ||
<head> | ||
<meta charset = "UTF-8"> | ||
<title>HTML5 - Audio Demo</title> | ||
<link rel = "stylesheet" type = "text/css" href = "styles/game.css"> | ||
</head> | ||
<body onload = "initialize()"> | ||
|
||
<button | ||
id = "id-play1" | ||
type="button" | ||
onclick = "playSound('audio/sound-1', 'Sound 1', 'id-play1', 'id-sound1-played');"> | ||
Sound 1 - Play! | ||
</button> | ||
<br/> | ||
<button | ||
id = "id-play2" | ||
type="button" | ||
onclick = "playSound('audio/sound-2', 'Sound 2', 'id-play2', 'id-sound2-played');"> | ||
Sound 2 - Play! | ||
</button> | ||
<br/> | ||
<button | ||
id = "id-play3" | ||
type = "button" | ||
onclick = "playSound('audio/bensound-extremeaction', 'Music', 'id-play3', 'id-music');"> | ||
Music - Play! | ||
</button> | ||
<br/> | ||
<span>Music Volume: </span><input | ||
type = "range" | ||
min = "0" max = "100" value = "100" | ||
oninput = "changeVolume(this.value)"> | ||
<hr/> | ||
|
||
<span>Sound 1: </span><span id = "id-sound1-played">unplayed</span> | ||
<br/> | ||
<span>Sound 2: </span><span id = "id-sound2-played">unplayed</span> | ||
<br/> | ||
<span>Music: </span><span id = "id-music">unplayed</span> | ||
|
||
<script>MyGame = {}</script> | ||
<script src = "scripts/player.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//------------------------------------------------------------------ | ||
// | ||
// This function performs the one-time game initialization. | ||
// | ||
//------------------------------------------------------------------ | ||
function initialize() { | ||
'use strict'; | ||
|
||
function loadSound(source, label, idButton) { | ||
let sound = new Audio(); | ||
sound.addEventListener('canplay', function() { | ||
console.log(`${source} is ready to play`); | ||
}); | ||
sound.addEventListener('play', function() { | ||
let elementButton = document.getElementById(idButton); | ||
elementButton.innerHTML = label + ' - Pause!' | ||
console.log(`${source} started playing`); | ||
}); | ||
sound.addEventListener('pause', function() { | ||
console.log(`${source} paused`); | ||
}); | ||
sound.addEventListener('canplaythrough', function() { | ||
console.log(`${source} can play through`); | ||
}); | ||
sound.addEventListener('progress', function() { | ||
console.log(`${source} progress in loading`); | ||
}); | ||
sound.addEventListener('timeupdate', function() { | ||
console.log(`${source} time update: ${this.currentTime}`); | ||
}); | ||
sound.src = source; | ||
return sound; | ||
} | ||
|
||
function loadAudio() { | ||
MyGame.sounds = {} | ||
// Reference: https://freesound.org/data/previews/156/156031_2703579-lq.mp3 | ||
MyGame.sounds['audio/sound-1'] = loadSound('audio/sound-1.mp3', 'Sound 1', 'id-play1'); | ||
// Reference: https://freesound.org//data/previews/109/109662_945474-lq.mp3 | ||
MyGame.sounds['audio/sound-2'] = loadSound('audio/sound-2.mp3', 'Sound 2', 'id-play2'); | ||
// Reference: https://www.bensound.com/royalty-free-music/track/extreme-action | ||
MyGame.sounds['audio/bensound-extremeaction'] = loadSound('audio/bensound-extremeaction.mp3', 'Music', 'id-play3'); | ||
} | ||
|
||
console.log('initializing...'); | ||
|
||
loadAudio(); | ||
} | ||
|
||
//------------------------------------------------------------------ | ||
// | ||
// Pauses the specified audio | ||
// | ||
//------------------------------------------------------------------ | ||
function pauseSound(whichSound, label, idButton, idStatus) { | ||
MyGame.sounds[whichSound].pause(); | ||
|
||
let elementStatus = document.getElementById(idStatus); | ||
elementStatus.innerHTML = 'paused'; | ||
|
||
let elementButton = document.getElementById(idButton); | ||
elementButton.innerHTML = `${label} - Continue!`; | ||
elementButton.onclick = function() { playSound(whichSound, label, idButton, idStatus); }; | ||
} | ||
|
||
//------------------------------------------------------------------ | ||
// | ||
// Plays the specified audio | ||
// | ||
//------------------------------------------------------------------ | ||
function playSound(whichSound, label, idButton, idStatus) { | ||
let elementStatus = document.getElementById(idStatus); | ||
let elementButton = document.getElementById(idButton); | ||
|
||
elementStatus.innerHTML = 'playing'; | ||
MyGame.sounds[whichSound].addEventListener('ended', function() { | ||
elementStatus.innerHTML = 'ended'; | ||
elementButton.innerHTML = `${label} - Play!`; | ||
elementButton.onclick = function() { playSound(whichSound, label, idButton, idStatus); }; | ||
}); | ||
|
||
elementButton.onclick = function() { pauseSound(whichSound, label, idButton, idStatus); }; | ||
|
||
MyGame.sounds[whichSound].play(); | ||
} | ||
|
||
//------------------------------------------------------------------ | ||
// | ||
// Allow the music volume to be changed | ||
// | ||
//------------------------------------------------------------------ | ||
function changeVolume(value) { | ||
MyGame.sounds['audio/bensound-extremeaction'].volume = value / 100; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
body | ||
{ | ||
margin: 0; | ||
} | ||
|
||
#canvas-main | ||
{ | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
background-color: rgb(0, 0, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function loadSound(source) { | ||
let sound = new Audio(); | ||
sound.src = source; | ||
return sound; | ||
} | ||
|
||
var ShipSounds = {}; | ||
ShipSounds['audio/sound-1'] = loadSound('audio/sound-1.mp3'); | ||
ShipSounds['audio/sound-2'] = loadSound('audio/sound-2.mp3'); |