diff --git a/js/game/control.mjs b/js/game/control.mjs index 685d8be..846f387 100644 --- a/js/game/control.mjs +++ b/js/game/control.mjs @@ -10,12 +10,14 @@ export const mapping = { thrust: 'KeyW', left: 'KeyA', right: 'KeyD', + reduce: 'ShiftLeft', exitEdit: 'Escape', inventory: 'KeyE', cycleRotation: 'KeyC', toggleTrace: 'KeyT', toggleMarkers: 'KeyR', - toggleMusic: 'KeyM' + toggleMusic: 'KeyM', + togglePause: 'KeyP' }; let held, pressed; @@ -26,7 +28,7 @@ export function tick() { if (state.editing) { tickEditing(); - } else if (state.playing && !state.gameOver) { + } else if (state.playing && !state.gameOver && !state.paused) { tickPlaying(); } @@ -34,6 +36,10 @@ export function tick() { if (input.mouse.scroll !== 0) { graphics.changeZoom(-input.mouse.scroll); } + + if (pressed[mapping.togglePause] && !state.gameOver) { + events.togglePause(); + } } if (state.gameOver) { @@ -46,8 +52,10 @@ export function tick() { } function tickPlaying() { + let power = held[mapping.reduce] ? 0.3 : 1; + if (held[mapping.thrust] && playerShip.fuel !== 0) { - playerShip.applyThrust({ forward: 1 }); + playerShip.applyThrust({ forward: power }); let vol = Math.min(0.7, graphics.perspective.zoom / 10); audio.volume('engine', vol); } else { @@ -63,11 +71,11 @@ function tickPlaying() { } if (held[mapping.left]) { - playerShip.applyThrust({ turnLeft: 1 }); + playerShip.applyThrust({ turnLeft: power }); } if (held[mapping.right]) { - playerShip.applyThrust({ turnRight: 1 }); + playerShip.applyThrust({ turnRight: power }); } if (pressed[mapping.inventory]) { @@ -85,9 +93,6 @@ function tickPlaying() { if (pressed[mapping.toggleMarkers]) { events.toggleMarkers(); } - - // For debugging. - if (pressed['KeyZ']) events.startGame(); } function tickEditing() { diff --git a/js/game/events.mjs b/js/game/events.mjs index c10c5be..4a54fba 100644 --- a/js/game/events.mjs +++ b/js/game/events.mjs @@ -32,7 +32,7 @@ function notify(message, time = 80) { export function tick() { if (notification === null) return; - if (notLife-- <= 0 || game.state.gameOver) + if ((notLife-- <= 0 || game.state.gameOver) && !game.state.paused) notification.text = ''; } @@ -50,7 +50,12 @@ export function toMenu() { } export function togglePause() { + console.log(game.state.paused); game.state.paused = !game.state.paused; + audio.play('pause'); + if (game.state.paused) { + notify('Paused', 0); + } } export function landShip(planet) { diff --git a/js/game/index.mjs b/js/game/index.mjs index 14bb8a7..fc32b69 100644 --- a/js/game/index.mjs +++ b/js/game/index.mjs @@ -58,11 +58,12 @@ export function changeView(view) { function tick() { events.tick(); - if (state.view == 'game') { + if (state.view == 'game' && !state.paused) { world.tick(); - control.tick(); } + control.tick(); + gui.tick(); graphics.render(); input.tick();