-
Notifications
You must be signed in to change notification settings - Fork 7
/
common.js
62 lines (54 loc) · 1.26 KB
/
common.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
59
60
61
62
'use strict';
var tileSize = 32;
var colorVariant = {
RED: 'red',
BLUE: 'blue',
GREEN: 'green'
};
var DIRECTION = {
DOWN: 'down',
UP: 'up',
LEFT: 'left',
RIGHT: 'right'
};
var uiFonts = {
TITLE: 'engeexpa',
HUD: 'zerothre',
RECORD: 'record',
INSTRUCTIONS: 'instructions'
};
function findCapsule(x, y) {
return _find(x, y, groups.capsules);
}
function findVirus(x, y) {
return _find(x, y, groups.viruses);
}
function findChanger(x, y) {
return _find(x, y, groups.changers);
}
function _find(x, y, group) {
var rtn = null;
group.forEachAlive(function(v) {
if (v.x === x && v.y === y) rtn = v;
});
return rtn;
}
function humanizeTime(time) {
if (time === undefined || time === null) return "--";
time = time / 1000;
var min = Math.floor(time / 60).toString();
var sec = Math.ceil(time % 60).toString();
if (min.length === 1) min = "0" + min
if (sec.length === 1) sec = "0" + sec
return min + ':' + sec;
}
function deleteStats() {
var storage = new Storage();
storage.delete('level.current');
for (var i=1; i<=game.global.totalLevels; i++) {
var bestMovesKey = ['level', i, 'moves'].join('.');
var bestTimeKey = ['level', i, 'time'].join('.');
storage.delete(bestMovesKey);
storage.delete(bestTimeKey);
}
}