Skip to content

Commit

Permalink
Bouncing enemy plays sound, WIP spatial audio
Browse files Browse the repository at this point in the history
  • Loading branch information
hubol committed Sep 28, 2024
1 parent f711da9 commit 70121da
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
3 changes: 3 additions & 0 deletions raw/sounds/impact/bouncing enemy land.wav
Git LFS file not shown
40 changes: 21 additions & 19 deletions src/assets/generated/sounds/generated-sfx-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ async function sfxs<T>(sfx: (ogg: string) => Promise<T>) {
"collect/valuable5.ogg",
"fluid/splash small.ogg",
"fluid/splash tiny.ogg",
"impact/bouncing enemy land.ogg",
"impact/defeat enemy.ogg",
"impact/vs enemy physical 0.ogg",
"impact/vs enemy physical 1.ogg",
Expand Down Expand Up @@ -40,33 +41,34 @@ async function sfxs<T>(sfx: (ogg: string) => Promise<T>) {
SplashTiny: sounds[4],
},
Impact: {
DefeatEnemy: sounds[5],
VsEnemyPhysical0: sounds[6],
VsEnemyPhysical1: sounds[7],
VsEnemyPhysical2: sounds[8],
VsPlayerPhysical: sounds[9],
BouncingEnemyLand: sounds[5],
DefeatEnemy: sounds[6],
VsEnemyPhysical0: sounds[7],
VsEnemyPhysical1: sounds[8],
VsEnemyPhysical2: sounds[9],
VsPlayerPhysical: sounds[10],
},
Interact: {
DoorOpen0: sounds[10],
DoorOpen1: sounds[11],
DoorOpen0: sounds[11],
DoorOpen1: sounds[12],
},
Terrain: {
EarthStep0: sounds[12],
EarthStep1: sounds[13],
EarthStep2: sounds[14],
EarthStep3: sounds[15],
MetalStep0: sounds[16],
MetalStep1: sounds[17],
MetalStep2: sounds[18],
MetalStep3: sounds[19],
EarthStep0: sounds[13],
EarthStep1: sounds[14],
EarthStep2: sounds[15],
EarthStep3: sounds[16],
MetalStep0: sounds[17],
MetalStep1: sounds[18],
MetalStep2: sounds[19],
MetalStep3: sounds[20],
},
Ui: {
Looks: {
Updated: sounds[20],
Updated: sounds[21],
},
NavigateBack: sounds[21],
NavigateInto: sounds[22],
Select: sounds[23],
NavigateBack: sounds[22],
NavigateInto: sounds[23],
Select: sounds[24],
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/assets/generated/sounds/sounds-ogg.zip
Git LFS file not shown
19 changes: 19 additions & 0 deletions src/igua/mixins/mxn-spatial-audio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DisplayObject, Rectangle } from "pixi.js";
import { Sound } from "../../lib/game-engine/audio/sound";
import { IRectangle, areRectanglesOverlapping } from "../../lib/math/rectangle";
import { renderer } from "../globals";

const screenRectangle: IRectangle = { x: 0, y: 0, width: renderer.width, height: renderer.height };
const r = new Rectangle();

export function mxnSpatialAudio(obj: DisplayObject) {
return obj.merge({
play(sound: Sound) {
// TODO should apply gain, panning based on obj position!!
// TODO should it return an instance?
if (areRectanglesOverlapping(obj.getBounds(true, r), screenRectangle)) {
sound.play();
}
},
});
}
4 changes: 4 additions & 0 deletions src/igua/objects/enemies/obj-angel-bouncing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { mxnEnemy } from "../../mixins/mxn-enemy";
import { RpgPlayer } from "../../rpg/rpg-player";
import { RpgAttack } from "../../rpg/rpg-attack";
import { RpgEnemyClass } from "../../rpg/rpg-enemy-class";
import { mxnSpatialAudio } from "../../mixins/mxn-spatial-audio";
import { Sfx } from "../../../assets/sounds";

const clownTxs = Tx.Enemy.CommonClown.split({ count: 2 });

Expand Down Expand Up @@ -67,6 +69,7 @@ export function objAngelBouncing() {
obj.speed.x = -event.previousSpeed.x; // TODO might be nice to get the normal
}
if (event.hitGround && !event.previousOnGround) {
obj.play(Sfx.Impact.BouncingEnemyLand);
obj.speed.y = -6;

// TODO play sound if on screen
Expand All @@ -84,6 +87,7 @@ export function objAngelBouncing() {
}
},
})
.mixin(mxnSpatialAudio)
.step(() => {
// if (obj.portal && !appliedOpaqueTint) {
// obj.opaqueTint = 0x20A090;
Expand Down

0 comments on commit 70121da

Please sign in to comment.