Sfoglia il codice sorgente

Add check for reaching initial state

ApisNecros 4 mesi fa
parent
commit
98e4a2fe47
1 ha cambiato i file con 17 aggiunte e 0 eliminazioni
  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
+        );
+    }
 };