import { GameObject } from "./gameObject.js";
import { cam } from "./cam.js";
import { controls } from "./controls.js";

export class Queen extends GameObject {
    constructor(options = {}) {
        super("queen", options);
        this.setSprite(options.sprite || "assets/ants/queen/1.png");
        this.setPosition(options.x || 0, options.y || 0);
        this.setSize(options.width || 41, options.height || 13);
        this.direction = options.direction || 30;

        this.active = options.active || false;
        this.isFixed = options.isFixed || true;
    }

    update(options = {}) {
        const allowRightClick = options.allowRightClick ?? true;

        this.rotateTowardsMouseIfAllowed(allowRightClick);
    }

    rotateTowardsMouseIfAllowed(allowRightClick = true) {
        if (allowRightClick && this.active && !this.isFixed && controls.mouse.buttons.right) {
            const dx = controls.mouse.x - (this.x + cam.x) * cam.zoom;
            const dy = controls.mouse.y - (this.y + cam.y) * cam.zoom;
            this.direction = Math.atan2(dy, dx) * 180 / Math.PI;
        }
    }
}