import { position } from "./position.js"; class coordinates extends position { #rotate; #head_rotate; constructor() { super(); this.#rotate = 0; this.#head_rotate = 0; } get rotate() { this.#check_rotate(); return this.#rotate; } set rotate(target) { if (typeof(target) !== "number") { throw new TypeError("Coordinate must be number."); } this.#rotate = target; this.#check_rotate(); } #check_rotate() { while (this.#rotate < 0) { this.#rotate += 360; } this.#rotate = this.#rotate % 360; } set head_rotate(target) { if (typeof(target) !== "number") { throw new TypeError("Coordinate must be number."); } this.#head_rotate = target % 90; this.#check_head_rotate(); } #check_head_rotate() { if (this.#head_rotate > 90) this.#head_rotate = 90; if (this.#head_rotate < -90) this.#head_rotate = -90; } get head_rotate() { this.#check_head_rotate(); return this.#head_rotate; } #radians(change = 0) { return (this.rotate + change) * Math.PI / 180; } move_front(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Steps must be number."); } this.y -= Math.cos(this.#radians()) * target; this.x -= Math.sin(this.#radians()) * target; } move_back(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Steps must be number."); } this.move_front(-target); } move_left(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Steps must be number."); } this.y += Math.cos(this.#radians(-90)) * target; this.x += Math.sin(this.#radians(-90)) * target; } move_right(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Steps must be number."); } this.move_left(-target); } rotate_clockwise(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Degrees must be number."); } this.#rotate -= target; } rotate_counterclockwise(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Degrees must be number."); } this.#rotate += target; } rotate_top(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Degrees must be number."); } this.#head_rotate += target; } rotate_bottom(target = 1) { if (typeof(target) !== "number") { throw new TypeError("Degrees must be number."); } this.#head_rotate -= target; } get as_string() { let dump = ""; dump += "X: " + this.x + "\n"; dump += "Y: " + this.y + "\n"; dump += "Z: " + this.z + "\n"; dump += "ROTATE: " + this.rotate; dump += "HEAD ROTATE: " + this.head_rotate; return dump; } } export { coordinates };