health bar
This commit is contained in:
parent
39907854f2
commit
74152fd8ce
3 changed files with 13 additions and 1 deletions
|
@ -4,7 +4,7 @@ const playerSize = 50.;
|
||||||
const playerSpeed=.2;
|
const playerSpeed=.2;
|
||||||
const bulletSpeed=playerSpeed*2;
|
const bulletSpeed=playerSpeed*2;
|
||||||
const halfSqrtTwo=0.70710678118;
|
const halfSqrtTwo=0.70710678118;
|
||||||
const defaulthealth=10
|
const defaulthealth=10.;
|
||||||
|
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,6 +108,7 @@ function game() {
|
||||||
player=Net.clientPlayer;
|
player=Net.clientPlayer;
|
||||||
players=Net.getPlayersToAdd();
|
players=Net.getPlayersToAdd();
|
||||||
Renderer.AddPlayer(player)
|
Renderer.AddPlayer(player)
|
||||||
|
Renderer.SetPlayerId(player.id)
|
||||||
|
|
||||||
console.log("Connected as id ",playerId);
|
console.log("Connected as id ",playerId);
|
||||||
Inp.player=player;
|
Inp.player=player;
|
||||||
|
|
11
js/render.js
11
js/render.js
|
@ -11,6 +11,11 @@ class Render {
|
||||||
this.bullets = [];
|
this.bullets = [];
|
||||||
this.mapsrc=mapsrc;
|
this.mapsrc=mapsrc;
|
||||||
this.ReloadAff();
|
this.ReloadAff();
|
||||||
|
this.playerid=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPlayerId(id) {
|
||||||
|
this.playerid=id
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPlayer(player) {
|
AddPlayer(player) {
|
||||||
|
@ -49,6 +54,12 @@ class Render {
|
||||||
this.ctx.fillStyle = 'white';
|
this.ctx.fillStyle = 'white';
|
||||||
this.ctx.font="10pt arial";
|
this.ctx.font="10pt arial";
|
||||||
this.ctx.fillText(player.name,player.x-player.name.length*10/3,player.y-playerSize/1.8);
|
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) {
|
RenderBullet(bullet) {
|
||||||
|
|
Loading…
Reference in a new issue