Add pause and precision controls
This commit is contained in:
parent
2959c39da7
commit
f91febfd3c
3 changed files with 22 additions and 11 deletions
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue