Fixed semicolon issues
[interactive-pacbot.git] / game / plugins / orientation.js
1 'use strict';
2
3 var Orientation = function() {
4         this.onLeft = new Phaser.Signal();
5         this.onRight = new Phaser.Signal();
6         this.onUp = new Phaser.Signal();
7         this.onDown = new Phaser.Signal();
8
9         var previousEvent = {
10                 gamma: 0,
11                 beta: 0
12         };
13
14         var threshhold = 15;
15
16         if (window.DeviceOrientationEvent) {
17                 window.addEventListener('deviceorientation', function(event) {
18                         if (event.gamma < -threshhold && previousEvent.gamma >= -threshhold) {
19                                 this.onLeft.dispatch();
20                         }
21                         if (event.gamma > threshhold && previousEvent.gamma <= threshhold) {
22                                 this.onRight.dispatch();
23                         }
24                         if (event.beta < -threshhold && previousEvent.beta >= -threshhold) {
25                                 this.onUp.dispatch();
26                         }
27                         if (event.beta > threshhold && previousEvent.beta <= threshhold) {
28                                 this.onDown.dispatch();
29                         }
30
31                         previousEvent.gamma = event.gamma;
32                         previousEvent.beta = event.beta;
33                 });
34         }
35 };
36
37
38 module.exports = Orientation;