123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848 |
- var jsGame = window.jsGame || {};
- (function () {
- window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout;
- window.cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCancelAnimationFrame || window.clearTimeout;
- String || (String = {});
- if (!String.format) String.format = function () {
- if (arguments.length == 0) return null;
- for (var a = arguments[0], c, d = 1, e = arguments.length; d < e; d++) {
- c = RegExp("\\{" + (d - 1) + "\\}", "gm");
- a = a.replace(c, arguments[d])
- }
- return a
- };
- if (!String.getByteLength) String.getByteLength = function (a) {
- var c = 0,
- d = a || "",
- e = d.length;
- for (a = 0; a < e; a++) c += d.charCodeAt(a) >= 0 & d.charCodeAt(a) <= 255 ? 1 : 2;
- return c
- };
- if (!Array || !Array.prototype) Array.prototype = {};
- Array.prototype.indexOfAttr = function (a, c) {
- 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) {
- e = l;
- break
- }
- return e
- };
- var b = {
- canvas: {
- id: "jsGameScreen",
- defaultId: "jsGameScreen",
- defaultFont: "12px Arial",
- defaultWidth: 240,
- defaultHeight: 320,
- defaultColor: "rgb(0, 0, 0)",
- bgColor: "#333333",
- cavansDoms: [],
- ctxs: [],
- device: "",
- fps: 1,
- touch: false,
- zoom: 1
- },
- system: {
- loadRes: null,
- pageLoad: null,
- menu: null,
- run: null,
- runFn: null,
- rafRun: null,
- stop: null,
- over: null,
- zone: null,
- active: null,
- lastDate: Date.now(),
- timeout: 30,
- isPause: false,
- gameFlow: 0,
- zoneArgs: null,
- activeArgs: null,
- spendTime: 0,
- loadResTimer: null,
- playTimer: null
- },
- event: {
- key: 0,
- keys: {
- up: false,
- down: false,
- left: false,
- right: false,
- a: false,
- b: false,
- c: false,
- menu: false,
- quit: false
- },
- lastKey: {
- up: false,
- down: false,
- left: false,
- right: false,
- a: false,
- b: false,
- c: false,
- menu: false,
- quit: false
- },
- pressedKey: {
- up: false,
- down: false,
- left: false,
- right: false,
- a: false,
- b: false,
- c: false,
- menu: false,
- quit: false
- },
- keyPressCtrl: {
- up: true,
- down: true,
- left: true,
- right: true,
- a: true,
- b: true,
- c: true,
- menu: true,
- quit: true
- },
- keyDownGo: false,
- keyUpGo: false,
- keyPressedGo: false,
- keyDownCallBack: null,
- keyUpCallBack: null,
- orientationChange: null,
- touchStart: null,
- touchEnd: null,
- touchMove: null,
- touchCancel: null,
- clickCallBack: null,
- mouseDownCallBack: null,
- mouseUpCallBack: null,
- mouseMoveCallBack: null,
- mouseDowned: false
- },
- image: {
- imgs: {},
- imgObjs: [],
- initImgs: {},
- asyncImgObjs: {},
- imgCount: 0,
- countLoaded: 0,
- reCountLoaded: 0
- },
- audio: {
- audios: [],
- fuckSkip: 0
- },
- ajax: {
- xhrObj: null,
- pool: [],
- poolLength: 5,
- date: Date.now(),
- isTimeout: false,
- param: {
- type: "get",
- data: null,
- dataType: "html",
- url: "",
- timeout: 5E3,
- before: function () { },
- success: function () { },
- error: function () { },
- complete: function () { }
- }
- },
- request: {
- gets: []
- },
- timer: {
- lockIds: {}
- },
- error: {
- img: {
- msg: "��Դ���س���",
- callBack: function () { }
- }
- }
- },
- i = {
- canvas: {
- context: {
- base: 0
- },
- graphics: {
- HCENTER: 1,
- VCENTER: 2,
- LEFT: 4,
- RIGHT: 8,
- TOP: 16,
- BOTTOM: 32,
- ANCHOR_LT: 20,
- ANCHOR_LV: 6,
- ANCHOR_LB: 36,
- ANCHOR_HT: 17,
- ANCHOR_HV: 3,
- ANCHOR_HB: 33,
- ANCHOR_RT: 24,
- ANCHOR_RV: 10,
- ANCHOR_RB: 40
- },
- trans: {
- TRANS_MIRROR: 2,
- TRANS_NONE: 0,
- TRANS_ROT90: 5,
- TRANS_ROT180: 3,
- TRANS_ROT270: 6,
- TRANS_MIRROR_ROT90: 7,
- TRANS_MIRROR_ROT180: 1,
- TRANS_MIRROR_ROT270: 4
- }
- },
- event: {
- key: {
- up: 38,
- down: 40,
- left: 37,
- right: 39,
- a: 90,
- b: 88,
- c: 67,
- menu: -6,
- quit: -7,
- pcmenu: 49,
- pcquit: 50
- }
- },
- system: {
- gameFlowType: {
- menu: 0,
- run: 1,
- stop: 2,
- over: 3,
- zone: 4,
- active: 5,
- loadImage: 6
- }
- }
- },
- k = {
- getCanvasDom: function () {
- var a;
- return function () {
- a || (a = jsGame.getDom(b.canvas.defaultId));
- return a
- }
- }(),
- getOffsetX: function (a) {
- return a.offsetX || (a.targetTouches && a.targetTouches[0] ? a.targetTouches[0].clientX - k.getCanvasDom().offsetLeft : a.clientX - k.getCanvasDom().offsetLeft) || 0
- },
- getOffsetY: function (a) {
- return a.offsetY || (a.targetTouches && a.targetTouches[0] ? a.targetTouches[0].clientY - k.getCanvasDom().offsetTop : a.clientY - k.getCanvasDom().offsetTop) || 0
- },
- keydown: function (a) {
- var c = k.checkKey(a.keyCode);
- if (b.event.keyDownGo) if (b.event.keys[c] != undefined) b.event.keys[c] = true;
- if (b.event.keyUpGo) if (b.event.lastKey[c] != undefined) b.event.lastKey[c] = false;
- if (b.event.keyPressCtrl[c] && b.event.keyPressedGo) {
- if (b.event.pressedKey[c] != undefined) b.event.pressedKey[c] = true;
- b.event.keyPressCtrl[c] = false
- }
- b.event.keyDownCallBack != null && b.event.keyDownCallBack(a)
- },
- keyup: function (a) {
- var c = k.checkKey(a.keyCode);
- if (b.event.keyDownGo) if (b.event.keys[c] != undefined) b.event.keys[c] = false;
- if (b.event.keyUpGo) if (b.event.lastKey[c] != undefined) b.event.lastKey[c] = true;
- if (b.event.keyPressedGo) {
- if (b.event.pressedKey[c] != undefined) b.event.pressedKey[c] = false;
- b.event.keyPressCtrl[c] = true
- }
- b.event.keyUpCallBack != null && b.event.keyUpCallBack(a)
- },
- orientationchange: function (a) {
- b.event.orientationChange != null && b.event.orientationChange(a)
- },
- touchstart: function (a) {
- b.event.touchStart != null && b.event.touchStart(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- touchend: function (a) {
- a.preventDefault();
- b.event.touchEnd != null && b.event.touchEnd(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- touchmove: function (a) {
- a.touches.length == 1 && a.preventDefault();
- b.event.touchMove != null && b.event.touchMove(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- touchcancel: function (a) {
- b.event.touchCancel != null && b.event.touchCancel(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- click: function (a) {
- b.event.clickCallBack != null && b.event.clickCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- mouseDown: function (a) {
- b.event.mouseDownCallBack != null && b.event.mouseDownCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- mouseUp: function (a) {
- b.event.mouseUpCallBack != null && b.event.mouseUpCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- mouseMove: function (a) {
- b.event.mouseMoveCallBack != null && b.event.mouseMoveCallBack(a, k.getOffsetX(a), k.getOffsetY(a))
- },
- checkKey: function (a) {
- var c = "0";
- switch (a) {
- case i.event.key.up:
- c = "up";
- break;
- case i.event.key.down:
- c = "down";
- break;
- case i.event.key.left:
- c = "left";
- break;
- case i.event.key.right:
- c = "right";
- break;
- case i.event.key.a:
- c = "a";
- break;
- case i.event.key.b:
- c = "b";
- break;
- case i.event.key.c:
- c = "c";
- break;
- case i.event.key.menu:
- c = "menu";
- break;
- case i.event.key.quit:
- c = "quit";
- break;
- case i.event.key.pcmenu:
- c = "menu";
- break;
- case i.event.key.pcquit:
- c = "quit"
- }
- return c
- },
- getDeviceConfig: function () {
- var a = navigator.userAgent.toLowerCase();
- return a.indexOf("duopaosafari") != -1 ? {
- device: "duopaoSafari",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("iphone") != -1 || a.indexOf("ipod") != -1 ? {
- device: "iphone",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("ipad") != -1 ? {
- device: "ipad",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("duopaoandroid") != -1 ? {
- device: "duopaoAndroid",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("duopaowindowsphone") != -1 ? {
- device: "duopaoWindowsPhone",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("opera mobi") != -1 ? {
- device: "operamobile",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("flyflow") != -1 ? {
- device: "flyflow",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("android") != -1 ? {
- device: "android",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("iemobile") != -1 ? {
- device: "iemobile",
- fps: 1,
- touch: false,
- zoom: 1
- } : a.indexOf("j2me") != -1 ? {
- device: "j2me",
- fps: 1,
- touch: false,
- zoom: 1
- } : a.indexOf("symbian v5") != -1 ? {
- device: "symbian5",
- fps: 1,
- touch: true,
- zoom: 1
- } : a.indexOf("symbian v3") != -1 ? {
- device: "symbian3",
- fps: 1,
- touch: false,
- zoom: 1
- } : a.indexOf("chrome") != -1 ? {
- device: "chrome",
- fps: 1,
- touch: false,
- zoom: 1
- } : a.indexOf("msie") != -1 ? {
- device: "ie",
- fps: 0.5,
- touch: false,
- zoom: 1
- } : a.indexOf("safari") != -1 ? {
- device: "safari",
- fps: 1,
- touch: false,
- zoom: 1
- } : a.indexOf("opera") != -1 ? {
- device: "opera",
- fps: 1,
- touch: false,
- zoom: 1
- } : a.indexOf("firefox") != -1 ? {
- device: "firefox",
- fps: 1,
- touch: false,
- zoom: 1
- } : {
- device: "",
- fps: 1,
- touch: false,
- zoom: 1
- }
- },
- loadImages: function (a, c) {
- if (parseInt(b.image.reCountLoaded) < parseInt(b.image.imgObjs.length * 0.3)) b.image.reCountLoaded += 0.1;
- var d = jsGame.canvas.screen.getWidth(),
- e = jsGame.canvas.screen.getHeight(),
- l = parseInt(d * 0.5),
- q = parseInt(d - l >> 1),
- s = parseInt(e - 20 >> 1);
- a = parseInt(b.image.reCountLoaded) > a ? parseInt(b.image.reCountLoaded) : a;
- a = a > c ? c : a;
- loadStor = "loading: " + a + " / " + c;
- 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");
- loadStor = null
- },
- setImage: function (a, c, d) {
- if (!a || !c) return false;
- if (!b.image.imgs[a]) {
- b.image.imgs[a] = jsGame.classes.getImage();
- b.image.imgs[a].onload = function () {
- b.image.countLoaded++;
- this.loaded = true
- };
- b.image.imgs[a].onerror = function () {
- var e = jsGame.args.getError("img");
- b.image.tips = [e.msg];
- e.callBack()
- };
- b.image.imgs[a].src = c;
- b.image.imgs[a].id = a;
- b.image.imgs[a].url = c;
- b.image.imgs[a].benchId = d
- }
- },
- initImageCallBack: null,
- loadImageCallBack: null,
- getAnchor: function (a, c, d, e, l) {
- switch (l) {
- case i.canvas.graphics.ANCHOR_HV:
- a -= parseInt(d / 2);
- c -= parseInt(e / 2);
- break;
- case i.canvas.graphics.ANCHOR_LV:
- c -= parseInt(e / 2);
- break;
- case i.canvas.graphics.ANCHOR_RV:
- a -= d;
- c -= parseInt(e / 2);
- break;
- case i.canvas.graphics.ANCHOR_HT:
- a -= parseInt(d / 2);
- break;
- case i.canvas.graphics.ANCHOR_RT:
- a -= d;
- break;
- case i.canvas.graphics.ANCHOR_HB:
- a -= parseInt(d / 2);
- c -= e;
- break;
- case i.canvas.graphics.ANCHOR_LB:
- c -= e;
- break;
- case i.canvas.graphics.ANCHOR_RB:
- a -= d;
- c -= e
- }
- return {
- x: a,
- y: c
- }
- },
- initUrlParams: function (a) {
- if (a.indexOf("?") >= 0) {
- var c = a.split("?");
- a = [];
- if (c[1].indexOf("&") >= 0) a = c[1].split("&");
- else a.push(c[1]);
- c = [];
- for (var d = 0; d < a.length; d++) if (a[d].indexOf("=") >= 0) {
- c = a[d].split("=");
- b.request.gets[c[0]] = c[1]
- }
- }
- }
- };
- jsGame = {
- init: function (a, c) {
- if (!a && !c) {
- this.version = 1.8;
- this.request.init();
- this.events.init();
- this.canvas.initDevice()
- } else {
- b.canvas.defaultWidth = a;
- b.canvas.defaultHeight = c
- }
- return this
- },
- extend: function (a, c, d) {
- d = d || {};
- if (c) {
- var e = function () { };
- e.prototype = c.prototype;
- a.prototype = new e;
- a.prototype.constructor = a;
- e = null
- }
- for (var l in d) a.prototype[l] = d[l];
- d = null;
- return a
- },
- error: function (a) {
- throw Error(a);
- },
- ajax: function (a) {
- a && b.ajax.pool.length < b.ajax.poolLength && b.ajax.pool.push(a);
- if (a && a.clear) b.ajax.pool = [];
- if (b.ajax.xhrObj == null && b.ajax.pool.length > 0) {
- b.ajax.xhrObj = this.objExtend(b.ajax.param, b.ajax.pool.shift() || {});
- b.ajax.xhrObj.type = b.ajax.xhrObj.type.toUpperCase();
- b.ajax.xhrObj.dataType = b.ajax.xhrObj.dataType.toUpperCase();
- b.ajax.xhrObj.xhr = jsGame.classes.getAjax();
- b.ajax.isTimeout = false;
- b.ajax.xhrObj.xhr.onreadystatechange = function () {
- if (b.ajax.isTimeout) return false;
- if (b.ajax.xhrObj && b.ajax.xhrObj.xhr.readyState == 4) {
- if (b.ajax.data) {
- clearTimeout(b.ajax.data);
- b.ajax.data = null
- }
- if (b.ajax.xhrObj.xhr.status == 200) {
- var e;
- switch (b.ajax.xhrObj.dataType) {
- case "HTML":
- e = b.ajax.xhrObj.xhr.responseText;
- break;
- default:
- e = b.ajax.xhrObj.xhr.responseText.replace(/<[^>].*?>/g, "");
- break;
- case "JSON":
- e = jsGame.getJson(b.ajax.xhrObj.xhr.responseText)
- }
- b.ajax.xhrObj.success(e, b.ajax.xhrObj);
- b.ajax.xhrObj.complete(b.ajax.xhrObj)
- } else b.ajax.xhrObj.error(b.ajax.xhrObj.xhr, "error", b.ajax.xhrObj);
- b.ajax.xhrObj = null;
- jsGame.ajax()
- }
- };
- b.ajax.xhrObj.xhr.open(b.ajax.xhrObj.type, b.ajax.xhrObj.url, true);
- b.ajax.xhrObj.before(b.ajax.xhrObj);
- b.ajax.xhrObj.type == "POST" && b.ajax.xhrObj.xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
- a = null;
- var c = b.ajax.xhrObj.data;
- if (typeof c == "string") a = c;
- else if (typeof c == "object") {
- a = [];
- for (var d in c) a.push(d + "=" + c[d]);
- a = a.join("&")
- }
- b.ajax.xhrObj.xhr.send(a);
- a = c = null;
- b.ajax.data = setTimeout(function () {
- jsGame.ajax({
- clear: true
- });
- b.ajax.isTimeout = true;
- if (b.ajax.xhrObj) {
- b.ajax.xhrObj.error(b.ajax.xhrObj.xhr, "timeout", b.ajax.xhrObj);
- b.ajax.xhrObj = null
- }
- }, b.ajax.xhrObj.timeout)
- }
- return this
- },
- getDom: function (a) {
- try {
- return document.getElementById(a)
- } catch (c) {
- return document.all[a]
- }
- },
- getScript: function () {
- var a = document.getElementsByTagName("head")[0],
- c = null,
- d = null;
- _error = _success = null;
- _disposed = function () {
- if (d) {
- clearTimeout(d);
- d = null
- }
- };
- return function (e) {
- if (!a || c) return false;
- e = jsGame.objExtend({
- url: "",
- before: function () { },
- success: function () { },
- error: function () { },
- timeout: 5E3,
- contentType: "text/javascript",
- destroyed: true
- }, e || {});
- if (e.url != "") {
- e.before();
- c = document.createElement("script");
- c.type = e.contentType;
- c.async = true;
- c.src = e.url;
- c.destroyed = e.destroyed;
- _success = e.success;
- _error = e.error;
- c.onload = function () {
- _disposed();
- if (_success) {
- _success();
- _success = null
- }
- this.destroyed && a.removeChild(this);
- c = null
- };
- a.appendChild(c);
- _disposed();
- d = setTimeout(function () {
- _disposed();
- if (_error) {
- _error("timeout");
- _error = null
- }
- c && c.destroyed && a.removeChild(c);
- c = null
- }, e.timeout)
- }
- e = null;
- return jsGame
- }
- }(),
- objExtend: function () {
- var a = this.clone(arguments[0]) || {},
- c = 1,
- d = arguments.length,
- e = false,
- l;
- if (typeof a === "boolean") {
- e = a;
- a = arguments[1] || {};
- c = 2
- }
- if (typeof a !== "object") a = {};
- if (d == c) {
- a = this;
- --c
- }
- for (; c < d; c++) if ((l = arguments[c]) != null) for (var q in l) {
- var s = a[q],
- r = l[q];
- if (a !== r) if (e && r && typeof r === "object" && !r.nodeType) a[q] = this.objExtend(e, s || (r.length != null ? [] : {}), r);
- else if (r !== undefined) a[q] = r
- }
- return a
- },
- getJson: function (a) {
- var c = {};
- try {
- c = window.JSON ? JSON.parse(a) : eval("(" + a + ")")
- } catch (d) { }
- return c
- },
- clone: function (a) {
- var c = a || [];
- if (typeof c == "object") if (c.length != undefined) {
- a = [];
- 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]
- } else {
- a = {};
- 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]
- }
- return a
- },
- classes: {
- init: function (a) {
- a.classes.timer.prototype.stop = function () {
- if (this.timeout) {
- clearTimeout(this.timeout);
- this.timeout = null
- }
- };
- a.classes.timer.prototype.start = function (c) {
- if (c) {
- this.time = this._initTime;
- this._dateTime = Date.now()
- }
- this.stop();
- this.timeout = setTimeout(function (d) {
- var e = Date.now(),
- l = parseInt(Math.round((e - d._dateTime) / d.millisec));
- d._dateTime = e;
- d.time -= l;
- d.callBack ? d.callBack(d) : d.stop();
- if (d.time >= 0) d.start();
- else {
- d.stop();
- d.time = 0
- }
- }, this.millisec, this)
- };
- a.classes.webSocket.prototype.send = function (c) {
- this.socket.send(c)
- };
- a.classes.webSocket.prototype.close = function () {
- this.socket.close()
- }
- },
- getAjax: function () {
- return new XMLHttpRequest
- },
- observer: function () {
- this.group = [];
- this.register = function (a) {
- if (a == null) return this;
- jsGame.commandFuns.inArray(a, this.group) == -1 && this.group.push(a);
- return this
- };
- this.unregister = function (a) {
- if (a == null) return this;
- a = jsGame.commandFuns.inArray(a, this.group);
- a > -1 && this.group.splice(a, 1);
- return this
- };
- this.notify = function (a) {
- for (var c = 0; c < this.group.length; c++) if (this.group[c] != null) this.group[c](a);
- return this
- };
- this.clear = function () {
- this.group.length > 0 && this.group.splice(0, this.group.length);
- return this
- }
- },
- getImage: function () {
- return new Image
- },
- timer: function (a, c, d, e, l) {
- this.id = a;
- this._initTime = c;
- this._dateTime = Date.now();
- this.time = this._initTime;
- this.callBack = d;
- this.millisec = e || 1E3;
- this.data = l;
- this.timeout = null
- },
- webSocket: function (a, c, d, e, l) {
- this.ipPort = a || "";
- this.socket = new WebSocket(this.ipPort);
- this.socket.onopen = c;
- this.socket.onmessage = d;
- this.socket.onclose = e;
- this.socket.onerror = l
- }
- },
- commandFuns: function () {
- var a = {
- arr: [],
- len: 0,
- v: 0
- };
- return {
- registerNotify: function (c, d) {
- c != null && c.register(d)
- },
- rangeRegisterNotify: function (c, d) {
- for (var e = 0; e < d.length; e++) jsGame.commandFuns.registerNotify(c, d[e])
- },
- unRegisterNotify: function (c, d) {
- c != null && c.unregister(d)
- },
- rangeUnRegisterNotify: function (c, d) {
- for (var e = 0; e < d.length; e++) jsGame.commandFuns.unRegisterNotify(c, d[e])
- },
- getRandom: function (c, d) {
- if (d) return Math.round(Math.random() * (d - c) + c);
- else {
- var e = c;
- if (!e || e < 0) e = 0;
- return Math.round(Math.random() * e)
- }
- },
- getArray: function (c, d) {
- a.arr = [];
- a.len = c.toString().length;
- a.v = c;
- for (var e = 0; e < a.len; e++) {
- a.arr.push(a.v % 10);
- a.v = parseInt(a.v / 10)
- }
- d || a.arr.reverse();
- return a.arr
- },
- inArray: function (c, d) {
- var e, l = d.length;
- for (e = 0; e < l; e++) if (c == d[e]) return e;
- return -1
- },
- collisionCheck: function (c, d, e, l, q, s, r, w) {
- 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;
- return false
- },
- circleCollisionCheck: function (c, d, e, l, q, s) {
- c = Math.abs(c - l);
- d = Math.abs(d - q);
- if (Math.sqrt(c * c + d * d) < e + s) return true;
- return false
- }
- }
- }(),
- args: {
- ajax: {
- type: "get",
- data: null,
- dataType: "html",
- url: "",
- before: function () { },
- success: function () { },
- error: function (a, c, d) {
- this.error(c + "[" + d + "]")
- },
- complete: function () { }
- },
- setError: function (a, c, d) {
- b.error[a] = {
- msg: c,
- callBack: d
- };
- return jsGame
- },
- getError: function (a) {
- if (b.error[a]) return b.error[a];
- return {
- msg: "",
- callBack: function () { }
- }
- },
- setAjax: function (a, c) {
- if (b.ajax[a]) b.ajax[a] = c;
- return jsGame
- },
- xhr: null,
- gc: {
- collectWaitTime: 1E3
- }
- },
- localStorage: function () {
- var a, c, d = function () {
- var e;
- try {
- e = window.localStorage;
- if (!e.getItem) e.getItem = function () {
- return null
- };
- if (!e.setItem) e.setItem = function () { }
- } catch (l) {
- e = {
- getItem: function () {
- return null
- },
- setItem: function () { }
- }
- }
- return e
- };
- return {
- init: function () {
- a = this;
- c || (c = d());
- return a
- },
- setItem: function (e, l) {
- try {
- c.setItem(e, l)
- } catch (q) { }
- return a
- },
- getItem: function (e) {
- return c.getItem(e)
- },
- removeItem: function (e) {
- c.removeItem(e);
- return a
- },
- clear: function () {
- c.clear();
- return a
- },
- key: function (e) {
- return c.key(e)
- },
- getLength: function () {
- return c.length
- },
- base: function () {
- return jsGame
- }
- }
- }(),
- sessionStorage: function () {
- var a, c, d = function () {
- var e;
- try {
- e = window.sessionStorage;
- if (!e.getItem) e.getItem = function () {
- return null
- };
- if (!e.setItem) e.setItem = function () { }
- } catch (l) {
- e = {
- getItem: function () {
- return null
- },
- setItem: function () { }
- }
- }
- return e
- };
- return {
- init: function () {
- a = this;
- c || (c = d());
- return a
- },
- setItem: function (e, l) {
- c.setItem(e, l);
- return a
- },
- getItem: function (e) {
- return c.getItem(e)
- },
- removeItem: function (e) {
- c.removeItem(e);
- return a
- },
- clear: function () {
- c.clear();
- return a
- },
- key: function (e) {
- return c.key(e)
- },
- getLength: function () {
- return c.length
- },
- base: function () {
- return jsGame
- }
- }
- }(),
- pageLoad: function (a) {
- if (b.system.pageLoad == null) {
- b.system.pageLoad = a;
- this.localStorage.init();
- this.sessionStorage.init();
- this.canvas.init();
- this.audio.init();
- this.gameFlow.init();
- this.classes.init(this);
- this.graphics.ANCHOR_LT = i.canvas.graphics.ANCHOR_LT;
- this.graphics.ANCHOR_LV = i.canvas.graphics.ANCHOR_LV;
- this.graphics.ANCHOR_LB = i.canvas.graphics.ANCHOR_LB;
- this.graphics.ANCHOR_HT = i.canvas.graphics.ANCHOR_HT;
- this.graphics.ANCHOR_HV = i.canvas.graphics.ANCHOR_HV;
- this.graphics.ANCHOR_HB = i.canvas.graphics.ANCHOR_HB;
- this.graphics.ANCHOR_RT = i.canvas.graphics.ANCHOR_RT;
- this.graphics.ANCHOR_RV = i.canvas.graphics.ANCHOR_RV;
- this.graphics.ANCHOR_RB = i.canvas.graphics.ANCHOR_RB;
- a = jsGame.getDom(b.canvas.defaultId);
- if (jsGame.canvas.screen.getTouch()) {
- window.addEventListener("orientationchange", k.orientationchange, false);
- a.ontouchstart = k.touchstart;
- a.ontouchend = k.touchend;
- a.ontouchmove = k.touchmove;
- a.ontouchcancel = k.touchcancel
- } else {
- document.onkeydown = k.keydown;
- document.onkeyup = k.keyup;
- if (jsGame.canvas.screen.getDevice() != "j2me" && jsGame.canvas.screen.getDevice().indexOf("symbian") == -1) {
- a.onclick = k.click;
- a.onmousedown = k.mouseDown;
- a.onmouseup = k.mouseUp;
- a.onmousemove = k.mouseMove;
- if (b.canvas.device == "iemobile") try {
- window.external.notify("RM," + b.canvas.id + ",0,0," + jsGame.canvas.screen.getWidth() + "," + jsGame.canvas.screen.getHeight() + ",0")
- } catch (c) { }
- }
- }
- a = null;
- if (k.initImageCallBack == null) k.initImageCallBack = k.loadImages;
- this.canvas.fillStyle(b.canvas.bgColor).fillRect(0, 0, jsGame.canvas.screen.getWidth(), jsGame.canvas.screen.getHeight());
- b.system.gameFlow = i.system.gameFlowType.run;
- if (b.system.loadRes == null) {
- b.system.loadRes = function () {
- var d = b.image.imgObjs.length - 1;
- k.initImageCallBack(b.image.countLoaded > d ? d : b.image.countLoaded, d);
- if (b.system.loadResTimer) {
- clearTimeout(b.system.loadResTimer);
- b.system.loadResTimer = null
- }
- if (b.image.countLoaded == b.image.imgObjs.length) {
- b.system.pageLoad(jsGame);
- b.image.imgObjs = [];
- b.image.initImgs = {};
- b.image.countLoaded = 0;
- b.image.reCountLoaded = 0;
- clearTimeout(b.system.loadRes);
- b.system.loadRes = null
- } else b.system.loadResTimer = setTimeout(b.system.loadRes, b.system.timeout)
- };
- b.system.loadRes()
- }
- }
- },
- menu: function (a) {
- if (b.system.menu == null && typeof a == "function") {
- b.system.gameFlow = i.system.gameFlowType.menu;
- b.system.menu = a
- }
- return this
- },
- run: function (a) {
- if (b.system.run == null) {
- if (b.system.runFn == null) b.system.runFn = a;
- b.system.run = function () {
- var c = Date.now();
- switch (b.system.gameFlow) {
- case i.system.gameFlowType.menu:
- b.system.menu();
- break;
- case i.system.gameFlowType.run:
- b.system.runFn();
- break;
- case i.system.gameFlowType.stop:
- b.system.stop();
- break;
- case i.system.gameFlowType.over:
- b.system.over();
- break;
- case i.system.gameFlowType.zone:
- b.system.zone(b.system.zoneArgs);
- break;
- case i.system.gameFlowType.active:
- b.system.active(b.system.activeArgs);
- break;
- case i.system.gameFlowType.loadImage:
- if (k.loadImageCallBack != null) {
- var d = b.image.imgCount - 1,
- e = b.image.countLoaded > d ? d : b.image.countLoaded;
- k.loadImageCallBack(e, d);
- if (e == d) {
- b.image.imgObjs = [];
- b.image.countLoaded = 0;
- jsGame.gameFlow.run()
- }
- if (b.image.imgObjs.length > 0) if (d = b.image.imgObjs.shift()) if (b.image.imgs[d.id]) b.image.countLoaded++;
- else k.setImage(d.id, d.src, d.benchId)
- }
- }
- b.system.spendTime = Date.now() - c
- };
- jsGame.play()
- }
- return this
- },
- stop: function (a) {
- if (b.system.stop == null && typeof a == "function") b.system.stop = a;
- return this
- },
- over: function (a) {
- if (b.system.over == null && typeof a == "function") b.system.over = a;
- return this
- },
- zone: function (a) {
- if (b.system.zone == null && typeof a == "function") b.system.zone = a;
- return this
- },
- active: function (a) {
- if (b.system.active == null && typeof a == "function") b.system.active = a;
- return this
- },
- play: function () {
- if (!b.system.playTimer) {
- b.system.isPause = false;
- (b.system.rafRun = function () {
- var a = Date.now();
- if (a - b.system.lastDate >= b.system.timeout - b.system.spendTime) {
- b.system.lastDate = a;
- b.system.isPause || b.system.run()
- }
- if (b.system.rafRun) b.system.playTimer = requestAnimationFrame(b.system.rafRun)
- })()
- }
- return this
- },
- pause: function () {
- if (b.system.playTimer) {
- b.system.isPause = true;
- b.system.rafRun = null;
- cancelAnimationFrame(b.system.playTimer);
- b.system.playTimer = null
- }
- return this
- },
- gameFlow: function () {
- var a;
- return {
- init: function () {
- return a = this
- },
- menu: function () {
- if (b.system.menu != null) b.system.gameFlow = i.system.gameFlowType.menu;
- return a
- },
- run: function () {
- if (b.system.run != null) b.system.gameFlow = i.system.gameFlowType.run;
- return a
- },
- stop: function () {
- if (b.system.stop != null) b.system.gameFlow = i.system.gameFlowType.stop;
- return a
- },
- over: function () {
- if (b.system.over != null) b.system.gameFlow = i.system.gameFlowType.over;
- return a
- },
- zone: function (c) {
- if (b.system.zone != null) {
- b.system.gameFlow = i.system.gameFlowType.zone;
- b.system.zoneArgs = c
- }
- return a
- },
- active: function (c) {
- if (b.system.active != null) {
- b.system.gameFlow = i.system.gameFlowType.active;
- b.system.activeArgs = c
- }
- return a
- },
- base: function () {
- return jsGame
- }
- }
- }(),
- keyIsPressed: function (a) {
- if (!b.event.keyDownGo) b.event.keyDownGo = true;
- return b.event.keys[a]
- },
- keyPressed: function (a) {
- if (a) {
- if (!b.event.keyPressedGo) b.event.keyPressedGo = true;
- var c = b.event.pressedKey[a];
- b.event.pressedKey[a] = false;
- return c
- } else {
- if (this.keyPressed("up")) return true;
- else if (this.keyPressed("down")) return true;
- else if (this.keyPressed("left")) return true;
- else if (this.keyPressed("right")) return true;
- else if (this.keyPressed("a")) return true;
- else if (this.keyPressed("b")) return true;
- else if (this.keyPressed("c")) return true;
- else if (this.keyPressed("menu")) return true;
- else if (this.keyPressed("quit")) return true;
- return false
- }
- },
- keyIsUnPressed: function (a) {
- if (!b.event.keyUpGo) b.event.keyUpGo = true;
- var c = b.event.lastKey[a];
- b.event.lastKey[a] = false;
- return c
- },
- keyReleased: function (a) {
- if (a) return this.keyIsUnPressed(a);
- else {
- if (this.keyReleased("up")) return true;
- else if (this.keyReleased("down")) return true;
- else if (this.keyReleased("left")) return true;
- else if (this.keyReleased("right")) return true;
- else if (this.keyReleased("a")) return true;
- else if (this.keyReleased("b")) return true;
- else if (this.keyReleased("c")) return true;
- else if (this.keyReleased("menu")) return true;
- else if (this.keyReleased("quit")) return true;
- return false
- }
- },
- keyRepeated: function (a) {
- if (a) return this.keyIsPressed(a);
- else {
- if (this.keyRepeated("up")) return true;
- else if (this.keyRepeated("down")) return true;
- else if (this.keyRepeated("left")) return true;
- else if (this.keyRepeated("right")) return true;
- else if (this.keyRepeated("a")) return true;
- else if (this.keyRepeated("b")) return true;
- else if (this.keyRepeated("c")) return true;
- else if (this.keyRepeated("menu")) return true;
- else if (this.keyRepeated("quit")) return true;
- return false
- }
- },
- canvas: function () {
- var a, c, d, e, l, q, s, r, w, x, y;
- return {
- init: function () {
- a = this;
- d = {
- x: 0,
- y: 0
- };
- e = {
- fillColor: "#000000",
- strokeColor: "#000000"
- };
- l = {
- x: 0,
- y: 0
- };
- q = {
- x: 0,
- y: 0
- };
- s = {
- x: 0,
- y: 0,
- fillStyle: "#FFFFFF",
- strokeStyle: "#CCCCCC"
- };
- return a.pass()
- },
- initDevice: function () {
- w = k.getDeviceConfig();
- b.canvas.device = w.device;
- b.canvas.fps = w.fps;
- b.canvas.touch = w.touch;
- b.canvas.zoom = w.zoom;
- return a
- },
- pass: function (f, g, j) {
- var h;
- h = !f || f == "" ? b.canvas.defaultId : f;
- if (!b.canvas.ctxs[h]) {
- f = f ? document.createElement("canvas") : a.base().getDom(h);
- b.canvas.ctxs[h] = null;
- delete b.canvas.ctxs[h];
- b.canvas.ctxs[h] = f.getContext("2d");
- f.width = g ? g : b.canvas.defaultWidth;
- f.style.width = parseInt(f.width * b.canvas.zoom) + "px";
- f.height = j ? j : b.canvas.defaultHeight;
- f.style.height = parseInt(f.height * b.canvas.zoom) + "px";
- b.canvas.cavansDoms[h] = null;
- delete b.canvas.cavansDoms[h];
- b.canvas.cavansDoms[h] = f
- }
- c = b.canvas.ctxs[h];
- c.font = b.canvas.defaultFont;
- r = b.canvas.cavansDoms[h];
- x = parseInt(r.width);
- y = parseInt(r.height);
- return a.screen.setId(h)
- },
- font: function (f) {
- b.canvas.defaultFont = f;
- c.font = b.canvas.defaultFont;
- return a
- },
- del: function (f) {
- if (b.canvas.ctxs[f]) {
- b.canvas.ctxs[f] = null;
- delete b.canvas.ctxs[f];
- b.canvas.cavansDoms[f] = null;
- delete b.canvas.cavansDoms[f]
- }
- return a
- },
- setCurrent: function (f) {
- return a.pass(f)
- },
- screen: {
- setId: function (f) {
- if (b.canvas.ctxs[f]) b.canvas.id = f;
- return a
- },
- getId: function () {
- return b.canvas.id
- },
- getWidth: function () {
- return x
- },
- setWidth: function (f) {
- b.canvas.defaultWidth = f;
- if (r) {
- r.width = b.canvas.defaultWidth;
- r.style.width = r.width + "px";
- x = parseInt(r.width)
- }
- return a
- },
- getHeight: function () {
- return y
- },
- setHeight: function (f) {
- b.canvas.defaultHeight = f;
- if (r) {
- r.height = b.canvas.defaultHeight;
- r.style.height = r.height + "px";
- y = parseInt(r.height)
- }
- return a
- },
- getDevice: function () {
- return b.canvas.device
- },
- getFps: function () {
- return b.canvas.fps
- },
- setFps: function (f) {
- if (f > 0) b.canvas.fps = f;
- return a
- },
- getTouch: function () {
- return b.canvas.touch
- },
- getZoom: function () {
- return b.canvas.zoom
- }
- },
- fillStyle: function (f) {
- c.fillStyle = f;
- return a
- },
- fillRect: function (f, g, j, h, n) {
- j = j ? j : 0;
- h = h ? h : 0;
- if (n) q = k.getAnchor(f, g, j, h, n);
- else {
- q.x = f;
- q.y = g
- }
- c.fillRect(q.x, q.y, j, h);
- return a
- },
- fillText: function (f, g, j, h) {
- c.font = h || b.canvas.defaultFont;
- c.fillText(f, g, j);
- return a
- },
- clearRect: function (f, g, j, h) {
- c.clearRect(f, g, j, h);
- return a
- },
- clearScreen: function () {
- return a.clearRect(0, 0, x, y)
- },
- fillScreen: function () {
- return a.fillRect(0, 0, x, y)
- },
- strokeStyle: function (f) {
- c.strokeStyle = f;
- return a
- },
- lineWidth: function (f) {
- c.lineWidth = f || 1;
- return a
- },
- strokeRect: function (f, g, j, h, n) {
- if (n) l = k.getAnchor(f, g, j, h, n);
- else {
- l.x = f;
- l.y = g
- }
- c.strokeRect(l.x, l.y, j, h);
- return a
- },
- strokeText: function (f, g, j, h) {
- c.font = h || b.canvas.defaultFont;
- c.strokeText(f, g, j);
- return a
- },
- setColor: function (f, g, j) {
- if (j == null) {
- e.fillColor = f;
- e.strokeColor = g ? g : f
- } else {
- e.fillColor = "rgb(" + f + ", " + g + ", " + j + ")";
- e.strokeColor = e.fillColor
- }
- return a.fillStyle(e.fillColor).strokeStyle(e.strokeColor)
- },
- drawImage: function (f, g, j, h, n, p, m, o, t, u) {
- var v = jsGame.getImage(f);
- if (v.src != null) {
- h = h <= 0 ? 0.1 : h;
- n = n <= 0 ? 0.1 : n;
- o = o <= 0 ? 0.1 : o;
- t = t <= 0 ? 0.1 : t;
- if (v.loaded) if (h) if (n) if (u) {
- d = k.getAnchor(p, m, o, t, u);
- c.drawImage(v, g, j, h, n, d.x, d.y, o, t)
- } else c.drawImage(v, g, j, h, n, p, m, o, t);
- else {
- d = k.getAnchor(g, j, jsGame.getImage(f).width, jsGame.getImage(f).height, h);
- c.drawImage(v, d.x, d.y)
- } else c.drawImage(v, g, j);
- else v.benchId && a.drawImage(v.benchId, g, j, h, n, p, m, o, t, u)
- } else if (g = b.image.asyncImgObjs[f]) {
- k.setImage(g.id, g.src, g.benchId);
- b.image.asyncImgObjs[f] = null;
- delete b.image.asyncImgObjs[f]
- }
- return a
- },
- drawRotate: function (f, g, j, h, n, p, m, o, t, u) {
- var v = parseInt(o >> 1),
- z = parseInt(t >> 1),
- A = jsGame.getImage(f);
- f = A ? A : b.canvas.cavansDoms[f];
- p -= v;
- m -= z;
- c.save();
- c.translate(p + v, m + z);
- c.rotate(u * Math.PI / 180);
- c.translate(-(p + v), -(m + z));
- c.drawImage(f, g, j, h, n, p, m, o, t);
- c.restore();
- return a
- },
- drawCache: function (f, g, j, h, n, p, m, o, t, u) {
- if (f = b.canvas.cavansDoms[f]) if (h) if (n) if (u) {
- d = k.getAnchor(p, m, o, t, u);
- c.drawImage(f, g, j, h, n, d.x, d.y, o, t)
- } else c.drawImage(f, g, j, h, n, p, m, o, t);
- else {
- d = k.getAnchor(g, j, f.width, f.height, h);
- c.drawImage(f, d.x, d.y)
- } else c.drawImage(f, g, j);
- return a
- },
- drawRegion: function (f, g, j, h, n, p, m, o) {
- switch (p) {
- default:
- c.setTransform(1, 0, 0, 1, m, o);
- break;
- case i.canvas.trans.TRANS_ROT90:
- c.setTransform(0, 1, -1, 0, n + m, o);
- break;
- case i.canvas.trans.TRANS_ROT180:
- c.setTransform(-1, 0, 0, -1, h + m, n + o);
- break;
- case i.canvas.trans.TRANS_ROT270:
- c.setTransform(0, -1, 1, 0, m, h + o);
- break;
- case i.canvas.trans.TRANS_MIRROR:
- c.setTransform(-1, 0, 0, 1, h + m, o);
- break;
- case i.canvas.trans.TRANS_MIRROR_ROT90:
- c.setTransform(0, -1, -1, 0, n + m, h + o);
- break;
- case i.canvas.trans.TRANS_MIRROR_ROT180:
- c.setTransform(1, 0, 0, -1, m, n + o);
- break;
- case i.canvas.trans.TRANS_MIRROR_ROT270:
- c.setTransform(0, 1, 1, 0, m, o)
- } (jsGame.getImage(f) ? a.drawImage : a.drawCache)(f, g, j, h, n, 0, 0, h, n);
- c.setTransform(1, 0, 0, 1, 0, 0);
- return a
- },
- drawNumber: function (f, g, j, h, n, p, m, o, t) {
- f = f.toString();
- var u = f.length;
- o = o ? o : j;
- t = t ? t : h;
- if (m == "center") {
- n -= parseInt(o * u >> 1);
- for (m = 0; m < u; m++) a.drawImage(g, parseInt(f.charAt(m)) * j, 0, j, h, n + m * o, p, o, t)
- } 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);
- 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);
- return a
- },
- moveTo: function (f, g) {
- c.moveTo(f, g);
- return a
- },
- lineTo: function (f, g) {
- c.lineTo(f, g);
- return a
- },
- stroke: function () {
- c.stroke();
- return a
- },
- fill: function () {
- c.fill();
- return a
- },
- beginPath: function () {
- c.beginPath();
- return a
- },
- closePath: function () {
- c.closePath();
- return a
- },
- arc: function (f, g, j, h, n, p) {
- c.arc(f, g, j, h, n, p);
- return a
- },
- quadraticCurveTo: function (f, g, j, h) {
- c.quadraticCurveTo(f, g, j, h);
- return a
- },
- bezierCurveTo: function (f, g, j, h, n, p) {
- c.bezierCurveTo(f, g, j, h, n, p);
- return a
- },
- measureText: function (f) {
- var g = c.measureText(f),
- j = g.width;
- g = g.height ? g.height : parseInt(c.font);
- return {
- width: a.screen.getDevice() == "j2me" ? c.measureText(f) : j,
- height: g
- }
- },
- translate: function (f, g) {
- c.translate(f, g);
- return a
- },
- drawLine: function (f, g, j, h) {
- return a.beginPath().moveTo(f, g).lineTo(j, h).closePath().stroke()
- },
- drawRect: function (f, g, j, h, n) {
- return a.strokeRect(f, g, j, h, n)
- },
- drawString: function (f, g, j, h, n, p, m, o) {
- s.x = g;
- s.y = j;
- c.font = o || b.canvas.defaultFont;
- if (h) switch (h) {
- case i.canvas.graphics.LEFT:
- s.x = 0;
- break;
- case i.canvas.graphics.VCENTER:
- s.x = parseInt(a.screen.getWidth() - a.measureText(f).width >> 1);
- break;
- case i.canvas.graphics.RIGHT:
- s.x = a.screen.getWidth() - a.measureText(f).width
- }
- if (n) {
- s.fillStyle = p ? p : "#000000";
- s.strokeStyle = m ? m : "#CCCCCC";
- a.fillStyle(s.strokeStyle).fillText(f, s.x + 1, s.y + 1, o).fillStyle(s.fillStyle)
- }
- return a.fillText(f, s.x, s.y, o).fillStyle(b.canvas.defaultColor)
- },
- drawSubstring: function (f, g, j, h, n, p, m, o, t, u) {
- return a.drawString(f.substring(g, g + j), h, n, p, m, o, t, u)
- },
- clip: function () {
- c.clip();
- return a
- },
- save: function () {
- c.save();
- return a
- },
- restore: function () {
- c.restore();
- return a
- },
- rect: function (f, g, j, h) {
- c.rect(f, g, j, h);
- return a
- },
- rotate: function (f) {
- c.rotate(f);
- return a
- },
- setTransform: function (f, g, j, h, n, p) {
- c.setTransform(f, g, j, h, n, p);
- return a
- },
- scale: function (f, g) {
- c.scale(f, g);
- return a
- },
- globalAlpha: function (f) {
- c.globalAlpha = f || 1;
- return a
- },
- getContext: function () {
- return c
- },
- base: function () {
- return jsGame
- }
- }
- }(),
- initImage: function (a) {
- b.image.imgs = [];
- if (a.length > 0) {
- jsGame.pushImage(a);
- for (var c = 0; c < b.image.imgObjs.length; c++) (a = b.image.imgObjs[c]) && k.setImage(a.id, a.src, a.benchId)
- }
- return this
- },
- loadImage: function (a) {
- if (b.system.gameFlow != i.system.gameFlowType.loadImage && a.length > 0) {
- b.system.gameFlow = i.system.gameFlowType.loadImage;
- b.image.imgObjs = a;
- b.image.imgCount = b.image.imgObjs.length;
- b.image.countLoaded = 0
- }
- return this
- },
- pushImage: function (a) {
- for (var c, d = 0, e = a.length; d < e; d++) if ((c = a[d]) && !b.image.initImgs[c.id]) {
- b.image.initImgs[c.id] = true;
- b.image.imgObjs.push(a[d])
- }
- return this
- },
- asyncImage: function (a) {
- for (var c, d = 0, e = a.length; d < e; d++) {
- c = a[d];
- b.image.asyncImgObjs[c.id] = c
- }
- return this
- },
- initImageCallBack: function (a) {
- if (typeof a == "function") k.initImageCallBack = a;
- return this
- },
- loadImageCallBack: function (a) {
- if (typeof a == "function") k.loadImageCallBack = a;
- return this
- },
- addImage: function (a, c) {
- if (a && c && !b.image.imgs[a]) b.image.imgs[a] = c;
- return this
- },
- getImage: function (a) {
- return b.image.imgs[a] ? b.image.imgs[a] : {
- src: null
- }
- },
- delImage: function (a) {
- if (b.image.imgs[a]) {
- b.image.imgs[a] = null;
- delete b.image.imgs[a]
- }
- return this
- },
- audio: function () {
- var a = null;
- return {
- init: function () {
- return a = this
- },
- play: function (c) {
- if (b.audio.audios[c]) try {
- b.audio.audios[c].paused && b.audio.audios[c].play()
- } catch (d) { }
- return a
- },
- pause: function (c) {
- if (b.audio.audios[c]) try {
- b.audio.audios[c].pause()
- } catch (d) { }
- return a
- },
- noSound: function () {
- for (var c in b.audio.audios) b.audio.audios[c].pause && b.audio.audios[c].pause();
- return a
- },
- load: function (c) {
- if (b.audio.audios[c]) try {
- b.audio.audios[c].load()
- } catch (d) { }
- return a
- },
- replay: function (c) {
- a.pause(c);
- a.load(c);
- a.play(c);
- return a
- },
- fuckAudio: function (c) {
- if (b.audio.audios[c] && b.audio.audios[c].paused) {
- b.audio.fuckSkip++;
- if (b.audio.fuckSkip == 10) {
- a.replay(c);
- b.audio.fuckSkip = 0
- }
- }
- return a
- },
- getAudio: function (c) {
- return b.audio.audios[c]
- }
- }
- }(),
- initAudio: function (a) {
- if (a.length > 0) {
- b.audio.audios = [];
- for (var c, d, e, l, q = 0; q < a.length; q++) if ((c = a[q]) && c.id != "" && c.src != "") {
- d = c.loop;
- e = c.preload;
- l = c.autoplay;
- b.audio.audios[c.id] = new Audio(c.src);
- b.audio.audios[c.id].id = c.id;
- b.audio.audios[c.id].loop = d;
- b.audio.audios[c.id].preload = e;
- b.audio.audios[c.id].autoplay = l
- }
- }
- return this
- },
- setRunFrequency: function (a) {
- b.system.timeout = a;
- return this
- },
- events: function () {
- var a;
- return {
- init: function () {
- return a = this
- },
- keyDown: function (c) {
- if (!b.event.keyDownGo) b.event.keyDownGo = true;
- if (!b.event.keyUpGo) b.event.keyUpGo = true;
- if (!b.event.keyPressedGo) b.event.keyPressedGo = true;
- b.event.keyDownCallBack = c;
- return a
- },
- keyUp: function (c) {
- if (!b.event.keyDownGo) b.event.keyDownGo = true;
- if (!b.event.keyUpGo) b.event.keyUpGo = true;
- if (!b.event.keyPressedGo) b.event.keyPressedGo = true;
- b.event.keyUpCallBack = c;
- return a
- },
- orientationChange: function (c) {
- b.event.orientationChange = c;
- return a
- },
- touchStart: function (c) {
- b.event.touchStart = c;
- return a
- },
- touchEnd: function (c) {
- b.event.touchEnd = c;
- return a
- },
- touchMove: function (c) {
- b.event.touchMove = c;
- return a
- },
- touchCancel: function (c) {
- b.event.touchCancel = c;
- return a
- },
- click: function (c) {
- b.event.clickCallBack = c;
- return a
- },
- mouseDown: function (c) {
- b.event.mouseDownCallBack = c;
- return a
- },
- mouseUp: function (c) {
- b.event.mouseUpCallBack = c;
- return a
- },
- mouseMove: function (c) {
- b.event.mouseMoveCallBack = c;
- return a
- },
- base: function () {
- return jsGame
- }
- }
- }(),
- ui: {},
- graphics: {
- HCENTER: i.canvas.graphics.HCENTER,
- VCENTER: i.canvas.graphics.VCENTER,
- LEFT: i.canvas.graphics.LEFT,
- RIGHT: i.canvas.graphics.RIGHT,
- TOP: i.canvas.graphics.TOP,
- BOTTOM: i.canvas.graphics.BOTTOM
- },
- trans: {
- TRANS_NONE: i.canvas.trans.TRANS_NONE,
- TRANS_ROT90: i.canvas.trans.TRANS_ROT90,
- TRANS_ROT180: i.canvas.trans.TRANS_ROT180,
- TRANS_ROT270: i.canvas.trans.TRANS_ROT270,
- TRANS_MIRROR: i.canvas.trans.TRANS_MIRROR,
- TRANS_MIRROR_ROT90: i.canvas.trans.TRANS_MIRROR_ROT90,
- TRANS_MIRROR_ROT180: i.canvas.trans.TRANS_MIRROR_ROT180,
- TRANS_MIRROR_ROT270: i.canvas.trans.TRANS_MIRROR_ROT270
- },
- request: function () {
- return {
- init: function () {
- k.initUrlParams(location.href)
- },
- get: function (a) {
- return b.request.gets[a] ? b.request.gets[a] : ""
- }
- }
- }()
- }.init()
- })();
|