Skip to content

Commit

Permalink
Simplify how sounds are queued.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomle committed Feb 19, 2020
1 parent bcb8141 commit 5c8e2bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 10 additions & 0 deletions public/js/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Trait {
constructor(name) {
this.NAME = name;

this.sounds = new Set();
this.tasks = [];
}

Expand All @@ -33,6 +34,14 @@ export class Trait {

}

playSounds(audioBoard, audioContext) {
this.sounds.forEach(name => {
audioBoard.playAudio(name, audioContext);
});

this.sounds.clear();
}

update() {

}
Expand Down Expand Up @@ -81,6 +90,7 @@ export default class Entity {
update(gameContext, level) {
this.traits.forEach(trait => {
trait.update(this, gameContext, level);
trait.playSounds(this.audio, gameContext.audioContext);
});

this.lifetime += gameContext.deltaTime;
Expand Down
3 changes: 1 addition & 2 deletions public/js/traits/Jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ export default class Jump extends Trait {
}
}


update(entity, gameContext, level) {
const deltaTime = gameContext.deltaTime;
if (this.requestTime > 0) {
if (this.ready > 0) {
entity.audio.playAudio('jump', gameContext.audioContext);
this.sounds.add('jump');
this.engageTime = this.duration;
this.requestTime = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions public/js/traits/Stomper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export default class Stomper extends Trait {
}
}

update(entity, {audioContext}) {
update(entity) {
if (this.didStomp) {
entity.audio.playAudio('stomp', audioContext);
this.sounds.add('stomp');
this.didStomp = false;
}
}
Expand Down

0 comments on commit 5c8e2bf

Please sign in to comment.