fix projectiles
This commit is contained in:
parent
0906441246
commit
4f42723f4a
7 changed files with 20 additions and 8 deletions
|
@ -11,8 +11,8 @@ class Body {
|
|||
this.fixtures = data.fixtures;
|
||||
this.b2body = false;
|
||||
this.updated = 0;
|
||||
|
||||
game.world.update(data.delta);
|
||||
|
||||
this.update(data.delta.slice(1));
|
||||
|
||||
this.com = {
|
||||
x: 0,
|
||||
|
|
|
@ -44,10 +44,9 @@ class World {
|
|||
};
|
||||
|
||||
update(data) {
|
||||
let array = new Float32Array(data);
|
||||
let i = 0;
|
||||
while (i < array.length) {
|
||||
let id = array[i++];
|
||||
while (i < data.length) {
|
||||
let id = data[i++];
|
||||
let body = this.bodies[id];
|
||||
|
||||
if (!body) {
|
||||
|
@ -55,7 +54,7 @@ class World {
|
|||
return;
|
||||
}
|
||||
|
||||
body.update(array.slice(i, i + body.interface.size));
|
||||
body.update(data.slice(i, i + body.interface.size));
|
||||
i += body.interface.size;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ const Body = require('../body.js');
|
|||
class Projectile extends Body {
|
||||
constructor(world) {
|
||||
super(world);
|
||||
|
||||
this.class = 'projectile';
|
||||
}
|
||||
|
||||
connect() {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ class Spawner {
|
|||
yvel: ship.vel.y
|
||||
};
|
||||
let missile = new Missile(this.world, pos, ship);
|
||||
this.world.addProjectile(missile);
|
||||
return missile;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue