export class Enemy{
    constructor(p5, x, y) {
        this.sprite = new p5.Sprite(x,y,36,36);
        this.sprite.image = '/assets/enemy.png';
        this.sprite.collider = 'dynamic';
        this.sprite.rotationLock = true;
        this.sprite.bounciness = 0;

        this.speed = 1.5;
        this.direction = 1 // 1 is right, -1 is left
        this.startX = x;
        this.patrolDisctance = 100; // how far it can walk
    }

    update(){
        // move in current direction
        this.sprite.vel.x = this.speed * this.direction;

        // flip direction once it reaches patrol distance
        if (this.sprite.x > this.startX + this.patrolDistance){
            this.direction = -1;
            this.sprite.mirror.x = -1; // we flip the image
        }
        if (this.sprite.x < this.startX - this.patrolDistance){
            this.direction = 1;
            this.sprite.mirror.x = 1; // flip image back
        }
    }
}