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'
}
},
projectiles: {
'02': 'img/projectiles/02.png'
},
backgrounds: {
'01': 'img/space.jpg'
}

View file

@ -34,6 +34,9 @@ class GUI {
}
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;
if (state != 'connected') {
this.gui.visible = true;
} else {
this.gui.visible = false;
} else {
this.gui.visible = true;
}
}
}

View file

@ -6,7 +6,7 @@ class BodyRenderer {
}
render(body) {
let pos = body.getPos();
let pos = body.pos;
let x = pos.x * SCALE;
let y = pos.y * SCALE;
let vx = -game.world.center.x;
@ -28,6 +28,8 @@ class BodyRenderer {
this.renderShip(body);
} else if (body.bodyType == 'asteroid') {
this.renderAsteroid(body);
} else if (body.bodyClass == 'projectile') {
this.renderProjectile(body);
} else {
this.renderBody(body);
}
@ -110,4 +112,16 @@ class BodyRenderer {
this.pallet.opacity(0.3);
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

@ -38,13 +38,17 @@ class Renderer {
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.opacity(0.3);
let img = game.assets.images.backgrounds['01'];
let bgx = -img.width / 2 - center.x / 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.renderGrid();

View file

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

View file

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

View file

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

View file

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