Planet.js 984 Bytes
Newer Older
1 2 3
import GameObject from "./GameObject.js";

const DEFAULT_HEALTH = 100,
4 5 6 7 8 9
  DEFAULT_WIDTH = 500,
  DEFAULT_HEIGHT = 500,
  DEFAULT_HIT_BOX_RADIUS = 270,
  DEFAULT_PLANET_COLOR = "#5bbe61",
  DEFAULT_PLANET_BORDER_COLOR = "#dafffe",
  DEFAULT_PLANET_BORDER_WIDTH = "20";
10

11
class Planet extends GameObject {
12 13 14

  constructor(x, y) {
    super(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HIT_BOX_RADIUS,
15
      0, 0, DEFAULT_PLANET_COLOR);
16
    this.health = DEFAULT_HEALTH;
17 18
    this.borderColor = DEFAULT_PLANET_BORDER_COLOR;
    this.borderWidth = DEFAULT_PLANET_BORDER_WIDTH;
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  }

  draw(context) {
    context.save();
    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();
    context.restore();
  }

}

37
export default Planet;