import { coordinates } from "./coordinates.js"; import { position } from "./position.js"; import { moving } from "./moving.js"; class actor extends coordinates { #movement; #rotation; #speed; constructor() { super(); this.#speed = 0.25; this.#movement = new moving(); this.#rotation = new moving(); } set speed(target) { if (typeof(target) !== "number") { throw new TypeError("Speed must be an number."); } this.#speed = target; } get speed() { return this.#speed; } rotate_cursor(cursor, size, scale = 2) { if (!(cursor instanceof position)) { throw new TypeError("Cursor compare must be an position object."); } if (!(size instanceof position)) { throw new TypeError("Size must be an position object."); } if (typeof(scale) !== "number") { throw new TypeError("Scale must be an number."); } const rotate = cursor.x / size.x * 360 * scale; const bottom_rotate = cursor.y / size.y * 180 * scale; this.rotate_bottom(bottom_rotate); this.rotate_clockwise(rotate); } get movement() { return this.#movement; } get rotation() { return this.#rotation; } update() { this.#update_position(); this.#update_rotation(); } #update_rotation() { this.rotate_clockwise(this.#speed * 10 * this.rotation.z); } #update_position() { this.move_front(this.#speed * this.movement.y); this.move_right(this.#speed * this.movement.x); } } export { actor };