| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- class coordinates {
- #x;
- #y;
- #z;
- #rotate;
- constructor() {
- this.#x = 0;
- this.#y = 0;
- this.#z = 0;
- this.#rotate = 0;
- }
- get x() {
- return this.#x;
- }
- get y() {
- return this.#y;
- }
- get z() {
- return this.#z;
- }
- get 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 numer.");
- }
- this.#y = target;
- }
- set z(target) {
- if (typeof(target) !== "number") {
- throw new TypeError("Coordinate must be numer.");
- }
- this.#z = target;
- }
- set rotate(target) {
- if (typeof(target) !== "number") {
- throw new TypeError("Coordinate must be numer.");
- }
- this.#rotate = target % 360;
- }
- #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.sin(this.#radians()) * target;
- this.#x += Math.cos(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.sin(this.#radians(-90)) * target;
- this.#x += Math.cos(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 = 0) {
- if (typeof(target) !== "number") {
- throw new TypeError("Degrees must be number.");
- }
- this.#rotate -= target;
- }
- rotate_counterclockwise(target = 0) {
- if (typeof(target) !== "number") {
- throw new TypeError("Degrees must be number.");
- }
- this.#rotate += target;
- }
- }
- export { coordinates };
|