Add ship movement

This commit is contained in:
asraelite 2018-03-03 15:58:51 +00:00
parent 09b3df649c
commit 4959519f39
15 changed files with 278 additions and 77 deletions

View file

@ -1,7 +1,10 @@
import {images as assets} from '../assets.mjs';
export default class Module {
constructor(x, y, {
name = 'Unnamed Module',
type = 'block',
id = 'unknown',
mass = 1,
// Fuel
filled = false,
@ -13,7 +16,31 @@ export default class Module {
this.name = name;
this.type = type;
this.mass = mass;
this.id = id;
this.images = assets.modules[this.type][this.id];
// Fuel
this.fuel = filled ? fuelCapacity : 0;
if (this.type == 'fuel') {
this.fuel = filled ? fuelCapacity : 0;
} else if (this.type == 'thruster') {
this.power = 0;
}
}
reset() {
if (this.type == 'thruster') {
this.power = 0;
}
}
get currentImage() {
if (this.type == 'thruster') {
return this.power > 0 ? this.images.on : this.images.off;
} else {
return this.images;
}
}
get com() {
return [this.x + 0.5, this.y + 0.5];
}
}