Преглед изворни кода

Add check for reaching initial state

ApisNecros пре 4 месеци
родитељ
комит
98e4a2fe47
1 измењених фајлова са 17 додато и 0 уклоњено
  1. 17 0
      12/Moon.js

+ 17 - 0
12/Moon.js

@@ -22,4 +22,21 @@ module.exports = class Moon {
          */
         this.velocity = new Vector3(0, 0, 0);
     }
+
+    /**
+     * Check whether or not the moon has returned to its initial position
+     *
+     * @returns {bool} True if the current position is the same as the initial position and if the velocity is zero
+     */
+    hasReachedInitialState() {
+        return (
+            this._initialPosition.x == this.position.x
+            && this._initialPosition.y == this.position.y
+            && this._initialPosition.z == this.position.z
+        ) && (
+            this.velocity.x == 0
+            && this.velocity.y == 0
+            && this.velocity.z == 0
+        );
+    }
 };