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

@ -11,8 +11,8 @@ class Body {
this.fixtures = data.fixtures; this.fixtures = data.fixtures;
this.b2body = false; this.b2body = false;
this.updated = 0; this.updated = 0;
game.world.update(data.delta); this.update(data.delta.slice(1));
this.com = { this.com = {
x: 0, x: 0,

View file

@ -44,10 +44,9 @@ class World {
}; };
update(data) { update(data) {
let array = new Float32Array(data);
let i = 0; let i = 0;
while (i < array.length) { while (i < data.length) {
let id = array[i++]; let id = data[i++];
let body = this.bodies[id]; let body = this.bodies[id];
if (!body) { if (!body) {
@ -55,7 +54,7 @@ class World {
return; return;
} }
body.update(array.slice(i, i + body.interface.size)); body.update(data.slice(i, i + body.interface.size));
i += body.interface.size; i += body.interface.size;
} }
}; };

View file

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

View file

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

View file

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

View file

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