import GameObject from "./GameObject.js"; const DEFAULT_VELOCITY = 1, DEFAULT_HEALTH = 100, DEFAULT_WIDTH = 50, DEFAULT_HEIGHT = 50, DEFAULT_DAMAGE = 10, DEFAULT_HIT_BOX_RADIUS = 30, DEFAULT_ENEMEY_COLOR = "#dd3939"; class Enemy extends GameObject { constructor(x, y, direction) { super(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HIT_BOX_RADIUS, DEFAULT_VELOCITY, direction, DEFAULT_ENEMEY_COLOR); this.health = DEFAULT_HEALTH; this.damage = DEFAULT_DAMAGE; } draw(context) { context.save(); context.fillStyle = this.color; context.beginPath(); context.translate(this.x, this.y); context.rotate(this.direction * Math.PI / 180); context.moveTo(0, -this.height / 2); context.lineTo(-(this.width / 2), this.height / 2); context.lineTo(this.width / 2, this.height / 2); context.closePath(); context.fill(); context.restore(); } static createEnemy(rangeX, rangeY, targetX, targetY) { let xPos = parseInt(Math.random() * rangeX), yPos = parseInt(Math.random() * rangeY), direction = Math.atan2(targetY - yPos, targetX - xPos) * 180 / Math.PI; return new Enemy(xPos, yPos, direction); } } export default Enemy;