Skip to content

Commit

Permalink
Add Cannon Sound and AudioBoard
Browse files Browse the repository at this point in the history
  • Loading branch information
pomle committed Mar 9, 2020
1 parent 21224a6 commit 750c205
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Binary file added public/audio/thwomp.ogg
Binary file not shown.
2 changes: 1 addition & 1 deletion public/js/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function loadEntities(audioContext) {
loadBulletBill(audioContext).then(addAs('bulletBill')),
]);

entityFactories['cannon'] = loadCannon(entityFactories);
await loadCannon(entityFactories, audioContext).then(addAs('cannon'));

return entityFactories;
}
11 changes: 8 additions & 3 deletions public/js/entities/Cannon.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {findPlayers} from '../player.js';
import Entity, {Trait} from '../Entity.js';
import Emitter from '../traits/Emitter.js';
import {loadAudioBoard} from '../loaders/audio.js';

export function loadCannon(entityFactory) {
return createCannonFactory(entityFactory);
export function loadCannon(entityFactory, audioContext) {
return loadAudioBoard('cannon', audioContext)
.then(audio => {
return createCannonFactory(entityFactory, audio);
});
}

function createCannonFactory(entityFactory) {
function createCannonFactory(entityFactory, audio) {
const createBullet = entityFactory.bulletBill;

const bulletEmitter = (entity, level) => {
Expand All @@ -24,6 +28,7 @@ function createCannonFactory(entityFactory) {

return function createCannon() {
const cannon = new Entity();
cannon.audio = audio;

const emitter = new Emitter();
emitter.interval = 4;
Expand Down
7 changes: 7 additions & 0 deletions public/sounds/cannon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"fx": {
"shoot": {
"url": "/audio/thwomp.ogg"
}
}
}

0 comments on commit 750c205

Please sign in to comment.