Fixed semicolon issues
[interactive-pacbot.git] / game / plugins / orientation.js
index 77ad9fc..af5a649 100644 (file)
@@ -13,26 +13,26 @@ var Orientation = function() {
 
        var threshhold = 15;
 
-       var processOrientationEvent = function(event) {
-               if (event.gamma < -threshhold && previousEvent.gamma >= -threshhold) {
-                       this.onLeft.dispatch();
-               }
-               if (event.gamma > threshhold && previousEvent.gamma <= threshhold) {
-                       this.onRight.dispatch();
-               }
-               if (event.beta < -threshhold && previousEvent.beta >= -threshhold) {
-                       this.onUp.dispatch();
-               }
-               if (event.beta > threshhold && previousEvent.beta <= threshhold) {
-                       this.onDown.dispatch();
-               }
-
-
-               previousEvent = event;
+       if (window.DeviceOrientationEvent) {
+               window.addEventListener('deviceorientation', function(event) {
+                       if (event.gamma < -threshhold && previousEvent.gamma >= -threshhold) {
+                               this.onLeft.dispatch();
+                       }
+                       if (event.gamma > threshhold && previousEvent.gamma <= threshhold) {
+                               this.onRight.dispatch();
+                       }
+                       if (event.beta < -threshhold && previousEvent.beta >= -threshhold) {
+                               this.onUp.dispatch();
+                       }
+                       if (event.beta > threshhold && previousEvent.beta <= threshhold) {
+                               this.onDown.dispatch();
+                       }
+
+                       previousEvent.gamma = event.gamma;
+                       previousEvent.beta = event.beta;
+               });
        }
-
-       window.addEventListener('deviceorientation', processOrientationEvent);
-}
+};
 
 
 module.exports = Orientation;