Skip to content

Commit

Permalink
Add splash.
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Sep 13, 2024
1 parent a71e631 commit 5cb8638
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/assets/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -37,6 +38,9 @@ export const manifest = {
},{
alias: "explosion3",
src: explosion3,
},{
alias: "splash",
src: splash,
}]
}]
} satisfies AssetsManifest;
11 changes: 11 additions & 0 deletions src/entities/phys/physicsEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -106,6 +107,7 @@ export class Game {
b[1].explosion2,
b[1].explosion3
];
PhysicsEntity.splashSound = b[1].splash;
}

public addEntity<T extends IGameEntity>(entity: T): T {
Expand Down

0 comments on commit 5cb8638

Please sign in to comment.