Enemy.js 1.11 KB
Newer Older
Alexander Bazo committed
1 2 3 4 5 6 7 8
const schema = require("@colyseus/schema"),
    GameObject = require("./GameObject.js");

const DEFAULT_VELOCITY = 1,
    DEFAULT_HEALTH = 100,
    DEFAULT_WIDTH = 50,
    DEFAULT_HEIGHT = 50,
    DEFAULT_DAMAGE = 10,
9
    DEFAULT_HIT_BOX_RADIUS = 30;
Alexander Bazo committed
10 11 12

class Enemy extends GameObject {

13
    constructor(x, y, width, height, hitBoxRadius, velocity, direction) {
Alexander Bazo committed
14
        super(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HIT_BOX_RADIUS,
15 16 17 18 19 20 21 22 23 24 25
            DEFAULT_VELOCITY, direction);
        this.lp = DEFAULT_HEALTH;
    this.damage = DEFAULT_DAMAGE;
    }

    setFocus() {
        this.focus = true;
    }

    removeFocus() {
        this.focus = false;
Alexander Bazo committed
26 27 28 29 30 31
    }

    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;
32
        return new Enemy(xPos, yPos, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HIT_BOX_RADIUS, DEFAULT_VELOCITY, direction);
Alexander Bazo committed
33 34 35 36 37
    }

}

schema.defineTypes(Enemy, {
38 39
    lp: "number",
    damage: "number"
Alexander Bazo committed
40 41 42 43
});


module.exports = Enemy;