-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
75 lines (61 loc) · 1.8 KB
/
helper.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
63
64
65
66
67
68
69
70
71
72
73
74
75
var Helper = function() {
}
Helper.randomInt = function(min,max) {
var rand = min + Math.random() * (max - min)
rand = Math.round(rand);
return rand;
}
Helper.randowColor = function() {
switch(Helper.randomInt(1,10)) {
case 1: return 'red';
case 2: return 'green';
case 3: return 'brown';
case 4: return 'black';
case 5: return 'blue';
case 6: return 'orange';
case 7: return 'aqua';
case 8: return 'firebrick';
case 9: return 'coral';
case 10: return 'yellow';
}
}
Helper.KEY_CODE = {
UP: 38,
Left: 37,
};
Helper.MacroCollision = function(obj1,obj2){
var XColl=false;
var YColl=false;
if ((obj1.x + obj1.width >= obj2.x) && (obj1.x <= obj2.x + obj2.width)) XColl = true;
if ((obj1.y + obj1.height >= obj2.y) && (obj1.y <= obj2.y + obj2.height)) YColl = true;
if (XColl&YColl){return true;}
return false;
}
Helper.setCookie = function (name, value, options) {
options = options || {};
var expires = options.expires;
if (typeof expires == "number" && expires) {
var d = new Date();
d.setTime(d.getTime() + expires * 1000);
expires = options.expires = d;
}
if (expires && expires.toUTCString) {
options.expires = expires.toUTCString();
}
value = encodeURIComponent(value);
var updatedCookie = name + "=" + value;
for (var propName in options) {
updatedCookie += "; " + propName;
var propValue = options[propName];
if (propValue !== true) {
updatedCookie += "=" + propValue;
}
}
document.cookie = updatedCookie;
}
Helper.getCookie = function (name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}