jsgamemin.js 41 KB

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