Trying out different sound waves
This commit is contained in:
1 parent
2912061094
commit
58ee03f8a8
4 files changed
+16
-11
No files matched your search
@@ -105,3 +105,6 @@ export const EXPLOSION_SHAKE_REDUCTION_FACTOR = 7;
|
||||
|
||||
export const FONT_WIDTH = 3;
|
||||
export const FONT_HEIGHT = 5;
|
||||
|
||||
export const SOUND_MUSIC_VOLUME = 0.3;
|
||||
export const SOUND_SFX_VOLUME = 0.05;
|
||||
+1
-1
@@ -132,7 +132,7 @@ function update() {
|
||||
weaponType.ammo -= 1;
|
||||
|
||||
projectile = {
|
||||
osc: createOsc(),
|
||||
osc: createOsc('sine'),
|
||||
player: player,
|
||||
weaponTypeId: weaponType.type,
|
||||
ox:px, oy:py, a, p,
|
||||
|
||||
+7
-5
@@ -1,12 +1,14 @@
|
||||
import {SOUND_MUSIC_VOLUME, SOUND_SFX_VOLUME} from './constants.js';
|
||||
|
||||
// @ts-ignore
|
||||
export const audio = new (window.AudioContext || window.webkitAudioContext)();
|
||||
|
||||
export const music = audio.createGain(audio);
|
||||
music.gain.setValueAtTime(0.4, audio.currentTime);
|
||||
music.gain.setValueAtTime(SOUND_MUSIC_VOLUME, audio.currentTime);
|
||||
music.connect(audio.destination);
|
||||
|
||||
export const sfx = audio.createGain(audio);
|
||||
sfx.gain.setValueAtTime(0.05, audio.currentTime);
|
||||
sfx.gain.setValueAtTime(SOUND_SFX_VOLUME, audio.currentTime);
|
||||
sfx.connect(audio.destination);
|
||||
|
||||
export async function createAudioLoop(src) {
|
||||
@@ -21,15 +23,15 @@ export async function createAudioLoop(src) {
|
||||
})
|
||||
}
|
||||
|
||||
export function createOsc() {
|
||||
export function createOsc(type='triangle') {
|
||||
const osc = audio.createOscillator();
|
||||
osc.type = 'triangle';
|
||||
osc.type = type;
|
||||
osc.connect(sfx);
|
||||
return osc;
|
||||
}
|
||||
|
||||
export function playTickSound() {
|
||||
const osc = createOsc();
|
||||
const osc = createOsc('triangle');
|
||||
osc.frequency.setValueAtTime(440, audio.currentTime);
|
||||
osc.frequency.setValueAtTime(0, audio.currentTime + 0.005);
|
||||
osc.start();
|
||||
|
||||
+5
-5
@@ -27,7 +27,7 @@ export const EXPLOSION_TYPES = {
|
||||
blast: {
|
||||
create(spec, x, y) {
|
||||
const {r} = spec;
|
||||
const osc = createOsc();
|
||||
const osc = createOsc('sawtooth');
|
||||
osc.start();
|
||||
return {type:'blast', x, y, r, cr:0, osc};
|
||||
},
|
||||
@@ -36,7 +36,7 @@ export const EXPLOSION_TYPES = {
|
||||
},
|
||||
draw(explosion, foreground) {
|
||||
const {x, y, cr, osc} = explosion;
|
||||
const f = cycle(explosion.cr, 6) % 2 === 0 ? 220 : 440;
|
||||
const f = cycle(explosion.cr, 6) % 2 === 0 ? 110 : 220;
|
||||
osc.frequency.setValueAtTime(f, audio.currentTime);
|
||||
drawExplosion(foreground, x, y, cr);
|
||||
},
|
||||
@@ -62,7 +62,7 @@ export const EXPLOSION_TYPES = {
|
||||
dirt: {
|
||||
create(spec, x, y) {
|
||||
const {r} = spec;
|
||||
const osc = createOsc();
|
||||
const osc = createOsc('sawtooth');
|
||||
osc.start();
|
||||
return {type:'dirt', x, y, r, cr:0, osc};
|
||||
},
|
||||
@@ -89,7 +89,7 @@ export const EXPLOSION_TYPES = {
|
||||
digBomb: {
|
||||
create(spec, x, y) {
|
||||
const {r} = spec;
|
||||
const osc = createOsc();
|
||||
const osc = createOsc('sawtooth');
|
||||
osc.start();
|
||||
return {type:'digBomb', x, y, r, cr:0, osc};
|
||||
},
|
||||
@@ -117,7 +117,7 @@ export const EXPLOSION_TYPES = {
|
||||
create(spec, x, y) {
|
||||
const {r} = spec;
|
||||
const pattern = [];
|
||||
const osc = createOsc();
|
||||
const osc = createOsc('sawtooth');
|
||||
osc.start();
|
||||
return {type:'dirtCone', x, y, r, cr:0, osc, pattern};
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user