add weapon selection gui

This commit is contained in:
Asraelite 2016-03-29 23:28:18 +01:00
parent 8ea6c2d937
commit 02245ca5a9
6 changed files with 39 additions and 2369 deletions

View file

@ -5,6 +5,7 @@ class GUI {
this.guiElement = document.getElementById('gui');
this.chat = new this.Chat(this);
this.weapons = new this.Weapons(this);
}
createElement(parent, type, data) {

View file

@ -8,10 +8,29 @@ GUI.prototype.Weapons = class {
}
update() {
let ship = game.world.playerShip;
if (!ship) return;
this.element.innerHTML = '';
ship.fixtures.forEach((fixture, i) => {
if (!fixture.type) return;
let div = document.createElement('div');
div.classList.add('weapon');
if (ship.activeFixture == i)
div.classList.add('active');
let img = `url(/img/turrets/${fixture.type}/normal.png)`;
div.style.backgroundImage = img;
this.element.appendChild(div);
});
}
switchWeapon(slot) {
this.currentWeapon = 0;
let el = this.element.querySelector('.weapon.active');
if (el)
el.classList.remove('active');
let weapons = this.element.querySelectorAll('.weapon');
if (weapons[slot])
weapons[slot].classList.add('active');
}
}

View file

@ -14,6 +14,7 @@ class Ship extends Body {
}[data.size];
this.lastMove = [];
this.bodyType = 'ship';
this.activeFixture = 0;
}
updateType(data) {

View file

@ -57,6 +57,7 @@ class World {
setPlayerShip(id) {
this.playerShip = this.bodies[id];
game.player.ship = this.playerShip;
game.gui.weapons.update();
}
tick() {