sinzmise-cetastories 2.0.0-1731114112124 → 2.0.0-1731116663626

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. package/404/index.html +1 -4033
  2. package/about/index.html +1 -4041
  3. package/album/index.html +1 -4050
  4. package/archives/2021/12/index.html +1 -3917
  5. package/archives/2021/index.html +1 -3917
  6. package/archives/2022/12/index.html +1 -3917
  7. package/archives/2022/index.html +1 -3917
  8. package/archives/2023/01/index.html +1 -4072
  9. package/archives/2023/02/index.html +1 -3917
  10. package/archives/2023/03/index.html +1 -4063
  11. package/archives/2023/04/index.html +1 -3992
  12. package/archives/2023/07/index.html +1 -4217
  13. package/archives/2023/08/index.html +1 -4067
  14. package/archives/2023/09/index.html +1 -3917
  15. package/archives/2023/10/index.html +1 -3917
  16. package/archives/2023/11/index.html +1 -3917
  17. package/archives/2023/12/index.html +1 -3918
  18. package/archives/2023/index.html +1 -4591
  19. package/archives/2023/page/2/index.html +1 -4572
  20. package/archives/2023/page/3/index.html +1 -3930
  21. package/archives/2024/01/index.html +1 -4142
  22. package/archives/2024/02/index.html +1 -3922
  23. package/archives/2024/03/index.html +1 -3916
  24. package/archives/2024/04/index.html +1 -3997
  25. package/archives/2024/05/index.html +1 -4065
  26. package/archives/2024/06/index.html +1 -3917
  27. package/archives/2024/07/index.html +1 -3917
  28. package/archives/2024/08/index.html +1 -3992
  29. package/archives/2024/09/index.html +1 -3917
  30. package/archives/2024/10/index.html +1 -3984
  31. package/archives/2024/index.html +1 -4576
  32. package/archives/2024/page/2/index.html +1 -4433
  33. package/archives/index.html +1 -4560
  34. package/archives/page/2/index.html +1 -4560
  35. package/archives/page/3/index.html +1 -4560
  36. package/archives/page/4/index.html +1 -4560
  37. package/archives/page/5/index.html +1 -4560
  38. package/assets/algolia/algoliasearch.js +3 -7182
  39. package/assets/algolia/algoliasearchLite.js +3 -4445
  40. package/atom.xml +31 -31
  41. package/bbs/bbs.html +1 -4012
  42. package/bbs/bbs.js +2 -12
  43. package/bbs/index.html +1 -4031
  44. package/categories/index.html +1 -4050
  45. package/categories//344/270/252/344/272/272/345/260/217/350/256/260/index.html +1 -4570
  46. package/categories//344/270/252/344/272/272/345/260/217/350/256/260/page/2/index.html +1 -4485
  47. package/categories//346/255/214/346/233/262/346/224/266/351/233/206/index.html +1 -3920
  48. package/categories//346/270/270/346/210/217/347/233/270/345/205/263/index.html +1 -4148
  49. package/categories//347/253/231/347/202/271/346/212/230/350/205/276/index.html +1 -4610
  50. package/categories//347/253/231/347/202/271/346/212/230/350/205/276/page/2/index.html +1 -4148
  51. package/categories//351/241/271/347/233/256/346/212/230/350/205/276/index.html +1 -4072
  52. package/charts/index.html +1 -4039
  53. package/comments/index.html +1 -4052
  54. package/css/custom2.css +2 -3
  55. package/css/first.css +2 -1868
  56. package/css/pace/big-counter.css +2 -39
  57. package/css/pace/corner-indicator.css +2 -72
  58. package/css/pace/flash.css +2 -76
  59. package/css/pace/mac-osx.css +2 -86
  60. package/css/pace/pace.css +2 -50
  61. package/css/plane.css +2 -59
  62. package/css/style.css +2 -8585
  63. package/css/tags.css +2 -3516
  64. package/essay/index.html +1 -4050
  65. package/fcircle/index.html +1 -4075
  66. package/games +2 -2
  67. package/index.html +1 -4717
  68. package/js/app.js +2 -1341
  69. package/js/autoload.js +2 -62
  70. package/js/ceta/fancybox.css +2 -2
  71. package/js/ceta/fancybox.umd.js +2 -2
  72. package/js/ceta/iconfontInkss.js +2 -1
  73. package/js/ceta/message.css +2 -6
  74. package/js/ceta/message.js +2 -6
  75. package/js/clock.js +2 -1
  76. package/js/kslink.js +2 -38
  77. package/js/newyear.js +2 -76
  78. package/js/plane.js +2 -2200
  79. package/js/plugins/aplayer.js +2 -186
  80. package/js/plugins/parallax.js +2 -191
  81. package/js/plugins/rightMenus.js +2 -623
  82. package/js/plugins/tags/contributors.js +2 -92
  83. package/js/plugins/tags/friends.js +2 -93
  84. package/js/plugins/tags/sites.js +2 -96
  85. package/js/search/algolia.js +2 -239
  86. package/js/search/hexo.js +2 -195
  87. package/js/search/meilisearch.js +2 -220
  88. package/js/txmap.js +2 -248
  89. package/link/index.html +1 -6180
  90. package/load.html +1 -294
  91. package/maps/assets/algolia/algoliasearch.js.map +1 -0
  92. package/maps/assets/algolia/algoliasearchLite.js.map +1 -0
  93. package/maps/bbs/bbs.js.map +1 -0
  94. package/maps/css/custom2.css.map +1 -0
  95. package/maps/css/first.css.map +1 -0
  96. package/maps/css/pace/big-counter.css.map +1 -0
  97. package/maps/css/pace/corner-indicator.css.map +1 -0
  98. package/maps/css/pace/flash.css.map +1 -0
  99. package/maps/css/pace/mac-osx.css.map +1 -0
  100. package/maps/css/pace/pace.css.map +1 -0
  101. package/maps/css/plane.css.map +1 -0
  102. package/maps/css/style.css.map +1 -0
  103. package/maps/css/tags.css.map +1 -0
  104. package/maps/js/app.js.map +1 -0
  105. package/maps/js/autoload.js.map +1 -0
  106. package/maps/js/ceta/fancybox.css.map +1 -0
  107. package/maps/js/ceta/fancybox.umd.js.map +1 -0
  108. package/maps/js/ceta/iconfontInkss.js.map +1 -0
  109. package/maps/js/ceta/message.css.map +1 -0
  110. package/maps/js/ceta/message.js.map +1 -0
  111. package/maps/js/clock.js.map +1 -0
  112. package/maps/js/kslink.js.map +1 -0
  113. package/maps/js/newyear.js.map +1 -0
  114. package/maps/js/plane.js.map +1 -0
  115. package/maps/js/plugins/aplayer.js.map +1 -0
  116. package/maps/js/plugins/parallax.js.map +1 -0
  117. package/maps/js/plugins/rightMenus.js.map +1 -0
  118. package/maps/js/plugins/tags/contributors.js.map +1 -0
  119. package/maps/js/plugins/tags/friends.js.map +1 -0
  120. package/maps/js/plugins/tags/sites.js.map +1 -0
  121. package/maps/js/search/algolia.js.map +1 -0
  122. package/maps/js/search/hexo.js.map +1 -0
  123. package/maps/js/search/meilisearch.js.map +1 -0
  124. package/maps/js/txmap.js.map +1 -0
  125. package/maps/sw.js.map +1 -0
  126. package/maps/weichuncai/css/style.css.map +1 -0
  127. package/maps/weichuncai/js/common.js.map +1 -0
  128. package/maps/weichuncai/js/jquery.js.map +1 -0
  129. package/maps/weichuncai/wcc-config.js.map +1 -0
  130. package/music/index.html +1 -4033
  131. package/package.json +1 -1
  132. package/page/2/index.html +1 -4578
  133. package/page/3/index.html +1 -4575
  134. package/page/4/index.html +1 -4572
  135. package/page/5/index.html +1 -3924
  136. package/posts/10021/index.html +5 -4130
  137. package/posts/10045/index.html +1 -4224
  138. package/posts/10733/index.html +1 -4125
  139. package/posts/10996/index.html +5 -4127
  140. package/posts/12779/index.html +1 -4134
  141. package/posts/13624/index.html +1 -4179
  142. package/posts/15688/index.html +1 -4133
  143. package/posts/15748/index.html +5 -4121
  144. package/posts/15799/index.html +1 -4130
  145. package/posts/15842/index.html +5 -4121
  146. package/posts/16107/index.html +1 -4111
  147. package/posts/18063/index.html +1 -4124
  148. package/posts/20412/index.html +1 -4134
  149. package/posts/21375/index.html +1 -4124
  150. package/posts/22945/index.html +4 -4169
  151. package/posts/23021/index.html +1 -4104
  152. package/posts/27531/index.html +5 -4121
  153. package/posts/28536/index.html +1 -4116
  154. package/posts/28733/index.html +1 -4168
  155. package/posts/29196/index.html +1 -4106
  156. package/posts/38917/index.html +1 -4144
  157. package/posts/38964/index.html +1 -4208
  158. package/posts/42487/index.html +1 -4135
  159. package/posts/42580/index.html +1 -4128
  160. package/posts/45875/index.html +1 -4118
  161. package/posts/46640/index.html +1 -4147
  162. package/posts/48762/index.html +1 -4109
  163. package/posts/50710/index.html +1 -4114
  164. package/posts/52677/index.html +1 -4125
  165. package/posts/53662/index.html +1 -4123
  166. package/posts/54386/index.html +1 -4116
  167. package/posts/54481/index.html +1 -4133
  168. package/posts/54787/index.html +5 -4124
  169. package/posts/56467/index.html +1 -4121
  170. package/posts/57692/index.html +1 -4143
  171. package/posts/58203/index.html +1 -4116
  172. package/posts/61417/index.html +1 -4117
  173. package/posts/61712/index.html +1 -4113
  174. package/posts/646/index.html +1 -4106
  175. package/posts/64856/index.html +1 -4120
  176. package/posts/64935/index.html +1 -4120
  177. package/search.xml +70 -70
  178. package/seas/index.html +1 -4050
  179. package/sw.js +2 -798
  180. package/tags/Flash/347/233/270/345/205/263/index.html +1 -3924
  181. package/tags/Steam/346/270/270/346/210/217/index.html +1 -3924
  182. package/tags/Windows/350/275/257/344/273/266/index.html +1 -3997
  183. package/tags/index.html +1 -4033
  184. package/tags//344/270/252/344/272/272/345/260/217/350/256/260/index.html +1 -4570
  185. package/tags//344/270/252/344/272/272/345/260/217/350/256/260/page/2/index.html +1 -4485
  186. package/tags//345/205/266/345/256/203/346/270/270/346/210/217/index.html +1 -4073
  187. package/tags//345/212/240/350/275/275/345/212/250/347/224/273/index.html +1 -3924
  188. package/tags//346/202/254/346/265/256/345/256/240/347/211/251-/347/234/213/346/235/277/345/250/230/index.html +1 -3925
  189. package/tags//346/255/214/346/233/262/346/224/266/351/233/206/index.html +1 -3920
  190. package/tags//346/270/270/346/210/217/347/233/270/345/205/263/index.html +1 -4148
  191. package/tags//347/253/231/347/202/271/345/272/225/351/203/250/351/255/224/346/224/271/index.html +1 -3924
  192. package/tags//347/253/231/347/202/271/346/212/230/350/205/276/index.html +1 -4610
  193. package/tags//347/253/231/347/202/271/346/212/230/350/205/276/page/2/index.html +1 -4148
  194. package/tags//350/207/252/345/273/272/351/203/250/347/275/262/index.html +1 -4224
  195. package/tags//351/241/265/351/235/242/351/255/224/346/224/271/index.html +1 -4075
  196. package/tags//351/241/271/347/233/256/346/212/230/350/205/276/index.html +1 -4072
  197. package/update/index.html +1 -4112
  198. package/weichuncai/css/style.css +2 -25
  199. package/weichuncai/js/common.js +2 -449
  200. package/weichuncai/js/jquery.js +2 -139
  201. package/weichuncai/wcc-config.js +2 -17
