import { coordinates } from "./coordinates.js"; import { position } from "./position.js"; import { moving_directions } from "./directions.js"; import { rotating_directions } from "./directions.js"; import { is_moving_direction } from "./directions.js"; import { is_rotating_direction } from "./directions.js"; class actor extends coordinates { #moving; #rotating; #speed; constructor() { super(); this.#speed = 0.25; this.#moving = moving_directions.stop; this.#rotating = moving_directions.stop; } 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) { 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."); } const rotate = cursor.x / size.x * 360; this.rotate_clockwise(rotate); } set moving(target) { if (!is_moving_direction(target)) { throw new TypeError("Direction must be in directions."); } this.#moving = target; } get moving() { return this.#moving; } set rotating(target) { if (!is_rotating_direction(target)) { throw new TypeError("Direction must be in directions."); } this.#rotating = target; } get rotating() { return this.#rotating; } update() { this.#update_position(); this.#update_rotation(); } #update_rotation() { switch (this.#rotating) { case rotating_directions.clockwise: this.rotate_clockwise(this.#speed * 10); return; case rotating_directions.counterclockwise: this.rotate_counterclockwise(this.#speed * 10); return; default: return; } } #update_position() { switch (this.#moving) { case moving_directions.front: this.move_front(this.#speed); return; case moving_directions.back: this.move_back(this.#speed); return; case moving_directions.left: this.move_left(this.#speed); return; case moving_directions.right: this.move_right(this.#speed); return; default: return; } } } export { actor };