add weapon selection gui
This commit is contained in:
parent
8ea6c2d937
commit
02245ca5a9
6 changed files with 39 additions and 2369 deletions
|
@ -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) {
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ class Ship extends Body {
|
|||
}[data.size];
|
||||
this.lastMove = [];
|
||||
this.bodyType = 'ship';
|
||||
this.activeFixture = 0;
|
||||
}
|
||||
|
||||
updateType(data) {
|
||||
|
|
|
@ -57,6 +57,7 @@ class World {
|
|||
setPlayerShip(id) {
|
||||
this.playerShip = this.bodies[id];
|
||||
game.player.ship = this.playerShip;
|
||||
game.gui.weapons.update();
|
||||
}
|
||||
|
||||
tick() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue