| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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 };
|