jsgamemin.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  1. var jsGame = window.jsGame || {};
  2. (function () {
  3. window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout;
  4. window.cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCancelAnimationFrame || window.clearTimeout;
  5. String || (String = {});
  6. if (!String.format) String.format = function () {
  7. if (arguments.length == 0) return null;
  8. for (var a = arguments[0], c, d = 1, e = arguments.length; d < e; d++) {
  9. c = RegExp("\\{" + (d - 1) + "\\}", "gm");
  10. a = a.replace(c, arguments[d])
  11. }
  12. return a
  13. };
  14. if (!String.getByteLength) String.getByteLength = function (a) {
  15. var c = 0,
  16. d = a || "",
  17. e = d.length;
  18. for (a = 0; a < e; a++) c += d.charCodeAt(a) >= 0 & d.charCodeAt(a) <= 255 ? 1 : 2;
  19. return c
  20. };
  21. if (!Array || !Array.prototype) Array.prototype = {};
  22. Array.prototype.indexOfAttr = function (a, c) {
  23. for (var d = (typeof a).toLowerCase(), e = -1, l = 0, q = this.length; l < q; l++) if (d == "string" && this[l][a] == c || d == "number" && this[l] == a) {
  24. e = l;
  25. break
  26. }
  27. return e
  28. };
  29. var b = {
  30. canvas: {
  31. id: "jsGameScreen",
  32. defaultId: "jsGameScreen",
  33. defaultFont: "12px Arial",
  34. defaultWidth: 240,
  35. defaultHeight: 320,
  36. defaultColor: "rgb(0, 0, 0)",
  37. bgColor: "#333333",
  38. cavansDoms: [],
  39. ctxs: [],
  40. device: "",
  41. fps: 1,
  42. touch: false,
  43. zoom: 1
  44. },
  45. system: {
  46. loadRes: null,
  47. pageLoad: null,
  48. menu: null,
  49. run: null,
  50. runFn: null,
  51. rafRun: null,
  52. stop: null,
  53. over: null,
  54. zone: null,
  55. active: null,
  56. lastDate: Date.now(),
  57. timeout: 30,
  58. isPause: false,
  59. gameFlow: 0,
  60. zoneArgs: null,
  61. activeArgs: null,
  62. spendTime: 0,
  63. loadResTimer: null,
  64. playTimer: null
  65. },
  66. event: {
  67. key: 0,
  68. keys: {
  69. up: false,
  70. down: false,
  71. left: false,
  72. right: false,
  73. a: false,
  74. b: false,
  75. c: false,
  76. menu: false,
  77. quit: false
  78. },
  79. lastKey: {
  80. up: false,
  81. down: false,
  82. left: false,
  83. right: false,
  84. a: false,
  85. b: false,
  86. c: false,
  87. menu: false,
  88. quit: false
  89. },
  90. pressedKey: {
  91. up: false,
  92. down: false,
  93. left: false,
  94. right: false,
  95. a: false,
  96. b: false,
  97. c: false,
  98. menu: false,
  99. quit: false
  100. },
  101. keyPressCtrl: {
  102. up: true,
  103. down: true,
  104. left: true,
  105. right: true,
  106. a: true,
  107. b: true,
  108. c: true,
  109. menu: true,
  110. quit: true
  111. },
  112. keyDownGo: false,
  113. keyUpGo: false,
  114. keyPressedGo: false,
  115. keyDownCallBack: null,
  116. keyUpCallBack: null,
  117. orientationChange: null,
  118. touchStart: null,
  119. touchEnd: null,
  120. touchMove: null,
  121. touchCancel: null,
  122. clickCallBack: null,
  123. mouseDownCallBack: null,
  124. mouseUpCallBack: null,
  125. mouseMoveCallBack: null,
  126. mouseDowned: false
  127. },
  128. image: {
  129. imgs: {},
  130. imgObjs: [],
  131. initImgs: {},
  132. asyncImgObjs: {},
  133. imgCount: 0,
  134. countLoaded: 0,
  135. reCountLoaded: 0
  136. },
  137. audio: {
  138. audios: [],
  139. fuckSkip: 0
  140. },
  141. ajax: {
  142. xhrObj: null,
  143. pool: [],
  144. poolLength: 5,
  145. date: Date.now(),
  146. isTimeout: false,
  147. param: {
  148. type: "get",
  149. data: null,
  150. dataType: "html",
  151. url: "",
  152. timeout: 5E3,
  153. before: function () { },
  154. success: function () { },
  155. error: function () { },
  156. complete: function () { }
  157. }
  158. },
  159. request: {
  160. gets: []
  161. },
  162. timer: {
  163. lockIds: {}
  164. },
  165. error: {
  166. img: {
  167. msg: "��Դ���س���",
  168. callBack: function () { }
  169. }
  170. }
  171. },
  172. i = {
  173. canvas: {
  174. context: {
  175. base: 0
  176. },
  177. graphics: {
  178. HCENTER: 1,
  179. VCENTER: 2,
  180. LEFT: 4,
  181. RIGHT: 8,
  182. TOP: 16,
  183. BOTTOM: 32,
  184. ANCHOR_LT: 20,
  185. ANCHOR_LV: 6,
  186. ANCHOR_LB: 36,
  187. ANCHOR_HT: 17,
  188. ANCHOR_HV: 3,
  189. ANCHOR_HB: 33,
  190. ANCHOR_RT: 24,
  191. ANCHOR_RV: 10,
  192. ANCHOR_RB: 40
  193. },
  194. trans: {
  195. TRANS_MIRROR: 2,
  196. TRANS_NONE: 0,
  197. TRANS_ROT90: 5,
  198. TRANS_ROT180: 3,
  199. TRANS_ROT270: 6,
  200. TRANS_MIRROR_ROT90: 7,
  201. TRANS_MIRROR_ROT180: 1,
  202. TRANS_MIRROR_ROT270: 4
  203. }
  204. },
  205. event: {
  206. key: {
  207. up: 38,
  208. down: 40,
  209. left: 37,
  210. right: 39,
  211. a: 90,
  212. b: 88,
  213. c: 67,
  214. menu: -6,
  215. quit: -7,
  216. pcmenu: 49,
  217. pcquit: 50
  218. }
  219. },
  220. system: {
  221. gameFlowType: {
  222. menu: 0,
  223. run: 1,
  224. stop: 2,
  225. over: 3,
  226. zone: 4,
  227. active: 5,
  228. loadImage: 6
  229. }
  230. }
  231. },
  232. k = {
  233. getCanvasDom: function () {
  234. var a;
  235. return function () {
  236. a || (a = jsGame.getDom(b.canvas.defaultId));
  237. return a
  238. }
  239. }(),
  240. getOffsetX: function (a) {
  241. return a.offsetX || (a.targetTouches && a.targetTouches[0] ? a.targetTouches[0].clientX - k.getCanvasDom().offsetLeft : a.clientX - k.getCanvasDom().offsetLeft) || 0
  242. },
  243. getOffsetY: function (a) {
  244. return a.offsetY || (a.targetTouches && a.targetTouches[0] ? a.targetTouches[0].clientY - k.getCanvasDom().offsetTop : a.clientY - k.getCanvasDom().offsetTop) || 0
  245. },
  246. keydown: function (a) {
  247. var c = k.checkKey(a.keyCode);
  248. if (b.event.keyDownGo) if (b.event.keys[c] != undefined) b.event.keys[c] = true;
  249. if (b.event.keyUpGo) if (b.event.lastKey[c] != undefined) b.event.lastKey[c] = false;
  250. if (b.event.keyPressCtrl[c] && b.event.keyPressedGo) {
  251. if (b.event.pressedKey[c] != undefined) b.event.pressedKey[c] = true;
  252. b.event.keyPressCtrl[c] = false
  253. }
  254. b.event.keyDownCallBack != null && b.event.keyDownCallBack(a)
  255. },
  256. keyup: function (a) {
  257. var c = k.checkKey(a.keyCode);
  258. if (b.event.keyDownGo) if (b.event.keys[c] != undefined) b.event.keys[c] = false;
  259. if (b.event.keyUpGo) if (b.event.lastKey[c] != undefined) b.event.lastKey[c] = true;
  260. if (b.event.keyPressedGo) {
  261. if (b.event.pressedKey[c] != undefined) b.event.pressedKey[c] = false;
  262. b.event.keyPressCtrl[c] = true
  263. }
  264. b.event.keyUpCallBack != null && b.event.keyUpCallBack(a)
  265. },
  266. orientationchange: function (a) {
  267. b.event.orientationChange != null && b.event.orientationChange(a)
  268. },
  269. touchstart: function (a) {
  270. b.event.touchStart != null && b.event.touchStart(a, k.getOffsetX(a), k.getOffsetY(a))
  271. },
  272. touchend: function (a) {
  273. a.preventDefault();
  274. b.event.touchEnd != null && b.event.touchEnd(a, k.getOffsetX(a), k.getOffsetY(a))
  275. },
  276. touchmove: function (a) {
  277. a.touches.length == 1 && a.preventDefault();
  278. b.event.touchMove != null && b.event.touchMove(a, k.getOffsetX(a), k.getOffsetY(a))
  279. },
  280. touchcancel: function (a) {
  281. b.event.touchCancel != null && b.event.touchCancel(a, k.getOffsetX(a), k.getOffsetY(a))
  282. },
  283. click: function (a) {
  284. b.event.clickCallBack != null && b.event.clickCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
  285. },
  286. mouseDown: function (a) {
  287. b.event.mouseDownCallBack != null && b.event.mouseDownCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
  288. },
  289. mouseUp: function (a) {
  290. b.event.mouseUpCallBack != null && b.event.mouseUpCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
  291. },
  292. mouseMove: function (a) {
  293. b.event.mouseMoveCallBack != null && b.event.mouseMoveCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
  294. },
  295. checkKey: function (a) {
  296. var c = "0";
  297. switch (a) {
  298. case i.event.key.up:
  299. c = "up";
  300. break;
  301. case i.event.key.down:
  302. c = "down";
  303. break;
  304. case i.event.key.left:
  305. c = "left";
  306. break;
  307. case i.event.key.right:
  308. c = "right";
  309. break;
  310. case i.event.key.a:
  311. c = "a";
  312. break;
  313. case i.event.key.b:
  314. c = "b";
  315. break;
  316. case i.event.key.c:
  317. c = "c";
  318. break;
  319. case i.event.key.menu:
  320. c = "menu";
  321. break;
  322. case i.event.key.quit:
  323. c = "quit";
  324. break;
  325. case i.event.key.pcmenu:
  326. c = "menu";
  327. break;
  328. case i.event.key.pcquit:
  329. c = "quit"
  330. }
  331. return c
  332. },
  333. getDeviceConfig: function () {
  334. var a = navigator.userAgent.toLowerCase();
  335. return a.indexOf("duopaosafari") != -1 ? {
  336. device: "duopaoSafari",
  337. fps: 1,
  338. touch: true,
  339. zoom: 1
  340. } : a.indexOf("iphone") != -1 || a.indexOf("ipod") != -1 ? {
  341. device: "iphone",
  342. fps: 1,
  343. touch: true,
  344. zoom: 1
  345. } : a.indexOf("ipad") != -1 ? {
  346. device: "ipad",
  347. fps: 1,
  348. touch: true,
  349. zoom: 1
  350. } : a.indexOf("duopaoandroid") != -1 ? {
  351. device: "duopaoAndroid",
  352. fps: 1,
  353. touch: true,
  354. zoom: 1
  355. } : a.indexOf("duopaowindowsphone") != -1 ? {
  356. device: "duopaoWindowsPhone",
  357. fps: 1,
  358. touch: true,
  359. zoom: 1
  360. } : a.indexOf("opera mobi") != -1 ? {
  361. device: "operamobile",
  362. fps: 1,
  363. touch: true,
  364. zoom: 1
  365. } : a.indexOf("flyflow") != -1 ? {
  366. device: "flyflow",
  367. fps: 1,
  368. touch: true,
  369. zoom: 1
  370. } : a.indexOf("android") != -1 ? {
  371. device: "android",
  372. fps: 1,
  373. touch: true,
  374. zoom: 1
  375. } : a.indexOf("iemobile") != -1 ? {
  376. device: "iemobile",
  377. fps: 1,
  378. touch: false,
  379. zoom: 1
  380. } : a.indexOf("j2me") != -1 ? {
  381. device: "j2me",
  382. fps: 1,
  383. touch: false,
  384. zoom: 1
  385. } : a.indexOf("symbian v5") != -1 ? {
  386. device: "symbian5",
  387. fps: 1,
  388. touch: true,
  389. zoom: 1
  390. } : a.indexOf("symbian v3") != -1 ? {
  391. device: "symbian3",
  392. fps: 1,
  393. touch: false,
  394. zoom: 1
  395. } : a.indexOf("chrome") != -1 ? {
  396. device: "chrome",
  397. fps: 1,
  398. touch: false,
  399. zoom: 1
  400. } : a.indexOf("msie") != -1 ? {
  401. device: "ie",
  402. fps: 0.5,
  403. touch: false,
  404. zoom: 1
  405. } : a.indexOf("safari") != -1 ? {
  406. device: "safari",
  407. fps: 1,
  408. touch: false,
  409. zoom: 1
  410. } : a.indexOf("opera") != -1 ? {
  411. device: "opera",
  412. fps: 1,
  413. touch: false,
  414. zoom: 1
  415. } : a.indexOf("firefox") != -1 ? {
  416. device: "firefox",
  417. fps: 1,
  418. touch: false,
  419. zoom: 1
  420. } : {
  421. device: "",
  422. fps: 1,
  423. touch: false,
  424. zoom: 1
  425. }
  426. },
  427. loadImages: function (a, c) {
  428. if (parseInt(b.image.reCountLoaded) < parseInt(b.image.imgObjs.length * 0.3)) b.image.reCountLoaded += 0.1;
  429. var d = jsGame.canvas.screen.getWidth(),
  430. e = jsGame.canvas.screen.getHeight(),
  431. l = parseInt(d * 0.5),
  432. q = parseInt(d - l >> 1),
  433. s = parseInt(e - 20 >> 1);
  434. a = parseInt(b.image.reCountLoaded) > a ? parseInt(b.image.reCountLoaded) : a;
  435. a = a > c ? c : a;
  436. loadStor = "loading: " + a + " / " + c;
  437. jsGame.canvas.fillStyle(b.canvas.bgColor).fillRect(0, 0, d, e).strokeRect(q, s, l, 20).fillStyle("#FFFFFF").fillRect(q, s, l, 20).fillStyle("#00FFFF").fillRect(q + 1, s + 1, parseInt(a / c * (l - 2)), 18).drawString(loadStor, 0, s + 14, jsGame.graphics.VCENTER, true, "#000000", "#FFFFFF");
  438. loadStor = null
  439. },
  440. setImage: function (a, c, d) {
  441. if (!a || !c) return false;
  442. if (!b.image.imgs[a]) {
  443. b.image.imgs[a] = jsGame.classes.getImage();
  444. b.image.imgs[a].onload = function () {
  445. b.image.countLoaded++;
  446. this.loaded = true
  447. };
  448. b.image.imgs[a].onerror = function () {
  449. var e = jsGame.args.getError("img");
  450. b.image.tips = [e.msg];
  451. e.callBack()
  452. };
  453. b.image.imgs[a].src = c;
  454. b.image.imgs[a].id = a;
  455. b.image.imgs[a].url = c;
  456. b.image.imgs[a].benchId = d
  457. }
  458. },
  459. initImageCallBack: null,
  460. loadImageCallBack: null,
  461. getAnchor: function (a, c, d, e, l) {
  462. switch (l) {
  463. case i.canvas.graphics.ANCHOR_HV:
  464. a -= parseInt(d / 2);
  465. c -= parseInt(e / 2);
  466. break;
  467. case i.canvas.graphics.ANCHOR_LV:
  468. c -= parseInt(e / 2);
  469. break;
  470. case i.canvas.graphics.ANCHOR_RV:
  471. a -= d;
  472. c -= parseInt(e / 2);
  473. break;
  474. case i.canvas.graphics.ANCHOR_HT:
  475. a -= parseInt(d / 2);
  476. break;
  477. case i.canvas.graphics.ANCHOR_RT:
  478. a -= d;
  479. break;
  480. case i.canvas.graphics.ANCHOR_HB:
  481. a -= parseInt(d / 2);
  482. c -= e;
  483. break;
  484. case i.canvas.graphics.ANCHOR_LB:
  485. c -= e;
  486. break;
  487. case i.canvas.graphics.ANCHOR_RB:
  488. a -= d;
  489. c -= e
  490. }
  491. return {
  492. x: a,
  493. y: c
  494. }
  495. },
  496. initUrlParams: function (a) {
  497. if (a.indexOf("?") >= 0) {
  498. var c = a.split("?");
  499. a = [];
  500. if (c[1].indexOf("&") >= 0) a = c[1].split("&");
  501. else a.push(c[1]);
  502. c = [];
  503. for (var d = 0; d < a.length; d++) if (a[d].indexOf("=") >= 0) {
  504. c = a[d].split("=");
  505. b.request.gets[c[0]] = c[1]
  506. }
  507. }
  508. }
  509. };
  510. jsGame = {
  511. init: function (a, c) {
  512. if (!a && !c) {
  513. this.version = 1.8;
  514. this.request.init();
  515. this.events.init();
  516. this.canvas.initDevice()
  517. } else {
  518. b.canvas.defaultWidth = a;
  519. b.canvas.defaultHeight = c
  520. }
  521. return this
  522. },
  523. extend: function (a, c, d) {
  524. d = d || {};
  525. if (c) {
  526. var e = function () { };
  527. e.prototype = c.prototype;
  528. a.prototype = new e;
  529. a.prototype.constructor = a;
  530. e = null
  531. }
  532. for (var l in d) a.prototype[l] = d[l];
  533. d = null;
  534. return a
  535. },
  536. error: function (a) {
  537. throw Error(a);
  538. },
  539. ajax: function (a) {
  540. a && b.ajax.pool.length < b.ajax.poolLength && b.ajax.pool.push(a);
  541. if (a && a.clear) b.ajax.pool = [];
  542. if (b.ajax.xhrObj == null && b.ajax.pool.length > 0) {
  543. b.ajax.xhrObj = this.objExtend(b.ajax.param, b.ajax.pool.shift() || {});
  544. b.ajax.xhrObj.type = b.ajax.xhrObj.type.toUpperCase();
  545. b.ajax.xhrObj.dataType = b.ajax.xhrObj.dataType.toUpperCase();
  546. b.ajax.xhrObj.xhr = jsGame.classes.getAjax();
  547. b.ajax.isTimeout = false;
  548. b.ajax.xhrObj.xhr.onreadystatechange = function () {
  549. if (b.ajax.isTimeout) return false;
  550. if (b.ajax.xhrObj && b.ajax.xhrObj.xhr.readyState == 4) {
  551. if (b.ajax.data) {
  552. clearTimeout(b.ajax.data);
  553. b.ajax.data = null
  554. }
  555. if (b.ajax.xhrObj.xhr.status == 200) {
  556. var e;
  557. switch (b.ajax.xhrObj.dataType) {
  558. case "HTML":
  559. e = b.ajax.xhrObj.xhr.responseText;
  560. break;
  561. default:
  562. e = b.ajax.xhrObj.xhr.responseText.replace(/<[^>].*?>/g, "");
  563. break;
  564. case "JSON":
  565. e = jsGame.getJson(b.ajax.xhrObj.xhr.responseText)
  566. }
  567. b.ajax.xhrObj.success(e, b.ajax.xhrObj);
  568. b.ajax.xhrObj.complete(b.ajax.xhrObj)
  569. } else b.ajax.xhrObj.error(b.ajax.xhrObj.xhr, "error", b.ajax.xhrObj);
  570. b.ajax.xhrObj = null;
  571. jsGame.ajax()
  572. }
  573. };
  574. b.ajax.xhrObj.xhr.open(b.ajax.xhrObj.type, b.ajax.xhrObj.url, true);
  575. b.ajax.xhrObj.before(b.ajax.xhrObj);
  576. b.ajax.xhrObj.type == "POST" && b.ajax.xhrObj.xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
  577. a = null;
  578. var c = b.ajax.xhrObj.data;
  579. if (typeof c == "string") a = c;
  580. else if (typeof c == "object") {
  581. a = [];
  582. for (var d in c) a.push(d + "=" + c[d]);
  583. a = a.join("&")
  584. }
  585. b.ajax.xhrObj.xhr.send(a);
  586. a = c = null;
  587. b.ajax.data = setTimeout(function () {
  588. jsGame.ajax({
  589. clear: true
  590. });
  591. b.ajax.isTimeout = true;
  592. if (b.ajax.xhrObj) {
  593. b.ajax.xhrObj.error(b.ajax.xhrObj.xhr, "timeout", b.ajax.xhrObj);
  594. b.ajax.xhrObj = null
  595. }
  596. }, b.ajax.xhrObj.timeout)
  597. }
  598. return this
  599. },
  600. getDom: function (a) {
  601. try {
  602. return document.getElementById(a)
  603. } catch (c) {
  604. return document.all[a]
  605. }
  606. },
  607. getScript: function () {
  608. var a = document.getElementsByTagName("head")[0],
  609. c = null,
  610. d = null;
  611. _error = _success = null;
  612. _disposed = function () {
  613. if (d) {
  614. clearTimeout(d);
  615. d = null
  616. }
  617. };
  618. return function (e) {
  619. if (!a || c) return false;
  620. e = jsGame.objExtend({
  621. url: "",
  622. before: function () { },
  623. success: function () { },
  624. error: function () { },
  625. timeout: 5E3,
  626. contentType: "text/javascript",
  627. destroyed: true
  628. }, e || {});
  629. if (e.url != "") {
  630. e.before();
  631. c = document.createElement("script");
  632. c.type = e.contentType;
  633. c.async = true;
  634. c.src = e.url;
  635. c.destroyed = e.destroyed;
  636. _success = e.success;
  637. _error = e.error;
  638. c.onload = function () {
  639. _disposed();
  640. if (_success) {
  641. _success();
  642. _success = null
  643. }
  644. this.destroyed && a.removeChild(this);
  645. c = null
  646. };
  647. a.appendChild(c);
  648. _disposed();
  649. d = setTimeout(function () {
  650. _disposed();
  651. if (_error) {
  652. _error("timeout");
  653. _error = null
  654. }
  655. c && c.destroyed && a.removeChild(c);
  656. c = null
  657. }, e.timeout)
  658. }
  659. e = null;
  660. return jsGame
  661. }
  662. }(),
  663. objExtend: function () {
  664. var a = this.clone(arguments[0]) || {},
  665. c = 1,
  666. d = arguments.length,
  667. e = false,
  668. l;
  669. if (typeof a === "boolean") {
  670. e = a;
  671. a = arguments[1] || {};
  672. c = 2
  673. }
  674. if (typeof a !== "object") a = {};
  675. if (d == c) {
  676. a = this;
  677. --c
  678. }
  679. for (; c < d; c++) if ((l = arguments[c]) != null) for (var q in l) {
  680. var s = a[q],
  681. r = l[q];
  682. if (a !== r) if (e && r && typeof r === "object" && !r.nodeType) a[q] = this.objExtend(e, s || (r.length != null ? [] : {}), r);
  683. else if (r !== undefined) a[q] = r
  684. }
  685. return a
  686. },
  687. getJson: function (a) {
  688. var c = {};
  689. try {
  690. c = window.JSON ? JSON.parse(a) : eval("(" + a + ")")
  691. } catch (d) { }
  692. return c
  693. },
  694. clone: function (a) {
  695. var c = a || [];
  696. if (typeof c == "object") if (c.length != undefined) {
  697. a = [];
  698. for (var d = 0, e = c.length; d < e; d++) if (c[d] !== undefined) a[d] = c[d] != null && typeof c[d] == "object" ? c[d].length != undefined ? c[d].slice(0) : c[d] : c[d]
  699. } else {
  700. a = {};
  701. for (d in c) if (c[d] !== undefined) a[d] = c[d] != null && typeof c[d] == "object" ? c[d].length != undefined ? c[d].slice(0) : c[d] : c[d]
  702. }
  703. return a
  704. },
  705. classes: {
  706. init: function (a) {
  707. a.classes.timer.prototype.stop = function () {
  708. if (this.timeout) {
  709. clearTimeout(this.timeout);
  710. this.timeout = null
  711. }
  712. };
  713. a.classes.timer.prototype.start = function (c) {
  714. if (c) {
  715. this.time = this._initTime;
  716. this._dateTime = Date.now()
  717. }
  718. this.stop();
  719. this.timeout = setTimeout(function (d) {
  720. var e = Date.now(),
  721. l = parseInt(Math.round((e - d._dateTime) / d.millisec));
  722. d._dateTime = e;
  723. d.time -= l;
  724. d.callBack ? d.callBack(d) : d.stop();
  725. if (d.time >= 0) d.start();
  726. else {
  727. d.stop();
  728. d.time = 0
  729. }
  730. }, this.millisec, this)
  731. };
  732. a.classes.webSocket.prototype.send = function (c) {
  733. this.socket.send(c)
  734. };
  735. a.classes.webSocket.prototype.close = function () {
  736. this.socket.close()
  737. }
  738. },
  739. getAjax: function () {
  740. return new XMLHttpRequest
  741. },
  742. observer: function () {
  743. this.group = [];
  744. this.register = function (a) {
  745. if (a == null) return this;
  746. jsGame.commandFuns.inArray(a, this.group) == -1 && this.group.push(a);
  747. return this
  748. };
  749. this.unregister = function (a) {
  750. if (a == null) return this;
  751. a = jsGame.commandFuns.inArray(a, this.group);
  752. a > -1 && this.group.splice(a, 1);
  753. return this
  754. };
  755. this.notify = function (a) {
  756. for (var c = 0; c < this.group.length; c++) if (this.group[c] != null) this.group[c](a);
  757. return this
  758. };
  759. this.clear = function () {
  760. this.group.length > 0 && this.group.splice(0, this.group.length);
  761. return this
  762. }
  763. },
  764. getImage: function () {
  765. return new Image
  766. },
  767. timer: function (a, c, d, e, l) {
  768. this.id = a;
  769. this._initTime = c;
  770. this._dateTime = Date.now();
  771. this.time = this._initTime;
  772. this.callBack = d;
  773. this.millisec = e || 1E3;
  774. this.data = l;
  775. this.timeout = null
  776. },
  777. webSocket: function (a, c, d, e, l) {
  778. this.ipPort = a || "";
  779. this.socket = new WebSocket(this.ipPort);
  780. this.socket.onopen = c;
  781. this.socket.onmessage = d;
  782. this.socket.onclose = e;
  783. this.socket.onerror = l
  784. }
  785. },
  786. commandFuns: function () {
  787. var a = {
  788. arr: [],
  789. len: 0,
  790. v: 0
  791. };
  792. return {
  793. registerNotify: function (c, d) {
  794. c != null && c.register(d)
  795. },
  796. rangeRegisterNotify: function (c, d) {
  797. for (var e = 0; e < d.length; e++) jsGame.commandFuns.registerNotify(c, d[e])
  798. },
  799. unRegisterNotify: function (c, d) {
  800. c != null && c.unregister(d)
  801. },
  802. rangeUnRegisterNotify: function (c, d) {
  803. for (var e = 0; e < d.length; e++) jsGame.commandFuns.unRegisterNotify(c, d[e])
  804. },
  805. getRandom: function (c, d) {
  806. if (d) return Math.round(Math.random() * (d - c) + c);
  807. else {
  808. var e = c;
  809. if (!e || e < 0) e = 0;
  810. return Math.round(Math.random() * e)
  811. }
  812. },
  813. getArray: function (c, d) {
  814. a.arr = [];
  815. a.len = c.toString().length;
  816. a.v = c;
  817. for (var e = 0; e < a.len; e++) {
  818. a.arr.push(a.v % 10);
  819. a.v = parseInt(a.v / 10)
  820. }
  821. d || a.arr.reverse();
  822. return a.arr
  823. },
  824. inArray: function (c, d) {
  825. var e, l = d.length;
  826. for (e = 0; e < l; e++) if (c == d[e]) return e;
  827. return -1
  828. },
  829. collisionCheck: function (c, d, e, l, q, s, r, w) {
  830. if (r && Math.abs(c + parseInt(e / 2) - (q + parseInt(r / 2))) < parseInt((e + r) / 2) && Math.abs(d + parseInt(l / 2) - (s + parseInt(w / 2))) < parseInt((l + w) / 2)) return true;
  831. return false
  832. },
  833. circleCollisionCheck: function (c, d, e, l, q, s) {
  834. c = Math.abs(c - l);
  835. d = Math.abs(d - q);
  836. if (Math.sqrt(c * c + d * d) < e + s) return true;
  837. return false
  838. }
  839. }
  840. }(),
  841. args: {
  842. ajax: {
  843. type: "get",
  844. data: null,
  845. dataType: "html",
  846. url: "",
  847. before: function () { },
  848. success: function () { },
  849. error: function (a, c, d) {
  850. this.error(c + "[" + d + "]")
  851. },
  852. complete: function () { }
  853. },
  854. setError: function (a, c, d) {
  855. b.error[a] = {
  856. msg: c,
  857. callBack: d
  858. };
  859. return jsGame
  860. },
  861. getError: function (a) {
  862. if (b.error[a]) return b.error[a];
  863. return {
  864. msg: "",
  865. callBack: function () { }
  866. }
  867. },
  868. setAjax: function (a, c) {
  869. if (b.ajax[a]) b.ajax[a] = c;
  870. return jsGame
  871. },
  872. xhr: null,
  873. gc: {
  874. collectWaitTime: 1E3
  875. }
  876. },
  877. localStorage: function () {
  878. var a, c, d = function () {
  879. var e;
  880. try {
  881. e = window.localStorage;
  882. if (!e.getItem) e.getItem = function () {
  883. return null
  884. };
  885. if (!e.setItem) e.setItem = function () { }
  886. } catch (l) {
  887. e = {
  888. getItem: function () {
  889. return null
  890. },
  891. setItem: function () { }
  892. }
  893. }
  894. return e
  895. };
  896. return {
  897. init: function () {
  898. a = this;
  899. c || (c = d());
  900. return a
  901. },
  902. setItem: function (e, l) {
  903. try {
  904. c.setItem(e, l)
  905. } catch (q) { }
  906. return a
  907. },
  908. getItem: function (e) {
  909. return c.getItem(e)
  910. },
  911. removeItem: function (e) {
  912. c.removeItem(e);
  913. return a
  914. },
  915. clear: function () {
  916. c.clear();
  917. return a
  918. },
  919. key: function (e) {
  920. return c.key(e)
  921. },
  922. getLength: function () {
  923. return c.length
  924. },
  925. base: function () {
  926. return jsGame
  927. }
  928. }
  929. }(),
  930. sessionStorage: function () {
  931. var a, c, d = function () {
  932. var e;
  933. try {
  934. e = window.sessionStorage;
  935. if (!e.getItem) e.getItem = function () {
  936. return null
  937. };
  938. if (!e.setItem) e.setItem = function () { }
  939. } catch (l) {
  940. e = {
  941. getItem: function () {
  942. return null
  943. },
  944. setItem: function () { }
  945. }
  946. }
  947. return e
  948. };
  949. return {
  950. init: function () {
  951. a = this;
  952. c || (c = d());
  953. return a
  954. },
  955. setItem: function (e, l) {
  956. c.setItem(e, l);
  957. return a
  958. },
  959. getItem: function (e) {
  960. return c.getItem(e)
  961. },
  962. removeItem: function (e) {
  963. c.removeItem(e);
  964. return a
  965. },
  966. clear: function () {
  967. c.clear();
  968. return a
  969. },
  970. key: function (e) {
  971. return c.key(e)
  972. },
  973. getLength: function () {
  974. return c.length
  975. },
  976. base: function () {
  977. return jsGame
  978. }
  979. }
  980. }(),
  981. pageLoad: function (a) {
  982. if (b.system.pageLoad == null) {
  983. b.system.pageLoad = a;
  984. this.localStorage.init();
  985. this.sessionStorage.init();
  986. this.canvas.init();
  987. this.audio.init();
  988. this.gameFlow.init();
  989. this.classes.init(this);
  990. this.graphics.ANCHOR_LT = i.canvas.graphics.ANCHOR_LT;
  991. this.graphics.ANCHOR_LV = i.canvas.graphics.ANCHOR_LV;
  992. this.graphics.ANCHOR_LB = i.canvas.graphics.ANCHOR_LB;
  993. this.graphics.ANCHOR_HT = i.canvas.graphics.ANCHOR_HT;
  994. this.graphics.ANCHOR_HV = i.canvas.graphics.ANCHOR_HV;
  995. this.graphics.ANCHOR_HB = i.canvas.graphics.ANCHOR_HB;
  996. this.graphics.ANCHOR_RT = i.canvas.graphics.ANCHOR_RT;
  997. this.graphics.ANCHOR_RV = i.canvas.graphics.ANCHOR_RV;
  998. this.graphics.ANCHOR_RB = i.canvas.graphics.ANCHOR_RB;
  999. a = jsGame.getDom(b.canvas.defaultId);
  1000. if (jsGame.canvas.screen.getTouch()) {
  1001. window.addEventListener("orientationchange", k.orientationchange, false);
  1002. a.ontouchstart = k.touchstart;
  1003. a.ontouchend = k.touchend;
  1004. a.ontouchmove = k.touchmove;
  1005. a.ontouchcancel = k.touchcancel
  1006. } else {
  1007. document.onkeydown = k.keydown;
  1008. document.onkeyup = k.keyup;
  1009. if (jsGame.canvas.screen.getDevice() != "j2me" && jsGame.canvas.screen.getDevice().indexOf("symbian") == -1) {
  1010. a.onclick = k.click;
  1011. a.onmousedown = k.mouseDown;
  1012. a.onmouseup = k.mouseUp;
  1013. a.onmousemove = k.mouseMove;
  1014. if (b.canvas.device == "iemobile") try {
  1015. window.external.notify("RM," + b.canvas.id + ",0,0," + jsGame.canvas.screen.getWidth() + "," + jsGame.canvas.screen.getHeight() + ",0")
  1016. } catch (c) { }
  1017. }
  1018. }
  1019. a = null;
  1020. if (k.initImageCallBack == null) k.initImageCallBack = k.loadImages;
  1021. this.canvas.fillStyle(b.canvas.bgColor).fillRect(0, 0, jsGame.canvas.screen.getWidth(), jsGame.canvas.screen.getHeight());
  1022. b.system.gameFlow = i.system.gameFlowType.run;
  1023. if (b.system.loadRes == null) {
  1024. b.system.loadRes = function () {
  1025. var d = b.image.imgObjs.length - 1;
  1026. k.initImageCallBack(b.image.countLoaded > d ? d : b.image.countLoaded, d);
  1027. if (b.system.loadResTimer) {
  1028. clearTimeout(b.system.loadResTimer);
  1029. b.system.loadResTimer = null
  1030. }
  1031. if (b.image.countLoaded == b.image.imgObjs.length) {
  1032. b.system.pageLoad(jsGame);
  1033. b.image.imgObjs = [];
  1034. b.image.initImgs = {};
  1035. b.image.countLoaded = 0;
  1036. b.image.reCountLoaded = 0;
  1037. clearTimeout(b.system.loadRes);
  1038. b.system.loadRes = null
  1039. } else b.system.loadResTimer = setTimeout(b.system.loadRes, b.system.timeout)
  1040. };
  1041. b.system.loadRes()
  1042. }
  1043. }
  1044. },
  1045. menu: function (a) {
  1046. if (b.system.menu == null && typeof a == "function") {
  1047. b.system.gameFlow = i.system.gameFlowType.menu;
  1048. b.system.menu = a
  1049. }
  1050. return this
  1051. },
  1052. run: function (a) {
  1053. if (b.system.run == null) {
  1054. if (b.system.runFn == null) b.system.runFn = a;
  1055. b.system.run = function () {
  1056. var c = Date.now();
  1057. switch (b.system.gameFlow) {
  1058. case i.system.gameFlowType.menu:
  1059. b.system.menu();
  1060. break;
  1061. case i.system.gameFlowType.run:
  1062. b.system.runFn();
  1063. break;
  1064. case i.system.gameFlowType.stop:
  1065. b.system.stop();
  1066. break;
  1067. case i.system.gameFlowType.over:
  1068. b.system.over();
  1069. break;
  1070. case i.system.gameFlowType.zone:
  1071. b.system.zone(b.system.zoneArgs);
  1072. break;
  1073. case i.system.gameFlowType.active:
  1074. b.system.active(b.system.activeArgs);
  1075. break;
  1076. case i.system.gameFlowType.loadImage:
  1077. if (k.loadImageCallBack != null) {
  1078. var d = b.image.imgCount - 1,
  1079. e = b.image.countLoaded > d ? d : b.image.countLoaded;
  1080. k.loadImageCallBack(e, d);
  1081. if (e == d) {
  1082. b.image.imgObjs = [];
  1083. b.image.countLoaded = 0;
  1084. jsGame.gameFlow.run()
  1085. }
  1086. if (b.image.imgObjs.length > 0) if (d = b.image.imgObjs.shift()) if (b.image.imgs[d.id]) b.image.countLoaded++;
  1087. else k.setImage(d.id, d.src, d.benchId)
  1088. }
  1089. }
  1090. b.system.spendTime = Date.now() - c
  1091. };
  1092. jsGame.play()
  1093. }
  1094. return this
  1095. },
  1096. stop: function (a) {
  1097. if (b.system.stop == null && typeof a == "function") b.system.stop = a;
  1098. return this
  1099. },
  1100. over: function (a) {
  1101. if (b.system.over == null && typeof a == "function") b.system.over = a;
  1102. return this
  1103. },
  1104. zone: function (a) {
  1105. if (b.system.zone == null && typeof a == "function") b.system.zone = a;
  1106. return this
  1107. },
  1108. active: function (a) {
  1109. if (b.system.active == null && typeof a == "function") b.system.active = a;
  1110. return this
  1111. },
  1112. play: function () {
  1113. if (!b.system.playTimer) {
  1114. b.system.isPause = false;
  1115. (b.system.rafRun = function () {
  1116. var a = Date.now();
  1117. if (a - b.system.lastDate >= b.system.timeout - b.system.spendTime) {
  1118. b.system.lastDate = a;
  1119. b.system.isPause || b.system.run()
  1120. }
  1121. if (b.system.rafRun) b.system.playTimer = requestAnimationFrame(b.system.rafRun)
  1122. })()
  1123. }
  1124. return this
  1125. },
  1126. pause: function () {
  1127. if (b.system.playTimer) {
  1128. b.system.isPause = true;
  1129. b.system.rafRun = null;
  1130. cancelAnimationFrame(b.system.playTimer);
  1131. b.system.playTimer = null
  1132. }
  1133. return this
  1134. },
  1135. gameFlow: function () {
  1136. var a;
  1137. return {
  1138. init: function () {
  1139. return a = this
  1140. },
  1141. menu: function () {
  1142. if (b.system.menu != null) b.system.gameFlow = i.system.gameFlowType.menu;
  1143. return a
  1144. },
  1145. run: function () {
  1146. if (b.system.run != null) b.system.gameFlow = i.system.gameFlowType.run;
  1147. return a
  1148. },
  1149. stop: function () {
  1150. if (b.system.stop != null) b.system.gameFlow = i.system.gameFlowType.stop;
  1151. return a
  1152. },
  1153. over: function () {
  1154. if (b.system.over != null) b.system.gameFlow = i.system.gameFlowType.over;
  1155. return a
  1156. },
  1157. zone: function (c) {
  1158. if (b.system.zone != null) {
  1159. b.system.gameFlow = i.system.gameFlowType.zone;
  1160. b.system.zoneArgs = c
  1161. }
  1162. return a
  1163. },
  1164. active: function (c) {
  1165. if (b.system.active != null) {
  1166. b.system.gameFlow = i.system.gameFlowType.active;
  1167. b.system.activeArgs = c
  1168. }
  1169. return a
  1170. },
  1171. base: function () {
  1172. return jsGame
  1173. }
  1174. }
  1175. }(),
  1176. keyIsPressed: function (a) {
  1177. if (!b.event.keyDownGo) b.event.keyDownGo = true;
  1178. return b.event.keys[a]
  1179. },
  1180. keyPressed: function (a) {
  1181. if (a) {
  1182. if (!b.event.keyPressedGo) b.event.keyPressedGo = true;
  1183. var c = b.event.pressedKey[a];
  1184. b.event.pressedKey[a] = false;
  1185. return c
  1186. } else {
  1187. if (this.keyPressed("up")) return true;
  1188. else if (this.keyPressed("down")) return true;
  1189. else if (this.keyPressed("left")) return true;
  1190. else if (this.keyPressed("right")) return true;
  1191. else if (this.keyPressed("a")) return true;
  1192. else if (this.keyPressed("b")) return true;
  1193. else if (this.keyPressed("c")) return true;
  1194. else if (this.keyPressed("menu")) return true;
  1195. else if (this.keyPressed("quit")) return true;
  1196. return false
  1197. }
  1198. },
  1199. keyIsUnPressed: function (a) {
  1200. if (!b.event.keyUpGo) b.event.keyUpGo = true;
  1201. var c = b.event.lastKey[a];
  1202. b.event.lastKey[a] = false;
  1203. return c
  1204. },
  1205. keyReleased: function (a) {
  1206. if (a) return this.keyIsUnPressed(a);
  1207. else {
  1208. if (this.keyReleased("up")) return true;
  1209. else if (this.keyReleased("down")) return true;
  1210. else if (this.keyReleased("left")) return true;
  1211. else if (this.keyReleased("right")) return true;
  1212. else if (this.keyReleased("a")) return true;
  1213. else if (this.keyReleased("b")) return true;
  1214. else if (this.keyReleased("c")) return true;
  1215. else if (this.keyReleased("menu")) return true;
  1216. else if (this.keyReleased("quit")) return true;
  1217. return false
  1218. }
  1219. },
  1220. keyRepeated: function (a) {
  1221. if (a) return this.keyIsPressed(a);
  1222. else {
  1223. if (this.keyRepeated("up")) return true;
  1224. else if (this.keyRepeated("down")) return true;
  1225. else if (this.keyRepeated("left")) return true;
  1226. else if (this.keyRepeated("right")) return true;
  1227. else if (this.keyRepeated("a")) return true;
  1228. else if (this.keyRepeated("b")) return true;
  1229. else if (this.keyRepeated("c")) return true;
  1230. else if (this.keyRepeated("menu")) return true;
  1231. else if (this.keyRepeated("quit")) return true;
  1232. return false
  1233. }
  1234. },
  1235. canvas: function () {
  1236. var a, c, d, e, l, q, s, r, w, x, y;
  1237. return {
  1238. init: function () {
  1239. a = this;
  1240. d = {
  1241. x: 0,
  1242. y: 0
  1243. };
  1244. e = {
  1245. fillColor: "#000000",
  1246. strokeColor: "#000000"
  1247. };
  1248. l = {
  1249. x: 0,
  1250. y: 0
  1251. };
  1252. q = {
  1253. x: 0,
  1254. y: 0
  1255. };
  1256. s = {
  1257. x: 0,
  1258. y: 0,
  1259. fillStyle: "#FFFFFF",
  1260. strokeStyle: "#CCCCCC"
  1261. };
  1262. return a.pass()
  1263. },
  1264. initDevice: function () {
  1265. w = k.getDeviceConfig();
  1266. b.canvas.device = w.device;
  1267. b.canvas.fps = w.fps;
  1268. b.canvas.touch = w.touch;
  1269. b.canvas.zoom = w.zoom;
  1270. return a
  1271. },
  1272. pass: function (f, g, j) {
  1273. var h;
  1274. h = !f || f == "" ? b.canvas.defaultId : f;
  1275. if (!b.canvas.ctxs[h]) {
  1276. f = f ? document.createElement("canvas") : a.base().getDom(h);
  1277. b.canvas.ctxs[h] = null;
  1278. delete b.canvas.ctxs[h];
  1279. b.canvas.ctxs[h] = f.getContext("2d");
  1280. f.width = g ? g : b.canvas.defaultWidth;
  1281. f.style.width = parseInt(f.width * b.canvas.zoom) + "px";
  1282. f.height = j ? j : b.canvas.defaultHeight;
  1283. f.style.height = parseInt(f.height * b.canvas.zoom) + "px";
  1284. b.canvas.cavansDoms[h] = null;
  1285. delete b.canvas.cavansDoms[h];
  1286. b.canvas.cavansDoms[h] = f
  1287. }
  1288. c = b.canvas.ctxs[h];
  1289. c.font = b.canvas.defaultFont;
  1290. r = b.canvas.cavansDoms[h];
  1291. x = parseInt(r.width);
  1292. y = parseInt(r.height);
  1293. return a.screen.setId(h)
  1294. },
  1295. font: function (f) {
  1296. b.canvas.defaultFont = f;
  1297. c.font = b.canvas.defaultFont;
  1298. return a
  1299. },
  1300. del: function (f) {
  1301. if (b.canvas.ctxs[f]) {
  1302. b.canvas.ctxs[f] = null;
  1303. delete b.canvas.ctxs[f];
  1304. b.canvas.cavansDoms[f] = null;
  1305. delete b.canvas.cavansDoms[f]
  1306. }
  1307. return a
  1308. },
  1309. setCurrent: function (f) {
  1310. return a.pass(f)
  1311. },
  1312. screen: {
  1313. setId: function (f) {
  1314. if (b.canvas.ctxs[f]) b.canvas.id = f;
  1315. return a
  1316. },
  1317. getId: function () {
  1318. return b.canvas.id
  1319. },
  1320. getWidth: function () {
  1321. return x
  1322. },
  1323. setWidth: function (f) {
  1324. b.canvas.defaultWidth = f;
  1325. if (r) {
  1326. r.width = b.canvas.defaultWidth;
  1327. r.style.width = r.width + "px";
  1328. x = parseInt(r.width)
  1329. }
  1330. return a
  1331. },
  1332. getHeight: function () {
  1333. return y
  1334. },
  1335. setHeight: function (f) {
  1336. b.canvas.defaultHeight = f;
  1337. if (r) {
  1338. r.height = b.canvas.defaultHeight;
  1339. r.style.height = r.height + "px";
  1340. y = parseInt(r.height)
  1341. }
  1342. return a
  1343. },
  1344. getDevice: function () {
  1345. return b.canvas.device
  1346. },
  1347. getFps: function () {
  1348. return b.canvas.fps
  1349. },
  1350. setFps: function (f) {
  1351. if (f > 0) b.canvas.fps = f;
  1352. return a
  1353. },
  1354. getTouch: function () {
  1355. return b.canvas.touch
  1356. },
  1357. getZoom: function () {
  1358. return b.canvas.zoom
  1359. }
  1360. },
  1361. fillStyle: function (f) {
  1362. c.fillStyle = f;
  1363. return a
  1364. },
  1365. fillRect: function (f, g, j, h, n) {
  1366. j = j ? j : 0;
  1367. h = h ? h : 0;
  1368. if (n) q = k.getAnchor(f, g, j, h, n);
  1369. else {
  1370. q.x = f;
  1371. q.y = g
  1372. }
  1373. c.fillRect(q.x, q.y, j, h);
  1374. return a
  1375. },
  1376. fillText: function (f, g, j, h) {
  1377. c.font = h || b.canvas.defaultFont;
  1378. c.fillText(f, g, j);
  1379. return a
  1380. },
  1381. clearRect: function (f, g, j, h) {
  1382. c.clearRect(f, g, j, h);
  1383. return a
  1384. },
  1385. clearScreen: function () {
  1386. return a.clearRect(0, 0, x, y)
  1387. },
  1388. fillScreen: function () {
  1389. return a.fillRect(0, 0, x, y)
  1390. },
  1391. strokeStyle: function (f) {
  1392. c.strokeStyle = f;
  1393. return a
  1394. },
  1395. lineWidth: function (f) {
  1396. c.lineWidth = f || 1;
  1397. return a
  1398. },
  1399. strokeRect: function (f, g, j, h, n) {
  1400. if (n) l = k.getAnchor(f, g, j, h, n);
  1401. else {
  1402. l.x = f;
  1403. l.y = g
  1404. }
  1405. c.strokeRect(l.x, l.y, j, h);
  1406. return a
  1407. },
  1408. strokeText: function (f, g, j, h) {
  1409. c.font = h || b.canvas.defaultFont;
  1410. c.strokeText(f, g, j);
  1411. return a
  1412. },
  1413. setColor: function (f, g, j) {
  1414. if (j == null) {
  1415. e.fillColor = f;
  1416. e.strokeColor = g ? g : f
  1417. } else {
  1418. e.fillColor = "rgb(" + f + ", " + g + ", " + j + ")";
  1419. e.strokeColor = e.fillColor
  1420. }
  1421. return a.fillStyle(e.fillColor).strokeStyle(e.strokeColor)
  1422. },
  1423. drawImage: function (f, g, j, h, n, p, m, o, t, u) {
  1424. var v = jsGame.getImage(f);
  1425. if (v.src != null) {
  1426. h = h <= 0 ? 0.1 : h;
  1427. n = n <= 0 ? 0.1 : n;
  1428. o = o <= 0 ? 0.1 : o;
  1429. t = t <= 0 ? 0.1 : t;
  1430. if (v.loaded) if (h) if (n) if (u) {
  1431. d = k.getAnchor(p, m, o, t, u);
  1432. c.drawImage(v, g, j, h, n, d.x, d.y, o, t)
  1433. } else c.drawImage(v, g, j, h, n, p, m, o, t);
  1434. else {
  1435. d = k.getAnchor(g, j, jsGame.getImage(f).width, jsGame.getImage(f).height, h);
  1436. c.drawImage(v, d.x, d.y)
  1437. } else c.drawImage(v, g, j);
  1438. else v.benchId && a.drawImage(v.benchId, g, j, h, n, p, m, o, t, u)
  1439. } else if (g = b.image.asyncImgObjs[f]) {
  1440. k.setImage(g.id, g.src, g.benchId);
  1441. b.image.asyncImgObjs[f] = null;
  1442. delete b.image.asyncImgObjs[f]
  1443. }
  1444. return a
  1445. },
  1446. drawRotate: function (f, g, j, h, n, p, m, o, t, u) {
  1447. var v = parseInt(o >> 1),
  1448. z = parseInt(t >> 1),
  1449. A = jsGame.getImage(f);
  1450. f = A ? A : b.canvas.cavansDoms[f];
  1451. p -= v;
  1452. m -= z;
  1453. c.save();
  1454. c.translate(p + v, m + z);
  1455. c.rotate(u * Math.PI / 180);
  1456. c.translate(-(p + v), -(m + z));
  1457. c.drawImage(f, g, j, h, n, p, m, o, t);
  1458. c.restore();
  1459. return a
  1460. },
  1461. drawCache: function (f, g, j, h, n, p, m, o, t, u) {
  1462. if (f = b.canvas.cavansDoms[f]) if (h) if (n) if (u) {
  1463. d = k.getAnchor(p, m, o, t, u);
  1464. c.drawImage(f, g, j, h, n, d.x, d.y, o, t)
  1465. } else c.drawImage(f, g, j, h, n, p, m, o, t);
  1466. else {
  1467. d = k.getAnchor(g, j, f.width, f.height, h);
  1468. c.drawImage(f, d.x, d.y)
  1469. } else c.drawImage(f, g, j);
  1470. return a
  1471. },
  1472. drawRegion: function (f, g, j, h, n, p, m, o) {
  1473. switch (p) {
  1474. default:
  1475. c.setTransform(1, 0, 0, 1, m, o);
  1476. break;
  1477. case i.canvas.trans.TRANS_ROT90:
  1478. c.setTransform(0, 1, -1, 0, n + m, o);
  1479. break;
  1480. case i.canvas.trans.TRANS_ROT180:
  1481. c.setTransform(-1, 0, 0, -1, h + m, n + o);
  1482. break;
  1483. case i.canvas.trans.TRANS_ROT270:
  1484. c.setTransform(0, -1, 1, 0, m, h + o);
  1485. break;
  1486. case i.canvas.trans.TRANS_MIRROR:
  1487. c.setTransform(-1, 0, 0, 1, h + m, o);
  1488. break;
  1489. case i.canvas.trans.TRANS_MIRROR_ROT90:
  1490. c.setTransform(0, -1, -1, 0, n + m, h + o);
  1491. break;
  1492. case i.canvas.trans.TRANS_MIRROR_ROT180:
  1493. c.setTransform(1, 0, 0, -1, m, n + o);
  1494. break;
  1495. case i.canvas.trans.TRANS_MIRROR_ROT270:
  1496. c.setTransform(0, 1, 1, 0, m, o)
  1497. } (jsGame.getImage(f) ? a.drawImage : a.drawCache)(f, g, j, h, n, 0, 0, h, n);
  1498. c.setTransform(1, 0, 0, 1, 0, 0);
  1499. return a
  1500. },
  1501. drawNumber: function (f, g, j, h, n, p, m, o, t) {
  1502. f = f.toString();
  1503. var u = f.length;
  1504. o = o ? o : j;
  1505. t = t ? t : h;
  1506. if (m == "center") {
  1507. n -= parseInt(o * u >> 1);
  1508. for (m = 0; m < u; m++) a.drawImage(g, parseInt(f.charAt(m)) * j, 0, j, h, n + m * o, p, o, t)
  1509. } else if (m == true) for (m = 0; m < u; m++) a.drawImage(g, parseInt(f.charAt(m)) * j, 0, j, h, n + m * o, p, o, t);
  1510. else if (m == false) for (m = u - 1; m >= 0; m--) a.drawImage(g, parseInt(f.charAt(m)) * j, 0, j, h, n - (u - 1 - m) * o, p, o, t, jsGame.graphics.ANCHOR_RT);
  1511. return a
  1512. },
  1513. moveTo: function (f, g) {
  1514. c.moveTo(f, g);
  1515. return a
  1516. },
  1517. lineTo: function (f, g) {
  1518. c.lineTo(f, g);
  1519. return a
  1520. },
  1521. stroke: function () {
  1522. c.stroke();
  1523. return a
  1524. },
  1525. fill: function () {
  1526. c.fill();
  1527. return a
  1528. },
  1529. beginPath: function () {
  1530. c.beginPath();
  1531. return a
  1532. },
  1533. closePath: function () {
  1534. c.closePath();
  1535. return a
  1536. },
  1537. arc: function (f, g, j, h, n, p) {
  1538. c.arc(f, g, j, h, n, p);
  1539. return a
  1540. },
  1541. quadraticCurveTo: function (f, g, j, h) {
  1542. c.quadraticCurveTo(f, g, j, h);
  1543. return a
  1544. },
  1545. bezierCurveTo: function (f, g, j, h, n, p) {
  1546. c.bezierCurveTo(f, g, j, h, n, p);
  1547. return a
  1548. },
  1549. measureText: function (f) {
  1550. var g = c.measureText(f),
  1551. j = g.width;
  1552. g = g.height ? g.height : parseInt(c.font);
  1553. return {
  1554. width: a.screen.getDevice() == "j2me" ? c.measureText(f) : j,
  1555. height: g
  1556. }
  1557. },
  1558. translate: function (f, g) {
  1559. c.translate(f, g);
  1560. return a
  1561. },
  1562. drawLine: function (f, g, j, h) {
  1563. return a.beginPath().moveTo(f, g).lineTo(j, h).closePath().stroke()
  1564. },
  1565. drawRect: function (f, g, j, h, n) {
  1566. return a.strokeRect(f, g, j, h, n)
  1567. },
  1568. drawString: function (f, g, j, h, n, p, m, o) {
  1569. s.x = g;
  1570. s.y = j;
  1571. c.font = o || b.canvas.defaultFont;
  1572. if (h) switch (h) {
  1573. case i.canvas.graphics.LEFT:
  1574. s.x = 0;
  1575. break;
  1576. case i.canvas.graphics.VCENTER:
  1577. s.x = parseInt(a.screen.getWidth() - a.measureText(f).width >> 1);
  1578. break;
  1579. case i.canvas.graphics.RIGHT:
  1580. s.x = a.screen.getWidth() - a.measureText(f).width
  1581. }
  1582. if (n) {
  1583. s.fillStyle = p ? p : "#000000";
  1584. s.strokeStyle = m ? m : "#CCCCCC";
  1585. a.fillStyle(s.strokeStyle).fillText(f, s.x + 1, s.y + 1, o).fillStyle(s.fillStyle)
  1586. }
  1587. return a.fillText(f, s.x, s.y, o).fillStyle(b.canvas.defaultColor)
  1588. },
  1589. drawSubstring: function (f, g, j, h, n, p, m, o, t, u) {
  1590. return a.drawString(f.substring(g, g + j), h, n, p, m, o, t, u)
  1591. },
  1592. clip: function () {
  1593. c.clip();
  1594. return a
  1595. },
  1596. save: function () {
  1597. c.save();
  1598. return a
  1599. },
  1600. restore: function () {
  1601. c.restore();
  1602. return a
  1603. },
  1604. rect: function (f, g, j, h) {
  1605. c.rect(f, g, j, h);
  1606. return a
  1607. },
  1608. rotate: function (f) {
  1609. c.rotate(f);
  1610. return a
  1611. },
  1612. setTransform: function (f, g, j, h, n, p) {
  1613. c.setTransform(f, g, j, h, n, p);
  1614. return a
  1615. },
  1616. scale: function (f, g) {
  1617. c.scale(f, g);
  1618. return a
  1619. },
  1620. globalAlpha: function (f) {
  1621. c.globalAlpha = f || 1;
  1622. return a
  1623. },
  1624. getContext: function () {
  1625. return c
  1626. },
  1627. base: function () {
  1628. return jsGame
  1629. }
  1630. }
  1631. }(),
  1632. initImage: function (a) {
  1633. b.image.imgs = [];
  1634. if (a.length > 0) {
  1635. jsGame.pushImage(a);
  1636. for (var c = 0; c < b.image.imgObjs.length; c++) (a = b.image.imgObjs[c]) && k.setImage(a.id, a.src, a.benchId)
  1637. }
  1638. return this
  1639. },
  1640. loadImage: function (a) {
  1641. if (b.system.gameFlow != i.system.gameFlowType.loadImage && a.length > 0) {
  1642. b.system.gameFlow = i.system.gameFlowType.loadImage;
  1643. b.image.imgObjs = a;
  1644. b.image.imgCount = b.image.imgObjs.length;
  1645. b.image.countLoaded = 0
  1646. }
  1647. return this
  1648. },
  1649. pushImage: function (a) {
  1650. for (var c, d = 0, e = a.length; d < e; d++) if ((c = a[d]) && !b.image.initImgs[c.id]) {
  1651. b.image.initImgs[c.id] = true;
  1652. b.image.imgObjs.push(a[d])
  1653. }
  1654. return this
  1655. },
  1656. asyncImage: function (a) {
  1657. for (var c, d = 0, e = a.length; d < e; d++) {
  1658. c = a[d];
  1659. b.image.asyncImgObjs[c.id] = c
  1660. }
  1661. return this
  1662. },
  1663. initImageCallBack: function (a) {
  1664. if (typeof a == "function") k.initImageCallBack = a;
  1665. return this
  1666. },
  1667. loadImageCallBack: function (a) {
  1668. if (typeof a == "function") k.loadImageCallBack = a;
  1669. return this
  1670. },
  1671. addImage: function (a, c) {
  1672. if (a && c && !b.image.imgs[a]) b.image.imgs[a] = c;
  1673. return this
  1674. },
  1675. getImage: function (a) {
  1676. return b.image.imgs[a] ? b.image.imgs[a] : {
  1677. src: null
  1678. }
  1679. },
  1680. delImage: function (a) {
  1681. if (b.image.imgs[a]) {
  1682. b.image.imgs[a] = null;
  1683. delete b.image.imgs[a]
  1684. }
  1685. return this
  1686. },
  1687. audio: function () {
  1688. var a = null;
  1689. return {
  1690. init: function () {
  1691. return a = this
  1692. },
  1693. play: function (c) {
  1694. if (b.audio.audios[c]) try {
  1695. b.audio.audios[c].paused && b.audio.audios[c].play()
  1696. } catch (d) { }
  1697. return a
  1698. },
  1699. pause: function (c) {
  1700. if (b.audio.audios[c]) try {
  1701. b.audio.audios[c].pause()
  1702. } catch (d) { }
  1703. return a
  1704. },
  1705. noSound: function () {
  1706. for (var c in b.audio.audios) b.audio.audios[c].pause && b.audio.audios[c].pause();
  1707. return a
  1708. },
  1709. load: function (c) {
  1710. if (b.audio.audios[c]) try {
  1711. b.audio.audios[c].load()
  1712. } catch (d) { }
  1713. return a
  1714. },
  1715. replay: function (c) {
  1716. a.pause(c);
  1717. a.load(c);
  1718. a.play(c);
  1719. return a
  1720. },
  1721. fuckAudio: function (c) {
  1722. if (b.audio.audios[c] && b.audio.audios[c].paused) {
  1723. b.audio.fuckSkip++;
  1724. if (b.audio.fuckSkip == 10) {
  1725. a.replay(c);
  1726. b.audio.fuckSkip = 0
  1727. }
  1728. }
  1729. return a
  1730. },
  1731. getAudio: function (c) {
  1732. return b.audio.audios[c]
  1733. }
  1734. }
  1735. }(),
  1736. initAudio: function (a) {
  1737. if (a.length > 0) {
  1738. b.audio.audios = [];
  1739. for (var c, d, e, l, q = 0; q < a.length; q++) if ((c = a[q]) && c.id != "" && c.src != "") {
  1740. d = c.loop;
  1741. e = c.preload;
  1742. l = c.autoplay;
  1743. b.audio.audios[c.id] = new Audio(c.src);
  1744. b.audio.audios[c.id].id = c.id;
  1745. b.audio.audios[c.id].loop = d;
  1746. b.audio.audios[c.id].preload = e;
  1747. b.audio.audios[c.id].autoplay = l
  1748. }
  1749. }
  1750. return this
  1751. },
  1752. setRunFrequency: function (a) {
  1753. b.system.timeout = a;
  1754. return this
  1755. },
  1756. events: function () {
  1757. var a;
  1758. return {
  1759. init: function () {
  1760. return a = this
  1761. },
  1762. keyDown: function (c) {
  1763. if (!b.event.keyDownGo) b.event.keyDownGo = true;
  1764. if (!b.event.keyUpGo) b.event.keyUpGo = true;
  1765. if (!b.event.keyPressedGo) b.event.keyPressedGo = true;
  1766. b.event.keyDownCallBack = c;
  1767. return a
  1768. },
  1769. keyUp: function (c) {
  1770. if (!b.event.keyDownGo) b.event.keyDownGo = true;
  1771. if (!b.event.keyUpGo) b.event.keyUpGo = true;
  1772. if (!b.event.keyPressedGo) b.event.keyPressedGo = true;
  1773. b.event.keyUpCallBack = c;
  1774. return a
  1775. },
  1776. orientationChange: function (c) {
  1777. b.event.orientationChange = c;
  1778. return a
  1779. },
  1780. touchStart: function (c) {
  1781. b.event.touchStart = c;
  1782. return a
  1783. },
  1784. touchEnd: function (c) {
  1785. b.event.touchEnd = c;
  1786. return a
  1787. },
  1788. touchMove: function (c) {
  1789. b.event.touchMove = c;
  1790. return a
  1791. },
  1792. touchCancel: function (c) {
  1793. b.event.touchCancel = c;
  1794. return a
  1795. },
  1796. click: function (c) {
  1797. b.event.clickCallBack = c;
  1798. return a
  1799. },
  1800. mouseDown: function (c) {
  1801. b.event.mouseDownCallBack = c;
  1802. return a
  1803. },
  1804. mouseUp: function (c) {
  1805. b.event.mouseUpCallBack = c;
  1806. return a
  1807. },
  1808. mouseMove: function (c) {
  1809. b.event.mouseMoveCallBack = c;
  1810. return a
  1811. },
  1812. base: function () {
  1813. return jsGame
  1814. }
  1815. }
  1816. }(),
  1817. ui: {},
  1818. graphics: {
  1819. HCENTER: i.canvas.graphics.HCENTER,
  1820. VCENTER: i.canvas.graphics.VCENTER,
  1821. LEFT: i.canvas.graphics.LEFT,
  1822. RIGHT: i.canvas.graphics.RIGHT,
  1823. TOP: i.canvas.graphics.TOP,
  1824. BOTTOM: i.canvas.graphics.BOTTOM
  1825. },
  1826. trans: {
  1827. TRANS_NONE: i.canvas.trans.TRANS_NONE,
  1828. TRANS_ROT90: i.canvas.trans.TRANS_ROT90,
  1829. TRANS_ROT180: i.canvas.trans.TRANS_ROT180,
  1830. TRANS_ROT270: i.canvas.trans.TRANS_ROT270,
  1831. TRANS_MIRROR: i.canvas.trans.TRANS_MIRROR,
  1832. TRANS_MIRROR_ROT90: i.canvas.trans.TRANS_MIRROR_ROT90,
  1833. TRANS_MIRROR_ROT180: i.canvas.trans.TRANS_MIRROR_ROT180,
  1834. TRANS_MIRROR_ROT270: i.canvas.trans.TRANS_MIRROR_ROT270
  1835. },
  1836. request: function () {
  1837. return {
  1838. init: function () {
  1839. k.initUrlParams(location.href)
  1840. },
  1841. get: function (a) {
  1842. return b.request.gets[a] ? b.request.gets[a] : ""
  1843. }
  1844. }
  1845. }()
  1846. }.init()
  1847. })();