Add music

This commit is contained in:
asraelite 2018-03-07 14:23:45 +00:00
parent 194c0bf846
commit bd97945e66
14 changed files with 82 additions and 20 deletions

View file

@ -16,8 +16,20 @@ export function start(name) {
}
export function stop(name) {
if (!playing.has(name)) return;
if (!playing.has(name)) return false;
let howl = playing.get(name);
if (howl.playing())
if (howl.playing()) {
howl.stop();
return true;
}
return false;
}
export function toggle(name) {
if (!stop(name)) start(name);
}
export function volume(name, level) {
if (!playing.has(name)) return;
playing.get(name).volume(level);
}

View file

@ -14,7 +14,8 @@ export const mapping = {
inventory: 'KeyE',
cycleRotation: 'KeyC',
toggleTrace: 'KeyT',
toggleMarkers: 'KeyR'
toggleMarkers: 'KeyR',
toggleMusic: 'KeyM'
};
let held, pressed;
@ -34,11 +35,17 @@ export function tick() {
graphics.changeZoom(-input.mouse.scroll);
}
}
if (pressed[mapping.toggleMusic]) {
audio.toggle('music');
}
}
function tickPlaying() {
if (held[mapping.thrust]) {
playerShip.applyThrust({ forward: 1 });
let vol = Math.min(0.7, graphics.perspective.zoom / 10);
audio.volume('engine', vol);
} else {
audio.stop('engine');
}

View file

@ -91,8 +91,9 @@ function getAttributes() {
info = 'Mass: ' + mass + '\n' +
'Fuel capacity: ' + fuel + '\n' +
'Thrust/mass ratio: ' + (thrust / mass).toFixed(1) + '\n' +
'Rotation speed: ' + (rotation / mass * 100).toFixed(1) + '\n' +
'Thrust/mass ratio: ' + (thrust / Math.max(mass, 1)).toFixed(1) + '\n' +
'Rotation speed: ' + (rotation / Math.max(mass, 1) * 100).toFixed(1)
+ '\n' +
'Cargo capacity: ' + cargo;
}

View file

@ -15,6 +15,15 @@ let notLife = 0;
let landedPlanets = new Set();
export function playMusic() {
audio.start('music');
audio.volume('music', 0.8);
}
export function stopMusic() {
audio.stop('music');
}
function notify(message, time = 80) {
if (notification === null) return;
notification.text = message;
@ -44,6 +53,10 @@ export function landShip(planet) {
game.state.landed = true;
}
export function howToPlay() {
game.state.controls = true;
}
function newPlanet(planet) {
let value = (planet.radius * 2 + 50) | 0;
landedPlanets.add(planet);
@ -70,7 +83,6 @@ 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,8 @@ export async function init() {
gui.init();
input.init();
//events.startGame();
//events.playMusic();
events.startGame();
//tick(); return;