General improvements
I forgot what I actually changed. It may not even be playable, I just want to get this up there.
This commit is contained in:
parent
8a0bf0ada9
commit
c73130e3ff
25 changed files with 584 additions and 274 deletions
|
@ -3,6 +3,7 @@ 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 * as world from '../world/index.mjs';
|
||||
import {playerShip} from '../world/index.mjs';
|
||||
import {state} from './index.mjs';
|
||||
|
||||
|
@ -19,7 +20,9 @@ export const mapping = {
|
|||
toggleMusic: 'KeyM',
|
||||
togglePause: 'KeyP',
|
||||
zoomIn: 'KeyZ',
|
||||
zoomOut: 'KeyX'
|
||||
zoomOut: 'KeyX',
|
||||
increaseSpeed: 'Period',
|
||||
decreaseSpeed: 'Comma',
|
||||
};
|
||||
|
||||
let held, pressed;
|
||||
|
@ -52,6 +55,14 @@ export function tick() {
|
|||
if (pressed[mapping.togglePause] && !state.gameOver) {
|
||||
events.togglePause();
|
||||
}
|
||||
|
||||
if (pressed[mapping.increaseSpeed]) {
|
||||
world.increaseSpeed();
|
||||
}
|
||||
|
||||
if (pressed[mapping.decreaseSpeed]) {
|
||||
world.decreaseSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
if (state.gameOver) {
|
||||
|
|
|
@ -29,8 +29,12 @@ export function init() {
|
|||
message = '';
|
||||
adjustSize();
|
||||
|
||||
adjustGraphics();
|
||||
}
|
||||
|
||||
function adjustGraphics() {
|
||||
let neededZoom = graphics.canvas.width / (Math.max(width, height) + 10);
|
||||
graphics.changePerspective('planet', 0, -5);
|
||||
graphics.changePerspective('planet', 0, -3);
|
||||
graphics.setZoom(neededZoom);
|
||||
}
|
||||
|
||||
|
@ -62,6 +66,9 @@ export function end() {
|
|||
let [dx, dy] = [nx - ox, ny - oy];
|
||||
ship.x -= dx;
|
||||
ship.y -= dy;
|
||||
const [rdx, rdy] = ship.rotateVector(dx, dy);
|
||||
ship.x -= rdx;
|
||||
ship.y -= rdy;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -73,6 +80,7 @@ function getAttributes() {
|
|||
let rotation = 0;
|
||||
let mass = 0;
|
||||
let thrust = 0;
|
||||
let computation = 0;
|
||||
|
||||
tiles.forEach(t => {
|
||||
if (t.type === null) return;
|
||||
|
@ -81,12 +89,15 @@ function getAttributes() {
|
|||
} else if (t.type === 'capsule') {
|
||||
rotation += t.module.rotation;
|
||||
cargo += t.module.capacity;
|
||||
computation += t.module.computation;
|
||||
} else if (t.type === 'thruster') {
|
||||
thrust += t.module.thrust;
|
||||
} else if (t.type === 'gyroscope') {
|
||||
rotation += t.module.rotation;
|
||||
} else if (t.type === 'cargo') {
|
||||
cargo += t.module.capacity;
|
||||
} else if (t.type === 'nafivation') {
|
||||
computation += t.module.computation;
|
||||
}
|
||||
mass += t.module.mass;
|
||||
});
|
||||
|
@ -96,7 +107,8 @@ function getAttributes() {
|
|||
'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;
|
||||
'Cargo capacity: ' + cargo + '\n' +
|
||||
'Navigational computation: ' + computation;
|
||||
}
|
||||
|
||||
export function validate() {
|
||||
|
|
|
@ -187,7 +187,7 @@ export function collectItem(type, id, name) {
|
|||
notify('Collected fuel: +10');
|
||||
return true;
|
||||
} else {
|
||||
if (inventory.usedSpace > inventory.capacity) {
|
||||
if (inventory.usedSpace >= inventory.capacity) {
|
||||
notify('No space left in inventory', 60);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -57,16 +57,9 @@ function loop(fn, fps = 60) {
|
|||
let interval = 1000 / fps;
|
||||
|
||||
(function loop(time) {
|
||||
fn();
|
||||
|
||||
requestAnimationFrame(loop);
|
||||
|
||||
// again, Date.now() if it's available
|
||||
let now = Date.now();
|
||||
let delta = now - then;
|
||||
|
||||
if (delta > interval) {
|
||||
then = now - (delta % interval);
|
||||
fn();
|
||||
}
|
||||
})(0);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue