Sound Effects
This commit is contained in:
parent
47f16c78be
commit
50692988e5
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 291 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 488 KiB |
|
|
@ -6,6 +6,11 @@ export default class CodeBugInvaders extends Phaser.Scene {
|
|||
preload() {
|
||||
this.load.json('cbiConfig', 'src/games/code-bug-invaders/config.json?v=2');
|
||||
this.load.audio('cbiMusic', 'assets/music/02-code-bug-invaders.mp3');
|
||||
this.load.audio('cbiComplete','assets/fx/complete.mp3');
|
||||
this.load.audio('cbifire', 'assets/fx/fire.mp3');
|
||||
this.load.audio('cbilaser', 'assets/fx/laser.mp3');
|
||||
this.load.audio('cbideath', 'assets/fx/death.mp3');
|
||||
this.load.audio('cbibugdeath', 'assets/fx/short_death.mp3');
|
||||
}
|
||||
|
||||
init(data) {
|
||||
|
|
@ -116,6 +121,9 @@ export default class CodeBugInvaders extends Phaser.Scene {
|
|||
// Limit to 2 bullets at once
|
||||
if (this.playerBullets.length < 2) {
|
||||
this.playerBullets.push({ x: this.player.x, y: this.player.y - 20 });
|
||||
const snd = this.sound.add('cbifire', { volume: 0.6 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
}
|
||||
}
|
||||
if (!this.keyA.isDown) this.keyAPressed = false;
|
||||
|
|
@ -170,6 +178,9 @@ export default class CodeBugInvaders extends Phaser.Scene {
|
|||
if (shooters.length > 0) {
|
||||
const shooter = Phaser.Utils.Array.GetRandom(shooters);
|
||||
this.bugBullets.push({ x: shooter.x, y: shooter.y + 20 });
|
||||
const snd = this.sound.add('cbilaser', { volume: 0.5 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -185,6 +196,9 @@ export default class CodeBugInvaders extends Phaser.Scene {
|
|||
bug.alive = false;
|
||||
this.bugsHit++;
|
||||
hit = true;
|
||||
const snd = this.sound.add('cbibugdeath', { volume: 0.6 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -202,6 +216,9 @@ export default class CodeBugInvaders extends Phaser.Scene {
|
|||
for (const bb of this.bugBullets) {
|
||||
if (Math.abs(bb.x - this.player.x) < 30 && Math.abs(bb.y - this.player.y) < 25) {
|
||||
this.player.alive = false;
|
||||
const snd = this.sound.add('cbideath', { volume: 0.8 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
this._endGame(false);
|
||||
return;
|
||||
}
|
||||
|
|
@ -222,6 +239,11 @@ export default class CodeBugInvaders extends Phaser.Scene {
|
|||
_endGame(success) {
|
||||
if (!this.gameActive) return;
|
||||
this.gameActive = false;
|
||||
if (success) {
|
||||
const snd = this.sound.add('cbiComplete', { volume: 0.8 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
}
|
||||
const msg = success ? 'BUGS SQUASHED!' : 'BUGS WIN!';
|
||||
const color = success ? '#00ff44' : '#ff2222';
|
||||
this.add.text(800, 440, msg, {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
|
||||
preload() {
|
||||
this.load.json('cdConfig', 'src/games/colorado-defense/config.json?v=2');
|
||||
this.load.json('cdCities', 'src/games/colorado-defense/cities.json');
|
||||
this.load.audio('cdMusic', 'assets/music/01-colorado-defense.mp3');
|
||||
this.load.audio('cdComplete','assets/fx/complete.mp3');
|
||||
this.load.audio('cdShoot', 'assets/fx/shoot.mp3');
|
||||
this.load.audio('cdFireball','assets/fx/fireball.mp3');
|
||||
this.load.audio('cdDestroy', 'assets/fx/destroy.mp3');
|
||||
}
|
||||
|
||||
init(data) {
|
||||
|
|
@ -35,6 +40,8 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
|
||||
this._buildBackground();
|
||||
this._buildCities();
|
||||
this._assignCityNames();
|
||||
this._buildCityLabels();
|
||||
this.mainGfx = this.add.graphics();
|
||||
this._buildHUD();
|
||||
this._setupInput();
|
||||
|
|
@ -43,6 +50,7 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
|
||||
shutdown() {
|
||||
stopMusic(this);
|
||||
this.interceptors.forEach(i => { if (i.sound) { i.sound.stop(); i.sound.destroy(); } });
|
||||
this.input.off('pointerdown');
|
||||
this.input.off('pointermove');
|
||||
}
|
||||
|
|
@ -73,6 +81,20 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
});
|
||||
}
|
||||
|
||||
_assignCityNames() {
|
||||
const pool = [...this.cache.json.get('cdCities')];
|
||||
Phaser.Utils.Array.Shuffle(pool);
|
||||
this.cities.forEach((c, i) => { c.name = pool[i]; });
|
||||
}
|
||||
|
||||
_buildCityLabels() {
|
||||
this.cities.forEach(c => {
|
||||
c.label = this.add.text(c.x, 871, c.name, {
|
||||
fontSize: '12px', fontFamily: 'monospace', color: '#aaffaa',
|
||||
}).setOrigin(0.5, 0).setDepth(5);
|
||||
});
|
||||
}
|
||||
|
||||
_buildHUD() {
|
||||
this.waveText = this.add.text(20, 40, 'WAVE 1', {
|
||||
fontSize: '24px', fontFamily: 'monospace', color: '#00ff00',
|
||||
|
|
@ -113,6 +135,8 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
|
||||
_fire(tx, ty) {
|
||||
if (!this.gameActive || ty >= 855) return;
|
||||
const sound = this.sound.add('cdShoot', { volume: 0.5, loop: true });
|
||||
sound.play();
|
||||
this.interceptors.push({
|
||||
sx: 800, sy: 855,
|
||||
tx, ty,
|
||||
|
|
@ -120,6 +144,7 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
dist: Math.max(1, Math.hypot(tx - 800, ty - 855)),
|
||||
progress: 0,
|
||||
speed: this.cfg.interceptorSpeed,
|
||||
sound,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -149,6 +174,11 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
i.x = i.sx + i.dx * i.progress;
|
||||
i.y = i.sy + i.dy * i.progress;
|
||||
if (i.progress >= 1) {
|
||||
i.sound.stop();
|
||||
i.sound.destroy();
|
||||
const boom = this.sound.add('cdFireball', { volume: 0.7 });
|
||||
boom.once('complete', () => boom.destroy());
|
||||
boom.play();
|
||||
this.explosions.push({
|
||||
x: i.tx, y: i.ty, r: 0,
|
||||
maxR: this.cfg.explosionRadius,
|
||||
|
|
@ -232,8 +262,11 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
for (const c of this.cities) {
|
||||
if (c.alive && Math.abs(c.x - mx) < 70) {
|
||||
c.alive = false;
|
||||
// Explosion on city
|
||||
if (c.label) c.label.setColor('#664422');
|
||||
this.explosions.push({ x: c.x, y: c.y - 15, r: 5, maxR: 50, growing: true });
|
||||
const snd = this.sound.add('cdDestroy', { volume: 0.8 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -242,6 +275,11 @@ export default class ColoradoDefense extends Phaser.Scene {
|
|||
_endGame(success) {
|
||||
if (!this.gameActive) return;
|
||||
this.gameActive = false;
|
||||
if (success) {
|
||||
const snd = this.sound.add('cdComplete', { volume: 0.8 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
}
|
||||
const msg = success ? 'COLORADO DEFENDED!' : 'CITIES DESTROYED!';
|
||||
const color = success ? '#00ff00' : '#ff2200';
|
||||
this.add.text(800, 440, msg, {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
"Denver",
|
||||
"Fort Collins",
|
||||
"Colorado Springs",
|
||||
"Fort Lupton",
|
||||
"Pueblo",
|
||||
"Limon",
|
||||
"Highlands Ranch",
|
||||
"Littleton",
|
||||
"Arvada",
|
||||
"Evergreen",
|
||||
"Englewood",
|
||||
"Gunnison",
|
||||
"Vail",
|
||||
"Aspen",
|
||||
"Winter Park",
|
||||
"Grand Junction"
|
||||
]
|
||||
|
|
@ -32,6 +32,8 @@ export default class DotDude extends Phaser.Scene {
|
|||
preload() {
|
||||
this.load.json('ddConfig', 'src/games/dot-dude/config.json?v=2');
|
||||
this.load.audio('ddMusic', 'assets/music/03-dot-dude.mp3');
|
||||
this.load.audio('ddPellet', 'assets/fx/pellet.mp3');
|
||||
this.load.audio('ddComplete', 'assets/fx/complete.mp3');
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
|
|
@ -179,6 +181,9 @@ export default class DotDude extends Phaser.Scene {
|
|||
this.dots[row][col] = 0;
|
||||
this.dotsEaten++;
|
||||
this.dotsText.setText(`${this.dotsEaten} / ${this.cfg.pelletsToPass}`);
|
||||
const snd = this.sound.add('ddPellet', { volume: 0.5 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
}
|
||||
|
||||
// Ghosts
|
||||
|
|
@ -386,6 +391,11 @@ export default class DotDude extends Phaser.Scene {
|
|||
_endGame(success) {
|
||||
if (!this.gameActive) return;
|
||||
this.gameActive = false;
|
||||
if (success) {
|
||||
const snd = this.sound.add('ddComplete', { volume: 0.8 });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
}
|
||||
const msg = success ? 'ALL DOTS EATEN!' : 'GHOST GOT YOU!';
|
||||
const color = success ? '#ffff00' : '#ff4444';
|
||||
this.add.text(800, 440, msg, {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ export default class SmashOut extends Phaser.Scene {
|
|||
preload() {
|
||||
this.load.json('soConfig', 'src/games/smash-out/config.json?v=2');
|
||||
this.load.audio('soMusic', 'assets/music/04-smash-out.mp3');
|
||||
this.load.audio('soComplete','assets/fx/complete.mp3');
|
||||
this.load.audio('soLaunch', 'assets/fx/launch.mp3');
|
||||
this.load.audio('soBounce', 'assets/fx/bounce.mp3');
|
||||
this.load.audio('soDestroy', 'assets/fx/short_death.mp3');
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
|
|
@ -125,6 +129,12 @@ export default class SmashOut extends Phaser.Scene {
|
|||
this._draw();
|
||||
}
|
||||
|
||||
_playFx(key, volume = 0.6) {
|
||||
const snd = this.sound.add(key, { volume });
|
||||
snd.once('complete', () => snd.destroy());
|
||||
snd.play();
|
||||
}
|
||||
|
||||
_launch() {
|
||||
this.ball.launched = true;
|
||||
this.launchHint.setVisible(false);
|
||||
|
|
@ -132,6 +142,7 @@ export default class SmashOut extends Phaser.Scene {
|
|||
const s = this.cfg.ballSpeed;
|
||||
this.ball.vx = Math.cos(angle) * s;
|
||||
this.ball.vy = Math.sin(angle) * s;
|
||||
this._playFx('soLaunch', 0.7);
|
||||
}
|
||||
|
||||
_moveBall(dt) {
|
||||
|
|
@ -142,9 +153,11 @@ export default class SmashOut extends Phaser.Scene {
|
|||
ball.y += ball.vy * dt;
|
||||
|
||||
// Wall bounces
|
||||
if (ball.x - r < 0) { ball.x = r; ball.vx = Math.abs(ball.vx); }
|
||||
if (ball.x + r > 1600) { ball.x = 1600 - r; ball.vx = -Math.abs(ball.vx); }
|
||||
if (ball.y - r < 0) { ball.y = r; ball.vy = Math.abs(ball.vy); }
|
||||
let wallBounced = false;
|
||||
if (ball.x - r < 0) { ball.x = r; ball.vx = Math.abs(ball.vx); wallBounced = true; }
|
||||
if (ball.x + r > 1600) { ball.x = 1600 - r; ball.vx = -Math.abs(ball.vx); wallBounced = true; }
|
||||
if (ball.y - r < 0) { ball.y = r; ball.vy = Math.abs(ball.vy); wallBounced = true; }
|
||||
if (wallBounced) this._playFx('soBounce', 0.5);
|
||||
|
||||
// Paddle bounce
|
||||
const { paddle } = this;
|
||||
|
|
@ -159,6 +172,7 @@ export default class SmashOut extends Phaser.Scene {
|
|||
ball.vx = Math.cos(angle) * speed;
|
||||
ball.vy = -Math.abs(Math.sin(angle) * speed);
|
||||
ball.y = pTop - r - 1;
|
||||
this._playFx('soBounce', 0.5);
|
||||
}
|
||||
|
||||
// Block collisions
|
||||
|
|
@ -190,6 +204,8 @@ export default class SmashOut extends Phaser.Scene {
|
|||
if (dist < r) {
|
||||
block.alive = false;
|
||||
this.bricksDestroyed++;
|
||||
this._playFx('soBounce', 0.4);
|
||||
this._playFx('soDestroy', 0.6);
|
||||
|
||||
// Determine bounce axis: use which edge the ball is closest to
|
||||
const overlapX = (ball.x < bLeft || ball.x > bRight)
|
||||
|
|
@ -217,6 +233,7 @@ export default class SmashOut extends Phaser.Scene {
|
|||
_endGame(success) {
|
||||
if (!this.gameActive) return;
|
||||
this.gameActive = false;
|
||||
if (success) this._playFx('soComplete', 0.8);
|
||||
const msg = success ? 'SMASHED IT!' : 'BALL LOST!';
|
||||
const color = success ? '#00ff44' : '#ff2222';
|
||||
this.add.text(800, 440, msg, {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ export default class MainMenu extends Phaser.Scene {
|
|||
preload() {
|
||||
this.load.json('gameConfig', 'config/game.json');
|
||||
this.load.audio('mainTheme', 'assets/music/00-main-theme.mp3');
|
||||
this.load.image('logo-title', 'assets/images/logo-title.png');
|
||||
this.load.image('logo-people', 'assets/images/logo-people.png');
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue