You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.8 KiB

2 years ago
class Leaderboard{
constructor(){
}
get pos(){
2 years ago
return p.createVector(game.pos.x, 0);
2 years ago
}
get width(){
return game.size;
}
get height(){
let h = 0;
if (this.bars[0])
h = this.bars[0].marginY;
this.bars.forEach(b => h += b.height + b.marginY);
return h;
}
setBarsFromPlayers(players){
this.bars = [];
players.forEach(p => this.bars.push(new Bar(p)));
}
display(){
this.bars.forEach(b => b.display());
}
}
class Bar{
constructor(player){
this.id = player.id;
}
get marginX(){
return game.size / game.winCount;
}
get marginY(){
2 years ago
return p.height * 0.005;
2 years ago
}
get pos(){
let lb = game.leaderboard;
let x = lb.pos.x + this.marginX;
let y = lb.pos.y + this.marginY + lb.bars.findIndex(b => b.id === this.id) * (this.height + this.marginY);
2 years ago
return p.createVector(x, y);
2 years ago
}
get height(){
return 40;
}
get width(){
return game.leaderboard.width - this.marginX * 2;
}
display(){
let count = game.winCount;
let imageSize = Math.min(this.height, this.width / count * 0.85);
let y = this.pos.y + this.height / 2;
let filled = game.fields.filter(f => f.ownerId === this.id).length;
for (let i = 0; i < count; i++){
let x = i * this.width / count + this.width / count / 2 + this.pos.x;
2 years ago
p.image(gemBorderImage, x, y, imageSize, imageSize);
2 years ago
}
for (let i = 0; i < filled; i++){
let x = i * this.width / count + this.width / count / 2 + this.pos.x;
2 years ago
p.image(gemContentGraphics[game.playerHues[this.id]], x, y, imageSize, imageSize);
2 years ago
}
}
}