package/js/plane.js CHANGED
@@ -1,2200 +1,2 @@
1
- /*
2
- Copyright (c) <2011, 2012> Rootof Creations HB, rootof.com, kickassapp.com
3
- */
4
- (function (window) {
5
- var JSONP = (function () {
6
- var counter = 0, head, query, key, window = this;
7
-
8
- function load(url) {
9
- var script = document.createElement('script'), done = false;
10
- script.src = url;
11
- script.async = true;
12
- script.onload = script.onreadystatechange = function () {
13
- if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
14
- done = true;
15
- script.onload = script.onreadystatechange = null;
16
- if (script && script.parentNode) {
17
- script.parentNode.removeChild(script);
18
- }
19
- }
20
- };
21
- if (!head) {
22
- head = document.getElementsByTagName('head')[0];
23
- if (!head)
24
- head = document.body;
25
- }
26
- head.appendChild(script);
27
- }
28
-
29
- function jsonp(url, params, callback) {
30
- query = "?";
31
- params = params || {};
32
- for (key in params) {
33
- if (params.hasOwnProperty(key)) {
34
- query += encodeURIComponent(key) + "=" + encodeURIComponent(params[key]) + "&";
35
- }
36
- }
37
- var jsonp = "json" + (++counter);
38
- window[jsonp] = function (data) {
39
- callback(data);
40
- try {
41
- delete window[jsonp];
42
- } catch (e) {
43
- }
44
- window[jsonp] = null;
45
- };
46
- load(url + query + "callback=" + jsonp);
47
- return jsonp;
48
- }
49
-
50
- return {get: jsonp};
51
- }());
52
- var CORS = {
53
- request: function (url, params, callback) {
54
- if (this.calledByExtension()) {
55
- this._callbacks[this._callbackId++] = callback;
56
- window.postMessage(JSON.stringify({
57
- from: "kickassapp-page",
58
- url: url,
59
- type: "callApi",
60
- params: params
61
- }), "*");
62
- return;
63
- }
64
- params = params || {};
65
- var query = "?";
66
- for (key in params) {
67
- if (params.hasOwnProperty(key)) {
68
- query += encodeURIComponent(key) + "=" + encodeURIComponent(params[key]) + "&";
69
- }
70
- }
71
- var xhr = new XMLHttpRequest();
72
- xhr.onreadystatechange = function () {
73
- if (xhr.readyState == 4) {
74
- callback(JSON.parse(xhr.responseText));
75
- }
76
- }
77
- xhr.open("GET", url + query);
78
- xhr.withCredentials = true;
79
- xhr.setRequestHeader("Content-Type", "application/json");
80
- xhr.send();
81
- }, calledByExtension: function () {
82
- return !!document.getElementById("kickass-has-been-initialized-yes-yes-yes");
83
- }, _callbacks: {}, _callbackId: 0
84
- }
85
- if (CORS.calledByExtension()) {
86
- window.addEventListener("message", function (e) {
87
- var messageData;
88
- try {
89
- messageData = JSON.parse(e.data);
90
- } catch (e) {
91
- return;
92
- }
93
- if (messageData.from === "kickassapp-extension" && messageData.sanityCheck === "kickassapp-extension-version1") {
94
- var message = messageData.payload;
95
- if (message.type === "response") {
96
- CORS._callbacks[message.requestId](message.body);
97
- delete CORS._callbacks[message.requestId];
98
- } else if (message.type === "destroy") {
99
- window.KICKASSGAME.destroy();
100
- }
101
- }
102
- }, false);
103
- }
104
-
105
- function getGlobalNamespace() {
106
- return window && window.INSTALL_SCOPE ? window.INSTALL_SCOPE : window;
107
- }
108
-
109
- var Class = function (methods) {
110
- var ret = function () {
111
- if (ret.$prototyping) return this;
112
- if (typeof this.initialize == 'function')
113
- return this.initialize.apply(this, arguments);
114
- };
115
- if (methods.Extends) {
116
- ret.parent = methods.Extends;
117
- methods.Extends.$prototyping = true;
118
- ret.prototype = new methods.Extends;
119
- methods.Extends.$prototyping = false;
120
- }
121
- for (var key in methods) if (methods.hasOwnProperty(key))
122
- ret.prototype[key] = methods[key];
123
- return ret;
124
- };
125
- if (typeof exports != 'undefined') exports.Class = Class;
126
- var Vector = new Class({
127
- initialize: function (x, y) {
128
- if (typeof x == 'object') {
129
- this.x = x.x;
130
- this.y = x.y;
131
- } else {
132
- this.x = x;
133
- this.y = y;
134
- }
135
- }, cp: function () {
136
- return new Vector(this.x, this.y);
137
- }, mul: function (factor) {
138
- this.x *= factor;
139
- this.y *= factor;
140
- return this;
141
- }, mulNew: function (factor) {
142
- return new Vector(this.x * factor, this.y * factor);
143
- }, div: function (factor) {
144
- this.x /= factor;
145
- this.y /= factor;
146
- return this;
147
- }, divNew: function (factor) {
148
- return new Vector(this.x / factor, this.y / factor);
149
- }, add: function (vec) {
150
- this.x += vec.x;
151
- this.y += vec.y;
152
- return this;
153
- }, addNew: function (vec) {
154
- return new Vector(this.x + vec.x, this.y + vec.y);
155
- }, sub: function (vec) {
156
- this.x -= vec.x;
157
- this.y -= vec.y;
158
- return this;
159
- }, subNew: function (vec) {
160
- return new Vector(this.x - vec.x, this.y - vec.y);
161
- }, rotate: function (angle) {
162
- var x = this.x, y = this.y;
163
- this.x = x * Math.cos(angle) - Math.sin(angle) * y;
164
- this.y = x * Math.sin(angle) + Math.cos(angle) * y;
165
- return this;
166
- }, rotateNew: function (angle) {
167
- return this.cp().rotate(angle);
168
- }, setAngle: function (angle) {
169
- var l = this.len();
170
- this.x = Math.cos(angle) * l;
171
- this.y = Math.sin(angle) * l;
172
- return this;
173
- }, setAngleNew: function (angle) {
174
- return this.cp().setAngle(angle);
175
- }, setLength: function (length) {
176
- var l = this.len();
177
- if (l) this.mul(length / l); else this.x = this.y = length;
178
- return this;
179
- }, setLengthNew: function (length) {
180
- return this.cp().setLength(length);
181
- }, normalize: function () {
182
- var l = this.len();
183
- if (l == 0)
184
- return this;
185
- this.x /= l;
186
- this.y /= l;
187
- return this;
188
- }, normalizeNew: function () {
189
- return this.cp().normalize();
190
- }, angle: function () {
191
- return Math.atan2(this.y, this.x);
192
- }, collidesWith: function (rect) {
193
- return this.x > rect.x && this.y > rect.y && this.x < rect.x + rect.width && this.y < rect.y + rect.height;
194
- }, len: function () {
195
- var l = Math.sqrt(this.x * this.x + this.y * this.y);
196
- if (l < 0.005 && l > -0.005) return 0;
197
- return l;
198
- }, is: function (test) {
199
- return typeof test == 'object' && this.x == test.x && this.y == test.y;
200
- }, dot: function (v2) {
201
- return this.x * v2.x + this.y * v2.y;
202
- }, inTriangle: function (a, b, c) {
203
- var v0 = c.subNew(a);
204
- var v1 = b.subNew(a);
205
- var v2 = p.subNew(a);
206
- var dot00 = v0.dot(v0);
207
- var dot01 = v0.dot(v1);
208
- var dot02 = v0.dot(v2);
209
- var dot11 = v1.dot(v1);
210
- var dot12 = v1.dot(v2);
211
- var invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
212
- var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
213
- var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
214
- return (u > 0) && (v > 0) && (u + v < 1);
215
- }, distanceFrom: function (vec) {
216
- return Math.sqrt(Math.pow((this.x - vec.x), 2), Math.pow(this.y - vec.y, 2));
217
- }, toString: function () {
218
- return '[Vector(' + this.x + ', ' + this.y + ') angle: ' + this.angle() + ', length: ' + this.len() + ']';
219
- }
220
- });
221
- if (typeof exports != 'undefined') exports.Vector = Vector;
222
- var Rect = new Class({
223
- initialize: function (x, y, w, h) {
224
- this.pos = new Vector(x, y);
225
- this.size = {width: w, height: h};
226
- }, hasPoint: function (point) {
227
- return point.x > this.getLeft() && point.x < this.getRight() && point.y > this.getTop() && point.y < this.getBottom();
228
- }, setLeft: function (left) {
229
- this.pos.x = left + this.size.width / 2;
230
- }, setTop: function (top) {
231
- this.pos.y = top + this.size.height / 2;
232
- }, getLeft: function () {
233
- return this.pos.x - this.size.width / 2;
234
- }, getTop: function () {
235
- return this.pos.y - this.size.height / 2;
236
- }, getRight: function () {
237
- return this.pos.x + this.size.width / 2;
238
- }, getBottom: function () {
239
- return this.pos.y + this.size.height / 2;
240
- }, cp: function () {
241
- return new Rect(this.pos.x, this.pos.y, this.size.width, this.size.height);
242
- }
243
- });
244
- if (typeof exports != 'undefined') exports.Rect = Rect;
245
- var Fx = new Class({
246
- initialize: function () {
247
- this.listeners = [];
248
- this.tweens = {};
249
- this.running = {};
250
- }, addListener: function (listener) {
251
- this.listeners.push(listener);
252
- }, add: function (key, props) {
253
- props = props || {};
254
- props.duration = props.duration || 500;
255
- props.transition = props.transition || Tween.Linear;
256
- props.repeats = typeof props.repeats == 'undefined' ? false : props.repeats;
257
- if (!props.tweens) {
258
- var start = props.start || 0;
259
- var end = typeof props.end == 'undefined' ? 1 : props.end;
260
- props.tweens = [[start, end]];
261
- }
262
- this.tweens[key] = props;
263
- }, update: function (time) {
264
- time = typeof time === 'number' ? time : now();
265
- for (var key in this.tweens) if (this.tweens.hasOwnProperty(key)) {
266
- if (!this.running[key]) {
267
- this.tweenStart(key, time);
268
- continue;
269
- }
270
- var tween = this.tweens[key];
271
- var tdelta = time - this.running[key].startTime;
272
- if (tdelta > tween.duration) {
273
- this.tweenFinished(tween, key);
274
- continue;
275
- }
276
- var delta = tween.transition(tdelta / tween.duration);
277
- var changes = [];
278
- for (var i = 0, t; t = tween.tweens[i]; i++) {
279
- var x = delta * (t[1] - t[0]) + t[0];
280
- changes.push(x);
281
- }
282
- this.fire(key, changes, delta);
283
- }
284
- }, tweenStart: function (key, time) {
285
- this.running[key] = {startTime: time};
286
- var values = [];
287
- for (var i = 0, tween; tween = this.tweens[key].tweens[i]; i++)
288
- values.push(tween[0]);
289
- this.fire(key, values, 0);
290
- }, tweenFinished: function (tween, key) {
291
- var values = [];
292
- for (var i = 0, t; t = tween.tweens[i]; i++)
293
- values.push(t[1]);
294
- this.fire(key, values, 1);
295
- if (!tween.repeats) {
296
- delete this.running[key];
297
- delete this.tweens[key];
298
- return;
299
- }
300
- this.tweenStart(key, now());
301
- }, fire: function (key, values, delta) {
302
- for (var i = 0, listener; listener = this.listeners[i]; i++)
303
- listener.set.call(listener, key, values, delta);
304
- }
305
- });
306
- var Tween = {
307
- Linear: function (x) {
308
- return x;
309
- }, Quadratic: function (x) {
310
- return x * x;
311
- }, Quintic: function (x) {
312
- return x * x * x;
313
- }, Shake: function (x) {
314
- return Math.sin(x);
315
- }
316
- };
317
- var GameGlobals = {
318
- FPS: 60, useAnimationFrame: true, boids: {flockRadius: 400, size: 100}, path: function () {
319
- return "https://kickassapp.com/" + Array.prototype.slice.call(arguments).join("");
320
- }, hasCanvas: (typeof document.createElement('canvas').getContext !== 'undefined'), bulletColor: 'black'
321
- };
322
- window.GameGlobals = GameGlobals;
323
- if (!Array.prototype.indexOf) {
324
- Array.prototype.indexOf = function (searchElement) {
325
- if (this === void 0 || this === null)
326
- throw new TypeError();
327
- var t = Object(this);
328
- var len = t.length >>> 0;
329
- if (len === 0)
330
- return -1;
331
- var n = 0;
332
- if (arguments.length > 0) {
333
- n = Number(arguments[1]);
334
- if (n !== n)
335
- n = 0; else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
336
- n = (n > 0 || -1) * Math.floor(Math.abs(n));
337
- }
338
- if (n >= len)
339
- return -1;
340
- var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
341
- for (; k < len; k++) {
342
- if (k in t && t[k] === searchElement)
343
- return k;
344
- }
345
- return -1;
346
- };
347
- }
348
-
349
- function now() {
350
- return (new Date()).getTime();
351
- }
352
-
353
- function bind(bound, func) {
354
- return function () {
355
- return func.apply(bound, arguments);
356
- };
357
- }
358
-
359
- function each(arr, func, bindObject) {
360
- if (typeof arr.forEach == 'function') {
361
- arr.forEach(func, bindObject);
362
- return arr;
363
- }
364
- for (var key in arr) if (arr.hasOwnProperty(key))
365
- func.call(bindObject || window, arr[key], key);
366
- return arr;
367
- }
368
-
369
- function addEvent(obj, type, fn) {
370
- if (obj.addEventListener)
371
- obj.addEventListener(type, fn, false); else if (obj.attachEvent) {
372
- obj["e" + type + fn] = fn;
373
- obj[type + fn] = function () {
374
- return obj["e" + type + fn](window.event);
375
- };
376
- obj.attachEvent("on" + type, obj[type + fn]);
377
- }
378
- }
379
-
380
- function removeEvent(obj, type, fn) {
381
- if (obj.removeEventListener)
382
- obj.removeEventListener(type, fn, false); else if (obj.detachEvent) {
383
- obj.detachEvent("on" + type, obj[type + fn]);
384
- obj[type + fn] = null;
385
- obj["e" + type + fn] = null;
386
- }
387
- }
388
-
389
- function stopEvent(e) {
390
- if (e.stopPropogation)
391
- e.stopPropogation();
392
- if (e.preventDefault)
393
- e.preventDefault();
394
- e.returnValue = false;
395
- }
396
-
397
- function elementIsContainedIn(element1, element2) {
398
- if (element.contains)
399
- return element1.contains(element2);
400
- return !!(element1.compareDocumentPosition(element2) & 16);
401
- };
402
-
403
- function code(name) {
404
- var table = {38: 'up', 40: 'down', 37: 'left', 39: 'right', 27: 'esc'};
405
- if (table[name]) return table[name];
406
- return String.fromCharCode(name);
407
- };
408
-
409
- function random(min, max) {
410
- return Math.floor(Math.random() * (max - min + 1) + min);
411
- };
412
-
413
- function getRect(element) {
414
- if (typeof element.getBoundingClientRect === 'function') {
415
- var rect = element.getBoundingClientRect();
416
- var sx = window.pageXOffset;
417
- var sy = window.pageYOffset;
418
- return {width: rect.width, height: rect.height, left: rect.left + sx, top: rect.top + sy};
419
- }
420
- var rect = {width: element.offsetWidth, height: element.offsetHeight, left: 0, top: 0};
421
- var el = element;
422
- while (el) {
423
- rect.left += el.offsetLeft;
424
- rect.top += el.offsetTop;
425
- el = el.offsetParent;
426
- }
427
- return rect;
428
- }
429
-
430
- function getCompatElement() {
431
- var doc = document;
432
- return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.documentElement : doc.body;
433
- }
434
-
435
- function getScrollSize() {
436
- var doc = getCompatElement();
437
- var min = {x: doc.clientWidth, y: doc.clientHeight};
438
- var body = document.body;
439
- return {
440
- x: Math.max(doc.scrollWidth, body.scrollWidth, min.x),
441
- y: Math.max(doc.scrollHeight, body.scrollHeight, min.y)
442
- };
443
- }
444
-
445
- function getStyle(element, prop) {
446
- if (element.style[prop])
447
- return element.style[prop];
448
- if (element.currentStyle)
449
- return element.currentStyle[prop];
450
- return document.defaultView.getComputedStyle(element, null).getPropertyValue(prop);
451
- }
452
-
453
- function setStyles(element, props) {
454
- for (var key in props) if (props.hasOwnProperty(key)) {
455
- var val = props[key];
456
- if (typeof val === "number" && key !== "opacity" && key !== "zIndex")
457
- val = val + 'px';
458
- element.style[key] = val;
459
- }
460
- };
461
-
462
- function hasClass(ele, cls) {
463
- return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
464
- }
465
-
466
- function addClass(ele, cls) {
467
- if (!hasClass(ele, cls)) ele.className += " " + cls;
468
- }
469
-
470
- function removeClass(ele, cls) {
471
- if (hasClass(ele, cls)) {
472
- var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
473
- ele.className = ele.className.replace(reg, ' ');
474
- }
475
- }
476
-
477
- function cloneElement(element) {
478
- return element.cloneNode(true);
479
- }
480
-
481
- function newElement(tag, props) {
482
- var el = document.createElement(tag);
483
- for (var key in props) if (props.hasOwnProperty(key)) {
484
- if (key === 'styles') {
485
- setStyles(el, props[key]);
486
- } else {
487
- el[key] = props[key];
488
- }
489
- }
490
- return el;
491
- }
492
-
493
- var requestAnimFrame = (function () {
494
- return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) {
495
- window.setTimeout(callback, 1000 / 60);
496
- };
497
- })();
498
-
499
- function delay(d, func, bound) {
500
- return setTimeout(bind(bound, func), d);
501
- }
502
-
503
- var KickAss = new Class({
504
- initialize: function (options) {
505
- if (options && options.mySite) {
506
- this.mySite = options.mySite;
507
- }
508
- this.players = [];
509
- this.elements = [];
510
- this.weaponClass = Weapons[1].cannonClass;
511
- this.scrollPos = new Vector(0, 0);
512
- this.scrollSize = new Vector(0, 0);
513
- this.windowSize = {width: 0, height: 0};
514
- this.updateWindowInfo();
515
- this.bulletManager = new BulletManager(this);
516
- this.bulletManager.updateEnemyIndex();
517
- this.explosionManager = new ExplosionManager(this);
518
- this.ui = new UIManager(this);
519
- this.bombManager = new BombManager(this);
520
- this.menuManager = new MenuManager(this);
521
- this.menuManager.create();
522
- if (typeof StatisticsManager !== "undefined") {
523
- this.statisticsManager = new StatisticsManager(this);
524
- }
525
- this.sessionManager = new SessionManager(this);
526
- this.lastUpdate = now();
527
- this.keyMap = {};
528
- this.keydownEvent = bind(this, this.keydown);
529
- this.keyupEvent = bind(this, this.keyup);
530
- this.multiplier = 10;
531
- if (this.isCampaign()) {
532
- this.audioManager = {
533
- explosion: new AudioManager(GameGlobals.path("static/sounds/game/explosion"), ["mp3", "ogg"]),
534
- shot: new AudioManager(GameGlobals.path("static/sounds/game/shot"), ["mp3", "ogg"])
535
- }
536
- } else {
537
- this.audioManager = {};
538
- }
539
- if (window.KickAssStyle && window.KickAssStyle === "white") {
540
- GameGlobals.bulletColor = "white";
541
- }
542
- addEvent(document, 'keydown', this.keydownEvent);
543
- addEvent(document, 'keyup', this.keyupEvent);
544
- addEvent(document, 'keypress', this.keydownEvent);
545
- }, begin: function () {
546
- this.addPlayer();
547
- this.sessionManager.isPlaying = true;
548
- if (!GameGlobals.useAnimationFrame) {
549
- this.loopTimer = window.setInterval(bind(this, this.loop), 1000 / GameGlobals.FPS);
550
- }
551
- if (GameGlobals.useAnimationFrame) {
552
- requestAnimFrame(bind(this, this.loop));
553
- }
554
- }, keydown: function (e) {
555
- var c = code(e.keyCode);
556
- this.keyMap[c] = true;
557
- switch (c) {
558
- case'left':
559
- case'right':
560
- case'up':
561
- case'down':
562
- case'esc':
563
- case' ':
564
- stopEvent(e);
565
- break;
566
- }
567
- switch (c) {
568
- case'esc':
569
- this.destroy();
570
- break;
571
- }
572
- }, keyup: function (e) {
573
- var c = code(e.keyCode);
574
- this.keyMap[c] = false;
575
- switch (c) {
576
- case'left':
577
- case'right':
578
- case'up':
579
- case'down':
580
- case'esc':
581
- case' ':
582
- if (e.stopPropogation) {
583
- e.stopPropogation();
584
- }
585
- if (e.preventDefault) {
586
- e.preventDefault();
587
- }
588
- e.returnValue = false;
589
- break;
590
- }
591
- }, loop: function () {
592
- var currentTime = now();
593
- var tdelta = (currentTime - this.lastUpdate) / 1000;
594
- this.updateWindowInfo();
595
- for (var i = 0, player; player = this.players[i]; i++) {
596
- player.update(tdelta);
597
- }
598
- this.bulletManager.update(tdelta);
599
- this.bombManager.update(tdelta);
600
- this.explosionManager.update(tdelta);
601
- this.ui.update(tdelta);
602
- if (this.statisticsManager) {
603
- this.statisticsManager.update(tdelta);
604
- }
605
- this.sessionManager.update(tdelta);
606
- this.lastUpdate = currentTime;
607
- if (GameGlobals.useAnimationFrame) {
608
- requestAnimFrame(bind(this, this.loop));
609
- }
610
- }, addPlayer: function () {
611
- var data = false;
612
- var ship = Ships.Standard;
613
- if (window.KICKASSSHIP && window.KICKASSSHIP.points) {
614
- ship = KICKASSSHIP;
615
- }
616
- if (this.mySite && this.mySite.getShipConfig()) {
617
- ship = this.mySite.getShipConfig();
618
- }
619
- var player = new Player(this);
620
- player.setShip(ship);
621
- this.players.push(player);
622
- this.explosionManager.addExplosion(player.pos);
623
- }, registerElement: function (el) {
624
- if (!el) {
625
- throw new Error("Can't register unexisting element.");
626
- }
627
- this.elements.push(el);
628
- }, unregisterElement: function (el) {
629
- this.elements.splice(this.elements.indexOf(el), 1);
630
- }, isKickAssElement: function (el) {
631
- for (var i = 0, element; element = this.elements[i]; i++) {
632
- if (el === element || elementIsContainedIn(element, el)) {
633
- return true;
634
- }
635
- }
636
- return false;
637
- }, isKeyPressed: function (key) {
638
- return !!this.keyMap[key];
639
- }, updateWindowInfo: function () {
640
- var isIEQuirks = (!!window.ActiveXObject) && document.compatMode == "BackCompat";
641
- this.windowSize = {
642
- width: document.documentElement.clientWidth,
643
- height: document.documentElement.clientHeight
644
- };
645
- if (isIEQuirks) {
646
- this.windowSize.width = document.body.clientWidth;
647
- this.windowSize.height = document.body.clientHeight;
648
- }
649
- if (this.menuManager && this.menuManager.isVisible()) {
650
- this.windowSize.height -= this.menuManager.getHeight();
651
- }
652
- this.scrollPos.x = window.pageXOffset || document.documentElement.scrollLeft;
653
- this.scrollPos.y = window.pageYOffset || document.documentElement.scrollTop;
654
- this.scrollSize = getScrollSize();
655
- }, hideAll: function () {
656
- for (var i = 0, el; el = this.elements[i]; i++) {
657
- el.style.visibility = 'hidden';
658
- }
659
- }, showAll: function () {
660
- for (var i = 0, el; el = this.elements[i]; i++) {
661
- el.style.visibility = 'visible';
662
- }
663
- }, updateShips: function (ship, isInitial) {
664
- if (!isInitial) {
665
- this.ui.showMessage("You're now flying<br /><em>" + ship.name + "<em>!!");
666
- }
667
- for (var i = 0, player; player = this.players[i]; i++) {
668
- player.setShip(ship);
669
- }
670
- }, changeWeapon: function (weapon, isInitial) {
671
- this.weaponClass = weapon.cannonClass;
672
- if (!isInitial) {
673
- this.ui.showMessage("Changed to " + weapon.name.toUpperCase() + "!!!!");
674
- }
675
- for (var i = 0, player; player = this.players[i]; i++) {
676
- player.setCannons(weapon.cannonClass);
677
- }
678
- }, changeWeaponById: function (id, isInitial) {
679
- if (Weapons[id]) {
680
- this.changeWeapon(Weapons[id], isInitial);
681
- }
682
- }, flyOutPlayers: function (x, y) {
683
- for (var i = 0, player; player = this.players[i]; i++) {
684
- player.flyTo(x, -player.size.height);
685
- player.isBound = false;
686
- }
687
- }, flyInPlayers: function () {
688
- for (var i = 0, player; player = this.players[i]; i++) {
689
- player.flyTo(player.pos.x, 100, function () {
690
- this.isBound = true;
691
- });
692
- }
693
- }, newRank: function (rank) {
694
- this.ui.showMessage("OMG. You leveled up to: <strong>" + rank + '</strong>!<br /><small>Be sure to check what cool new stuff you get in the menu.</small>');
695
- }, fireBomb: function () {
696
- this.bombManager.blow();
697
- }, destroy: function () {
698
- removeEvent(document, 'keydown', this.keydownEvent);
699
- removeEvent(document, 'keypress', this.keydownEvent);
700
- removeEvent(document, 'keyup', this.keyupEvent);
701
- for (var i = 0, player; player = this.players[i]; i++) {
702
- player.destroy();
703
- }
704
- this.bulletManager.destroy();
705
- this.explosionManager.destroy();
706
- this.menuManager.destroy();
707
- if (!GameGlobals.useAnimationFrame) {
708
- clearInterval(this.loopTimer);
709
- }
710
- getGlobalNamespace().KICKASSGAME = false;
711
- if (this.isCampaign()) {
712
- document.location.reload();
713
- }
714
- }, isCampaign: function () {
715
- return getGlobalNamespace().IS_CLOUDFLARE_GAME;
716
- }, isMySite: function () {
717
- return !!getGlobalNamespace().KICKASS_SITE_KEY;
718
- }, shouldShowAd: function () {
719
- return !this.mySite && !this.isCampaign();
720
- }, shouldShowMenu: function () {
721
- return !this.mySite && !this.isCampaign();
722
- }, shouldShowHowToImage: function () {
723
- return this.mySite || this.isCampaign();
724
- }
725
- });
726
- window.KickAss = KickAss;
727
- var StatisticsManager = new Class({
728
- initialize: function (game) {
729
- this.game = game;
730
- this.data = {};
731
- this.data.startedPlaying = now();
732
- this.data.elementsDestroyed = 0;
733
- this.data.shotsFired = 0;
734
- this.data.distanceFlownInPixels = 0;
735
- this.data.totalPointsThisSession = 0;
736
- this.data.usedThrusters = 0;
737
- this.lastUpdate = 0;
738
- }, usedThrusters: function () {
739
- this.data.usedThrusters = 1;
740
- }, increaseDistanceWithPixels: function (px) {
741
- this.data.distanceFlownInPixels += px;
742
- }, increasePointsGainedWithPoints: function (points) {
743
- this.data.totalPointsThisSession += points;
744
- }, addShotFired: function () {
745
- this.data.shotsFired++;
746
- if (this.game.audioManager.shot) {
747
- this.game.audioManager.shot.play();
748
- }
749
- }, addElementsDestroyed: function () {
750
- this.data.elementsDestroyed++;
751
- }, update: function (tdelta) {
752
- this.lastUpdate += tdelta;
753
- if (this.lastUpdate > 0.25) {
754
- this.syncWithServer();
755
- this.lastUpdate = 0;
756
- }
757
- }, syncWithServer: function () {
758
- var fragment = [];
759
- for (var key in this.data) if (this.data.hasOwnProperty(key)) {
760
- fragment.push(key + ':' + this.data[key]);
761
- }
762
- this.game.menuManager.sendMessageToMenu("stats:!" + fragment.join('|'));
763
- }
764
- });
765
- var MySite = new Class({
766
- initialize: function (key) {
767
- this.key = key;
768
- }, load: function (callback) {
769
- CORS.request(GameGlobals.path('mysite/api.json'), {
770
- site_key: this.key,
771
- url: document.location.toString()
772
- }, bind(this, function (data) {
773
- if (data && data.embed) {
774
- this.mySiteData = data.embed;
775
- callback(true);
776
- } else {
777
- callback(false);
778
- }
779
- }));
780
- }, install: function () {
781
- }, getShipId: function () {
782
- return this.mySiteData && this.mySiteData.settings.ship;
783
- }, getShipConfig: function () {
784
- return this.mySiteData && this.mySiteData.settings.ship_config;
785
- }, getShareURL: function () {
786
- return this.mySiteData && this.mySiteData.settings.share_url;
787
- }
788
- });
789
- var Menu = new Class({
790
- initialize: function (game) {
791
- this.game = game;
792
- this.size = {height: 300};
793
- }, generate: function (parent) {
794
- this.container = document.createElement('div');
795
- this.container.className = 'KICKASSELEMENT';
796
- this.container.id = 'kickass-profile-menu';
797
- parent.appendChild(this.container);
798
- var shipId = getGlobalNamespace().KICKASSSHIPID || "";
799
- this.url = GameGlobals.path('intermediate_postmessage.html?url=' +
800
- encodeURIComponent(getGlobalNamespace().KICKASSURL || document.location.href) + "&origin=" + encodeURIComponent(document.location.href) + "&preship=" + (shipId) + "&is_campaign=" + (this.game.isCampaign() ? "true" : "") + "&is_mysite=" + (this.game.isMySite() ? "true" : ""));
801
- this.isSocketReady = false;
802
- this.socketIframe = document.createElement("iframe");
803
- this.socketIframe.frameborder = '0';
804
- this.socketIframe.className = 'KICKASSELEMENT';
805
- this.socketIframe.width = '100%';
806
- this.socketIframe.height = this.size.height + 'px';
807
- this.container.appendChild(this.socketIframe);
808
- this.menuOrigin = "https://kickassapp.com/".replace(/\/$/, "");
809
- this.socketIframe.src = this.url;
810
- this.onMessage = bind(this, function (event) {
811
- if (event.origin !== this.menuOrigin && event.origin !== this.menuOrigin.replace("http://", "https://")) {
812
- console.log("ignoring event from", event.origin);
813
- return;
814
- }
815
- var message = event.data;
816
- if (message === "ready") {
817
- this.onGameReady();
818
- return;
819
- }
820
- var t = message.split(':!');
821
- if (t.length !== 2) {
822
- return;
823
- }
824
- var type = t.shift().replace(/^./g, function (match) {
825
- return match.charAt(0).toUpperCase();
826
- });
827
- if (typeof this['messageType' + type] === "function") {
828
- this['messageType' + type](t.join(":!"));
829
- }
830
- });
831
- window.addEventListener("message", this.onMessage, false);
832
- this.game.registerElement(this.container);
833
- }, socketPostMessage: function (message) {
834
- this.socketIframe.contentWindow.postMessage(message, this.menuOrigin);
835
- }, onGameReady: function () {
836
- this.isSocketReady = true;
837
- this.game.registerElement(this.container.getElementsByTagName('iframe')[0]);
838
- this.socketPostMessage("url:!" + (getGlobalNamespace().KICKASSURL || document.location.href));
839
- if (this.game.statisticsManager) {
840
- this.game.statisticsManager.syncWithServer();
841
- }
842
- this.game.menuManager.onGameReady();
843
- }, sendMessage: function (message) {
844
- if (!this.isSocketReady) {
845
- return;
846
- }
847
- if (message != this.lastMessage) {
848
- try {
849
- this.socketPostMessage(message);
850
- } catch (e) {
851
- }
852
- this.lastMessage = message;
853
- }
854
- }, messageTypeChangeShip: function (pieces) {
855
- pieces = pieces.split(",");
856
- var shipId = pieces[0];
857
- var weaponId = pieces[1];
858
- var isInitial = pieces[2] === 'initial';
859
- if (this.shipId === shipId) {
860
- return;
861
- }
862
- if (isInitial && getGlobalNamespace().KICKASSSHIP) {
863
- return;
864
- }
865
- this.shipId = shipId;
866
- CORS.request(GameGlobals.path('designer/ship/' + shipId + '/construction.json'), {
867
- ship_id: shipId,
868
- is_initial: isInitial ? '1' : '0'
869
- }, bind(this, function (data) {
870
- this.game.updateShips(data.data, isInitial);
871
- try {
872
- window.focus();
873
- } catch (e) {
874
- }
875
- }));
876
- if (!isInitial) {
877
- this.parent.hideMenu();
878
- }
879
- }, messageTypeChangeWeapon: function (weaponId, isInitial) {
880
- this.game.changeWeaponById(weaponId, isInitial);
881
- }, messageTypeSetMultiplier: function (mod) {
882
- mod = parseInt(mod, 10);
883
- if (isNaN(mod) || !mod) {
884
- return;
885
- }
886
- this.game.multiplier = mod;
887
- }, messageTypeNewRank: function (rank) {
888
- this.game.newRank(rank);
889
- }, messageTypePlayerMessage: function (message) {
890
- this.game.ui.showMessage(message);
891
- }, destroy: function () {
892
- this.game.unregisterElement(this.container);
893
- this.game.unregisterElement(this.iframe);
894
- window.removeEventListener("message", this.onMessage, false);
895
- this.container.parentNode.removeChild(this.container);
896
- }
897
- });
898
- var MenuManager = new Class({
899
- initialize: function (game) {
900
- this.game = game;
901
- this.numPoints = 0;
902
- if (!getGlobalNamespace().KICKASS_INLINE_CSS) {
903
- this.includeCSS(GameGlobals.path('css/menustyles.css'));
904
- }
905
- }, generateDefaults: function () {
906
- for (var id in Weapons) if (Weapons.hasOwnProperty(id)) {
907
- this.addWeapon(Weapons[id], id);
908
- }
909
- this.hideBombMenu();
910
- }, create: function () {
911
- this.container = document.createElement('div');
912
- this.container.className = 'KICKASSELEMENT KICKASShidden ' + (this.game.shouldShowMenu() ? "" : "KICKASSNOMENU");
913
- this.container.id = 'kickass-menu';
914
- if (this.game.shouldShowMenu()) {
915
- this.container.style.bottom = '-250px';
916
- this.container.style.display = 'none';
917
- } else {
918
- removeClass(this.container, "KICKASShidden");
919
- }
920
- getAppContainerElement().appendChild(this.container);
921
- var adHTML = "";
922
- this.container.innerHTML = '<div id="kickass-howto-image" class="KICKASSELEMENT kickass-howto-invisible"></div>' + '<div id="kickass-pointstab" style="width: 200px;" class="KICKASSELEMENT">' +
923
- adHTML + '<div id="kickass-bomb-menu" class="KICKASSELEMENT KICKASShidden">' + '<ul id="kickass-bomb-list" class="KICKASSELEMENT">' + '</ul>' + '</div>' + '<div id="kickass-weapons-menu" class="KICKASSELEMENT KICKASShidden" style="display:none">' + '<ul id="kickass-weapons-list" class="KICKASSELEMENT">' + '</ul>' + '</div>' + '<div id="kickass-pointstab-wrapper" class="KICKASSELEMENT">' + '<div id="kickass-points" class="KICKASSELEMENT">' +
924
- this.numPoints + '</div>' + '<div id="kickass-esctoquit" class="KICKASSELEMENT">Press esc to quit</div>' +
925
- this.getShareHTML() + '</div>' + '</div>';
926
- this.pointsTab = document.getElementById('kickass-pointstab');
927
- this.pointsTabWrapper = document.getElementById('kickass-pointstab-wrapper');
928
- this.points = document.getElementById('kickass-points');
929
- this.escToQuit = document.getElementById('kickass-esctoquit');
930
- this.howToImage = document.getElementById('kickass-howto-image');
931
- this.weaponsMenu = document.getElementById('kickass-weapons-menu');
932
- this.weaponsList = document.getElementById('kickass-weapons-list');
933
- this.bombLink = document.getElementById('kickass-bomb-menu');
934
- var all = this.container.getElementsByTagName('*');
935
- for (var i = 0; i < all.length; i++) {
936
- this.game.registerElement(all[i]);
937
- }
938
- this.game.registerElement(this.container);
939
- if (this.game.shouldShowMenu()) {
940
- this.menu = new Menu(this.game);
941
- this.menu.parent = this;
942
- this.menu.generate(this.container);
943
- } else {
944
- setTimeout(function () {
945
- this.onGameReady();
946
- }.bind(this), 100);
947
- }
948
- addEvent(this.bombLink, 'click', bind(this, function (e) {
949
- stopEvent(e);
950
- this.game.fireBomb();
951
- }));
952
- addEvent(this.pointsTabWrapper, 'click', bind(this, this.toggleMenu));
953
- addEvent(this.weaponsMenu, 'click', bind(this, this.toggleWeaponsMenu));
954
- this.generateDefaults();
955
- }, getShareHTML: function () {
956
- return "";
957
- }, onGameReady: function () {
958
- this.container.style.display = 'block';
959
- if (this.game.shouldShowHowToImage()) {
960
- setTimeout(bind(this, function () {
961
- removeClass(this.howToImage, "kickass-howto-invisible");
962
- }), 10);
963
- setTimeout(bind(this, function () {
964
- addClass(this.howToImage, "kickass-howto-invisible");
965
- }), 4000);
966
- }
967
- }, navigateTo: function (page, dontShowMenu) {
968
- if (!dontShowMenu) {
969
- this.showMenu();
970
- }
971
- if (this.menu) {
972
- this.menu.socketPostMessage('navigate:!' + page);
973
- }
974
- }, toggleMenu: function () {
975
- if (this.game.shouldShowMenu()) {
976
- if (hasClass(this.container, 'KICKASShidden')) {
977
- this.showMenu();
978
- } else {
979
- this.hideMenu();
980
- }
981
- } else {
982
- this.showMenu();
983
- }
984
- }, toggleWeaponsMenu: function () {
985
- if (hasClass(this.weaponsMenu, 'KICKASShidden')) {
986
- this.showWeaponsMenu();
987
- } else {
988
- this.hideWeaponsMenu();
989
- }
990
- }, hideWeaponsMenu: function () {
991
- this.weaponsMenu.style.width = '';
992
- addClass(this.weaponsMenu, 'KICKASShidden');
993
- }, showWeaponsMenu: function () {
994
- var last = this.weaponsMenu.getElementsByTagName('li');
995
- last = last[last.length - 1];
996
- this.weaponsMenu.style.width = (last.offsetLeft + last.offsetWidth - 47) + 'px';
997
- removeClass(this.weaponsMenu, 'KICKASShidden');
998
- }, showMenu: function () {
999
- if (this.game.shouldShowMenu()) {
1000
- this.container.style.bottom = '';
1001
- removeClass(this.container, 'KICKASShidden');
1002
- }
1003
- }, hideMenu: function () {
1004
- this.container.style.bottom = '';
1005
- addClass(this.container, 'KICKASShidden');
1006
- }, showBombMenu: function () {
1007
- this.bombLink.style.width = "";
1008
- }, hideBombMenu: function () {
1009
- this.bombLink.style.width = "0px";
1010
- }, getHeight: function () {
1011
- return this.container.clientHeight;
1012
- }, isVisible: function () {
1013
- return !hasClass(this.container, 'KICKASShidden');
1014
- }, addPoints: function (killed, pos) {
1015
- var points = killed * this.game.multiplier;
1016
- this.numPoints += points;
1017
- this.points.innerHTML = this.numPoints;
1018
- if (this.game.statisticsManager) {
1019
- this.game.statisticsManager.increasePointsGainedWithPoints(points);
1020
- }
1021
- this.game.ui.addPointsBubbleAt(pos, points);
1022
- }, includeCSS: function (file) {
1023
- var link = document.createElement('link');
1024
- link.rel = 'stylesheet';
1025
- link.type = 'text/css';
1026
- link.href = file;
1027
- (document.head || document.body).appendChild(link);
1028
- }, sendMessageToMenu: function (fragment) {
1029
- if (this.menu) {
1030
- this.menu.sendMessage(fragment);
1031
- }
1032
- }, addWeapon: function (weapon, id) {
1033
- var li = document.createElement('li');
1034
- li.className = 'KICKASSELEMENT kickass-weapon-item';
1035
- li.weapon = weapon;
1036
- li.style.backgroundImage = 'url(' + GameGlobals.path('css/gfx/kickass/weap-' + weapon.id + '.png') + ')';
1037
- li.innerHTML = '<span class="KICKASSELEMENT">' + weapon.name + '</span>';
1038
- this.weaponsList.appendChild(li);
1039
- addEvent(li, 'click', bind(this, function (e) {
1040
- stopEvent(e);
1041
- this.changeWeapon(weapon);
1042
- this.sendMessageToMenu("changeWeapon:!" + id);
1043
- }));
1044
- }, changeWeapon: function (weapon) {
1045
- this.game.changeWeapon(weapon);
1046
- }, destroy: function () {
1047
- var all = this.container.getElementsByTagName('*');
1048
- for (var i = 0; i < all.length; i++) {
1049
- this.game.unregisterElement(all[i]);
1050
- }
1051
- this.game.unregisterElement(this.container);
1052
- if (this.menu) {
1053
- this.menu.destroy();
1054
- }
1055
- this.container.parentNode.removeChild(this.container);
1056
- }
1057
- });
1058
- var UIManager = new Class({
1059
- initialize: function (game) {
1060
- this.UNIQID = 0;
1061
- this.game = game;
1062
- this.pointBubbles = {};
1063
- this.messages = {};
1064
- this.fx = new Fx();
1065
- this.fx.addListener(this);
1066
- }, update: function (tdelta) {
1067
- this.fx.update();
1068
- }, set: function (key, value, delta) {
1069
- var type = key.split('-')[0];
1070
- var id = key.split('-')[1];
1071
- if (this.pointBubbles[id]) {
1072
- var bubble = this.pointBubbles[id];
1073
- bubble.style.top = value[0] + 'px';
1074
- bubble.style.opacity = value[1];
1075
- if (delta == 1 && bubble.parentNode) {
1076
- bubble.parentNode.removeChild(bubble);
1077
- delete this.pointBubbles[id];
1078
- }
1079
- } else if (this.messages[id] && type == 'messagedown') {
1080
- var message = this.messages[id];
1081
- message.style.top = value[0] + 'px';
1082
- if (delta == 1) {
1083
- setTimeout(bind(this, function () {
1084
- this.fx.add('messageup-' + id, {
1085
- tweens: [[value[0], -100]],
1086
- transition: Tween.Quadratic,
1087
- duration: 300
1088
- });
1089
- }), message.staytime || 4000);
1090
- }
1091
- } else if (this.messages[id] && type == 'messageup') {
1092
- var message = this.messages[id];
1093
- message.style.top = value[0] + 'px';
1094
- if (delta == 1) {
1095
- message.parentNode.removeChild(message);
1096
- delete this.messages[id];
1097
- }
1098
- }
1099
- }, addPointsBubbleAt: function (pos, points) {
1100
- var id = 'bubble' + (this.UNIQID++);
1101
- var y = this.game.scrollPos.y + pos.y;
1102
- var bubble = newElement('span', {
1103
- innerHTML: points,
1104
- className: 'KICKASSELEMENT',
1105
- styles: {
1106
- position: 'absolute',
1107
- font: "20px Arial",
1108
- fontWeight: "bold",
1109
- opacity: "1",
1110
- color: "black",
1111
- textShadow: "#fff 1px 1px 3px",
1112
- top: y,
1113
- zIndex: "10000000"
1114
- }
1115
- });
1116
- bubble.style.left = pos.x - bubble.offsetWidth / 2 + 'px';
1117
- getAppContainerElement().appendChild(bubble);
1118
- this.pointBubbles[id] = bubble;
1119
- this.fx.add('bubble-' + id, {tweens: [[y, y - 15], [1, 0]]});
1120
- }, showMessage: function (html, staytime) {
1121
- staytime = staytime || false;
1122
- var width = 300;
1123
- var id = this.UNIQID++;
1124
- var message = newElement('div', {
1125
- innerHTML: html,
1126
- className: 'KICKASSELEMENT',
1127
- id: 'kickass-message-' + id,
1128
- styles: {
1129
- position: 'fixed',
1130
- top: -100,
1131
- left: '50%',
1132
- marginLeft: -width / 2,
1133
- width: width,
1134
- background: '#222',
1135
- opacity: 0.8,
1136
- padding: '10px',
1137
- color: '#fff',
1138
- textAlign: 'center',
1139
- borderRadius: 15,
1140
- font: '20px Arial',
1141
- fontWeight: 'bold',
1142
- zIndex: "10000000"
1143
- }
1144
- });
1145
- message.staytime = staytime;
1146
- getAppContainerElement().appendChild(message);
1147
- var to = this.getLowestBubbleY();
1148
- message.kickassto = to;
1149
- this.fx.add('messagedown-' + id, {duration: 300, tweens: [[-100, to]], transition: Tween.Quadratic});
1150
- this.messages[id] = message;
1151
- return message;
1152
- }, getLowestBubbleY: function () {
1153
- var top = 100;
1154
- for (var id in this.messages) if (this.messages.hasOwnProperty(id))
1155
- top = Math.max(this.messages[id].kickassto + this.messages[id].offsetHeight + 10, top);
1156
- return top;
1157
- }
1158
- });
1159
- var AudioManager = new Class({
1160
- initialize: function (src, formats) {
1161
- this.src = src;
1162
- this.formats = formats;
1163
- channels = 8;
1164
- this.supportsAudio = (typeof document.createElement('audio').play) != 'undefined';
1165
- if (this.supportsAudio) {
1166
- this.numChannels = channels;
1167
- this.channels = [];
1168
- for (var i = 0; i < this.numChannels; i++) {
1169
- this.channels.push({isPlaying: false, element: this.prepareElement(this.buildAudioElement())});
1170
- }
1171
- }
1172
- }, buildAudioElement: function () {
1173
- var TYPES = {"ogg": "audio/ogg", "mp3": "audio/mpeg"}
1174
- var audio = document.createElement("audio");
1175
- for (var i = 0, format; format = this.formats[i]; i++) {
1176
- var source = document.createElement("source");
1177
- source.src = this.src + "." + format;
1178
- source.type = TYPES[format];
1179
- audio.appendChild(source);
1180
- }
1181
- return audio;
1182
- }, prepareElement: function (el) {
1183
- if (typeof el.addEventListener == 'undefined')
1184
- return el;
1185
- var self = this;
1186
- el.addEventListener('ended', function (e) {
1187
- self.audioEnded(el);
1188
- }, false);
1189
- return el;
1190
- }, audioEnded: function (target) {
1191
- for (var i = 0, channel; channel = this.channels[i]; i++) {
1192
- if (channel.element === target) {
1193
- channel.isPlaying = false;
1194
- }
1195
- }
1196
- }, play: function () {
1197
- if (!this.supportsAudio) return;
1198
- for (var i = 0, channel; channel = this.channels[i]; i++) {
1199
- if (!channel.isPlaying) {
1200
- channel.isPlaying = true;
1201
- if (typeof channel.element.play == 'function')
1202
- channel.element.play();
1203
- return;
1204
- }
1205
- }
1206
- }
1207
- });
1208
- var Ships = {
1209
- Standard: {
1210
- points: [[-10, 10], [0, -15], [10, 10]],
1211
- thrusters: [{s: {w: 20, h: 7}, p: {x: 0, y: 14}, a: 0}],
1212
- cannons: [{p: {x: 0, y: -15}, a: 0}]
1213
- }
1214
- };
1215
- var PLAYERIDS = 0;
1216
- var Player = new Class({
1217
- initialize: function (game) {
1218
- this.id = PLAYERIDS++;
1219
- this.game = game;
1220
- this.tween = false;
1221
- this.isBound = true;
1222
- this.pos = new Vector(1630, 217);//飞机初始化位置
1223
- this.vel = new Vector(0, 0);
1224
- this.acc = new Vector(0, 0);
1225
- this.dir = new Vector(0, 1);
1226
- this.currentRotation = 0;
1227
- this.isBroken = false;
1228
- this.lineOffsets = [];
1229
- this.deadTime = 0;
1230
- this.friction = 0.95;
1231
- this.terminalVelocity = 2000;
1232
- this.lastPos = new Vector(0, 0);
1233
- }, setShip: function (ship) {
1234
- this.ship = ship;
1235
- this.verts = [];
1236
- for (var i = 0, vert; vert = this.ship.points[i]; i++)
1237
- this.verts.push(new Vector(vert[0], vert[1]));
1238
- this.verts.push(this.verts[0]);
1239
- this.thrusters = [];
1240
- this.cannons = [];
1241
- this.addThrusters(this.ship.thrusters);
1242
- this.addCannons(this.ship.cannons);
1243
- this.size = this.getSizeFromVertsAndObjects();
1244
- this.bounds = this.calculateBounds();
1245
- if (this.sheet) {
1246
- this.sheet.destroy();
1247
- }
1248
- this.sheet = new Sheet(new Rect(100, 100, this.bounds.x, this.bounds.y));
1249
- this.forceRedraw = true;
1250
- }, setCannons: function (cannonClass) {
1251
- var newCannons = [];
1252
- for (var i = 0, cannon; cannon = this.cannons[i]; i++) {
1253
- var newCannon = new cannonClass(this, this.game, cannon.pos.x, cannon.pos.y, cannon.angle);
1254
- newCannons.push(newCannon);
1255
- cannon.destroy();
1256
- }
1257
- this.cannons = newCannons;
1258
- }, addThrusters: function (thrusters) {
1259
- for (var i = 0, data; data = thrusters[i]; i++) {
1260
- var thruster = new Thruster(data);
1261
- this.thrusters.push(thruster);
1262
- }
1263
- }, addCannons: function (cannons) {
1264
- for (var i = 0, data; data = cannons[i]; i++) {
1265
- var weaponClass = WeaponMap[data.m] || WeaponMap.cannon;
1266
- var cannon = new weaponClass.cannonClass(this, this.game, data.p.x, data.p.y, data.a);
1267
- cannon.player = this;
1268
- cannon.game = this.game;
1269
- this.cannons.push(cannon);
1270
- }
1271
- }, update: function (tdelta) {
1272
- if (this.isBroken) {
1273
- if (!this.lineOffsets.length) {
1274
- for (var i = 0; i < (this.verts.length - 1); i++)
1275
- this.lineOffsets[i] = {
1276
- pos: new Vector(0, 0),
1277
- dir: (new Vector(1, 1)).setAngle(Math.PI * 2 * Math.random())
1278
- };
1279
- }
1280
- for (var i = 0; i < this.lineOffsets.length; i++) {
1281
- this.lineOffsets[i].pos.add(this.lineOffsets[i].dir.cp().setLength(50).mul(tdelta));
1282
- }
1283
- this.sheet.clear();
1284
- this.sheet.setAngle(this.dir.angle());
1285
- this.sheet.setPosition(this.pos);
1286
- this.sheet.drawBrokenPlayer(this.verts, this.lineOffsets);
1287
- if (now() - this.deadTime > 1000.0) {
1288
- this.isBroken = false;
1289
- this.lineOffsets = [];
1290
- this.randomPos();
1291
- }
1292
- return;
1293
- }
1294
- if (!this.tween) {
1295
- if (this.game.isKeyPressed('left') || this.game.isKeyPressed('right')) {
1296
- if (this.game.isKeyPressed('left'))
1297
- this.rotateLeft(tdelta);
1298
- if (this.game.isKeyPressed('right'))
1299
- this.rotateRight(tdelta);
1300
- } else {
1301
- this.stopRotate();
1302
- }
1303
- if (this.game.isKeyPressed('up'))
1304
- this.activateThrusters(); else
1305
- this.stopThrusters();
1306
- }
1307
- if (this.game.isKeyPressed(' ')) {
1308
- this.isShooting = true;
1309
- if (!this.isBroken)
1310
- this.shootPressed();
1311
- } else if (this.isShooting) {
1312
- this.isShooting = false;
1313
- this.shootReleased();
1314
- }
1315
- if (this.currentRotation)
1316
- this.dir.setAngle(this.dir.angle() + this.currentRotation * tdelta);
1317
- var frictionedAcc = this.acc.mulNew(tdelta).sub(this.vel.mulNew(tdelta * this.friction));
1318
- this.vel.add(frictionedAcc);
1319
- if (this.vel.len() > this.terminalVelocity)
1320
- this.vel.setLength(this.terminalVelocity);
1321
- var posDelta = this.vel.mulNew(tdelta);
1322
- this.pos.add(posDelta);
1323
- if (this.game.statisticsManager) {
1324
- this.game.statisticsManager.increaseDistanceWithPixels(posDelta.len());
1325
- }
1326
- var showFlames = !this.acc.is({x: 0, y: 0});
1327
- for (var i = 0, thruster; thruster = this.thrusters[i]; i++) {
1328
- thruster.setIsShown(showFlames);
1329
- thruster.update(tdelta);
1330
- }
1331
- if (this.isBound)
1332
- this.checkBounds();
1333
- if (!this.lastPos.is(this.pos) || this.currentRotation || this.forceRedraw) {
1334
- this.forceRedraw = false;
1335
- this.sheet.clear();
1336
- this.sheet.setAngle(this.dir.angle() + Math.PI / 2);
1337
- this.sheet.setPosition(this.pos);
1338
- if (showFlames) {
1339
- for (var i = 0, thruster; thruster = this.thrusters[i]; i++)
1340
- thruster.drawTo(this.sheet);
1341
- }
1342
- this.sheet.drawPlayer(this.verts);
1343
- this.lastPos = this.pos.cp();
1344
- }
1345
- for (var i = 0, cannon; cannon = this.cannons[i]; i++) {
1346
- cannon.update(tdelta);
1347
- }
1348
- }, randomPos: function () {
1349
- var w = this.game.windowSize.width;
1350
- var h = this.game.windowSize.height;
1351
- this.pos = new Vector(random(0, w), random(0, h));
1352
- }, checkBounds: function () {
1353
- if (this.tween)
1354
- return;
1355
- var w = this.game.windowSize.width;
1356
- var h = this.game.windowSize.height;
1357
- var rightBound = this.pos.x + this.sheet.rect.size.width / 2;
1358
- var bottomBound = this.pos.y + this.sheet.rect.size.height / 2;
1359
- if (rightBound > w) {
1360
- window.scrollTo(this.game.scrollPos.x + 50, this.game.scrollPos.y);
1361
- this.pos.x = 0;
1362
- } else if (this.pos.x < 0) {
1363
- window.scrollTo(this.game.scrollPos.x - 50, this.game.scrollPos.y);
1364
- this.pos.x = w - this.sheet.rect.size.width / 2;
1365
- }
1366
- if (bottomBound > h) {
1367
- window.scrollTo(this.game.scrollPos.x, this.game.scrollPos.y + h * 0.75);
1368
- this.pos.y = 0;
1369
- } else if (this.pos.y < 0) {
1370
- window.scrollTo(this.game.scrollPos.x, this.game.scrollPos.y - h * 0.75);
1371
- this.pos.y = h - this.sheet.rect.size.height / 2;
1372
- }
1373
- }, inRect: function (rect) {
1374
- var ret = false;
1375
- for (var i = 0, vert; vert = this.verts[i]; i++) {
1376
- if (rect.hasPoint(new Vector(vert.x + this.pos.x, vert.y + this.pos.y)))
1377
- ret = true;
1378
- }
1379
- return ret;
1380
- }, hit: function (by) {
1381
- if (this.isBroken) return;
1382
- this.isBroken = true;
1383
- this.deadTime = now();
1384
- }, activateThrusters: function () {
1385
- if (this.game.statisticsManager) {
1386
- this.game.statisticsManager.usedThrusters();
1387
- }
1388
- this.acc = (new Vector(500, 0)).setAngle(this.dir.angle());
1389
- }, stopThrusters: function () {
1390
- this.acc = new Vector(0, 0);
1391
- }, rotateLeft: function (tdelta) {
1392
- this.currentRotation = Math.max(-Math.PI * 2, this.currentRotation - Math.PI * 10 * tdelta);
1393
- }, rotateRight: function (tdelta) {
1394
- this.currentRotation = Math.min(Math.PI * 2, this.currentRotation + Math.PI * 10 * tdelta);
1395
- }, stopRotate: function () {
1396
- this.currentRotation = 0;
1397
- }, getSizeFromVertsAndObjects: function () {
1398
- var largestDistance = 0;
1399
- for (var i = 0, vert; vert = this.verts[i]; i++)
1400
- largestDistance = Math.max(largestDistance, (new Vector(vert)).len());
1401
- for (var i = 0, obj; obj = this.thrusters[i]; i++) {
1402
- var p1 = (new Vector(obj.pos.x - obj.size.width / 2, obj.pos.y - obj.size.height / 2)).rotate(obj.angle);
1403
- var p2 = (new Vector(obj.pos.x + obj.size.width / 2, obj.pos.y - obj.size.height / 2)).rotate(obj.angle);
1404
- var p3 = (new Vector(obj.pos.x - obj.size.width / 2, obj.pos.y + obj.size.height / 2)).rotate(obj.angle);
1405
- var p4 = (new Vector(obj.pos.x + obj.size.width / 2, obj.pos.y + obj.size.height / 2)).rotate(obj.angle);
1406
- largestDistance = Math.max(largestDistance, p1.len(), p2.len(), p3.len(), p4.len());
1407
- }
1408
- return {width: largestDistance * 2, height: largestDistance * 2};
1409
- }, calculateBounds: function () {
1410
- return {
1411
- x: Math.max(this.size.width, this.size.height) * 1,
1412
- y: Math.max(this.size.height, this.size.width) * 1
1413
- };
1414
- }, shootPressed: function () {
1415
- for (var i = 0, cannon; cannon = this.cannons[i]; i++)
1416
- cannon.shootPressed();
1417
- }, shootReleased: function () {
1418
- for (var i = 0, cannon; cannon = this.cannons[i]; i++)
1419
- cannon.shootReleased();
1420
- }, flyTo: function (x, y, callback) {
1421
- this.tween = {
1422
- start: {pos: this.pos.cp(), dir: this.dir.cp()},
1423
- to: new Vector(x, y),
1424
- callback: callback || function () {
1425
- }
1426
- };
1427
- this.tween.time = this.getTimeforTween();
1428
- }, destroy: function () {
1429
- this.sheet.destroy();
1430
- }
1431
- });
1432
- var Thruster = new Class({
1433
- initialize: function (data, ship) {
1434
- this.pos = new Vector(data.p);
1435
- this.size = {width: data.s.w, height: data.s.h};
1436
- this.angle = data.a || 0;
1437
- this.ship = ship;
1438
- this.isShown = false;
1439
- this.flameY = 1;
1440
- this.fx = new Fx();
1441
- this.fx.addListener(this);
1442
- this.flames = {r: [], y: []};
1443
- this.lastFrameUpdate = 0;
1444
- this.generateFlames();
1445
- }, update: function (tdelta) {
1446
- this.fx.update();
1447
- if (now() - this.lastFrameUpdate > 1000 / 60)
1448
- this.generateFlames();
1449
- }, set: function (key, value) {
1450
- switch (key) {
1451
- case'flames':
1452
- this.flameY = value;
1453
- break;
1454
- }
1455
- }, setIsShown: function (isShown) {
1456
- if (!this.isShown && isShown) {
1457
- this.flameY = 0.0;
1458
- this.generateFlames();
1459
- this.fx.add('flames', {start: this.flameY, end: 1, duration: 250, transition: Tween.Quintic});
1460
- }
1461
- this.isShown = isShown;
1462
- }, drawTo: function (sheet) {
1463
- sheet.drawFlames(this.flames, this.angle);
1464
- }, generateFlames: function () {
1465
- var redWidth = this.size.width, redIncrease = this.size.width * 0.05, yellowWidth = this.size.width * 0.8,
1466
- yellowIncrease = yellowWidth * 0.1, halfRed = redWidth / 2, halfYellow = yellowWidth / 2,
1467
- offsetY = -this.size.height / 2, metaY = 0;
1468
- var px = this.pos.x;
1469
- var py = this.pos.y - this.size.height / 2;
1470
-
1471
- function vec(x, y) {
1472
- return new Vector(x, y);
1473
- }
1474
-
1475
- this.flames.r = [vec(-halfRed + px, py)];
1476
- this.flames.y = [vec(-halfYellow + px, py)];
1477
- this.flames.self = this;
1478
- for (var x = 0; x < redWidth; x += redIncrease)
1479
- this.flames.r.push(vec(x - halfRed + px, this.flameY * random(this.size.height * 0.7, this.size.height) + py));
1480
- this.flames.r.push(vec(halfRed + px, py));
1481
- for (var x = 0; x < yellowWidth; x += yellowIncrease)
1482
- this.flames.y.push(vec(x - halfYellow + px, this.flameY * random(this.size.height * 0.4, this.size.height * 0.7) + py));
1483
- this.flames.y.push(vec(halfYellow + px, py));
1484
- this.lastFrameUpdate = now();
1485
- var pos = vec(px, py);
1486
- for (var i = 0, p; p = this.flames.r[i]; i++)
1487
- p.sub(pos).rotate(this.angle).add(pos);
1488
- for (var i = 0, p; p = this.flames.y[i]; i++)
1489
- p.sub(pos).rotate(this.angle).add(pos);
1490
- }
1491
- });
1492
- var BombManager = new Class({
1493
- initialize: function (game) {
1494
- this.game = game;
1495
- this.bombShowDelay = 30;
1496
- this.nextBomb = this.bombShowDelay;
1497
- }, update: function (tdelta) {
1498
- if (this.game.isKeyPressed('F') && this.isReady()) {
1499
- this.blow();
1500
- }
1501
- if (this.nextBomb === -1 || !this.game.sessionManager.isPlaying) {
1502
- return;
1503
- }
1504
- this.nextBomb -= tdelta;
1505
- if (this.nextBomb < 0) {
1506
- this.game.menuManager.showBombMenu();
1507
- this.nextBomb = -1;
1508
- this.game.ui.showMessage("BOMB IS READY<br />(lower right corner or F)");
1509
- }
1510
- }, blow: function () {
1511
- var message = this.game.ui.showMessage("3...", 5000);
1512
- delay(1000, function () {
1513
- message.innerHTML = "2...";
1514
- }, this);
1515
- delay(2000, function () {
1516
- message.innerHTML = "1...";
1517
- }, this);
1518
- delay(3000, function () {
1519
- message.innerHTML = "boom";
1520
- }, this);
1521
- delay(3000, this.blowStuffUp, this);
1522
- this.nextBomb = this.bombShowDelay;
1523
- }, blowStuffUp: function () {
1524
- this.game.bulletManager.updateEnemyIndex();
1525
- var index = this.game.bulletManager.enemyIndex;
1526
- for (var i = 0, el; (el = index[i]) && i < 10; i++) {
1527
- var rect = getRect(el);
1528
- var center = new Vector(rect.left + rect.width / 2, rect.top + rect.height / 2);
1529
- this.game.explosionManager.addExplosion(center, el, MegaParticleExplosion);
1530
- el.parentNode.removeChild(el);
1531
- }
1532
- this.game.menuManager.hideBombMenu();
1533
- this.nextBomb = this.bombShowDelay;
1534
- }, isReady: function () {
1535
- return this.nextBomb === -1;
1536
- }
1537
- });
1538
- var ELEMENTSTHATARENOTTOBEINCLUDED = ['BR', 'SCRIPT', 'STYLE', 'TITLE', 'META', 'HEAD', 'OPTION', 'OPTGROUP', 'LINK'];
1539
- var ELEMENTSIZETHRESHOLD = 5;
1540
- var BulletManager = new Class({
1541
- initialize: function (game) {
1542
- this.game = game;
1543
- this.lastBlink = 0;
1544
- this.blinkActive = false;
1545
- this.enemyIndex = [];
1546
- this.updateDelay = 2.5;
1547
- this.nextUpdate = this.updateDelay;
1548
- }, update: function (tdelta) {
1549
- if (this.game.isKeyPressed('B')) {
1550
- this.blink();
1551
- } else if (this.blinkActive) {
1552
- this.endBlink();
1553
- }
1554
- this.nextUpdate -= tdelta;
1555
- if (this.nextUpdate < 0) {
1556
- this.updateEnemyIndex();
1557
- }
1558
- }, blink: function () {
1559
- if (now() - this.lastBlink > 250) {
1560
- for (var i = 0, el; el = this.enemyIndex[i]; i++) {
1561
- if (!this.blinkActive)
1562
- el.style.outline = '1px solid red'; else
1563
- el.style.outline = el.KICKASSOLDBORDER;
1564
- }
1565
- this.blinkActive = !this.blinkActive;
1566
- this.lastBlink = now();
1567
- if (!this.blinkActive) {
1568
- this.updateEnemyIndex();
1569
- }
1570
- }
1571
- }, endBlink: function () {
1572
- for (var i = 0, el; el = this.enemyIndex[i]; i++)
1573
- el.style.outline = el.KICKASSOLDBORDER;
1574
- this.lastBlink = 0;
1575
- this.blinkActive = false;
1576
- }, updateEnemyIndex: function () {
1577
- var all = document.getElementsByTagName('*');
1578
- this.enemyIndex = [];
1579
- for (var i = 0, el; el = all[i]; i++) {
1580
- if (this.isDestroyable(el)) {
1581
- this.enemyIndex.push(el);
1582
- el.KICKASSOLDBORDER = el.style.outline || (document.defaultView.getComputedStyle(el, null).outline);
1583
- }
1584
- }
1585
- this.nextUpdate = this.updateDelay;
1586
- }, isDestroyable: function (element, ignoreSize) {
1587
- if (this.shouldIgnoreElement(element, ignoreSize))
1588
- return false;
1589
- for (var i = 0, child; child = element.childNodes[i]; i++) {
1590
- if (child.nodeType === 1 && ELEMENTSTHATARENOTTOBEINCLUDED.indexOf(child.tagName) === -1 && (child.offsetWidth >= ELEMENTSIZETHRESHOLD && child.offsetHeight >= ELEMENTSIZETHRESHOLD) && document.defaultView.getComputedStyle(child, null).visibility !== 'hidden') {
1591
- return false;
1592
- }
1593
- }
1594
- return true;
1595
- }, isDestroyableFromCollision: function (element) {
1596
- return this.isDestroyable(element, true);
1597
- }, shouldIgnoreElement: function (element, ignoreSize) {
1598
- if (element.nodeType !== 1)
1599
- return true;
1600
- if (element == document.documentElement || element == document.body)
1601
- return true;
1602
- if (ELEMENTSTHATARENOTTOBEINCLUDED.indexOf(element.tagName) !== -1)
1603
- return true;
1604
- if (element.style.visibility == 'hidden' || element.style.display == 'none')
1605
- return true;
1606
- if (typeof element.className == "string" && element.className.indexOf('KICKASSELEMENT') != -1)
1607
- return true;
1608
- if (!ignoreSize) {
1609
- if (element.offsetWidth < ELEMENTSIZETHRESHOLD || element.offsetHeight < ELEMENTSIZETHRESHOLD)
1610
- return true;
1611
- }
1612
- var rect;
1613
- if (element.offsetLeft < 0 || element.offsetTop < 0) {
1614
- rect = getRect(element);
1615
- if (rect.left + rect.width < 0 || rect.top + rect.height < 0)
1616
- return true;
1617
- }
1618
- if (!rect)
1619
- rect = getRect(element);
1620
- if (rect.top >= this.game.scrollSize.y)
1621
- return true;
1622
- return false;
1623
- }, destroy: function () {
1624
- for (var key in this.bullets) if (this.bullets.hasOwnProperty(key))
1625
- for (var i = 0, bullet; bullet = this.bullets[key][i]; i++)
1626
- bullet.destroy();
1627
- this.bullets = {};
1628
- }
1629
- });
1630
- var SessionManager = new Class({
1631
- initialize: function (game) {
1632
- this.game = game;
1633
- this.isPlaying = false;
1634
- }, update: function (tdelta) {
1635
- if (this.isPlaying && this.game.bulletManager.enemyIndex.length == 0) {
1636
- this.weHaveWon();
1637
- }
1638
- }, weHaveWon: function () {
1639
- this.isPlaying = false;
1640
- this.game.ui.showMessage("You're done!");
1641
- if (this.game.isCampaign()) {
1642
- this.game.menuManager.showMenu();
1643
- this.game.menuManager.navigateTo('highscores');
1644
- } else {
1645
- this.game.menuManager.showMenu();
1646
- }
1647
- this.game.menuManager.sendMessageToMenu("gameFinished:!");
1648
- }
1649
- });
1650
- var ExplosionManager = new Class({
1651
- initialize: function (game) {
1652
- this.game = game;
1653
- this.explosions = [];
1654
- }, update: function (tdelta) {
1655
- var time = now();
1656
- for (var i = 0, explosion; explosion = this.explosions[i]; i++) {
1657
- if (time - explosion.bornAt > (explosion.ttl || 500)) {
1658
- explosion.destroy();
1659
- this.explosions.splice(i, 1);
1660
- continue;
1661
- }
1662
- explosion.update(tdelta);
1663
- }
1664
- }, addExplosion: function (pos, forElement, explosionClass) {
1665
- explosionClass = explosionClass || ParticleExplosion;
1666
- var explosion = new explosionClass(pos, forElement);
1667
- explosion.game = this.game;
1668
- explosion.checkBounds();
1669
- this.explosions.push(explosion);
1670
- if (this.game.audioManager.explosion) {
1671
- this.game.audioManager.explosion.play();
1672
- }
1673
- }, destroy: function () {
1674
- for (var i = 0, explosion; explosion = this.explosions[i]; i++)
1675
- explosion.destroy();
1676
- this.explosions = [];
1677
- }
1678
- });
1679
- var Cannon = new Class({
1680
- initialize: function (player, game, x, y, angle) {
1681
- this.player = player;
1682
- this.game = game;
1683
- this.pos = new Vector(x, y);
1684
- this.angle = angle || 0;
1685
- }, shootPressed: function () {
1686
- }, shootReleased: function () {
1687
- }, checkCollisions: function () {
1688
- }, getExplosionClass: function () {
1689
- return ParticleExplosion;
1690
- }, update: function (tdelta) {
1691
- this.game.hideAll();
1692
- this.checkCollisions(tdelta);
1693
- this.game.showAll();
1694
- }, checkCollision: function (bullet) {
1695
- var hit = bullet.checkCollision();
1696
- if (!hit)
1697
- return false;
1698
- this.game.explosionManager.addExplosion(bullet.pos, hit, this.getExplosionClass());
1699
- this.game.menuManager.addPoints(Math.min(hit.getElementsByTagName('*').length + 1, 100), bullet.pos);
1700
- if (!hit.isShot) {
1701
- hit.parentNode.removeChild(hit);
1702
- }
1703
- if (this.game.statisticsManager) {
1704
- this.game.statisticsManager.addElementsDestroyed();
1705
- }
1706
- return true;
1707
- }, createBullet: function (bulletClass) {
1708
- var pos = this.getABulletPos();
1709
- var dir = this.getABulletDir();
1710
- var bullet = new bulletClass(pos, dir);
1711
- bullet.game = this.game;
1712
- bullet.manager = this;
1713
- bullet.initCanvas();
1714
- bullet.vel.add(bullet.vel.cp().setLength(this.player.vel.len()));
1715
- return bullet;
1716
- }, getABulletPos: function () {
1717
- return this.player.pos.cp().add(this.pos.cp().rotate(this.player.dir.angle() + Math.PI / 2));
1718
- }, getABulletDir: function () {
1719
- return this.player.dir.cp().rotate(this.angle);
1720
- }, destroy: function () {
1721
- }
1722
- });
1723
- var LaserCannon = new Class({
1724
- Extends: Cannon, initialize: function (player, game, x, y, angle) {
1725
- Cannon.prototype.initialize.apply(this, arguments);
1726
- this.lasers = [];
1727
- }, getExplosionClass: function () {
1728
- return SplitExplosion;
1729
- }, update: function (tdelta) {
1730
- if (!this.lasers.length)
1731
- return;
1732
- this.removeOld();
1733
- Cannon.prototype.update.call(this, tdelta);
1734
- }, checkCollisions: function (tdelta) {
1735
- for (var i = 0, laser; laser = this.lasers[i]; i++) {
1736
- laser.update(tdelta);
1737
- if (this.checkCollision(laser)) {
1738
- }
1739
- }
1740
- }, removeOld: function () {
1741
- for (var i = 0, laser; laser = this.lasers[i]; i++) {
1742
- if (laser.outOfBounds) {
1743
- laser.destroy();
1744
- this.lasers.splice(i, 1);
1745
- }
1746
- }
1747
- }, shootPressed: function () {
1748
- if (this.lasers.length > 5) {
1749
- return;
1750
- }
1751
- if (now() - this.lastFired < 500) {
1752
- return;
1753
- }
1754
- this.lastFired = now();
1755
- if (this.game.statisticsManager) {
1756
- this.game.statisticsManager.addShotFired();
1757
- }
1758
- this.lasers.push(this.createBullet(LaserBullet));
1759
- }, destroy: function () {
1760
- if (this.lasers.length) {
1761
- for (var i = 0, laser; laser = this.lasers[i]; i++) {
1762
- laser.destroy();
1763
- }
1764
- this.lasers = [];
1765
- }
1766
- }
1767
- });
1768
- var BallCannon = new Class({
1769
- Extends: Cannon, initialize: function () {
1770
- Cannon.prototype.initialize.apply(this, arguments);
1771
- this.lastFired = 0;
1772
- this.bullets = [];
1773
- }, getExplosionClass: function () {
1774
- return ParticleExplosion;
1775
- }, update: function (tdelta) {
1776
- if (!this.bullets.length) {
1777
- return;
1778
- }
1779
- this.removeOld();
1780
- Cannon.prototype.update.call(this, tdelta);
1781
- }, removeOld: function () {
1782
- var time = now();
1783
- for (var i = 0, bullet; bullet = this.bullets[i]; i++) {
1784
- if (time - bullet.bornAt > 2000) {
1785
- bullet.destroy();
1786
- this.bullets.splice(i, 1);
1787
- }
1788
- }
1789
- }, checkCollisions: function (tdelta) {
1790
- for (var i = 0, bullet; bullet = this.bullets[i]; i++) {
1791
- bullet.update(tdelta);
1792
- if (this.checkCollision(bullet)) {
1793
- bullet.destroy();
1794
- this.bullets.splice(i, 1);
1795
- }
1796
- }
1797
- }, shootPressed: function () {
1798
- if (now() - this.lastFired < 200) {
1799
- return;
1800
- }
1801
- this.lastFired = now();
1802
- this.addBullet();
1803
- if (this.game.statisticsManager) {
1804
- this.game.statisticsManager.addShotFired();
1805
- }
1806
- }, addBullet: function () {
1807
- if (this.bullets.length > 7) {
1808
- this.bullets[0].destroy();
1809
- this.bullets.shift();
1810
- }
1811
- var bullet = this.createBullet(Bullet);
1812
- this.bullets.push(bullet);
1813
- }, destroy: function () {
1814
- for (var i = 0, bullet; bullet = this.bullets[i]; i++) {
1815
- bullet.destroy();
1816
- }
1817
- this.bullets = [];
1818
- }
1819
- });
1820
- var Bullet = new Class({
1821
- initialize: function (pos, dir) {
1822
- this.pos = pos.cp();
1823
- this.dir = dir;
1824
- this.vel = new Vector(500, 500);
1825
- this.bornAt = now();
1826
- }, initCanvas: function () {
1827
- this.sheet = new Sheet(new Rect(this.pos.x, this.pos.y, 5, 5));
1828
- this.sheet.drawBullet();
1829
- }, draw: function () {
1830
- this.sheet.setPosition(this.pos);
1831
- }, update: function (tdelta) {
1832
- this.pos.add(this.vel.setAngle(this.dir.angle()).mulNew(tdelta));
1833
- this.checkBounds();
1834
- this.draw();
1835
- }, checkCollision: function () {
1836
- var element = document.elementFromPoint(this.pos.x, this.pos.y);
1837
- if (element && element.nodeType == 3)
1838
- element = element.parentNode;
1839
- var didFind = element && this.game.bulletManager.isDestroyableFromCollision(element) ? element : false;
1840
- return didFind;
1841
- }, checkBounds: function () {
1842
- var w = this.game.windowSize.width;
1843
- var h = this.game.windowSize.height;
1844
- var rightBound = this.pos.x + this.sheet.rect.size.width / 2;
1845
- var bottomBound = this.pos.y + this.sheet.rect.size.height / 2;
1846
- if (rightBound > w)
1847
- this.pos.x = 0; else if (this.pos.x < 0)
1848
- this.pos.x = w - this.sheet.rect.size.width / 2;
1849
- if (bottomBound > h)
1850
- this.pos.y = 0; else if (this.pos.y < 0)
1851
- this.pos.y = h - this.sheet.rect.size.height / 2;
1852
- }, destroy: function () {
1853
- this.sheet.destroy();
1854
- }
1855
- });
1856
- var LaserBullet = new Class({
1857
- Extends: Bullet, initialize: function () {
1858
- Bullet.prototype.initialize.apply(this, arguments);
1859
- this.vel = new Vector(750, 750);
1860
- this.lastDrawPos = this.pos.cp();
1861
- }, initCanvas: function () {
1862
- var s = Math.max(GameGlobals.laserImage.width, GameGlobals.laserImage.height);
1863
- this.sheet = new Sheet(new Rect(0, 0, s, s));
1864
- }, update: function (tdelta) {
1865
- Bullet.prototype.update.apply(this, arguments);
1866
- }, draw: function () {
1867
- this.sheet.drawLaser(this.pos, this.dir);
1868
- this.lastDrawPos = this.pos.cp();
1869
- }, checkBounds: function () {
1870
- var w = this.game.windowSize.width;
1871
- var h = this.game.windowSize.height;
1872
- var rightBound = this.pos.x + this.sheet.rect.size.width / 2;
1873
- var bottomBound = this.pos.y + this.sheet.rect.size.height / 2;
1874
- if (rightBound > w || this.pos.x < 0)
1875
- this.outOfBounds = true;
1876
- if (bottomBound > h || this.pos.y < 0)
1877
- this.outOfBounds = true;
1878
- }, destroy: function () {
1879
- this.sheet.destroy();
1880
- }
1881
- });
1882
- GameGlobals.laserImage = document.createElement('img');
1883
- GameGlobals.laserImage.src = GameGlobals.path('css/gfx/kickass/laser.png');
1884
- var Explosion = new Class({
1885
- initialize: function (pos, element) {
1886
- this.bornAt = now();
1887
- this.pos = pos.cp();
1888
- }, update: function (tdelta) {
1889
- }, checkBounds: function () {
1890
- }, destroy: function () {
1891
- }
1892
- });
1893
- var ParticleExplosion = new Class({
1894
- Extends: Explosion, initialize: function (pos, element) {
1895
- Explosion.prototype.initialize.apply(this, arguments);
1896
- this.particleVel = new Vector(150, 0);
1897
- this.particles = [];
1898
- this.generateParticles();
1899
- this.sheet = new Sheet(new Rect(pos.x, pos.y, 250, 250));
1900
- }, update: function (tdelta) {
1901
- for (var i = 0, particle; particle = this.particles[i]; i++)
1902
- particle.pos.add(particle.vel.mulNew(tdelta).mul(random(0.5, 1.0)).setAngle(particle.dir.angle()));
1903
- this.sheet.clear();
1904
- this.sheet.drawExplosion(this.particles);
1905
- }, generateParticles: function () {
1906
- for (var i = 0, j = !GameGlobals.hasCanvas ? 10 : 40; i < j; i++) {
1907
- this.particles.push({
1908
- dir: (new Vector(random(0, 20) - 10, random(0, 20) - 10)).normalize(),
1909
- vel: this.particleVel.cp(),
1910
- pos: new Vector(0, 0),
1911
- color: ['yellow', 'red'][random(0, 1)]
1912
- });
1913
- }
1914
- }, checkBounds: function () {
1915
- var right = this.sheet.rect.getRight();
1916
- var bottom = this.sheet.rect.getBottom();
1917
- var w = this.game.windowSize.width;
1918
- var h = this.game.windowSize.height;
1919
- if (right > w)
1920
- this.pos.x -= right - w;
1921
- if (bottom > h)
1922
- this.pos.y -= bottom - h;
1923
- this.sheet.setPosition(this.pos);
1924
- }, destroy: function () {
1925
- this.sheet.destroy();
1926
- }
1927
- });
1928
- var MegaParticleExplosion = new Class({
1929
- Extends: ParticleExplosion, initialize: function (pos, element) {
1930
- Explosion.prototype.initialize.apply(this, arguments);
1931
- this.particleVel = new Vector(200, 0);
1932
- this.particles = [];
1933
- this.generateParticles();
1934
- this.sheet = new Sheet(new Rect(pos.x, pos.y, 500, 500));
1935
- this.ttl = 2000;
1936
- this.generationDelay = 0.6;
1937
- this.generationTimes = 2;
1938
- this.nextGenerate = this.generationDelay;
1939
- }, update: function (tdelta) {
1940
- this.nextGenerate -= tdelta;
1941
- if (this.nextGenerate <= 0 && this.generationTimes > 0) {
1942
- this.nextGenerate = this.generationDelay;
1943
- this.generateParticles();
1944
- this.generationTimes--;
1945
- }
1946
- ParticleExplosion.prototype.update.call(this, tdelta);
1947
- }
1948
- });
1949
- var SplitExplosion = new Class({
1950
- Extends: Explosion, initialize: function (pos, element) {
1951
- if (!element) return;
1952
- Explosion.prototype.initialize.apply(this, arguments);
1953
- this.element = element;
1954
- this.fx = new Fx();
1955
- this.fx.addListener(this);
1956
- this.start();
1957
- }, update: function (tdelta) {
1958
- if (!this.element) return;
1959
- this.fx.update();
1960
- }, set: function (key, value) {
1961
- if (key == 'opacity') {
1962
- }
1963
- }, start: function () {
1964
- var pieces = this.createClones();
1965
- var left = pieces[0], right = pieces[1];
1966
- var lT = 'rotate(-' + random(30, 50) + 'deg) translate(-100px, 40px)';
1967
- var rT = 'rotate(' + random(30, 50) + 'deg) translate(100px, 40px)';
1968
- setStyles(left, {'transform': lT});
1969
- setStyles(right, {'transform': rT});
1970
- this.left = left;
1971
- this.right = right;
1972
- this.fx.add('opacity', {start: 1, end: 0.5, duration: 500});
1973
- }, createClones: function () {
1974
- var coords = getRect(this.element);
1975
- var leftContainer = this.createContainer(coords);
1976
- var rightContainer = this.createContainer(coords);
1977
- var left = cloneElement(this.element);
1978
- var right = cloneElement(this.element);
1979
- addClass(left, 'KICKASSELEMENT');
1980
- addClass(right, 'KICKASSELEMENT');
1981
- var styles = {margin: 0, overflow: 'hidden'};
1982
- setStyles(left, styles);
1983
- setStyles(right, styles);
1984
- leftContainer.appendChild(left);
1985
- rightContainer.appendChild(right);
1986
- rightContainer.style.left = coords.left + coords.width / 2 + 'px';
1987
- rightContainer.scrollLeft += coords.width / 2;
1988
- this.element.style.opacity = 0;
1989
- this.element.style.visibility = 'hidden';
1990
- this.element.style.display = 'none';
1991
- return each([leftContainer, rightContainer], function (el) {
1992
- el.style.transition = 'transform 500ms ease-in';
1993
- });
1994
- }, createContainer: function (coords) {
1995
- var ret = document.createElement('div');
1996
- setStyles(ret, {
1997
- position: 'absolute',
1998
- left: coords.left,
1999
- top: coords.top,
2000
- width: coords.width * 0.5,
2001
- height: coords.height,
2002
- overflow: 'hidden'
2003
- });
2004
- getAppContainerElement().appendChild(ret);
2005
- return ret;
2006
- }, destroy: function () {
2007
- try {
2008
- this.left.parentNode.removeChild(this.left);
2009
- this.right.parentNode.removeChild(this.right);
2010
- this.element.parentNode.removeChild(this.element);
2011
- } catch (e) {
2012
- }
2013
- }
2014
- });
2015
- var Weapons = {
2016
- 1: {name: 'Cannon', id: 'cannon', cannonClass: BallCannon},
2017
- 2: {name: 'Laser', id: 'laser', cannonClass: LaserCannon}
2018
- };
2019
- var WeaponMap = {'cannon': Weapons[1], 'laser': Weapons[2]};
2020
- var SheetCanvas = new Class({
2021
- initialize: function (rect) {
2022
- this.canvas = document.createElement('canvas');
2023
- this.canvas.className = 'KICKASSELEMENT';
2024
- with (this.canvas.style) {
2025
- position = 'absolute';
2026
- zIndex = '1000000';
2027
- }
2028
- GameGlobals.kickass.registerElement(this.canvas);
2029
- if (this.canvas.getContext)
2030
- this.ctx = this.canvas.getContext('2d');
2031
- this.rect = rect;
2032
- this.angle = 0;
2033
- this.updateCanvas();
2034
- getAppContainerElement().appendChild(this.canvas);
2035
- }, tracePoly: function (verts) {
2036
- if (!verts[0]) return;
2037
- this.ctx.save();
2038
- this.ctx.translate(this.rect.size.width / 2, this.rect.size.height / 2);
2039
- this.ctx.rotate(this.angle);
2040
- this.ctx.beginPath();
2041
- this.ctx.moveTo(verts[0].x, verts[0].y);
2042
- for (var i = 0; i < verts.length; i++) {
2043
- this.ctx.lineTo(verts[i].x, verts[i].y);
2044
- }
2045
- this.ctx.restore();
2046
- }, setAngle: function (angle) {
2047
- this.angle = angle;
2048
- }, updateCanvas: function () {
2049
- if (this.canvas.width != this.rect.size.width)
2050
- this.canvas.width = this.rect.size.width;
2051
- if (this.canvas.height != this.rect.size.height)
2052
- this.canvas.height = this.rect.size.height;
2053
- this.canvas.style.left = GameGlobals.kickass.scrollPos.x + (this.rect.pos.x - this.rect.size.width / 2) + 'px';
2054
- this.canvas.style.top = GameGlobals.kickass.scrollPos.y + (this.rect.pos.y - this.rect.size.height / 2) + 'px';
2055
- }, drawLine: function (xFrom, yFrom, xTo, yTo) {
2056
- this.ctx.save();
2057
- this.ctx.translate(this.rect.size.width / 2, this.rect.size.height / 2);
2058
- this.ctx.beginPath();
2059
- this.ctx.moveTo(xFrom, yFrom);
2060
- this.ctx.lineTo(xTo, yTo);
2061
- this.ctx.closePath();
2062
- this.ctx.stroke();
2063
- this.ctx.restore();
2064
- }, drawCircle: function (radius, pos) {
2065
- pos = pos || {x: 0, y: 0};
2066
- this.ctx.save();
2067
- this.ctx.translate(this.rect.size.width / 2, this.rect.size.height / 2);
2068
- if (pos)
2069
- this.ctx.translate(pos.x, pos.y);
2070
- this.ctx.beginPath();
2071
- this.ctx.arc(0, 0, radius, 0, Math.PI * 2, true);
2072
- this.ctx.fill();
2073
- this.ctx.closePath();
2074
- this.ctx.restore();
2075
- }, drawRect: function (x, y, w, h) {
2076
- this.ctx.save();
2077
- this.ctx.translate(this.rect.size.width / 2, this.rect.size.height / 2);
2078
- this.ctx.translate(x, y);
2079
- this.ctx.fillRect(x, y, w, h);
2080
- this.ctx.restore();
2081
- this.ctx.fill();
2082
- }, drawImageFull: function (image) {
2083
- this.ctx.drawImage(image, 0, 0, this.rect.size.width, this.rect.size.height);
2084
- }, drawImage: function (image, x, y) {
2085
- this.ctx.save();
2086
- this.ctx.translate(this.rect.size.width / 2 + x, this.rect.size.height / 2 + y);
2087
- this.ctx.rotate(this.angle);
2088
- this.ctx.drawImage(image, 0, -11);
2089
- this.ctx.restore();
2090
- }, setFillColor: function (color) {
2091
- this.ctx.fillStyle = color;
2092
- }, setStrokeColor: function (color) {
2093
- this.ctx.strokeStyle = color;
2094
- }, setLineWidth: function (width) {
2095
- this.ctx.lineWidth = width;
2096
- }, fillPath: function () {
2097
- this.ctx.fill();
2098
- }, strokePath: function () {
2099
- this.ctx.stroke();
2100
- }, clear: function () {
2101
- this.ctx.clearRect(0, 0, this.rect.size.width, this.rect.size.height);
2102
- }, destroy: function () {
2103
- GameGlobals.kickass.unregisterElement(this.canvas);
2104
- this.canvas.parentNode.removeChild(this.canvas);
2105
- }
2106
- });
2107
- var Sheet = new Class({
2108
- initialize: function (rect) {
2109
- this.rect = rect;
2110
- this.drawer = new SheetCanvas(rect);
2111
- }, clear: function () {
2112
- this.drawer.clear();
2113
- }, setPosition: function (pos) {
2114
- this.rect.pos = pos.cp();
2115
- this.drawer.rect = this.rect;
2116
- this.drawer.updateCanvas();
2117
- }, setAngle: function (angle) {
2118
- this.drawer.setAngle(angle);
2119
- }, drawPlayer: function (verts) {
2120
- this.drawer.setFillColor('white');
2121
- this.drawer.setStrokeColor('black');
2122
- this.drawer.setLineWidth(1.5);
2123
- this.drawer.tracePoly(verts);
2124
- this.drawer.fillPath();
2125
- this.drawer.tracePoly(verts);
2126
- this.drawer.strokePath();
2127
- }, drawBrokenPlayer: function (verts, lineOffsets) {
2128
- this.drawer.setStrokeColor('black');
2129
- this.drawer.setLineWidth(1.5);
2130
- for (var i = 1, vert, lastVert = verts[0]; vert = verts[i]; i++, lastVert = vert) {
2131
- var o = lineOffsets[i - 1];
2132
- this.drawer.drawLine(lastVert.x + o.pos.x, lastVert.x + o.pos.y, vert.x + o.pos.x, vert.y + o.pos.y);
2133
- }
2134
- }, drawFlames: function (flames, angle) {
2135
- this.drawer.setLineWidth(1.5);
2136
- this.drawer.setFillColor('red');
2137
- this.drawer.tracePoly(flames.r);
2138
- this.drawer.fillPath();
2139
- this.drawer.setFillColor('yellow');
2140
- this.drawer.tracePoly(flames.y);
2141
- this.drawer.fillPath();
2142
- }, drawBullet: function () {
2143
- this.drawer.setFillColor(GameGlobals.bulletColor);
2144
- this.drawer.drawCircle(2.5);
2145
- }, drawExplosion: function (particles) {
2146
- for (var i = 0, particle; particle = particles[i]; i++) {
2147
- this.drawer.setFillColor(particle.color);
2148
- this.drawer.drawRect(particle.pos.x, particle.pos.y, 3, 3);
2149
- }
2150
- }, drawFace: function (face) {
2151
- this.drawer.drawImageFull(face);
2152
- }, drawLaser: function (pos, dir) {
2153
- this.clear();
2154
- this.setPosition(pos);
2155
- this.drawer.setAngle(dir.angle());
2156
- this.drawer.drawImage(GameGlobals.laserImage, 0, 0);
2157
- }, transformToSheetCoordinates: function (vec) {
2158
- var ret = vec.cp().sub(new Vector(this.rect.size.width / 2, this.rect.size.height / 2));
2159
- return ret;
2160
- }, destroy: function () {
2161
- this.drawer.destroy();
2162
- }
2163
- });
2164
- var namespace = getGlobalNamespace();
2165
-
2166
- var initKickAss = function () {
2167
- // If an instance of KickAss is already present, we add a player
2168
- if (!namespace.KICKASSGAME) {
2169
- if (namespace.KICKASS_SITE_KEY) {
2170
- var mySite = new MySite(namespace.KICKASS_SITE_KEY);
2171
- mySite.load(function (ok) {
2172
- namespace.KICKASSGAME = GameGlobals.kickass = new KickAss({
2173
- mySite: ok ? mySite : false
2174
- });
2175
-
2176
- namespace.KICKASSGAME.begin();
2177
- });
2178
- } else {
2179
- namespace.KICKASSGAME = GameGlobals.kickass = new KickAss();
2180
- namespace.KICKASSGAME.begin();
2181
- }
2182
- } else {
2183
- namespace.KICKASSGAME.addPlayer();
2184
- }
2185
- };
2186
-
2187
- if (namespace.LAZYLOAD_KICKASS) {
2188
- window.startBrowserBlaster = initKickAss;
2189
- } else {
2190
- initKickAss();
2191
- }
2192
-
2193
- function getAppContainerElement() {
2194
- if (namespace.KICKASS_CONTAINER_ELEMENT) {
2195
- return document.getElementById(namespace.KICKASS_CONTAINER_ELEMENT);
2196
- } else {
2197
- return document.body;
2198
- }
2199
- }
2200
- })(typeof exports != 'undefined' ? exports : window);
1
+ (function(window){var JSONP=function(){var t,e,s,i=0,n=this;return{get:function(a,o,h){for(s in e="?",o=o||{})o.hasOwnProperty(s)&&(e+=encodeURIComponent(s)+"="+encodeURIComponent(o[s])+"&");var r="json"+ ++i;return n[r]=function(t){h(t);try{delete n[r]}catch(t){}n[r]=null},function(e){var s=document.createElement("script"),i=!1;s.src=e,s.async=!0,s.onload=s.onreadystatechange=function(){i||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState||(i=!0,s.onload=s.onreadystatechange=null,s&&s.parentNode&&s.parentNode.removeChild(s))},t||(t=document.getElementsByTagName("head")[0])||(t=document.body),t.appendChild(s)}(a+e+"callback="+r),r}}}(),CORS={request:function(t,e,s){if(this.calledByExtension())return this._callbacks[this._callbackId++]=s,void window.postMessage(JSON.stringify({from:"kickassapp-page",url:t,type:"callApi",params:e}),"*");e=e||{};var i="?";for(key in e)e.hasOwnProperty(key)&&(i+=encodeURIComponent(key)+"="+encodeURIComponent(e[key])+"&");var n=new XMLHttpRequest;n.onreadystatechange=function(){4==n.readyState&&s(JSON.parse(n.responseText))},n.open("GET",t+i),n.withCredentials=!0,n.setRequestHeader("Content-Type","application/json"),n.send()},calledByExtension:function(){return!!document.getElementById("kickass-has-been-initialized-yes-yes-yes")},_callbacks:{},_callbackId:0};function getGlobalNamespace(){return window&&window.INSTALL_SCOPE?window.INSTALL_SCOPE:window}CORS.calledByExtension()&&window.addEventListener("message",(function(t){var e;try{e=JSON.parse(t.data)}catch(t){return}if("kickassapp-extension"===e.from&&"kickassapp-extension-version1"===e.sanityCheck){var s=e.payload;"response"===s.type?(CORS._callbacks[s.requestId](s.body),delete CORS._callbacks[s.requestId]):"destroy"===s.type&&window.KICKASSGAME.destroy()}}),!1);var Class=function(t){var e=function(){return e.$prototyping?this:"function"==typeof this.initialize?this.initialize.apply(this,arguments):void 0};for(var s in t.Extends&&(e.parent=t.Extends,t.Extends.$prototyping=!0,e.prototype=new t.Extends,t.Extends.$prototyping=!1),t)t.hasOwnProperty(s)&&(e.prototype[s]=t[s]);return e};"undefined"!=typeof exports&&(exports.Class=Class);var Vector=new Class({initialize:function(t,e){"object"==typeof t?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)},cp:function(){return new Vector(this.x,this.y)},mul:function(t){return this.x*=t,this.y*=t,this},mulNew:function(t){return new Vector(this.x*t,this.y*t)},div:function(t){return this.x/=t,this.y/=t,this},divNew:function(t){return new Vector(this.x/t,this.y/t)},add:function(t){return this.x+=t.x,this.y+=t.y,this},addNew:function(t){return new Vector(this.x+t.x,this.y+t.y)},sub:function(t){return this.x-=t.x,this.y-=t.y,this},subNew:function(t){return new Vector(this.x-t.x,this.y-t.y)},rotate:function(t){var e=this.x,s=this.y;return this.x=e*Math.cos(t)-Math.sin(t)*s,this.y=e*Math.sin(t)+Math.cos(t)*s,this},rotateNew:function(t){return this.cp().rotate(t)},setAngle:function(t){var e=this.len();return this.x=Math.cos(t)*e,this.y=Math.sin(t)*e,this},setAngleNew:function(t){return this.cp().setAngle(t)},setLength:function(t){var e=this.len();return e?this.mul(t/e):this.x=this.y=t,this},setLengthNew:function(t){return this.cp().setLength(t)},normalize:function(){var t=this.len();return 0==t||(this.x/=t,this.y/=t),this},normalizeNew:function(){return this.cp().normalize()},angle:function(){return Math.atan2(this.y,this.x)},collidesWith:function(t){return this.x>t.x&&this.y>t.y&&this.x<t.x+t.width&&this.y<t.y+t.height},len:function(){var t=Math.sqrt(this.x*this.x+this.y*this.y);return t<.005&&t>-.005?0:t},is:function(t){return"object"==typeof t&&this.x==t.x&&this.y==t.y},dot:function(t){return this.x*t.x+this.y*t.y},inTriangle:function(t,e,s){var i=s.subNew(t),n=e.subNew(t),a=p.subNew(t),o=i.dot(i),h=i.dot(n),r=i.dot(a),l=n.dot(n),c=n.dot(a),d=1/(o*l-h*h),u=(l*r-h*c)*d,m=(o*c-h*r)*d;return u>0&&m>0&&u+m<1},distanceFrom:function(t){return Math.sqrt(Math.pow(this.x-t.x,2),Math.pow(this.y-t.y,2))},toString:function(){return"[Vector("+this.x+", "+this.y+") angle: "+this.angle()+", length: "+this.len()+"]"}});"undefined"!=typeof exports&&(exports.Vector=Vector);var Rect=new Class({initialize:function(t,e,s,i){this.pos=new Vector(t,e),this.size={width:s,height:i}},hasPoint:function(t){return t.x>this.getLeft()&&t.x<this.getRight()&&t.y>this.getTop()&&t.y<this.getBottom()},setLeft:function(t){this.pos.x=t+this.size.width/2},setTop:function(t){this.pos.y=t+this.size.height/2},getLeft:function(){return this.pos.x-this.size.width/2},getTop:function(){return this.pos.y-this.size.height/2},getRight:function(){return this.pos.x+this.size.width/2},getBottom:function(){return this.pos.y+this.size.height/2},cp:function(){return new Rect(this.pos.x,this.pos.y,this.size.width,this.size.height)}});"undefined"!=typeof exports&&(exports.Rect=Rect);var Fx=new Class({initialize:function(){this.listeners=[],this.tweens={},this.running={}},addListener:function(t){this.listeners.push(t)},add:function(t,e){if((e=e||{}).duration=e.duration||500,e.transition=e.transition||Tween.Linear,e.repeats=void 0!==e.repeats&&e.repeats,!e.tweens){var s=e.start||0,i=void 0===e.end?1:e.end;e.tweens=[[s,i]]}this.tweens[t]=e},update:function(t){for(var e in t="number"==typeof t?t:now(),this.tweens)if(this.tweens.hasOwnProperty(e)){if(!this.running[e]){this.tweenStart(e,t);continue}var s=this.tweens[e],i=t-this.running[e].startTime;if(i>s.duration){this.tweenFinished(s,e);continue}for(var n,a=s.transition(i/s.duration),o=[],h=0;n=s.tweens[h];h++){var r=a*(n[1]-n[0])+n[0];o.push(r)}this.fire(e,o,a)}},tweenStart:function(t,e){this.running[t]={startTime:e};for(var s,i=[],n=0;s=this.tweens[t].tweens[n];n++)i.push(s[0]);this.fire(t,i,0)},tweenFinished:function(t,e){for(var s,i=[],n=0;s=t.tweens[n];n++)i.push(s[1]);if(this.fire(e,i,1),!t.repeats)return delete this.running[e],void delete this.tweens[e];this.tweenStart(e,now())},fire:function(t,e,s){for(var i,n=0;i=this.listeners[n];n++)i.set.call(i,t,e,s)}}),Tween={Linear:function(t){return t},Quadratic:function(t){return t*t},Quintic:function(t){return t*t*t},Shake:function(t){return Math.sin(t)}},GameGlobals={FPS:60,useAnimationFrame:!0,boids:{flockRadius:400,size:100},path:function(){return"https://kickassapp.com/"+Array.prototype.slice.call(arguments).join("")},hasCanvas:void 0!==document.createElement("canvas").getContext,bulletColor:"black"};function now(){return(new Date).getTime()}function bind(t,e){return function(){return e.apply(t,arguments)}}function each(t,e,s){if("function"==typeof t.forEach)return t.forEach(e,s),t;for(var i in t)t.hasOwnProperty(i)&&e.call(s||window,t[i],i);return t}function addEvent(t,e,s){t.addEventListener?t.addEventListener(e,s,!1):t.attachEvent&&(t["e"+e+s]=s,t[e+s]=function(){return t["e"+e+s](window.event)},t.attachEvent("on"+e,t[e+s]))}function removeEvent(t,e,s){t.removeEventListener?t.removeEventListener(e,s,!1):t.detachEvent&&(t.detachEvent("on"+e,t[e+s]),t[e+s]=null,t["e"+e+s]=null)}function stopEvent(t){t.stopPropogation&&t.stopPropogation(),t.preventDefault&&t.preventDefault(),t.returnValue=!1}function elementIsContainedIn(t,e){return element.contains?t.contains(e):!!(16&t.compareDocumentPosition(e))}function code(t){var e={38:"up",40:"down",37:"left",39:"right",27:"esc"};return e[t]?e[t]:String.fromCharCode(t)}function random(t,e){return Math.floor(Math.random()*(e-t+1)+t)}function getRect(t){if("function"==typeof t.getBoundingClientRect){var e=t.getBoundingClientRect(),s=window.pageXOffset,i=window.pageYOffset;return{width:e.width,height:e.height,left:e.left+s,top:e.top+i}}e={width:t.offsetWidth,height:t.offsetHeight,left:0,top:0};for(var n=t;n;)e.left+=n.offsetLeft,e.top+=n.offsetTop,n=n.offsetParent;return e}function getCompatElement(){var t=document;return t.compatMode&&"CSS1Compat"!=t.compatMode?t.body:t.documentElement}function getScrollSize(){var t=getCompatElement(),e={x:t.clientWidth,y:t.clientHeight},s=document.body;return{x:Math.max(t.scrollWidth,s.scrollWidth,e.x),y:Math.max(t.scrollHeight,s.scrollHeight,e.y)}}function getStyle(t,e){return t.style[e]?t.style[e]:t.currentStyle?t.currentStyle[e]:document.defaultView.getComputedStyle(t,null).getPropertyValue(e)}function setStyles(t,e){for(var s in e)if(e.hasOwnProperty(s)){var i=e[s];"number"==typeof i&&"opacity"!==s&&"zIndex"!==s&&(i+="px"),t.style[s]=i}}function hasClass(t,e){return t.className.match(new RegExp("(\\s|^)"+e+"(\\s|$)"))}function addClass(t,e){hasClass(t,e)||(t.className+=" "+e)}function removeClass(t,e){if(hasClass(t,e)){var s=new RegExp("(\\s|^)"+e+"(\\s|$)");t.className=t.className.replace(s," ")}}function cloneElement(t){return t.cloneNode(!0)}function newElement(t,e){var s=document.createElement(t);for(var i in e)e.hasOwnProperty(i)&&("styles"===i?setStyles(s,e[i]):s[i]=e[i]);return s}window.GameGlobals=GameGlobals,Array.prototype.indexOf||(Array.prototype.indexOf=function(t){if(null==this)throw new TypeError;var e=Object(this),s=e.length>>>0;if(0===s)return-1;var i=0;if(arguments.length>0&&((i=Number(arguments[1]))!=i?i=0:0!==i&&i!==1/0&&i!==-1/0&&(i=(i>0||-1)*Math.floor(Math.abs(i)))),i>=s)return-1;for(var n=i>=0?i:Math.max(s-Math.abs(i),0);n<s;n++)if(n in e&&e[n]===t)return n;return-1});var requestAnimFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t,e){window.setTimeout(t,1e3/60)};function delay(t,e,s){return setTimeout(bind(s,e),t)}var KickAss=new Class({initialize:function(t){t&&t.mySite&&(this.mySite=t.mySite),this.players=[],this.elements=[],this.weaponClass=Weapons[1].cannonClass,this.scrollPos=new Vector(0,0),this.scrollSize=new Vector(0,0),this.windowSize={width:0,height:0},this.updateWindowInfo(),this.bulletManager=new BulletManager(this),this.bulletManager.updateEnemyIndex(),this.explosionManager=new ExplosionManager(this),this.ui=new UIManager(this),this.bombManager=new BombManager(this),this.menuManager=new MenuManager(this),this.menuManager.create(),void 0!==StatisticsManager&&(this.statisticsManager=new StatisticsManager(this)),this.sessionManager=new SessionManager(this),this.lastUpdate=now(),this.keyMap={},this.keydownEvent=bind(this,this.keydown),this.keyupEvent=bind(this,this.keyup),this.multiplier=10,this.isCampaign()?this.audioManager={explosion:new AudioManager(GameGlobals.path("static/sounds/game/explosion"),["mp3","ogg"]),shot:new AudioManager(GameGlobals.path("static/sounds/game/shot"),["mp3","ogg"])}:this.audioManager={},window.KickAssStyle&&"white"===window.KickAssStyle&&(GameGlobals.bulletColor="white"),addEvent(document,"keydown",this.keydownEvent),addEvent(document,"keyup",this.keyupEvent),addEvent(document,"keypress",this.keydownEvent)},begin:function(){this.addPlayer(),this.sessionManager.isPlaying=!0,GameGlobals.useAnimationFrame||(this.loopTimer=window.setInterval(bind(this,this.loop),1e3/GameGlobals.FPS)),GameGlobals.useAnimationFrame&&requestAnimFrame(bind(this,this.loop))},keydown:function(t){var e=code(t.keyCode);switch(this.keyMap[e]=!0,e){case"left":case"right":case"up":case"down":case"esc":case" ":stopEvent(t)}if("esc"===e)this.destroy()},keyup:function(t){var e=code(t.keyCode);switch(this.keyMap[e]=!1,e){case"left":case"right":case"up":case"down":case"esc":case" ":t.stopPropogation&&t.stopPropogation(),t.preventDefault&&t.preventDefault(),t.returnValue=!1}},loop:function(){var t=now(),e=(t-this.lastUpdate)/1e3;this.updateWindowInfo();for(var s,i=0;s=this.players[i];i++)s.update(e);this.bulletManager.update(e),this.bombManager.update(e),this.explosionManager.update(e),this.ui.update(e),this.statisticsManager&&this.statisticsManager.update(e),this.sessionManager.update(e),this.lastUpdate=t,GameGlobals.useAnimationFrame&&requestAnimFrame(bind(this,this.loop))},addPlayer:function(){var t=Ships.Standard;window.KICKASSSHIP&&window.KICKASSSHIP.points&&(t=KICKASSSHIP),this.mySite&&this.mySite.getShipConfig()&&(t=this.mySite.getShipConfig());var e=new Player(this);e.setShip(t),this.players.push(e),this.explosionManager.addExplosion(e.pos)},registerElement:function(t){if(!t)throw new Error("Can't register unexisting element.");this.elements.push(t)},unregisterElement:function(t){this.elements.splice(this.elements.indexOf(t),1)},isKickAssElement:function(t){for(var e,s=0;e=this.elements[s];s++)if(t===e||elementIsContainedIn(e,t))return!0;return!1},isKeyPressed:function(t){return!!this.keyMap[t]},updateWindowInfo:function(){var t=!!window.ActiveXObject&&"BackCompat"==document.compatMode;this.windowSize={width:document.documentElement.clientWidth,height:document.documentElement.clientHeight},t&&(this.windowSize.width=document.body.clientWidth,this.windowSize.height=document.body.clientHeight),this.menuManager&&this.menuManager.isVisible()&&(this.windowSize.height-=this.menuManager.getHeight()),this.scrollPos.x=window.pageXOffset||document.documentElement.scrollLeft,this.scrollPos.y=window.pageYOffset||document.documentElement.scrollTop,this.scrollSize=getScrollSize()},hideAll:function(){for(var t,e=0;t=this.elements[e];e++)t.style.visibility="hidden"},showAll:function(){for(var t,e=0;t=this.elements[e];e++)t.style.visibility="visible"},updateShips:function(t,e){e||this.ui.showMessage("You're now flying<br /><em>"+t.name+"<em>!!");for(var s,i=0;s=this.players[i];i++)s.setShip(t)},changeWeapon:function(t,e){this.weaponClass=t.cannonClass,e||this.ui.showMessage("Changed to "+t.name.toUpperCase()+"!!!!");for(var s,i=0;s=this.players[i];i++)s.setCannons(t.cannonClass)},changeWeaponById:function(t,e){Weapons[t]&&this.changeWeapon(Weapons[t],e)},flyOutPlayers:function(t,e){for(var s,i=0;s=this.players[i];i++)s.flyTo(t,-s.size.height),s.isBound=!1},flyInPlayers:function(){for(var t,e=0;t=this.players[e];e++)t.flyTo(t.pos.x,100,(function(){this.isBound=!0}))},newRank:function(t){this.ui.showMessage("OMG. You leveled up to: <strong>"+t+"</strong>!<br /><small>Be sure to check what cool new stuff you get in the menu.</small>")},fireBomb:function(){this.bombManager.blow()},destroy:function(){removeEvent(document,"keydown",this.keydownEvent),removeEvent(document,"keypress",this.keydownEvent),removeEvent(document,"keyup",this.keyupEvent);for(var t,e=0;t=this.players[e];e++)t.destroy();this.bulletManager.destroy(),this.explosionManager.destroy(),this.menuManager.destroy(),GameGlobals.useAnimationFrame||clearInterval(this.loopTimer),getGlobalNamespace().KICKASSGAME=!1,this.isCampaign()&&document.location.reload()},isCampaign:function(){return getGlobalNamespace().IS_CLOUDFLARE_GAME},isMySite:function(){return!!getGlobalNamespace().KICKASS_SITE_KEY},shouldShowAd:function(){return!this.mySite&&!this.isCampaign()},shouldShowMenu:function(){return!this.mySite&&!this.isCampaign()},shouldShowHowToImage:function(){return this.mySite||this.isCampaign()}});window.KickAss=KickAss;var StatisticsManager=new Class({initialize:function(t){this.game=t,this.data={},this.data.startedPlaying=now(),this.data.elementsDestroyed=0,this.data.shotsFired=0,this.data.distanceFlownInPixels=0,this.data.totalPointsThisSession=0,this.data.usedThrusters=0,this.lastUpdate=0},usedThrusters:function(){this.data.usedThrusters=1},increaseDistanceWithPixels:function(t){this.data.distanceFlownInPixels+=t},increasePointsGainedWithPoints:function(t){this.data.totalPointsThisSession+=t},addShotFired:function(){this.data.shotsFired++,this.game.audioManager.shot&&this.game.audioManager.shot.play()},addElementsDestroyed:function(){this.data.elementsDestroyed++},update:function(t){this.lastUpdate+=t,this.lastUpdate>.25&&(this.syncWithServer(),this.lastUpdate=0)},syncWithServer:function(){var t=[];for(var e in this.data)this.data.hasOwnProperty(e)&&t.push(e+":"+this.data[e]);this.game.menuManager.sendMessageToMenu("stats:!"+t.join("|"))}}),MySite=new Class({initialize:function(t){this.key=t},load:function(t){CORS.request(GameGlobals.path("mysite/api.json"),{site_key:this.key,url:document.location.toString()},bind(this,(function(e){e&&e.embed?(this.mySiteData=e.embed,t(!0)):t(!1)})))},install:function(){},getShipId:function(){return this.mySiteData&&this.mySiteData.settings.ship},getShipConfig:function(){return this.mySiteData&&this.mySiteData.settings.ship_config},getShareURL:function(){return this.mySiteData&&this.mySiteData.settings.share_url}}),Menu=new Class({initialize:function(t){this.game=t,this.size={height:300}},generate:function(t){this.container=document.createElement("div"),this.container.className="KICKASSELEMENT",this.container.id="kickass-profile-menu",t.appendChild(this.container);var e=getGlobalNamespace().KICKASSSHIPID||"";this.url=GameGlobals.path("intermediate_postmessage.html?url="+encodeURIComponent(getGlobalNamespace().KICKASSURL||document.location.href)+"&origin="+encodeURIComponent(document.location.href)+"&preship="+e+"&is_campaign="+(this.game.isCampaign()?"true":"")+"&is_mysite="+(this.game.isMySite()?"true":"")),this.isSocketReady=!1,this.socketIframe=document.createElement("iframe"),this.socketIframe.frameborder="0",this.socketIframe.className="KICKASSELEMENT",this.socketIframe.width="100%",this.socketIframe.height=this.size.height+"px",this.container.appendChild(this.socketIframe),this.menuOrigin="https://kickassapp.com/".replace(/\/$/,""),this.socketIframe.src=this.url,this.onMessage=bind(this,(function(t){if(t.origin===this.menuOrigin||t.origin===this.menuOrigin.replace("http://","https://")){var e=t.data;if("ready"!==e){var s=e.split(":!");if(2===s.length){var i=s.shift().replace(/^./g,(function(t){return t.charAt(0).toUpperCase()}));"function"==typeof this["messageType"+i]&&this["messageType"+i](s.join(":!"))}}else this.onGameReady()}else console.log("ignoring event from",t.origin)})),window.addEventListener("message",this.onMessage,!1),this.game.registerElement(this.container)},socketPostMessage:function(t){this.socketIframe.contentWindow.postMessage(t,this.menuOrigin)},onGameReady:function(){this.isSocketReady=!0,this.game.registerElement(this.container.getElementsByTagName("iframe")[0]),this.socketPostMessage("url:!"+(getGlobalNamespace().KICKASSURL||document.location.href)),this.game.statisticsManager&&this.game.statisticsManager.syncWithServer(),this.game.menuManager.onGameReady()},sendMessage:function(t){if(this.isSocketReady&&t!=this.lastMessage){try{this.socketPostMessage(t)}catch(t){}this.lastMessage=t}},messageTypeChangeShip:function(t){var e=(t=t.split(","))[0],s=(t[1],"initial"===t[2]);this.shipId!==e&&(s&&getGlobalNamespace().KICKASSSHIP||(this.shipId=e,CORS.request(GameGlobals.path("designer/ship/"+e+"/construction.json"),{ship_id:e,is_initial:s?"1":"0"},bind(this,(function(t){this.game.updateShips(t.data,s);try{window.focus()}catch(t){}}))),s||this.parent.hideMenu()))},messageTypeChangeWeapon:function(t,e){this.game.changeWeaponById(t,e)},messageTypeSetMultiplier:function(t){t=parseInt(t,10),!isNaN(t)&&t&&(this.game.multiplier=t)},messageTypeNewRank:function(t){this.game.newRank(t)},messageTypePlayerMessage:function(t){this.game.ui.showMessage(t)},destroy:function(){this.game.unregisterElement(this.container),this.game.unregisterElement(this.iframe),window.removeEventListener("message",this.onMessage,!1),this.container.parentNode.removeChild(this.container)}}),MenuManager=new Class({initialize:function(t){this.game=t,this.numPoints=0,getGlobalNamespace().KICKASS_INLINE_CSS||this.includeCSS(GameGlobals.path("css/menustyles.css"))},generateDefaults:function(){for(var t in Weapons)Weapons.hasOwnProperty(t)&&this.addWeapon(Weapons[t],t);this.hideBombMenu()},create:function(){this.container=document.createElement("div"),this.container.className="KICKASSELEMENT KICKASShidden "+(this.game.shouldShowMenu()?"":"KICKASSNOMENU"),this.container.id="kickass-menu",this.game.shouldShowMenu()?(this.container.style.bottom="-250px",this.container.style.display="none"):removeClass(this.container,"KICKASShidden"),getAppContainerElement().appendChild(this.container);this.container.innerHTML='<div id="kickass-howto-image" class="KICKASSELEMENT kickass-howto-invisible"></div><div id="kickass-pointstab" style="width: 200px;" class="KICKASSELEMENT"><div id="kickass-bomb-menu" class="KICKASSELEMENT KICKASShidden"><ul id="kickass-bomb-list" class="KICKASSELEMENT"></ul></div><div id="kickass-weapons-menu" class="KICKASSELEMENT KICKASShidden" style="display:none"><ul id="kickass-weapons-list" class="KICKASSELEMENT"></ul></div><div id="kickass-pointstab-wrapper" class="KICKASSELEMENT"><div id="kickass-points" class="KICKASSELEMENT">'+this.numPoints+'</div><div id="kickass-esctoquit" class="KICKASSELEMENT">Press esc to quit</div>'+this.getShareHTML()+"</div></div>",this.pointsTab=document.getElementById("kickass-pointstab"),this.pointsTabWrapper=document.getElementById("kickass-pointstab-wrapper"),this.points=document.getElementById("kickass-points"),this.escToQuit=document.getElementById("kickass-esctoquit"),this.howToImage=document.getElementById("kickass-howto-image"),this.weaponsMenu=document.getElementById("kickass-weapons-menu"),this.weaponsList=document.getElementById("kickass-weapons-list"),this.bombLink=document.getElementById("kickass-bomb-menu");for(var t=this.container.getElementsByTagName("*"),e=0;e<t.length;e++)this.game.registerElement(t[e]);this.game.registerElement(this.container),this.game.shouldShowMenu()?(this.menu=new Menu(this.game),this.menu.parent=this,this.menu.generate(this.container)):setTimeout(function(){this.onGameReady()}.bind(this),100),addEvent(this.bombLink,"click",bind(this,(function(t){stopEvent(t),this.game.fireBomb()}))),addEvent(this.pointsTabWrapper,"click",bind(this,this.toggleMenu)),addEvent(this.weaponsMenu,"click",bind(this,this.toggleWeaponsMenu)),this.generateDefaults()},getShareHTML:function(){return""},onGameReady:function(){this.container.style.display="block",this.game.shouldShowHowToImage()&&(setTimeout(bind(this,(function(){removeClass(this.howToImage,"kickass-howto-invisible")})),10),setTimeout(bind(this,(function(){addClass(this.howToImage,"kickass-howto-invisible")})),4e3))},navigateTo:function(t,e){e||this.showMenu(),this.menu&&this.menu.socketPostMessage("navigate:!"+t)},toggleMenu:function(){this.game.shouldShowMenu()?hasClass(this.container,"KICKASShidden")?this.showMenu():this.hideMenu():this.showMenu()},toggleWeaponsMenu:function(){hasClass(this.weaponsMenu,"KICKASShidden")?this.showWeaponsMenu():this.hideWeaponsMenu()},hideWeaponsMenu:function(){this.weaponsMenu.style.width="",addClass(this.weaponsMenu,"KICKASShidden")},showWeaponsMenu:function(){var t=this.weaponsMenu.getElementsByTagName("li");t=t[t.length-1],this.weaponsMenu.style.width=t.offsetLeft+t.offsetWidth-47+"px",removeClass(this.weaponsMenu,"KICKASShidden")},showMenu:function(){this.game.shouldShowMenu()&&(this.container.style.bottom="",removeClass(this.container,"KICKASShidden"))},hideMenu:function(){this.container.style.bottom="",addClass(this.container,"KICKASShidden")},showBombMenu:function(){this.bombLink.style.width=""},hideBombMenu:function(){this.bombLink.style.width="0px"},getHeight:function(){return this.container.clientHeight},isVisible:function(){return!hasClass(this.container,"KICKASShidden")},addPoints:function(t,e){var s=t*this.game.multiplier;this.numPoints+=s,this.points.innerHTML=this.numPoints,this.game.statisticsManager&&this.game.statisticsManager.increasePointsGainedWithPoints(s),this.game.ui.addPointsBubbleAt(e,s)},includeCSS:function(t){var e=document.createElement("link");e.rel="stylesheet",e.type="text/css",e.href=t,(document.head||document.body).appendChild(e)},sendMessageToMenu:function(t){this.menu&&this.menu.sendMessage(t)},addWeapon:function(t,e){var s=document.createElement("li");s.className="KICKASSELEMENT kickass-weapon-item",s.weapon=t,s.style.backgroundImage="url("+GameGlobals.path("css/gfx/kickass/weap-"+t.id+".png")+")",s.innerHTML='<span class="KICKASSELEMENT">'+t.name+"</span>",this.weaponsList.appendChild(s),addEvent(s,"click",bind(this,(function(s){stopEvent(s),this.changeWeapon(t),this.sendMessageToMenu("changeWeapon:!"+e)})))},changeWeapon:function(t){this.game.changeWeapon(t)},destroy:function(){for(var t=this.container.getElementsByTagName("*"),e=0;e<t.length;e++)this.game.unregisterElement(t[e]);this.game.unregisterElement(this.container),this.menu&&this.menu.destroy(),this.container.parentNode.removeChild(this.container)}}),UIManager=new Class({initialize:function(t){this.UNIQID=0,this.game=t,this.pointBubbles={},this.messages={},this.fx=new Fx,this.fx.addListener(this)},update:function(t){this.fx.update()},set:function(t,e,s){var i=t.split("-")[0],n=t.split("-")[1];if(this.pointBubbles[n]){var a=this.pointBubbles[n];a.style.top=e[0]+"px",a.style.opacity=e[1],1==s&&a.parentNode&&(a.parentNode.removeChild(a),delete this.pointBubbles[n])}else if(this.messages[n]&&"messagedown"==i){(o=this.messages[n]).style.top=e[0]+"px",1==s&&setTimeout(bind(this,(function(){this.fx.add("messageup-"+n,{tweens:[[e[0],-100]],transition:Tween.Quadratic,duration:300})})),o.staytime||4e3)}else if(this.messages[n]&&"messageup"==i){var o;(o=this.messages[n]).style.top=e[0]+"px",1==s&&(o.parentNode.removeChild(o),delete this.messages[n])}},addPointsBubbleAt:function(t,e){var s="bubble"+this.UNIQID++,i=this.game.scrollPos.y+t.y,n=newElement("span",{innerHTML:e,className:"KICKASSELEMENT",styles:{position:"absolute",font:"20px Arial",fontWeight:"bold",opacity:"1",color:"black",textShadow:"#fff 1px 1px 3px",top:i,zIndex:"10000000"}});n.style.left=t.x-n.offsetWidth/2+"px",getAppContainerElement().appendChild(n),this.pointBubbles[s]=n,this.fx.add("bubble-"+s,{tweens:[[i,i-15],[1,0]]})},showMessage:function(t,e){e=e||!1;var s=this.UNIQID++,i=newElement("div",{innerHTML:t,className:"KICKASSELEMENT",id:"kickass-message-"+s,styles:{position:"fixed",top:-100,left:"50%",marginLeft:-150,width:300,background:"#222",opacity:.8,padding:"10px",color:"#fff",textAlign:"center",borderRadius:15,font:"20px Arial",fontWeight:"bold",zIndex:"10000000"}});i.staytime=e,getAppContainerElement().appendChild(i);var n=this.getLowestBubbleY();return i.kickassto=n,this.fx.add("messagedown-"+s,{duration:300,tweens:[[-100,n]],transition:Tween.Quadratic}),this.messages[s]=i,i},getLowestBubbleY:function(){var t=100;for(var e in this.messages)this.messages.hasOwnProperty(e)&&(t=Math.max(this.messages[e].kickassto+this.messages[e].offsetHeight+10,t));return t}}),AudioManager=new Class({initialize:function(t,e){if(this.src=t,this.formats=e,channels=8,this.supportsAudio=void 0!==document.createElement("audio").play,this.supportsAudio){this.numChannels=channels,this.channels=[];for(var s=0;s<this.numChannels;s++)this.channels.push({isPlaying:!1,element:this.prepareElement(this.buildAudioElement())})}},buildAudioElement:function(){for(var t,e={ogg:"audio/ogg",mp3:"audio/mpeg"},s=document.createElement("audio"),i=0;t=this.formats[i];i++){var n=document.createElement("source");n.src=this.src+"."+t,n.type=e[t],s.appendChild(n)}return s},prepareElement:function(t){if(void 0===t.addEventListener)return t;var e=this;return t.addEventListener("ended",(function(s){e.audioEnded(t)}),!1),t},audioEnded:function(t){for(var e,s=0;e=this.channels[s];s++)e.element===t&&(e.isPlaying=!1)},play:function(){if(this.supportsAudio)for(var t,e=0;t=this.channels[e];e++)if(!t.isPlaying)return t.isPlaying=!0,void("function"==typeof t.element.play&&t.element.play())}}),Ships={Standard:{points:[[-10,10],[0,-15],[10,10]],thrusters:[{s:{w:20,h:7},p:{x:0,y:14},a:0}],cannons:[{p:{x:0,y:-15},a:0}]}},PLAYERIDS=0,Player=new Class({initialize:function(t){this.id=PLAYERIDS++,this.game=t,this.tween=!1,this.isBound=!0,this.pos=new Vector(1630,217),this.vel=new Vector(0,0),this.acc=new Vector(0,0),this.dir=new Vector(0,1),this.currentRotation=0,this.isBroken=!1,this.lineOffsets=[],this.deadTime=0,this.friction=.95,this.terminalVelocity=2e3,this.lastPos=new Vector(0,0)},setShip:function(t){this.ship=t,this.verts=[];for(var e,s=0;e=this.ship.points[s];s++)this.verts.push(new Vector(e[0],e[1]));this.verts.push(this.verts[0]),this.thrusters=[],this.cannons=[],this.addThrusters(this.ship.thrusters),this.addCannons(this.ship.cannons),this.size=this.getSizeFromVertsAndObjects(),this.bounds=this.calculateBounds(),this.sheet&&this.sheet.destroy(),this.sheet=new Sheet(new Rect(100,100,this.bounds.x,this.bounds.y)),this.forceRedraw=!0},setCannons:function(t){for(var e,s=[],i=0;e=this.cannons[i];i++){var n=new t(this,this.game,e.pos.x,e.pos.y,e.angle);s.push(n),e.destroy()}this.cannons=s},addThrusters:function(t){for(var e,s=0;e=t[s];s++){var i=new Thruster(e);this.thrusters.push(i)}},addCannons:function(t){for(var e,s=0;e=t[s];s++){var i=new(WeaponMap[e.m]||WeaponMap.cannon).cannonClass(this,this.game,e.p.x,e.p.y,e.a);i.player=this,i.game=this.game,this.cannons.push(i)}},update:function(t){if(this.isBroken){if(!this.lineOffsets.length)for(var e=0;e<this.verts.length-1;e++)this.lineOffsets[e]={pos:new Vector(0,0),dir:new Vector(1,1).setAngle(2*Math.PI*Math.random())};for(e=0;e<this.lineOffsets.length;e++)this.lineOffsets[e].pos.add(this.lineOffsets[e].dir.cp().setLength(50).mul(t));return this.sheet.clear(),this.sheet.setAngle(this.dir.angle()),this.sheet.setPosition(this.pos),this.sheet.drawBrokenPlayer(this.verts,this.lineOffsets),void(now()-this.deadTime>1e3&&(this.isBroken=!1,this.lineOffsets=[],this.randomPos()))}this.tween||(this.game.isKeyPressed("left")||this.game.isKeyPressed("right")?(this.game.isKeyPressed("left")&&this.rotateLeft(t),this.game.isKeyPressed("right")&&this.rotateRight(t)):this.stopRotate(),this.game.isKeyPressed("up")?this.activateThrusters():this.stopThrusters()),this.game.isKeyPressed(" ")?(this.isShooting=!0,this.isBroken||this.shootPressed()):this.isShooting&&(this.isShooting=!1,this.shootReleased()),this.currentRotation&&this.dir.setAngle(this.dir.angle()+this.currentRotation*t);var s=this.acc.mulNew(t).sub(this.vel.mulNew(t*this.friction));this.vel.add(s),this.vel.len()>this.terminalVelocity&&this.vel.setLength(this.terminalVelocity);var i=this.vel.mulNew(t);this.pos.add(i),this.game.statisticsManager&&this.game.statisticsManager.increaseDistanceWithPixels(i.len());var n=!this.acc.is({x:0,y:0});for(e=0;a=this.thrusters[e];e++)a.setIsShown(n),a.update(t);if(this.isBound&&this.checkBounds(),!this.lastPos.is(this.pos)||this.currentRotation||this.forceRedraw){if(this.forceRedraw=!1,this.sheet.clear(),this.sheet.setAngle(this.dir.angle()+Math.PI/2),this.sheet.setPosition(this.pos),n){var a;for(e=0;a=this.thrusters[e];e++)a.drawTo(this.sheet)}this.sheet.drawPlayer(this.verts),this.lastPos=this.pos.cp()}var o;for(e=0;o=this.cannons[e];e++)o.update(t)},randomPos:function(){var t=this.game.windowSize.width,e=this.game.windowSize.height;this.pos=new Vector(random(0,t),random(0,e))},checkBounds:function(){if(!this.tween){var t=this.game.windowSize.width,e=this.game.windowSize.height,s=this.pos.x+this.sheet.rect.size.width/2,i=this.pos.y+this.sheet.rect.size.height/2;s>t?(window.scrollTo(this.game.scrollPos.x+50,this.game.scrollPos.y),this.pos.x=0):this.pos.x<0&&(window.scrollTo(this.game.scrollPos.x-50,this.game.scrollPos.y),this.pos.x=t-this.sheet.rect.size.width/2),i>e?(window.scrollTo(this.game.scrollPos.x,this.game.scrollPos.y+.75*e),this.pos.y=0):this.pos.y<0&&(window.scrollTo(this.game.scrollPos.x,this.game.scrollPos.y-.75*e),this.pos.y=e-this.sheet.rect.size.height/2)}},inRect:function(t){for(var e,s=!1,i=0;e=this.verts[i];i++)t.hasPoint(new Vector(e.x+this.pos.x,e.y+this.pos.y))&&(s=!0);return s},hit:function(t){this.isBroken||(this.isBroken=!0,this.deadTime=now())},activateThrusters:function(){this.game.statisticsManager&&this.game.statisticsManager.usedThrusters(),this.acc=new Vector(500,0).setAngle(this.dir.angle())},stopThrusters:function(){this.acc=new Vector(0,0)},rotateLeft:function(t){this.currentRotation=Math.max(2*-Math.PI,this.currentRotation-10*Math.PI*t)},rotateRight:function(t){this.currentRotation=Math.min(2*Math.PI,this.currentRotation+10*Math.PI*t)},stopRotate:function(){this.currentRotation=0},getSizeFromVertsAndObjects:function(){for(var t,e=0,s=0;t=this.verts[s];s++)e=Math.max(e,new Vector(t).len());var i;for(s=0;i=this.thrusters[s];s++){var n=new Vector(i.pos.x-i.size.width/2,i.pos.y-i.size.height/2).rotate(i.angle),a=new Vector(i.pos.x+i.size.width/2,i.pos.y-i.size.height/2).rotate(i.angle),o=new Vector(i.pos.x-i.size.width/2,i.pos.y+i.size.height/2).rotate(i.angle),h=new Vector(i.pos.x+i.size.width/2,i.pos.y+i.size.height/2).rotate(i.angle);e=Math.max(e,n.len(),a.len(),o.len(),h.len())}return{width:2*e,height:2*e}},calculateBounds:function(){return{x:1*Math.max(this.size.width,this.size.height),y:1*Math.max(this.size.height,this.size.width)}},shootPressed:function(){for(var t,e=0;t=this.cannons[e];e++)t.shootPressed()},shootReleased:function(){for(var t,e=0;t=this.cannons[e];e++)t.shootReleased()},flyTo:function(t,e,s){this.tween={start:{pos:this.pos.cp(),dir:this.dir.cp()},to:new Vector(t,e),callback:s||function(){}},this.tween.time=this.getTimeforTween()},destroy:function(){this.sheet.destroy()}}),Thruster=new Class({initialize:function(t,e){this.pos=new Vector(t.p),this.size={width:t.s.w,height:t.s.h},this.angle=t.a||0,this.ship=e,this.isShown=!1,this.flameY=1,this.fx=new Fx,this.fx.addListener(this),this.flames={r:[],y:[]},this.lastFrameUpdate=0,this.generateFlames()},update:function(t){this.fx.update(),now()-this.lastFrameUpdate>1e3/60&&this.generateFlames()},set:function(t,e){if("flames"===t)this.flameY=e},setIsShown:function(t){!this.isShown&&t&&(this.flameY=0,this.generateFlames(),this.fx.add("flames",{start:this.flameY,end:1,duration:250,transition:Tween.Quintic})),this.isShown=t},drawTo:function(t){t.drawFlames(this.flames,this.angle)},generateFlames:function(){var t=this.size.width,e=.05*this.size.width,s=.8*this.size.width,i=.1*s,n=t/2,a=s/2,o=(this.size.height,this.pos.x),h=this.pos.y-this.size.height/2;function r(t,e){return new Vector(t,e)}this.flames.r=[r(-n+o,h)],this.flames.y=[r(-a+o,h)],this.flames.self=this;for(var l=0;l<t;l+=e)this.flames.r.push(r(l-n+o,this.flameY*random(.7*this.size.height,this.size.height)+h));this.flames.r.push(r(n+o,h));for(l=0;l<s;l+=i)this.flames.y.push(r(l-a+o,this.flameY*random(.4*this.size.height,.7*this.size.height)+h));this.flames.y.push(r(a+o,h)),this.lastFrameUpdate=now();for(var c=r(o,h),d=0;u=this.flames.r[d];d++)u.sub(c).rotate(this.angle).add(c);var u;for(d=0;u=this.flames.y[d];d++)u.sub(c).rotate(this.angle).add(c)}}),BombManager=new Class({initialize:function(t){this.game=t,this.bombShowDelay=30,this.nextBomb=this.bombShowDelay},update:function(t){this.game.isKeyPressed("F")&&this.isReady()&&this.blow(),-1!==this.nextBomb&&this.game.sessionManager.isPlaying&&(this.nextBomb-=t,this.nextBomb<0&&(this.game.menuManager.showBombMenu(),this.nextBomb=-1,this.game.ui.showMessage("BOMB IS READY<br />(lower right corner or F)")))},blow:function(){var t=this.game.ui.showMessage("3...",5e3);delay(1e3,(function(){t.innerHTML="2..."}),this),delay(2e3,(function(){t.innerHTML="1..."}),this),delay(3e3,(function(){t.innerHTML="boom"}),this),delay(3e3,this.blowStuffUp,this),this.nextBomb=this.bombShowDelay},blowStuffUp:function(){this.game.bulletManager.updateEnemyIndex();for(var t,e=this.game.bulletManager.enemyIndex,s=0;(t=e[s])&&s<10;s++){var i=getRect(t),n=new Vector(i.left+i.width/2,i.top+i.height/2);this.game.explosionManager.addExplosion(n,t,MegaParticleExplosion),t.parentNode.removeChild(t)}this.game.menuManager.hideBombMenu(),this.nextBomb=this.bombShowDelay},isReady:function(){return-1===this.nextBomb}}),ELEMENTSTHATARENOTTOBEINCLUDED=["BR","SCRIPT","STYLE","TITLE","META","HEAD","OPTION","OPTGROUP","LINK"],ELEMENTSIZETHRESHOLD=5,BulletManager=new Class({initialize:function(t){this.game=t,this.lastBlink=0,this.blinkActive=!1,this.enemyIndex=[],this.updateDelay=2.5,this.nextUpdate=this.updateDelay},update:function(t){this.game.isKeyPressed("B")?this.blink():this.blinkActive&&this.endBlink(),this.nextUpdate-=t,this.nextUpdate<0&&this.updateEnemyIndex()},blink:function(){if(now()-this.lastBlink>250){for(var t,e=0;t=this.enemyIndex[e];e++)this.blinkActive?t.style.outline=t.KICKASSOLDBORDER:t.style.outline="1px solid red";this.blinkActive=!this.blinkActive,this.lastBlink=now(),this.blinkActive||this.updateEnemyIndex()}},endBlink:function(){for(var t,e=0;t=this.enemyIndex[e];e++)t.style.outline=t.KICKASSOLDBORDER;this.lastBlink=0,this.blinkActive=!1},updateEnemyIndex:function(){var t=document.getElementsByTagName("*");this.enemyIndex=[];for(var e,s=0;e=t[s];s++)this.isDestroyable(e)&&(this.enemyIndex.push(e),e.KICKASSOLDBORDER=e.style.outline||document.defaultView.getComputedStyle(e,null).outline);this.nextUpdate=this.updateDelay},isDestroyable:function(t,e){if(this.shouldIgnoreElement(t,e))return!1;for(var s,i=0;s=t.childNodes[i];i++)if(1===s.nodeType&&-1===ELEMENTSTHATARENOTTOBEINCLUDED.indexOf(s.tagName)&&s.offsetWidth>=ELEMENTSIZETHRESHOLD&&s.offsetHeight>=ELEMENTSIZETHRESHOLD&&"hidden"!==document.defaultView.getComputedStyle(s,null).visibility)return!1;return!0},isDestroyableFromCollision:function(t){return this.isDestroyable(t,!0)},shouldIgnoreElement:function(t,e){return 1!==t.nodeType||(t==document.documentElement||t==document.body||(-1!==ELEMENTSTHATARENOTTOBEINCLUDED.indexOf(t.tagName)||("hidden"==t.style.visibility||"none"==t.style.display||("string"==typeof t.className&&-1!=t.className.indexOf("KICKASSELEMENT")||(!e&&(t.offsetWidth<ELEMENTSIZETHRESHOLD||t.offsetHeight<ELEMENTSIZETHRESHOLD)||((t.offsetLeft<0||t.offsetTop<0)&&((s=getRect(t)).left+s.width<0||s.top+s.height<0)||(s||(s=getRect(t)),s.top>=this.game.scrollSize.y)))))));var s},destroy:function(){for(var t in this.bullets)if(this.bullets.hasOwnProperty(t))for(var e,s=0;e=this.bullets[t][s];s++)e.destroy();this.bullets={}}}),SessionManager=new Class({initialize:function(t){this.game=t,this.isPlaying=!1},update:function(t){this.isPlaying&&0==this.game.bulletManager.enemyIndex.length&&this.weHaveWon()},weHaveWon:function(){this.isPlaying=!1,this.game.ui.showMessage("You're done!"),this.game.isCampaign()?(this.game.menuManager.showMenu(),this.game.menuManager.navigateTo("highscores")):this.game.menuManager.showMenu(),this.game.menuManager.sendMessageToMenu("gameFinished:!")}}),ExplosionManager=new Class({initialize:function(t){this.game=t,this.explosions=[]},update:function(t){for(var e,s=now(),i=0;e=this.explosions[i];i++)s-e.bornAt>(e.ttl||500)?(e.destroy(),this.explosions.splice(i,1)):e.update(t)},addExplosion:function(t,e,s){var i=new(s=s||ParticleExplosion)(t,e);i.game=this.game,i.checkBounds(),this.explosions.push(i),this.game.audioManager.explosion&&this.game.audioManager.explosion.play()},destroy:function(){for(var t,e=0;t=this.explosions[e];e++)t.destroy();this.explosions=[]}}),Cannon=new Class({initialize:function(t,e,s,i,n){this.player=t,this.game=e,this.pos=new Vector(s,i),this.angle=n||0},shootPressed:function(){},shootReleased:function(){},checkCollisions:function(){},getExplosionClass:function(){return ParticleExplosion},update:function(t){this.game.hideAll(),this.checkCollisions(t),this.game.showAll()},checkCollision:function(t){var e=t.checkCollision();return!!e&&(this.game.explosionManager.addExplosion(t.pos,e,this.getExplosionClass()),this.game.menuManager.addPoints(Math.min(e.getElementsByTagName("*").length+1,100),t.pos),e.isShot||e.parentNode.removeChild(e),this.game.statisticsManager&&this.game.statisticsManager.addElementsDestroyed(),!0)},createBullet:function(t){var e=new t(this.getABulletPos(),this.getABulletDir());return e.game=this.game,e.manager=this,e.initCanvas(),e.vel.add(e.vel.cp().setLength(this.player.vel.len())),e},getABulletPos:function(){return this.player.pos.cp().add(this.pos.cp().rotate(this.player.dir.angle()+Math.PI/2))},getABulletDir:function(){return this.player.dir.cp().rotate(this.angle)},destroy:function(){}}),LaserCannon=new Class({Extends:Cannon,initialize:function(t,e,s,i,n){Cannon.prototype.initialize.apply(this,arguments),this.lasers=[]},getExplosionClass:function(){return SplitExplosion},update:function(t){this.lasers.length&&(this.removeOld(),Cannon.prototype.update.call(this,t))},checkCollisions:function(t){for(var e,s=0;e=this.lasers[s];s++)e.update(t),this.checkCollision(e)},removeOld:function(){for(var t,e=0;t=this.lasers[e];e++)t.outOfBounds&&(t.destroy(),this.lasers.splice(e,1))},shootPressed:function(){this.lasers.length>5||now()-this.lastFired<500||(this.lastFired=now(),this.game.statisticsManager&&this.game.statisticsManager.addShotFired(),this.lasers.push(this.createBullet(LaserBullet)))},destroy:function(){if(this.lasers.length){for(var t,e=0;t=this.lasers[e];e++)t.destroy();this.lasers=[]}}}),BallCannon=new Class({Extends:Cannon,initialize:function(){Cannon.prototype.initialize.apply(this,arguments),this.lastFired=0,this.bullets=[]},getExplosionClass:function(){return ParticleExplosion},update:function(t){this.bullets.length&&(this.removeOld(),Cannon.prototype.update.call(this,t))},removeOld:function(){for(var t,e=now(),s=0;t=this.bullets[s];s++)e-t.bornAt>2e3&&(t.destroy(),this.bullets.splice(s,1))},checkCollisions:function(t){for(var e,s=0;e=this.bullets[s];s++)e.update(t),this.checkCollision(e)&&(e.destroy(),this.bullets.splice(s,1))},shootPressed:function(){now()-this.lastFired<200||(this.lastFired=now(),this.addBullet(),this.game.statisticsManager&&this.game.statisticsManager.addShotFired())},addBullet:function(){this.bullets.length>7&&(this.bullets[0].destroy(),this.bullets.shift());var t=this.createBullet(Bullet);this.bullets.push(t)},destroy:function(){for(var t,e=0;t=this.bullets[e];e++)t.destroy();this.bullets=[]}}),Bullet=new Class({initialize:function(t,e){this.pos=t.cp(),this.dir=e,this.vel=new Vector(500,500),this.bornAt=now()},initCanvas:function(){this.sheet=new Sheet(new Rect(this.pos.x,this.pos.y,5,5)),this.sheet.drawBullet()},draw:function(){this.sheet.setPosition(this.pos)},update:function(t){this.pos.add(this.vel.setAngle(this.dir.angle()).mulNew(t)),this.checkBounds(),this.draw()},checkCollision:function(){var t=document.elementFromPoint(this.pos.x,this.pos.y);return t&&3==t.nodeType&&(t=t.parentNode),!(!t||!this.game.bulletManager.isDestroyableFromCollision(t))&&t},checkBounds:function(){var t=this.game.windowSize.width,e=this.game.windowSize.height,s=this.pos.x+this.sheet.rect.size.width/2,i=this.pos.y+this.sheet.rect.size.height/2;s>t?this.pos.x=0:this.pos.x<0&&(this.pos.x=t-this.sheet.rect.size.width/2),i>e?this.pos.y=0:this.pos.y<0&&(this.pos.y=e-this.sheet.rect.size.height/2)},destroy:function(){this.sheet.destroy()}}),LaserBullet=new Class({Extends:Bullet,initialize:function(){Bullet.prototype.initialize.apply(this,arguments),this.vel=new Vector(750,750),this.lastDrawPos=this.pos.cp()},initCanvas:function(){var t=Math.max(GameGlobals.laserImage.width,GameGlobals.laserImage.height);this.sheet=new Sheet(new Rect(0,0,t,t))},update:function(t){Bullet.prototype.update.apply(this,arguments)},draw:function(){this.sheet.drawLaser(this.pos,this.dir),this.lastDrawPos=this.pos.cp()},checkBounds:function(){var t=this.game.windowSize.width,e=this.game.windowSize.height,s=this.pos.x+this.sheet.rect.size.width/2,i=this.pos.y+this.sheet.rect.size.height/2;(s>t||this.pos.x<0)&&(this.outOfBounds=!0),(i>e||this.pos.y<0)&&(this.outOfBounds=!0)},destroy:function(){this.sheet.destroy()}});GameGlobals.laserImage=document.createElement("img"),GameGlobals.laserImage.src=GameGlobals.path("css/gfx/kickass/laser.png");var Explosion=new Class({initialize:function(t,e){this.bornAt=now(),this.pos=t.cp()},update:function(t){},checkBounds:function(){},destroy:function(){}}),ParticleExplosion=new Class({Extends:Explosion,initialize:function(t,e){Explosion.prototype.initialize.apply(this,arguments),this.particleVel=new Vector(150,0),this.particles=[],this.generateParticles(),this.sheet=new Sheet(new Rect(t.x,t.y,250,250))},update:function(t){for(var e,s=0;e=this.particles[s];s++)e.pos.add(e.vel.mulNew(t).mul(random(.5,1)).setAngle(e.dir.angle()));this.sheet.clear(),this.sheet.drawExplosion(this.particles)},generateParticles:function(){for(var t=0,e=GameGlobals.hasCanvas?40:10;t<e;t++)this.particles.push({dir:new Vector(random(0,20)-10,random(0,20)-10).normalize(),vel:this.particleVel.cp(),pos:new Vector(0,0),color:["yellow","red"][random(0,1)]})},checkBounds:function(){var t=this.sheet.rect.getRight(),e=this.sheet.rect.getBottom(),s=this.game.windowSize.width,i=this.game.windowSize.height;t>s&&(this.pos.x-=t-s),e>i&&(this.pos.y-=e-i),this.sheet.setPosition(this.pos)},destroy:function(){this.sheet.destroy()}}),MegaParticleExplosion=new Class({Extends:ParticleExplosion,initialize:function(t,e){Explosion.prototype.initialize.apply(this,arguments),this.particleVel=new Vector(200,0),this.particles=[],this.generateParticles(),this.sheet=new Sheet(new Rect(t.x,t.y,500,500)),this.ttl=2e3,this.generationDelay=.6,this.generationTimes=2,this.nextGenerate=this.generationDelay},update:function(t){this.nextGenerate-=t,this.nextGenerate<=0&&this.generationTimes>0&&(this.nextGenerate=this.generationDelay,this.generateParticles(),this.generationTimes--),ParticleExplosion.prototype.update.call(this,t)}}),SplitExplosion=new Class({Extends:Explosion,initialize:function(t,e){e&&(Explosion.prototype.initialize.apply(this,arguments),this.element=e,this.fx=new Fx,this.fx.addListener(this),this.start())},update:function(t){this.element&&this.fx.update()},set:function(t,e){},start:function(){var t=this.createClones(),e=t[0],s=t[1],i="rotate(-"+random(30,50)+"deg) translate(-100px, 40px)",n="rotate("+random(30,50)+"deg) translate(100px, 40px)";setStyles(e,{transform:i}),setStyles(s,{transform:n}),this.left=e,this.right=s,this.fx.add("opacity",{start:1,end:.5,duration:500})},createClones:function(){var t=getRect(this.element),e=this.createContainer(t),s=this.createContainer(t),i=cloneElement(this.element),n=cloneElement(this.element);addClass(i,"KICKASSELEMENT"),addClass(n,"KICKASSELEMENT");var a={margin:0,overflow:"hidden"};return setStyles(i,a),setStyles(n,a),e.appendChild(i),s.appendChild(n),s.style.left=t.left+t.width/2+"px",s.scrollLeft+=t.width/2,this.element.style.opacity=0,this.element.style.visibility="hidden",this.element.style.display="none",each([e,s],(function(t){t.style.transition="transform 500ms ease-in"}))},createContainer:function(t){var e=document.createElement("div");return setStyles(e,{position:"absolute",left:t.left,top:t.top,width:.5*t.width,height:t.height,overflow:"hidden"}),getAppContainerElement().appendChild(e),e},destroy:function(){try{this.left.parentNode.removeChild(this.left),this.right.parentNode.removeChild(this.right),this.element.parentNode.removeChild(this.element)}catch(t){}}}),Weapons={1:{name:"Cannon",id:"cannon",cannonClass:BallCannon},2:{name:"Laser",id:"laser",cannonClass:LaserCannon}},WeaponMap={cannon:Weapons[1],laser:Weapons[2]},SheetCanvas=new Class({initialize:function(rect){with(this.canvas=document.createElement("canvas"),this.canvas.className="KICKASSELEMENT",this.canvas.style)position="absolute",zIndex="1000000";GameGlobals.kickass.registerElement(this.canvas),this.canvas.getContext&&(this.ctx=this.canvas.getContext("2d")),this.rect=rect,this.angle=0,this.updateCanvas(),getAppContainerElement().appendChild(this.canvas)},tracePoly:function(t){if(t[0]){this.ctx.save(),this.ctx.translate(this.rect.size.width/2,this.rect.size.height/2),this.ctx.rotate(this.angle),this.ctx.beginPath(),this.ctx.moveTo(t[0].x,t[0].y);for(var e=0;e<t.length;e++)this.ctx.lineTo(t[e].x,t[e].y);this.ctx.restore()}},setAngle:function(t){this.angle=t},updateCanvas:function(){this.canvas.width!=this.rect.size.width&&(this.canvas.width=this.rect.size.width),this.canvas.height!=this.rect.size.height&&(this.canvas.height=this.rect.size.height),this.canvas.style.left=GameGlobals.kickass.scrollPos.x+(this.rect.pos.x-this.rect.size.width/2)+"px",this.canvas.style.top=GameGlobals.kickass.scrollPos.y+(this.rect.pos.y-this.rect.size.height/2)+"px"},drawLine:function(t,e,s,i){this.ctx.save(),this.ctx.translate(this.rect.size.width/2,this.rect.size.height/2),this.ctx.beginPath(),this.ctx.moveTo(t,e),this.ctx.lineTo(s,i),this.ctx.closePath(),this.ctx.stroke(),this.ctx.restore()},drawCircle:function(t,e){e=e||{x:0,y:0},this.ctx.save(),this.ctx.translate(this.rect.size.width/2,this.rect.size.height/2),e&&this.ctx.translate(e.x,e.y),this.ctx.beginPath(),this.ctx.arc(0,0,t,0,2*Math.PI,!0),this.ctx.fill(),this.ctx.closePath(),this.ctx.restore()},drawRect:function(t,e,s,i){this.ctx.save(),this.ctx.translate(this.rect.size.width/2,this.rect.size.height/2),this.ctx.translate(t,e),this.ctx.fillRect(t,e,s,i),this.ctx.restore(),this.ctx.fill()},drawImageFull:function(t){this.ctx.drawImage(t,0,0,this.rect.size.width,this.rect.size.height)},drawImage:function(t,e,s){this.ctx.save(),this.ctx.translate(this.rect.size.width/2+e,this.rect.size.height/2+s),this.ctx.rotate(this.angle),this.ctx.drawImage(t,0,-11),this.ctx.restore()},setFillColor:function(t){this.ctx.fillStyle=t},setStrokeColor:function(t){this.ctx.strokeStyle=t},setLineWidth:function(t){this.ctx.lineWidth=t},fillPath:function(){this.ctx.fill()},strokePath:function(){this.ctx.stroke()},clear:function(){this.ctx.clearRect(0,0,this.rect.size.width,this.rect.size.height)},destroy:function(){GameGlobals.kickass.unregisterElement(this.canvas),this.canvas.parentNode.removeChild(this.canvas)}}),Sheet=new Class({initialize:function(t){this.rect=t,this.drawer=new SheetCanvas(t)},clear:function(){this.drawer.clear()},setPosition:function(t){this.rect.pos=t.cp(),this.drawer.rect=this.rect,this.drawer.updateCanvas()},setAngle:function(t){this.drawer.setAngle(t)},drawPlayer:function(t){this.drawer.setFillColor("white"),this.drawer.setStrokeColor("black"),this.drawer.setLineWidth(1.5),this.drawer.tracePoly(t),this.drawer.fillPath(),this.drawer.tracePoly(t),this.drawer.strokePath()},drawBrokenPlayer:function(t,e){this.drawer.setStrokeColor("black"),this.drawer.setLineWidth(1.5);for(var s,i=1,n=t[0];s=t[i];i++,n=s){var a=e[i-1];this.drawer.drawLine(n.x+a.pos.x,n.x+a.pos.y,s.x+a.pos.x,s.y+a.pos.y)}},drawFlames:function(t,e){this.drawer.setLineWidth(1.5),this.drawer.setFillColor("red"),this.drawer.tracePoly(t.r),this.drawer.fillPath(),this.drawer.setFillColor("yellow"),this.drawer.tracePoly(t.y),this.drawer.fillPath()},drawBullet:function(){this.drawer.setFillColor(GameGlobals.bulletColor),this.drawer.drawCircle(2.5)},drawExplosion:function(t){for(var e,s=0;e=t[s];s++)this.drawer.setFillColor(e.color),this.drawer.drawRect(e.pos.x,e.pos.y,3,3)},drawFace:function(t){this.drawer.drawImageFull(t)},drawLaser:function(t,e){this.clear(),this.setPosition(t),this.drawer.setAngle(e.angle()),this.drawer.drawImage(GameGlobals.laserImage,0,0)},transformToSheetCoordinates:function(t){return t.cp().sub(new Vector(this.rect.size.width/2,this.rect.size.height/2))},destroy:function(){this.drawer.destroy()}}),namespace=getGlobalNamespace(),initKickAss=function(){if(namespace.KICKASSGAME)namespace.KICKASSGAME.addPlayer();else if(namespace.KICKASS_SITE_KEY){var t=new MySite(namespace.KICKASS_SITE_KEY);t.load((function(e){namespace.KICKASSGAME=GameGlobals.kickass=new KickAss({mySite:!!e&&t}),namespace.KICKASSGAME.begin()}))}else namespace.KICKASSGAME=GameGlobals.kickass=new KickAss,namespace.KICKASSGAME.begin()};function getAppContainerElement(){return namespace.KICKASS_CONTAINER_ELEMENT?document.getElementById(namespace.KICKASS_CONTAINER_ELEMENT):document.body}namespace.LAZYLOAD_KICKASS?window.startBrowserBlaster=initKickAss:initKickAss()})("undefined"!=typeof exports?exports:window);
2
+ //# sourceMappingURL=../maps/js/plane.js.map