Add score and fuel overlay
This commit is contained in:
parent
27c6a8bcd0
commit
4f8fd6e1af
13 changed files with 130 additions and 37 deletions
|
@ -1,8 +1,8 @@
|
|||
import * as input from '../input.mjs';
|
||||
import * as events from './events.mjs';
|
||||
import * as player from './player.mjs';
|
||||
import * as graphics from '../graphics/index.mjs';
|
||||
import * as inventory from './inventory.mjs';
|
||||
import {playerShip} from '../world/index.mjs';
|
||||
import {state} from './index.mjs';
|
||||
|
||||
export const mapping = {
|
||||
|
@ -36,15 +36,15 @@ export function tick() {
|
|||
|
||||
function tickPlaying() {
|
||||
if (held[mapping.thrust]) {
|
||||
player.ship.applyThrust({ forward: 1 });
|
||||
playerShip.applyThrust({ forward: 1 });
|
||||
}
|
||||
|
||||
if (held[mapping.left]) {
|
||||
player.ship.applyThrust({ turnLeft: 1 });
|
||||
playerShip.applyThrust({ turnLeft: 1 });
|
||||
}
|
||||
|
||||
if (held[mapping.right]) {
|
||||
player.ship.applyThrust({ turnRight: 1 });
|
||||
playerShip.applyThrust({ turnRight: 1 });
|
||||
}
|
||||
|
||||
if (pressed[mapping.inventory]) {
|
||||
|
@ -67,4 +67,6 @@ function tickEditing() {
|
|||
if (pressed[mapping.exitEdit]) {
|
||||
events.endEditing();
|
||||
}
|
||||
|
||||
if (pressed['KeyX']) throw new Error();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ export let height = 0;
|
|||
export let position = [0, 0];
|
||||
export let bounds = [0, 0, 0, 0];
|
||||
export let message = '';
|
||||
export let info = '';
|
||||
|
||||
export function init() {
|
||||
let ship = world.playerShip;
|
||||
|
@ -38,6 +39,7 @@ function adjustSize() {
|
|||
let [sx, ex, sy, ey] = getBoundaries();
|
||||
[width, height] = [ex - sx + margin * 2 + 1, ey - sy + margin * 2 + 1];
|
||||
position = [sx - margin, sy - margin];
|
||||
getAttributes();
|
||||
}
|
||||
|
||||
export function end() {
|
||||
|
@ -65,6 +67,35 @@ export function end() {
|
|||
return result;
|
||||
}
|
||||
|
||||
function getAttributes() {
|
||||
let cargo = 0;
|
||||
let fuel = 0;
|
||||
let rotation = 0;
|
||||
let mass = 0;
|
||||
let thrust = 0;
|
||||
|
||||
tiles.forEach(t => {
|
||||
if (t.type === null) return;
|
||||
if (t.type === 'fuel') {
|
||||
fuel += t.module.fuelCapacity;
|
||||
} else if (t.type === 'capsule') {
|
||||
rotation += t.module.rotation;
|
||||
cargo += t.module.capacity;
|
||||
} else if (t.type === 'thruster') {
|
||||
thrust += t.module.thrust;
|
||||
} else if (t.type === 'gyroscope') {
|
||||
rotation += t.module.rotation;
|
||||
}
|
||||
mass += t.module.mass;
|
||||
});
|
||||
|
||||
info = 'Mass: ' + mass + '\n' +
|
||||
'Fuel capacity: ' + fuel + '\n' +
|
||||
'Thrust/mass ratio: ' + (thrust / mass).toFixed(1) + '\n' +
|
||||
'Rotation speed: ' + (rotation / mass * 100).toFixed(1) + '\n' +
|
||||
'Cargo capacity: ' + cargo;
|
||||
}
|
||||
|
||||
function validate() {
|
||||
let capsulesFound = 0;
|
||||
let thrustersFound = 0;
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
import * as game from './index.mjs';
|
||||
import * as graphics from '../graphics/index.mjs';
|
||||
import * as world from '../world/index.mjs';
|
||||
import * as player from './player.mjs';
|
||||
import * as inventory from './inventory.mjs';
|
||||
import * as particle from '../world/particle.mjs';
|
||||
import * as edit from './edit.mjs';
|
||||
import * as audio from './audio.mjs';
|
||||
|
||||
export let shipLanded = false;
|
||||
export let score = 0;
|
||||
|
||||
let notification = null;
|
||||
let notLife = 0;
|
||||
|
||||
let landedPlanets = new Set();
|
||||
|
||||
function notify(message) {
|
||||
if (notification === null) return;
|
||||
notification.text = message;
|
||||
notLife = 60;
|
||||
notLife = 80;
|
||||
}
|
||||
|
||||
export function tick() {
|
||||
|
@ -33,11 +35,21 @@ export function startGame() {
|
|||
graphics.perspective.focusPlayer();
|
||||
}
|
||||
|
||||
export function landShip() {
|
||||
export function landShip(planet) {
|
||||
shipLanded = true;
|
||||
if (!landedPlanets.has(planet)) {
|
||||
newPlanet(planet);
|
||||
}
|
||||
game.state.landed = true;
|
||||
}
|
||||
|
||||
function newPlanet(planet) {
|
||||
let value = (planet.radius + 30) | 0;
|
||||
landedPlanets.add(planet);
|
||||
score += value;
|
||||
notify('Landed on new planet: +' + value);
|
||||
}
|
||||
|
||||
export function launchShip() {
|
||||
shipLanded = false;
|
||||
game.state.landed = false;
|
||||
|
@ -95,5 +107,7 @@ export function tossItem() {
|
|||
export function collectItem(type, id) {
|
||||
inventory.addItem(type, id);
|
||||
audio.play('itemPickup');
|
||||
score += 20;
|
||||
notify('Collected module: +20');
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import * as inventory from './inventory.mjs';
|
|||
import * as world from '../world/index.mjs';
|
||||
import * as events from './events.mjs';
|
||||
import * as control from './control.mjs';
|
||||
import * as player from './player.mjs';
|
||||
import * as edit from './edit.mjs';
|
||||
|
||||
export let state;
|
||||
|
@ -45,7 +44,6 @@ export function changeView(view) {
|
|||
state.editing = false;
|
||||
state.paused = false;
|
||||
world.init();
|
||||
player.init();
|
||||
inventory.init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import * as world from '../world/index.mjs';
|
||||
import * as inventory from './inventory.mjs';
|
||||
|
||||
export let ship;
|
||||
|
||||
export function init() {
|
||||
ship = world.playerShip;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue