Switch to Howler for audio

This commit is contained in:
asraelite 2018-03-07 12:21:43 +00:00
parent 3eb74e44aa
commit 194c0bf846
13 changed files with 78 additions and 19 deletions

View file

@ -1,5 +1,23 @@
import {audio} from '../assets.mjs';
const playing = new Map();
export function play(name) {
audio[name].cloneNode(true).play();
audio[name].play();
}
export function start(name) {
if (!playing.has(name))
playing.set(name, audio[name]);
let howl = playing.get(name);
howl.loop(true);
howl.play();
}
export function stop(name) {
if (!playing.has(name)) return;
let howl = playing.get(name);
if (howl.playing())
howl.stop();
}

View file

@ -2,6 +2,7 @@ import * as input from '../input.mjs';
import * as events from './events.mjs';
import * as graphics from '../graphics/index.mjs';
import * as inventory from './inventory.mjs';
import * as audio from './audio.mjs';
import {playerShip} from '../world/index.mjs';
import {state} from './index.mjs';
@ -38,6 +39,12 @@ export function tick() {
function tickPlaying() {
if (held[mapping.thrust]) {
playerShip.applyThrust({ forward: 1 });
} else {
audio.stop('engine');
}
if (pressed[mapping.thrust]) {
audio.start('engine');
}
if (held[mapping.left]) {

View file

@ -45,7 +45,7 @@ export function landShip(planet) {
}
function newPlanet(planet) {
let value = (planet.radius + 30) | 0;
let value = (planet.radius * 2 + 50) | 0;
landedPlanets.add(planet);
audio.play('newPlanet');
score += value;
@ -70,6 +70,7 @@ export function toggleEdit() {
export function toggleTrace() {
let trace = graphics.toggleTrace();
notify('Path prediction: ' + (trace ? 'on' : 'off'));
audio.start('engine');
}
export function toggleMarkers() {

View file

@ -24,7 +24,7 @@ export async function init() {
gui.init();
input.init();
events.startGame();
//events.startGame();
//tick(); return;

View file

@ -11,6 +11,9 @@ let onupdate = () => {};
export function init() {
items.clear();
addItem('connector', 'xheavy');
addItem('connector', 'xheavy');
addItem('connector', 'xheavy');
addItem('connector', 'xheavy');
}
export function getTiles() {