health bar

This commit is contained in:
Baptiste 2023-12-07 09:35:35 +01:00
parent 39907854f2
commit 74152fd8ce
3 changed files with 13 additions and 1 deletions

View file

@ -4,7 +4,7 @@ const playerSize = 50.;
const playerSpeed=.2;
const bulletSpeed=playerSpeed*2;
const halfSqrtTwo=0.70710678118;
const defaulthealth=10
const defaulthealth=10.;
class Player
{

View file

@ -108,6 +108,7 @@ function game() {
player=Net.clientPlayer;
players=Net.getPlayersToAdd();
Renderer.AddPlayer(player)
Renderer.SetPlayerId(player.id)
console.log("Connected as id ",playerId);
Inp.player=player;

View file

@ -11,6 +11,11 @@ class Render {
this.bullets = [];
this.mapsrc=mapsrc;
this.ReloadAff();
this.playerid=0;
}
SetPlayerId(id) {
this.playerid=id
}
AddPlayer(player) {
@ -49,6 +54,12 @@ class Render {
this.ctx.fillStyle = 'white';
this.ctx.font="10pt arial";
this.ctx.fillText(player.name,player.x-player.name.length*10/3,player.y-playerSize/1.8);
if(player.id==this.playerid) {
this.ctx.fillStyle = 'red';
this.ctx.fillRect(player.x-playerSize/2-5, player.y-playerSize/2, playerSize+10, 5);
this.ctx.fillStyle = '#7AFF33';
this.ctx.fillRect(player.x-playerSize/2-5, player.y-playerSize/2, player.health*(playerSize+10)/defaulthealth, 5);
}
}
RenderBullet(bullet) {