Add zooming

This commit is contained in:
asraelite 2018-03-03 13:29:14 +00:00
parent 56a09f98c5
commit b02675f4fb
12 changed files with 156 additions and 29 deletions

View file

@ -10,7 +10,7 @@ export default class Body {
this.rvel = 0;
this.mass = mass;
}
tickGravity(bodies) {
bodies.forEach(b => {
let force = b.mass / this.mass / (distanceTo(b) ** 2) * G;

View file

@ -1,10 +1,29 @@
import {images as assets} from '../assets.mjs';
import Body from './body.mjs';
export default class Celestial extends Body {
constructor(x, y, radius, {
density = 1,
mass = (radius ** 2) * density
type = 'rock'
}) {
let mass = (radius ** 2) * density
super(x, y, mass);
this.radius = radius;
this.type = type;
let imageArr = Object.values(assets.celestials[this.type]);
this.image = imageArr[Math.random() * imageArr.length | 0];
}
tick() {
}
get center() {
return [this.x + this.radius / 2, this.y + this.radius / 2];
}
get diameter() {
return this.radius * 2;
}
}

View file

@ -17,6 +17,8 @@ export function init() {
entities.clear();
celestials.clear();
spawn.player();
spawn.startPlanet();
}
export function tick() {

View file

@ -3,6 +3,9 @@ export default class Module {
name = 'Unnamed Module',
type = 'block',
mass = 1,
// Fuel
filled = false,
fuelCapacity = 0,
...properties
}) {
this.x = x;
@ -10,6 +13,7 @@ export default class Module {
this.name = name;
this.type = type;
this.mass = mass;
// Fuel
this.fuel = filled ? fuelCapacity : 0;
}
}

View file

@ -1,6 +1,6 @@
import Ship from './ship.mjs';
import Module from './module.mjs';
import Celestial from './ship.mjs';
import Celestial from './celestial.mjs';
import {modules} from '../data.mjs';
import * as world from './index.mjs';
@ -11,9 +11,18 @@ export function player() {
ship.addModule(0, 2, modules.thruster.light);
world.ships.add(ship);
world.setPlayerShip(ship);
return ship;
}
// Make module length = 1, define all other length off that.
export function celestial() {
let celestial = new Celestial(0, 50, 45)
export function startPlanet() {
return celestial(-40, 10, 40, {
density: 1,
type: 'green'
});
}
export function celestial(x, y, radius, params) {
let celestial = new Celestial(x, y, radius, params);
world.celestials.add(celestial);
return celestial;
}