add robust fixture rendering

This commit is contained in:
Asraelite 2016-03-30 15:58:06 +01:00
parent ef2d067b38
commit cf4e8024af
13 changed files with 140 additions and 64 deletions

View file

@ -14,6 +14,9 @@ Game.prototype.loadAssets = _ => {
turrets: {
'01': {
small: 'img/turrets/01/normal.png'
},
'02': {
small: 'img/turrets/02/normal.png'
}
},
projectiles: {

View file

@ -19,9 +19,9 @@ class BodyRenderer {
pallet.view(x, y, false, pos.r);
for (let f of body.fixtures) {
if (!f.type) continue;
let img = game.assets.images.turrets[f.type].small;
this.pallet.image(img, f.x - 32, f.y - 32, 0);
if (!f.fixture || !f.hidden) continue;
let img = game.assets.images.turrets[f.fixture].small;
this.pallet.image(img, f.x - 32, f.y - 32, f.angle);
}
if (body.bodyType == 'ship') {
@ -34,6 +34,13 @@ class BodyRenderer {
this.renderBody(body);
}
for (let f of body.fixtures) {
if (!f.fixture || f.hidden) continue;
let img = game.assets.images.turrets[f.fixture].small;
this.pallet.image(img, f.x - 32, f.y - 32, f.angle);
}
pallet.restore();
pallet.restore();
}
@ -62,7 +69,7 @@ class BodyRenderer {
context.stroke();
}
this.pallet.restore();
//this.pallet.restore();
}
renderBody(body) {
@ -83,7 +90,7 @@ class BodyRenderer {
context.stroke();
}
this.pallet.restore();
//this.pallet.restore();
}
renderShip(ship) {
@ -103,7 +110,7 @@ class BodyRenderer {
this.pallet.square('#f00', ship.debug.x * SCALE, ship.debug.y * SCALE, 2);
}
this.pallet.restore();
//this.pallet.restore();
}
renderShipNameplate(ship) {
@ -122,6 +129,6 @@ class BodyRenderer {
let img = game.assets.images.projectiles['02'];
let pos = body.pos;
this.pallet.image(img, -32, -32, 0);
this.pallet.restore();
//this.pallet.restore();
}
};

View file

@ -6,10 +6,10 @@ class Asteroid extends Body {
}
updateType(data) {
//this.debug = data.debug;
this.debug = data.debug;
}
tickType() {
}
}

View file

@ -3,7 +3,8 @@
class Body {
constructor(data) {
this.interface = data.interface;
let s = this.interface.order.length + this.interface.fixtures;
let s = this.interface.order.length;
s += this.interface.fixtures.order.length * this.interface.fixtures.num;
this.interface.size = s;
this.id = data.id
this.frame = data.frame;
@ -36,9 +37,7 @@ class Body {
update(data) {
let values = {};
Array.from(data).map((v, i) => {
values[this.interface.order[i]] = v
});
this.interface.order.forEach(v => values[v] = data.shift());
this.x = values.x;
this.y = values.y;
this.xvel = values.xvel;
@ -46,7 +45,14 @@ class Body {
this.r = values.r;
this.rvel = values.rvel;
this.updated = 10;
this.debug = values.debug;
this.fixtures.forEach(fixture => {
let obj = {};
this.interface.fixtures.order.forEach(v => obj[v] = data.shift());
fixture.angle = obj.angle;
fixture.state = obj.state;
});
this.updateType(values);
}