class coordinates { #x; #y; #z; #rotate; #head_rotate; constructor() { this.#x = 0; this.#y = 0; this.#z = 0; this.#rotate = 0; this.#head_rotate = 0; } get x() { return this.#x; } get y() { return this.#y; } get z() { return this.#z; } get rotate() { this.#check_rotate(); return this.#rotate; } set x(target) { if (typeof(target) !== "number") { throw new TypeError("Coordinate must be numer."); } this.#x = target; } set y(target) { if (typeof(target) !== "number") { throw new TypeError("Coordinate must be number."); } this.#y = target; } set z(target) { if (typeof(target) !== "number") { throw new TypeError("Coordinate must be number."); } this.#z = target; } 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 };