Add crashing
This commit is contained in:
parent
bd97945e66
commit
60f77c36a9
9 changed files with 67 additions and 10 deletions
|
@ -27,6 +27,37 @@ export function createEndEditBurst(ship) {
|
|||
}
|
||||
}
|
||||
|
||||
export function createCrash(ship) {
|
||||
for (let i = 0; i < ship.mass + 3; i++) {
|
||||
particles.add(new Particle(...ship.poc, {
|
||||
color: '#f2e860',
|
||||
lifetime: Math.random() * 50 + 40,
|
||||
size: Math.random() * 0.2 + 0.2,
|
||||
spray: 0.9,
|
||||
gravity: true
|
||||
}));
|
||||
}
|
||||
for (let i = 0; i < ship.mass + 3; i++) {
|
||||
particles.add(new Particle(...ship.poc, {
|
||||
color: '#f75722',
|
||||
lifetime: Math.random() * 50 + 40,
|
||||
size: Math.random() * 0.2 + 0.2,
|
||||
spray: 0.5,
|
||||
gravity: true
|
||||
}));
|
||||
}
|
||||
for (let i = 0; i < ship.mass * 2 + 3; i++) {
|
||||
particles.add(new Particle(...ship.poc, {
|
||||
color: '#888',
|
||||
lifetime: Math.random() * 30 + 55,
|
||||
size: Math.random() * 0.5 + 0.4,
|
||||
spray: 2,
|
||||
friction: 0.9,
|
||||
gravity: false
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export function createPickupBurst(ship, point) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
particles.add(new Particle(...point, {
|
||||
|
|
|
@ -22,6 +22,7 @@ export default class Ship extends Body {
|
|||
this.rotationPower = 0;
|
||||
this.cargoCapacity = 0;
|
||||
this.thrust = 0;
|
||||
this.crashed = false;
|
||||
}
|
||||
|
||||
get com() {
|
||||
|
@ -48,7 +49,7 @@ export default class Ship extends Body {
|
|||
}
|
||||
|
||||
tick() {
|
||||
window.q = [];
|
||||
if (this.crashed) return;
|
||||
if (!state.editing) this.tickMotion();
|
||||
if (!this.landed) this.tickGravity(world.celestials);
|
||||
if (!state.editing) this.resolveCollisions();
|
||||
|
@ -151,10 +152,19 @@ export default class Ship extends Body {
|
|||
let dis = body.distanceTo({ com: p });
|
||||
if (dis < body.radius + 0.5 + consts.EPSILON) {
|
||||
this.approach(body, dis - (body.radius + 0.5));
|
||||
this.moduleCollided(module);
|
||||
this.halt();
|
||||
this.resolveCelestialCollision(p, body, module);
|
||||
this.lastContactModule = module;
|
||||
this.poc = p;
|
||||
this.lastContactModule = module;
|
||||
}
|
||||
}
|
||||
|
||||
moduleCollided(module) {
|
||||
let speed = Math.sqrt(this.xvel ** 2 + this.yvel ** 2);
|
||||
if (module.type !== 'thruster' || speed > consts.CRASH_SPEED) {
|
||||
events.crash();
|
||||
this.crashed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue