fix projectiles

This commit is contained in:
Asraelite 2016-03-29 01:44:02 +01:00
parent 0906441246
commit 4f42723f4a
7 changed files with 20 additions and 8 deletions

View file

@ -14,6 +14,13 @@ class Body {
this.type = 'body';
this.b2body = false;
this.x = data.x || 0;
this.y = data.y || 0;
this.xvel = data.xvel || 0;
this.yvel = data.yvel || 0;
this.r = data.r || 0;
this.rvel = data.rvel || 0;
this.mounts = data.mounts || [];
this.health = data.health || 1;
this.mounts = this.mounts.map(m => new Mount(this, m));
@ -113,7 +120,7 @@ class Body {
fixtures: this.mounts.map(m => m.packFull()),
delta: this.packDelta(),
interface: this.interface
}
};
let typePacket = this.packTypeFull();
for (let i in typePacket)

View file

@ -5,9 +5,11 @@ const Rope = require('../../copula/rope.js');
class Grapple extends Projectile {
constructor(world, pos, source) {
// pos.x *= 32, pos.y *= 32, idk why
super(world, pos);
this.r = pos.r;
this.x = pos.x * 32;
this.y = pos.y * 32;
this.xvel += Math.cos(this.r) * 0.25;
this.yvel += Math.sin(this.r) * 0.25;

View file

@ -5,6 +5,8 @@ const Body = require('../body.js');
class Projectile extends Body {
constructor(world) {
super(world);
this.class = 'projectile';
}
connect() {

View file

@ -75,6 +75,7 @@ class World {
this.bodies.add(body);
if (body.type == 'asteroid') this.asteroids.add(body);
if (body.type == 'structure') this.structures.add(body);
if (body.class == 'projectile') this.projectiles.add(body);
this.physics.createBody(body);
this.room.broadcast('create', body.packFull());
}

View file

@ -30,6 +30,7 @@ class Spawner {
yvel: ship.vel.y
};
let missile = new Missile(this.world, pos, ship);
this.world.addProjectile(missile);
return missile;
}