add grappling hook sprite

This commit is contained in:
Asraelite 2016-03-30 00:53:23 +01:00
parent 02245ca5a9
commit e9d1596c2f
12 changed files with 34 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

View file

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

View file

@ -34,6 +34,9 @@ class GUI {
} }
set visible(visible) { set visible(visible) {
this.guiElement.style.display = visible ? 'block' : 'hidden'; if (visible)
this.guiElement.classList.remove('hidden');
else
this.guiElement.classList.add('hidden');
} }
} }

View file

@ -62,9 +62,9 @@ class Game {
this._state = state; this._state = state;
if (state != 'connected') { if (state != 'connected') {
this.gui.visible = true;
} else {
this.gui.visible = false; this.gui.visible = false;
} else {
this.gui.visible = true;
} }
} }
} }

View file

@ -6,7 +6,7 @@ class BodyRenderer {
} }
render(body) { render(body) {
let pos = body.getPos(); let pos = body.pos;
let x = pos.x * SCALE; let x = pos.x * SCALE;
let y = pos.y * SCALE; let y = pos.y * SCALE;
let vx = -game.world.center.x; let vx = -game.world.center.x;
@ -28,6 +28,8 @@ class BodyRenderer {
this.renderShip(body); this.renderShip(body);
} else if (body.bodyType == 'asteroid') { } else if (body.bodyType == 'asteroid') {
this.renderAsteroid(body); this.renderAsteroid(body);
} else if (body.bodyClass == 'projectile') {
this.renderProjectile(body);
} else { } else {
this.renderBody(body); this.renderBody(body);
} }
@ -110,4 +112,16 @@ class BodyRenderer {
this.pallet.opacity(0.3); this.pallet.opacity(0.3);
this.pallet.text(ship.name, x, y, '#fff', 'FreePixel', 16, 'center', 'bottom'); this.pallet.text(ship.name, x, y, '#fff', 'FreePixel', 16, 'center', 'bottom');
} }
renderProjectile(body) {
if (body.bodyType != 'grapple') {
this.renderBody(body);
return;
}
let img = game.assets.images.projectiles['02'];
let pos = body.pos;
this.pallet.image(img, -32, -32, 0);
this.pallet.restore();
}
}; };

View file

@ -37,6 +37,10 @@ class Renderer {
this.pallet.fill('#020202'); this.pallet.fill('#020202');
this.context.save(); this.context.save();
this.context.beginPath();
this.context.rect(0, 0, cw, ch);
this.context.clip();
this.pallet.view(cw / 2, ch / 2, 1, 0); this.pallet.view(cw / 2, ch / 2, 1, 0);
@ -44,7 +48,7 @@ class Renderer {
let img = game.assets.images.backgrounds['01']; let img = game.assets.images.backgrounds['01'];
let bgx = -img.width / 2 - center.x / 20; let bgx = -img.width / 2 - center.x / 20;
let bgy = -img.height / 2 - center.y / 20; let bgy = -img.height / 2 - center.y / 20;
this.pallet.image(img, bgx, bgy); this.pallet.image(img, bgx, bgy, 0, img.width * 1.5, img.height * 1.5);
this.pallet.opacity(1); this.pallet.opacity(1);
this.renderGrid(); this.renderGrid();

View file

@ -10,6 +10,8 @@ class Body {
this.fixtures = data.fixtures; this.fixtures = data.fixtures;
this.b2body = false; this.b2body = false;
this.updated = 0; this.updated = 0;
this.bodyClass = data.class;
this.bodyType = data.type;
this.update(data.delta.slice(1)); this.update(data.delta.slice(1));

View file

@ -13,7 +13,6 @@ class Ship extends Body {
'large': 24 'large': 24
}[data.size]; }[data.size];
this.lastMove = []; this.lastMove = [];
this.bodyType = 'ship';
this.activeFixture = 0; this.activeFixture = 0;
} }

View file

@ -21,6 +21,8 @@ body
#gui #gui
color #fff color #fff
&.hidden *
display: none
.container .container
position fixed position fixed
#chat #chat

View file

@ -116,6 +116,7 @@ class Body {
packFull() { packFull() {
let packet = { let packet = {
type: this.type, type: this.type,
class: this.class,
id: this.id, id: this.id,
frame: this.frame, frame: this.frame,
fixtures: this.mounts.map(m => m.packFull()), fixtures: this.mounts.map(m => m.packFull()),