Skip to content

Commit

Permalink
Add basic sounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Sep 16, 2024
1 parent 9224972 commit 3e82d5c
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/assets/ASSETS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sounds provided by https://gameburp.itch.io/2000-game-sound-fx
Binary file added src/assets/explosion_1.ogg
Binary file not shown.
Binary file added src/assets/explosion_2.ogg
Binary file not shown.
Binary file added src/assets/explosion_3.ogg
Binary file not shown.
17 changes: 14 additions & 3 deletions src/assets/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import island1 from "./island1.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";


// Sounds
import metalBounceLight from "./metal_bounce_light.ogg";
import metalBounceHeavy from "./metal_bounce_heavy.ogg";
import explosion1 from "./explosion_1.ogg";
import explosion2 from "./explosion_2.ogg";
import explosion3 from "./explosion_3.ogg";

export const manifest = {
bundles: [{
Expand All @@ -34,6 +39,12 @@ export const manifest = {
assets: [{
alias: "bounce",
src: bounce,
},{
alias: "metalBounceLight",
src: metalBounceLight,
}, {
alias: "metalBounceHeavy",
src: metalBounceHeavy,
},{
alias: "explosion1",
src: explosion1,
Expand Down
Binary file added src/assets/metal_bounce_heavy.ogg
Binary file not shown.
Binary file added src/assets/metal_bounce_light.ogg
Binary file not shown.
1 change: 0 additions & 1 deletion src/entities/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class Background implements IGameEntity {
}

addRainParticle() {
console.log("VP", this.viewport.position, this.viewport.center);
const x = this.viewport.center.x + Math.round(Math.random()*this.viewport.screenWidth) - this.viewport.screenWidth/2;
const y = this.viewport.center.y + (0-Math.round(Math.random()*this.viewport.screenHeight) - 200);
this.rainParticles.push({
Expand Down
6 changes: 3 additions & 3 deletions src/entities/explosion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export class Explosion implements IGameEntity {
kind: "fire"|"pop"
}[] = []

static create(parent: Container, point: Vector, initialRadius: number) {
const ent = new Explosion(point, initialRadius);
static create(parent: Container, point: Vector, initialRadius: number, shrapnelMin = 8, shrapnelMax = 25) {
const ent = new Explosion(point, initialRadius, shrapnelMin, shrapnelMax);
parent.addChild(ent.gfx);
return ent;
}

private constructor(point: Vector, private initialRadius: number, shrapnelMin = 8, shrapnelMax = 25) {
private constructor(point: Vector, private initialRadius: number, shrapnelMin: number, shrapnelMax: number) {
for (let index = 0; index < (shrapnelMin + Math.ceil(Math.random() * (shrapnelMax-shrapnelMin))); index++) {
const xSpeed = (Math.random()*7)-3.5;
const kind = Math.random() >= 0.75 ? "fire" : "pop";
Expand Down
9 changes: 7 additions & 2 deletions src/entities/phys/grenade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class Grenade extends TimedExplosive {
private static readonly DENSITY = 35;
private static bodyVertices = loadSvg(grenadePaths, 50, 1, 1, Vector.create(0.5, 0.5));
public static texture: Texture;
public static bounceSound: Sound;
public static bounceSoundsLight: Sound;
public static boundSoundHeavy: Sound;

static async create(game: Game, parent: Container, composite: Composite, position: {x: number, y: number}, initialForce: { x: number, y: number}) {
const ent = new Grenade(game, position, await Grenade.bodyVertices, initialForce, composite);
Expand Down Expand Up @@ -83,10 +84,14 @@ export class Grenade extends TimedExplosive {
return false;
}

const velocity = Vector.magnitude(this.body.velocity);

// TODO: can these interrupt?
if (!this.bounceSoundPlayback?.progress || this.bounceSoundPlayback.progress === 1 && this.timer > 0) {
// TODO: Hacks
Promise.resolve(Grenade.bounceSound.play()).then((instance) =>{
Promise.resolve(
(velocity >= 4 ? Grenade.boundSoundHeavy : Grenade.bounceSoundsLight).play()
).then((instance) =>{
this.bounceSoundPlayback = instance;
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/entities/phys/timedExplosive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export abstract class TimedExplosive extends PhysicsEntity implements IMatterEnt
// Detect if anything is around us.
const circ = Bodies.circle(point.x, point.y, radius);
const hit = Query.collides(circ, this.game.matterEngine.world.bodies).sort((a,b) => b.depth - a.depth);
this.game.addEntity(Explosion.create(this.game.viewport, point, radius));
this.game.addEntity(Explosion.create(this.game.viewport, point, radius, 15, 35));
console.log("Timed explosive hit", hit);
// Find contact point with any terrain
for (const hitBody of hit) {
Expand Down
3 changes: 2 additions & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export class Game {
// TODO: Do this better.
const { textures, sounds } = getAssets();
Grenade.texture = textures.grenade;
Grenade.bounceSound = sounds.bounce;
Grenade.bounceSoundsLight = sounds.metalBounceLight;
Grenade.boundSoundHeavy = sounds.metalBounceHeavy;
BazookaShell.texture = textures.bazooka_shell;
Worm.texture = textures.grenade;
Explosion.explosionSounds =
Expand Down

0 comments on commit 3e82d5c

Please sign in to comment.