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