-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.js
61 lines (43 loc) · 1.25 KB
/
Setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// globals
var canvas;
var ctx;
var alpha=0;
var beta=0;
var gamma=0;
var motionDevice = false;
var collisionCounter = document.querySelector('.collisions .count');
var gammaCounter = document.querySelector('.motion .gamma');
var betaCounter = document.querySelector('.motion .beta');
// for game controls
var keysDown = {};
// game objects
var player;
var goals = [];
var enemies = [];
var items = [];
var decorations = [];
var allObjects = [];
var possibleCollisions = [];
// for game levels
var level = "demo";
var levelLogicBefore = function() {}; // a function to execute before each level
var levelLogicLoop = function() {}; // a function to execute every time the loop is called
// basic canvas setup
canvas = document.getElementById('main-canvas');
ctx = canvas.getContext('2d');
ctx.clearRect(0,0, canvas.width, canvas.height);
// check if device has motion
if(window.DeviceMotionEvent){
console.log("Device motion events enabled");
window.ondeviceorientation = function(event) {
alpha = Math.round(event.alpha);
beta = Math.round(event.beta);
gamma = Math.round(event.gamma);
// visual output
gammaCounter.innerHTML = gamma+"";
betaCounter.innerHTML = beta+"";
};
motionDevice = true;
} else {
console.log("No device motion events");
}