Planet.js 1.1 KB
Newer Older
1
const DEFAULT_HEALTH = 100,
2 3 4
  DEFAULT_WIDTH = 500,
  DEFAULT_HEIGHT = 500,
  DEFAULT_HIT_BOX_RADIUS = 270,
5
  DEFAULT_PLANET_COLOR = "#900c47",
6
  DEFAULT_PLANET_BORDER_COLOR = "#dafffe",
7 8 9 10
  DEFAULT_PLANET_BORDER_WIDTH = "20",
  DEFAULT_PLANET_TEXT_OFFSET = 20,
  DEFAULT_PLANET_TEXT_FONT = "32px ShareTech",
  DEFAULT_PLANET_TEXT_COLOR = "#FFF";
11

12
class Planet  {
13

14
  static draw(context) {
15
    context.save();
16
    // Draw planet
17 18 19 20 21 22 23 24 25
    context.fillStyle = this.color;
    context.strokeStyle = this.borderColor;
    context.lineWidth = this.borderWidth;
    context.beginPath();
    context.ellipse(this.x, this.y, this.width / 2, this.height / 2, Math.PI /
      4, 0, 2 * Math.PI);
    context.closePath();
    context.fill();
    context.stroke();
26 27 28 29 30 31 32 33
    // Draw current shield/health status
    context.beginPath();
    context.font = DEFAULT_PLANET_TEXT_FONT;
    context.fillStyle = DEFAULT_PLANET_TEXT_COLOR;
    context.textAlign = "center";
    context.fillText(`Shields at ${this.health}%`, this.x, this.y -
      DEFAULT_PLANET_TEXT_OFFSET);
    context.closePath();
34 35 36 37 38
    context.restore();
  }

}

39
export default Planet;