add weapon selection gui
This commit is contained in:
parent
8ea6c2d937
commit
02245ca5a9
6 changed files with 39 additions and 2369 deletions
2364
processed.txt
2364
processed.txt
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,7 @@ class GUI {
|
||||||
this.guiElement = document.getElementById('gui');
|
this.guiElement = document.getElementById('gui');
|
||||||
|
|
||||||
this.chat = new this.Chat(this);
|
this.chat = new this.Chat(this);
|
||||||
|
this.weapons = new this.Weapons(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
createElement(parent, type, data) {
|
createElement(parent, type, data) {
|
||||||
|
|
|
@ -8,10 +8,29 @@ GUI.prototype.Weapons = class {
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
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) {
|
switchWeapon(slot) {
|
||||||
this.currentWeapon = 0;
|
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];
|
}[data.size];
|
||||||
this.lastMove = [];
|
this.lastMove = [];
|
||||||
this.bodyType = 'ship';
|
this.bodyType = 'ship';
|
||||||
|
this.activeFixture = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateType(data) {
|
updateType(data) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ class World {
|
||||||
setPlayerShip(id) {
|
setPlayerShip(id) {
|
||||||
this.playerShip = this.bodies[id];
|
this.playerShip = this.bodies[id];
|
||||||
game.player.ship = this.playerShip;
|
game.player.ship = this.playerShip;
|
||||||
|
game.gui.weapons.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
|
|
|
@ -58,3 +58,15 @@ body
|
||||||
bottom 0
|
bottom 0
|
||||||
left 50%
|
left 50%
|
||||||
transform translate(-50%, 0)
|
transform translate(-50%, 0)
|
||||||
|
> .weapon
|
||||||
|
background-position center
|
||||||
|
background-size 64px
|
||||||
|
background-color rgba(0, 0, 0, 0.5)
|
||||||
|
float: left
|
||||||
|
width: 48px
|
||||||
|
height: 48px
|
||||||
|
&.active
|
||||||
|
background-color rgba(15, 15, 15, 0.3)
|
||||||
|
width 44px
|
||||||
|
height 44px
|
||||||
|
border 2px solid rgba(30, 30, 30, 0.2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue