World.js 976 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
import GameObject from "./GameObject.js";

const DEFAULT_HEALTH = 100,
  DEFAULT_WIDTH = 200,
  DEFAULT_HEIGHT = 200,
  DEFAULT_HIT_BOX_RADIUS = 100,
  DEFAULT_WORLD_COLOR = "#0d396f",
  DEFAULT_WORLD_BORDER_COLOR = "#dafffe",
  DEFAULT_WORLD_BORDER_WIDTH = "10";

class World extends GameObject {

  constructor(x, y) {
    super(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HIT_BOX_RADIUS,
      0, 0, DEFAULT_WORLD_COLOR);
    this.health = DEFAULT_HEALTH;
    this.borderColor = DEFAULT_WORLD_BORDER_COLOR;
    this.borderWidth = DEFAULT_WORLD_BORDER_WIDTH;
  }

  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();
  }

}

export default World;