function renderPlayer(me, player) {
  const { x, y, direction } = player;
  const canvasX = canvas.width / 2 + x - me.x;
  const canvasY = canvas.height / 2 + y - me.y;

  // Draw ship
  const randomColor = 'hsl(' + 360 * Math.random() + ', 50%, 50%)';

  context.save();
  context.translate(canvasX, canvasY);
  context.rotate(direction);
  context.drawImage(
    getAsset('ship2.svg'),
    -PLAYER_RADIUS,
    -PLAYER_RADIUS,
    PLAYER_RADIUS * 2,
    PLAYER_RADIUS * 2,
  );
  context.restore();

  // Draw health bar
  context.fillStyle = 'white';
  context.fillRect(
    canvasX - PLAYER_RADIUS,
    canvasY + PLAYER_RADIUS + 8,
    PLAYER_RADIUS * 2,
    2,
  );
  context.fillStyle = 'red';
  context.fillRect(
    canvasX - PLAYER_RADIUS + PLAYER_RADIUS * 2 * player.hp / PLAYER_MAX_HP,
    canvasY + PLAYER_RADIUS + 8,
    PLAYER_RADIUS * 2 * (1 - player.hp / PLAYER_MAX_HP),
    2,
  );
}
// Renders a ship at the given coordinates
Renders a ship at the given coordinates
Renders a ship at the given coordinates
function renderPlayer(me, player) {
  const { x, y, direction } = player;
  const canvasX = canvas.width / 2 + x - me.x;
  const canvasY = canvas.height / 2 + y - me.y;
  const randomColor = 'hsl(' + 360 * Math.random() + ', 50%, 50%)';
  context.save();
  context.translate(canvasX, canvasY);
  context.rotate(direction);
  context.drawImage(
    getAsset('ship2.svg'),
    -PLAYER_RADIUS,
    -PLAYER_RADIUS,
    PLAYER_RADIUS * 2,
    PLAYER_RADIUS * 2,
  );
  context.restore();
  context.fillStyle = 'white';
  context.fillRect(
    canvasX - PLAYER_RADIUS,
    canvasY + PLAYER_RADIUS + 8,
    PLAYER_RADIUS * 2,
    2,
  );
  context.fillStyle = 'red';
  context.fillRect(
    canvasX - PLAYER_RADIUS + PLAYER_RADIUS * 2 * player.hp / PLAYER_MAX_HP,
    canvasY + PLAYER_RADIUS + 8,
    PLAYER_RADIUS * 2 * (1 - player.hp / PLAYER_MAX_HP),
    2,
  );
}
function renderPlayer ( me , player ) { const { x , y , direction } = player ; const canvasX = canvas . width / 2 + x - me . x ; const canvasY = canvas . height / 2 + y - me . y ; const randomColor = 'hsl(' + 360 * Math . random ( ) + ', 50%, 50%)' ; context . save ( ) ; context . translate ( canvasX , canvasY ) ; context . rotate ( direction ) ; context . drawImage ( getAsset ( 'ship2.svg' ) , - PLAYER_RADIUS , - PLAYER_RADIUS , PLAYER_RADIUS * 2 , PLAYER_RADIUS * 2 , ) ; context . restore ( ) ; context . fillStyle = 'white' ; context . fillRect ( canvasX - PLAYER_RADIUS , canvasY + PLAYER_RADIUS + 8 , PLAYER_RADIUS * 2 , 2 , ) ; context . fillStyle = 'red' ; context . fillRect ( canvasX - PLAYER_RADIUS + PLAYER_RADIUS * 2 * player . hp / PLAYER_MAX_HP , canvasY + PLAYER_RADIUS + 8 , PLAYER_RADIUS * 2 * ( 1 - player . hp / PLAYER_MAX_HP ) , 2 , ) ; }
Renders a ship at the given coordinates
Renders a ship at the given coordinates
// Draw ship // Draw health bar