Skip to content

Commit

Permalink
Abstract SFX
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Creech committed Feb 12, 2024
1 parent 60c5af8 commit c45e9a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { GameTextImpl } from "./gametext.ts";
import { KeyboardImpl } from "./keyboard.ts";
import { Point } from "./point.ts";
import { RandomImpl } from "./random.ts";
import { SFX } from "./sfx.ts";
import { SFXImpl } from "./sfx.ts";

const keyboard = new KeyboardImpl();
const sfx = new SFX(keyboard);
const sfx = new SFXImpl(keyboard);

const canvas: HTMLCanvasElement = document.getElementById(
"canvas",
Expand Down
12 changes: 9 additions & 3 deletions src/sfx.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Keyboard } from "./keyboard.ts";

export class SFX {
export interface SFX {
laser(): void

explosion(): void;
}

export class SFXImpl implements SFX {
private readonly laserWav: HTMLAudioElement;
private readonly explosionWav: HTMLAudioElement;

constructor(private readonly keyboard: Keyboard) {
this.laserWav = SFX.load("39459__THE_bizniss__laser.wav");
this.explosionWav = SFX.load("51467__smcameron__missile_explosion.wav");
this.laserWav = SFXImpl.load("39459__THE_bizniss__laser.wav");
this.explosionWav = SFXImpl.load("51467__smcameron__missile_explosion.wav");
}

private static load(fn: string): HTMLAudioElement {
Expand Down

0 comments on commit c45e9a1

Please sign in to comment.