diff --git a/src/assets/manifest.ts b/src/assets/manifest.ts index 1906a25..eef2499 100644 --- a/src/assets/manifest.ts +++ b/src/assets/manifest.ts @@ -4,6 +4,7 @@ import grenadeSrc from "./grenade.png"; import bazookaShellSrc from "./bazooka.png"; import terrain2 from "./terrain2.png"; import bounce from "./borrowed/grenade.ogg"; +import splash from "./borrowed/splash.ogg"; import explosion1 from "./borrowed/explosion1.ogg"; import explosion2 from "./borrowed/explosion2.ogg"; import explosion3 from "./borrowed/explosion3.ogg"; @@ -37,6 +38,9 @@ export const manifest = { },{ alias: "explosion3", src: explosion3, + },{ + alias: "splash", + src: splash, }] }] } satisfies AssetsManifest; \ No newline at end of file diff --git a/src/entities/phys/physicsEntity.ts b/src/entities/phys/physicsEntity.ts index 74d9b59..7a74c6a 100644 --- a/src/entities/phys/physicsEntity.ts +++ b/src/entities/phys/physicsEntity.ts @@ -4,6 +4,7 @@ import { IMatterEntity } from "../entity"; import { Water } from "../water"; import { BodyWireframe } from "../../mixins/bodyWireframe."; import globalFlags from "../../flags"; +import { IMediaInstance, Sound } from "@pixi/sound"; /** * Any object that is physically present in the world i.e. a worm. @@ -13,7 +14,10 @@ export abstract class PhysicsEntity implements IMatterEntity { protected sinkingY = 0; protected wireframe: BodyWireframe; + public static splashSound: Sound; + priority: UPDATE_PRIORITY = UPDATE_PRIORITY.NORMAL; + private splashSoundPlayback?: IMediaInstance; public get destroyed() { return this.sprite.destroyed; @@ -59,6 +63,13 @@ export abstract class PhysicsEntity implements IMatterEntity { console.log('onCollision'); if (otherEnt instanceof Water) { console.log('hit water'); + + if (!this.splashSoundPlayback?.progress || this.splashSoundPlayback.progress === 1) { + // TODO: Hacks + Promise.resolve(PhysicsEntity.splashSound.play()).then((instance) =>{ + this.splashSoundPlayback = instance; + }) + } // Time to sink this.isSinking = true; this.sinkingY = contactPoint.y + 200; diff --git a/src/game.ts b/src/game.ts index aeb4020..2e39788 100644 --- a/src/game.ts +++ b/src/game.ts @@ -12,6 +12,7 @@ import Matter, { Common, Engine, Events, Body } from "matter-js"; import grenadeIsland from './scenarios/grenadeIsland'; import { Viewport } from 'pixi-viewport'; import globalFlags from "./flags"; +import { PhysicsEntity } from "./entities/phys/physicsEntity"; Common.setDecomp(polyDecomp); @@ -106,6 +107,7 @@ export class Game { b[1].explosion2, b[1].explosion3 ]; + PhysicsEntity.splashSound = b[1].splash; } public addEntity(entity: T): T {