Add score and fuel overlay
This commit is contained in:
parent
27c6a8bcd0
commit
4f8fd6e1af
13 changed files with 130 additions and 37 deletions
|
@ -24,8 +24,8 @@ export const TIP_ANGLE = 0.25;
|
||||||
export const TIP_SPEED = 0.03;
|
export const TIP_SPEED = 0.03;
|
||||||
// Ship flight mechanics. Speed measured in units per tick.
|
// Ship flight mechanics. Speed measured in units per tick.
|
||||||
export const FUEL_BURN_RATE = 0.01;
|
export const FUEL_BURN_RATE = 0.01;
|
||||||
export const THRUST_POWER = 0.007;
|
export const THRUST_POWER = 0.004;
|
||||||
export const TURN_POWER = 0.05;
|
export const TURN_POWER = 0.07;
|
||||||
// Distance at which an orbited planet will not be considered a parent body.
|
// Distance at which an orbited planet will not be considered a parent body.
|
||||||
export const MAX_PARENT_CELESTIAL_DISTANCE = 120;
|
export const MAX_PARENT_CELESTIAL_DISTANCE = 120;
|
||||||
// Ship editing.
|
// Ship editing.
|
||||||
|
|
|
@ -11,7 +11,7 @@ export const modules = {
|
||||||
mass: 2,
|
mass: 2,
|
||||||
connectivity: [false, false, true, false],
|
connectivity: [false, false, true, false],
|
||||||
capacity: 2,
|
capacity: 2,
|
||||||
rotation: 0.1
|
rotation: 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fuel: {
|
fuel: {
|
||||||
|
@ -29,13 +29,12 @@ export const modules = {
|
||||||
light: {
|
light: {
|
||||||
name: 'Light Main Thruster',
|
name: 'Light Main Thruster',
|
||||||
tooltip: 'Powerful enough to lift a small ship, but not much ' +
|
tooltip: 'Powerful enough to lift a small ship, but not much ' +
|
||||||
'more. Not very efficient.',
|
'more.',
|
||||||
type: 'thruster',
|
type: 'thruster',
|
||||||
id: 'light',
|
id: 'light',
|
||||||
mass: 2,
|
mass: 2,
|
||||||
connectivity: [true, false, false, false],
|
connectivity: [true, false, false, false],
|
||||||
thrust: 10,
|
thrust: 10
|
||||||
isp: 200
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
connector: {
|
connector: {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import * as input from '../input.mjs';
|
import * as input from '../input.mjs';
|
||||||
import * as events from './events.mjs';
|
import * as events from './events.mjs';
|
||||||
import * as player from './player.mjs';
|
|
||||||
import * as graphics from '../graphics/index.mjs';
|
import * as graphics from '../graphics/index.mjs';
|
||||||
import * as inventory from './inventory.mjs';
|
import * as inventory from './inventory.mjs';
|
||||||
|
import {playerShip} from '../world/index.mjs';
|
||||||
import {state} from './index.mjs';
|
import {state} from './index.mjs';
|
||||||
|
|
||||||
export const mapping = {
|
export const mapping = {
|
||||||
|
@ -36,15 +36,15 @@ export function tick() {
|
||||||
|
|
||||||
function tickPlaying() {
|
function tickPlaying() {
|
||||||
if (held[mapping.thrust]) {
|
if (held[mapping.thrust]) {
|
||||||
player.ship.applyThrust({ forward: 1 });
|
playerShip.applyThrust({ forward: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (held[mapping.left]) {
|
if (held[mapping.left]) {
|
||||||
player.ship.applyThrust({ turnLeft: 1 });
|
playerShip.applyThrust({ turnLeft: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (held[mapping.right]) {
|
if (held[mapping.right]) {
|
||||||
player.ship.applyThrust({ turnRight: 1 });
|
playerShip.applyThrust({ turnRight: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pressed[mapping.inventory]) {
|
if (pressed[mapping.inventory]) {
|
||||||
|
@ -67,4 +67,6 @@ function tickEditing() {
|
||||||
if (pressed[mapping.exitEdit]) {
|
if (pressed[mapping.exitEdit]) {
|
||||||
events.endEditing();
|
events.endEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pressed['KeyX']) throw new Error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ export let height = 0;
|
||||||
export let position = [0, 0];
|
export let position = [0, 0];
|
||||||
export let bounds = [0, 0, 0, 0];
|
export let bounds = [0, 0, 0, 0];
|
||||||
export let message = '';
|
export let message = '';
|
||||||
|
export let info = '';
|
||||||
|
|
||||||
export function init() {
|
export function init() {
|
||||||
let ship = world.playerShip;
|
let ship = world.playerShip;
|
||||||
|
@ -38,6 +39,7 @@ function adjustSize() {
|
||||||
let [sx, ex, sy, ey] = getBoundaries();
|
let [sx, ex, sy, ey] = getBoundaries();
|
||||||
[width, height] = [ex - sx + margin * 2 + 1, ey - sy + margin * 2 + 1];
|
[width, height] = [ex - sx + margin * 2 + 1, ey - sy + margin * 2 + 1];
|
||||||
position = [sx - margin, sy - margin];
|
position = [sx - margin, sy - margin];
|
||||||
|
getAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function end() {
|
export function end() {
|
||||||
|
@ -65,6 +67,35 @@ export function end() {
|
||||||
return result;
|
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() {
|
function validate() {
|
||||||
let capsulesFound = 0;
|
let capsulesFound = 0;
|
||||||
let thrustersFound = 0;
|
let thrustersFound = 0;
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
import * as game from './index.mjs';
|
import * as game from './index.mjs';
|
||||||
import * as graphics from '../graphics/index.mjs';
|
import * as graphics from '../graphics/index.mjs';
|
||||||
import * as world from '../world/index.mjs';
|
import * as world from '../world/index.mjs';
|
||||||
import * as player from './player.mjs';
|
|
||||||
import * as inventory from './inventory.mjs';
|
import * as inventory from './inventory.mjs';
|
||||||
import * as particle from '../world/particle.mjs';
|
import * as particle from '../world/particle.mjs';
|
||||||
import * as edit from './edit.mjs';
|
import * as edit from './edit.mjs';
|
||||||
import * as audio from './audio.mjs';
|
import * as audio from './audio.mjs';
|
||||||
|
|
||||||
export let shipLanded = false;
|
export let shipLanded = false;
|
||||||
|
export let score = 0;
|
||||||
|
|
||||||
let notification = null;
|
let notification = null;
|
||||||
let notLife = 0;
|
let notLife = 0;
|
||||||
|
|
||||||
|
let landedPlanets = new Set();
|
||||||
|
|
||||||
function notify(message) {
|
function notify(message) {
|
||||||
if (notification === null) return;
|
if (notification === null) return;
|
||||||
notification.text = message;
|
notification.text = message;
|
||||||
notLife = 60;
|
notLife = 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tick() {
|
export function tick() {
|
||||||
|
@ -33,11 +35,21 @@ export function startGame() {
|
||||||
graphics.perspective.focusPlayer();
|
graphics.perspective.focusPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function landShip() {
|
export function landShip(planet) {
|
||||||
shipLanded = true;
|
shipLanded = true;
|
||||||
|
if (!landedPlanets.has(planet)) {
|
||||||
|
newPlanet(planet);
|
||||||
|
}
|
||||||
game.state.landed = true;
|
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() {
|
export function launchShip() {
|
||||||
shipLanded = false;
|
shipLanded = false;
|
||||||
game.state.landed = false;
|
game.state.landed = false;
|
||||||
|
@ -95,5 +107,7 @@ export function tossItem() {
|
||||||
export function collectItem(type, id) {
|
export function collectItem(type, id) {
|
||||||
inventory.addItem(type, id);
|
inventory.addItem(type, id);
|
||||||
audio.play('itemPickup');
|
audio.play('itemPickup');
|
||||||
|
score += 20;
|
||||||
|
notify('Collected module: +20');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import * as inventory from './inventory.mjs';
|
||||||
import * as world from '../world/index.mjs';
|
import * as world from '../world/index.mjs';
|
||||||
import * as events from './events.mjs';
|
import * as events from './events.mjs';
|
||||||
import * as control from './control.mjs';
|
import * as control from './control.mjs';
|
||||||
import * as player from './player.mjs';
|
|
||||||
import * as edit from './edit.mjs';
|
import * as edit from './edit.mjs';
|
||||||
|
|
||||||
export let state;
|
export let state;
|
||||||
|
@ -45,7 +44,6 @@ export function changeView(view) {
|
||||||
state.editing = false;
|
state.editing = false;
|
||||||
state.paused = false;
|
state.paused = false;
|
||||||
world.init();
|
world.init();
|
||||||
player.init();
|
|
||||||
inventory.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;
|
|
||||||
}
|
|
|
@ -7,7 +7,6 @@ export function render() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderElement(element) {
|
function renderElement(element) {
|
||||||
//console.log(element.options);
|
|
||||||
if (element.options.draw) {
|
if (element.options.draw) {
|
||||||
if (element.type === 'frame') renderFrame(element);
|
if (element.type === 'frame') renderFrame(element);
|
||||||
if (element.type === 'image') renderImage(element);
|
if (element.type === 'image') renderImage(element);
|
||||||
|
@ -93,7 +92,7 @@ function renderItemButton(element) {
|
||||||
context.drawImage(element.image, ox, oy, dw, dh);
|
context.drawImage(element.image, ox, oy, dw, dh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.quantity > 1) { // CHANGE TO 1
|
if (element.quantity > 1) {
|
||||||
context.textAlign = 'right';
|
context.textAlign = 'right';
|
||||||
context.textBaseline = 'bottom';
|
context.textBaseline = 'bottom';
|
||||||
context.fillStyle = '#fff';
|
context.fillStyle = '#fff';
|
||||||
|
@ -110,6 +109,6 @@ function renderEdit(element) {
|
||||||
function renderInventory(element) {
|
function renderInventory(element) {
|
||||||
context.globalAlpha = 0.1;
|
context.globalAlpha = 0.1;
|
||||||
context.fillStyle = '#541';
|
context.fillStyle = '#541';
|
||||||
context.fillRect(...element.shape);
|
context.fillRect(...element.parent.shape);
|
||||||
context.globalAlpha = 1;
|
context.globalAlpha = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ export default class GuiEdit extends GuiElement {
|
||||||
this.parent.options.drawChildren = this.active;
|
this.parent.options.drawChildren = this.active;
|
||||||
if (!this.active) return;
|
if (!this.active) return;
|
||||||
|
|
||||||
this.textElements.info.text = edit.message;
|
this.textElements.info.text = edit.info;
|
||||||
|
|
||||||
[this.tileWidth, this.tileHeight] = [edit.width, edit.height];
|
[this.tileWidth, this.tileHeight] = [edit.width, edit.height];
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import GuiText from './text.mjs';
|
||||||
import GuiInventory from './inventory.mjs';
|
import GuiInventory from './inventory.mjs';
|
||||||
import * as events from '../game/events.mjs';
|
import * as events from '../game/events.mjs';
|
||||||
import {state} from '../game/index.mjs';
|
import {state} from '../game/index.mjs';
|
||||||
|
import * as world from '../world/index.mjs';
|
||||||
|
|
||||||
export function root() {
|
export function root() {
|
||||||
return new GuiFrame(0, 0, canvas.width, canvas.height, {
|
return new GuiFrame(0, 0, canvas.width, canvas.height, {
|
||||||
|
@ -51,11 +52,41 @@ export function game() {
|
||||||
editButton.options.disabled = state.editing && editMessage !== '';
|
editButton.options.disabled = state.editing && editMessage !== '';
|
||||||
if (state.editing) {
|
if (state.editing) {
|
||||||
editButton.text = 'Finish';
|
editButton.text = 'Finish';
|
||||||
|
if (editMessage !== '') editButton.text = '(' + editMessage + ')';
|
||||||
} else {
|
} else {
|
||||||
editButton.text = 'Edit rocket';
|
editButton.text = 'Edit rocket';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let fuel = new GuiText('', 0, 0, 0, 0, {
|
||||||
|
size: 14,
|
||||||
|
align: 'right',
|
||||||
|
valign: 'bottom'
|
||||||
|
});
|
||||||
|
shadow.append(fuel);
|
||||||
|
fuel.posRelative({x: 1, y: 1});
|
||||||
|
fuel.y -= 10;
|
||||||
|
fuel.x -= 10;
|
||||||
|
fuel.tick = () => {
|
||||||
|
let ship = world.playerShip;
|
||||||
|
fuel.text = 'Fuel: ' + ship.fuel.toFixed(1) + '/' +
|
||||||
|
ship.maxFuel.toFixed(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
let score = new GuiText('', 0, 0, 0, 0, {
|
||||||
|
size: 14,
|
||||||
|
align: 'left',
|
||||||
|
valign: 'bottom'
|
||||||
|
});
|
||||||
|
shadow.append(score);
|
||||||
|
score.posRelative({x: 0, y: 1});
|
||||||
|
score.y -= 10;
|
||||||
|
score.x += 10;
|
||||||
|
score.tick = () => {
|
||||||
|
score.text = 'Score: ' + events.score
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
let editShadow = root();
|
let editShadow = root();
|
||||||
shadow.append(editShadow);
|
shadow.append(editShadow);
|
||||||
editShadow.posRelative({x: 0.45, y: 0, w: 0.55, h: 0.6});
|
editShadow.posRelative({x: 0.45, y: 0, w: 0.55, h: 0.6});
|
||||||
|
@ -68,11 +99,12 @@ export function game() {
|
||||||
|
|
||||||
let editInfoText = new GuiText('', 0, 0, 0, 0, {
|
let editInfoText = new GuiText('', 0, 0, 0, 0, {
|
||||||
size: 12,
|
size: 12,
|
||||||
align: 'center'
|
align: 'right'
|
||||||
});
|
});
|
||||||
editShadow.append(editInfoText);
|
editShadow.append(editInfoText);
|
||||||
editInfoText.posRelative({x: 0.5, y: 1});
|
editInfoText.posRelative({x: 1, y: 1});
|
||||||
editInfoText.y += 5;
|
editInfoText.y += 5;
|
||||||
|
editInfoText.x -= 20;
|
||||||
|
|
||||||
let editWarnText = new GuiText('', 0, 0, 0, 0, {
|
let editWarnText = new GuiText('', 0, 0, 0, 0, {
|
||||||
size: 12,
|
size: 12,
|
||||||
|
|
|
@ -23,19 +23,17 @@ export function init() {
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('keyup', event => {
|
window.addEventListener('keyup', event => {
|
||||||
keyCode.pressed[event.code] = false;
|
|
||||||
keyCode.held[event.code] = false;
|
keyCode.held[event.code] = false;
|
||||||
key.pressed[event.key] = false;
|
|
||||||
key.held[event.key] = false;
|
key.held[event.key] = false;
|
||||||
});
|
});
|
||||||
// Ṕ͕͖ẖ̨’̖̺͓̪̹n̼͇͔̯̝̖g̙̩̭͕ͅͅl̻̰͘u͎̥͍̗ͅi̼̞̪̩͚̜͖ ̫̝̻͚͟m͎̳̙̭̩̩̕g̟̤̬̮l̫̕w̶͚͈͚̟͔’͖n͏̝͖̞̺ͅa͏̹͓̬̺f̗̬̬̬̖̫͜h͙̘̝̱̬̗͜ ̼͎͖C̱͔̱͖ṭ̬̱͖h̵̰̼̘̩ùlh̙́u̪̫ ̪̺̹̙̯R̞͓̹̞’͍͎͉͎̦͙ͅl͇̠̮y̙̪̰̪͙̖e̢̩͉͙̼h̗͔̹̳ ̶w̨̼͍̝̭̣̣ͅg̶̳̦̳a̴͉̹͙̭̟ͅh͈͎̞̜͉́’̼̜̠͞n̲a̯g̮͚͓̝l̠ ̹̹̱͙̝f̧̝͖̱h̪̟̻͖̖t͎͘aͅg̤̘͜n̶͈̻̻̝̳
|
// Ṕ͕͖ẖ̨’̖̺͓̪̹n̼͇͔̯̝̖g̙̩̭͕ͅͅl̻̰͘u͎̥͍̗ͅi̼̞̪̩͚̜͖ ̫̝̻͚͟m͎̳̙̭̩̩̕g̟̤̬̮l̫̕w̶͚͈͚̟͔’͖n͏̝͖̞̺ͅa͏̹͓̬̺f̗̬̬̬̖̫͜h͙̘̝̱̬̗͜ ̼͎͖C̱͔̱͖ṭ̬̱͖h̵̰̼̘̩ùlh̙́u̪̫ ̪̺̹̙̯R̞͓̹̞’͍͎͉͎̦͙ͅl͇̠̮y̙̪̰̪͙̖e̢̩͉͙̼h̗͔̹̳ ̶w̨̼͍̝̭̣̣ͅg̶̳̦̳a̴͉̹͙̭̟ͅh͈͎̞̜͉́’̼̜̠͞n̲a̯g̮͚͓̝l̠ ̹̹̱͙̝f̧̝͖̱h̪̟̻͖̖t͎͘aͅg̤̘͜n̶͈̻̻̝̳
|
||||||
window.addEventListener('mousedown', event => {
|
window.addEventListener('mousedown', event => {
|
||||||
mouse.pressed[event.button] = !mouse.held[event.button];
|
mouse.pressed[event.button] = !mouse.held[event.button];
|
||||||
mouse.held[event.button] = true;
|
mouse.held[event.button] = true;
|
||||||
|
tickAfterMouse = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('mouseup', event => {
|
window.addEventListener('mouseup', event => {
|
||||||
mouse.pressed[event.button] = false;
|
|
||||||
mouse.held[event.button] = false;
|
mouse.held[event.button] = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,8 @@ export default class Body {
|
||||||
|
|
||||||
applyDirectionalForce(x, y, r) {
|
applyDirectionalForce(x, y, r) {
|
||||||
let [vx, vy] = this.rotateVector(x, y);
|
let [vx, vy] = this.rotateVector(x, y);
|
||||||
this.xvel += vx;
|
this.xvel += vx / this.mass;
|
||||||
this.yvel += vy;
|
this.yvel += vy / this.mass;
|
||||||
this.rvel += r / this.mass;
|
this.rvel += r / this.mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,11 @@ export default class Ship extends Body {
|
||||||
this.landed = false;
|
this.landed = false;
|
||||||
this.lastContactModule = null;
|
this.lastContactModule = null;
|
||||||
this.poc = this.com;
|
this.poc = this.com;
|
||||||
|
this.maxFuel = 0;
|
||||||
|
this.fuel = 0;
|
||||||
|
this.rotationPower = 0;
|
||||||
|
this.cargoCapacity = 0;
|
||||||
|
this.thrust = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
get com() {
|
get com() {
|
||||||
|
@ -56,8 +61,13 @@ export default class Ship extends Body {
|
||||||
|
|
||||||
this.modules.forEach(m => m.reset());
|
this.modules.forEach(m => m.reset());
|
||||||
|
|
||||||
if (events.shipLanded != this.landed)
|
if (events.shipLanded != this.landed) {
|
||||||
this.landed ? events.landShip() : events.launchShip();
|
if (this.landed) {
|
||||||
|
events.landShip(this.parentCelestial)
|
||||||
|
} else {
|
||||||
|
events.launchShip()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearModules() {
|
clearModules() {
|
||||||
|
@ -85,6 +95,23 @@ export default class Ship extends Body {
|
||||||
let [lx, ly] = this.localCom;
|
let [lx, ly] = this.localCom;
|
||||||
this.maxRadius = points.reduce((a, [bx, by]) =>
|
this.maxRadius = points.reduce((a, [bx, by]) =>
|
||||||
Math.max(Math.sqrt((bx - lx) ** 2 + (by - ly) ** 2), a), 0) + 1;
|
Math.max(Math.sqrt((bx - lx) ** 2 + (by - ly) ** 2), a), 0) + 1;
|
||||||
|
|
||||||
|
this.maxFuel = 0;
|
||||||
|
this.rotationPower = 0;
|
||||||
|
this.cargoCapacity = 0;
|
||||||
|
|
||||||
|
this.modules.forEach(m => {
|
||||||
|
if (m.type === 'fuel') {
|
||||||
|
this.maxFuel += m.data.fuelCapacity;
|
||||||
|
} else if (m.type === 'capsule') {
|
||||||
|
this.rotationPower += m.data.rotation;
|
||||||
|
this.cargoCapacity += m.data.capacity;
|
||||||
|
} else if (m.type === 'thruster') {
|
||||||
|
this.thrust += m.data.thrust;
|
||||||
|
} else if (m.type === 'gyroscope') {
|
||||||
|
this.rotationPower += m.data.rotation;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
colliding(point, radius) {
|
colliding(point, radius) {
|
||||||
|
@ -158,8 +185,9 @@ export default class Ship extends Body {
|
||||||
applyThrust({ forward = 0, left = 0, right = 0, back = 0,
|
applyThrust({ forward = 0, left = 0, right = 0, back = 0,
|
||||||
turnLeft = 0, turnRight = 0}) {
|
turnLeft = 0, turnRight = 0}) {
|
||||||
|
|
||||||
let thrustForce = -forward * consts.THRUST_POWER;
|
let thrustForce = -forward * consts.THRUST_POWER * this.thrust;
|
||||||
let turnForce = (turnRight - turnLeft) * consts.TURN_POWER;
|
let turnForce = (turnRight - turnLeft) * consts.TURN_POWER;
|
||||||
|
turnForce *= this.rotationPower;
|
||||||
|
|
||||||
this.applyDirectionalForce(0, thrustForce, turnForce);
|
this.applyDirectionalForce(0, thrustForce, turnForce);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue