game.js 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691
  1. var Jok = Jok || {};
  2. Jok.JokState = function () {
  3. createjs.Container.call(this);
  4. this.name = "";
  5. };
  6. function btMoreGame() {
  7. Play68.goHome();
  8. //window.location.href = btGame.URL.getMoreGame();
  9. }
  10. /*ih5game.setShare({
  11. desc: "可耐的小黄人又来了,别以为你脱了吊带裤我就不认识你了。小伙伴们快来跟小黄人愉快的玩耍吧。"
  12. });*/
  13. var showSGLinks = true;
  14. var loc = window.location.href;
  15. var specificPartnersStr = "iwin.com,p=www.mobileforce.pl";
  16. var specificPartnersArr = specificPartnersStr.split(",");
  17. for (i = 0; i < specificPartnersArr.length; i++) {
  18. if (loc.indexOf(specificPartnersArr[i]) != -1) {
  19. showSGLinks = false;
  20. }
  21. }
  22. Jok.JokState.prototype = Object.create(createjs.Container.prototype);
  23. Jok.JokState.prototype.constructor = Jok.JokState;
  24. Jok.JokState.prototype.dispose = function () {
  25. };
  26. Jok.JokState.prototype.create = function () {
  27. };
  28. Jok.JokState.prototype.update = function () {
  29. };
  30. MyButtonBase = function (actionFunc, pos, scaleBegin, nameAnimDown) {
  31. createjs.Container.call(this);
  32. this.actionFunc = actionFunc;
  33. this._actionDefault = null;
  34. this.x = pos.x;
  35. this.y = pos.y;
  36. this._scaleBegin = scaleBegin;
  37. this.scaleX = this._scaleBegin.x;
  38. this.scaleY = this._scaleBegin.y;
  39. if (nameAnimDown) {
  40. if (nameAnimDown.length > 0) {
  41. this.sprDown = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, nameAnimDown);
  42. this.sprDown.stop();
  43. this.addChild(this.sprDown);
  44. }
  45. }
  46. this.onWork();
  47. this.TIME_ANIM = 300;
  48. this.SCALE_ANIM = 1.11;
  49. this.tweenSize = null;
  50. this.eventScaleBegin = createjs.proxy(this.scaleBegin, this);
  51. this.eventScaleEnd = createjs.proxy(this.scaleEnd, this);
  52. };
  53. MyButtonBase.prototype = Object.create(createjs.Container.prototype);
  54. MyButtonBase.prototype.constructor = MyButtonBase;
  55. MyButtonBase.prototype.addBmpTTT = function (bmp, center, width, height) {
  56. console.log("bmp = " + bmp);
  57. console.log("MyButtonBase.prototype.addBmpTTT width = " + width);
  58. if (width) {
  59. } else {
  60. if (bmp.getBounds()) {
  61. width = bmp.getBounds().width;
  62. height = bmp.getBounds().height;
  63. } else {
  64. width = 202;
  65. height = 50;
  66. }
  67. }
  68. if (center) {
  69. bmp.x = -width / 2;
  70. bmp.y = -height / 2;
  71. }
  72. var hitArea = new createjs.Shape((new createjs.Graphics).beginFill("#000000").drawRect(bmp.x, bmp.y, width, height));
  73. this.hitArea = hitArea;
  74. this.addChild(bmp);
  75. console.log("this.addChild(bmp);");
  76. };
  77. MyButtonBase.prototype.initUp = function (nameAnimUp) {
  78. this.sprUp = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, nameAnimUp);
  79. this.sprUp.stop();
  80. this.addChild(this.sprUp);
  81. };
  82. MyButtonBase.prototype.action = function (evt) {
  83. if (this.tweenSize == null) {
  84. (new MusicManager).playMouse();
  85. if (this.actionFunc != null) {
  86. this.actionFunc();
  87. }
  88. this.tweenSize = createjs.Tween.get(this).to({
  89. scaleX: this._scaleBegin.x * this.SCALE_ANIM,
  90. scaleY: this._scaleBegin.y * this.SCALE_ANIM
  91. }, this.TIME_ANIM, createjs.Ease.quartInOut).call(this.eventScaleBegin);
  92. }
  93. };
  94. MyButtonBase.prototype.scaleBegin = function (evt) {
  95. this.tweenSize = createjs.Tween.get(this).to({
  96. scaleX: this._scaleBegin.x,
  97. scaleY: this._scaleBegin.y
  98. }, this.TIME_ANIM, createjs.Ease.quartInOut).call(this.eventScaleEnd);
  99. };
  100. MyButtonBase.prototype.scaleEnd = function (evt) {
  101. this.tweenSize = null;
  102. };
  103. MyButtonBase.prototype.onSetAction = function (actionDefault) {
  104. this.offWork();
  105. this._actionDefault = actionDefault;
  106. this.onWork();
  107. };
  108. MyButtonBase.prototype.onWork = function () {
  109. if (!this.hasEventListener("click")) {
  110. if (this._actionDefault != null) {
  111. this.on("click", this._actionDefault);
  112. } else {
  113. this.eventAction = this.on("click", createjs.proxy(this.action, this));
  114. }
  115. }
  116. this.cursor = "pointer";
  117. };
  118. MyButtonBase.prototype.offWork = function () {
  119. console.log("MyButtonBase.prototype.offWork");
  120. if (this.hasEventListener("click")) {
  121. this.off("click", this.eventAction);
  122. }
  123. this.cursor = "arrow";
  124. };
  125. GameManager = function () {
  126. Jok.JokState.call(this);
  127. this.levelId = 0;
  128. this.stage = (new Jok.JokG).stage;
  129. this.work = false;
  130. this.engine = (new Jok.JokG).jokEngine;
  131. this.stage = (new Jok.JokG).stage;
  132. this.CELL_WIDTH = 60;
  133. this.CELL_HEIGHT = 60;
  134. this.CELL_Y_BEGIN = -200;
  135. this.CELL_W = 10;
  136. this.CELL_H = 10;
  137. this.AEOBJECT_ALIEN_ID = 101;
  138. this.AEOBJECT_EXIT_ID = 102;
  139. this.AEOBJECT_ARROW_ID = 103;
  140. this.AEOBJECT_SPRING_ID = 104;
  141. this.AEOBJECT_ICE_ID = 105;
  142. this.AEOBJECT_TELEPORT_ID = 106;
  143. this.initAnimData();
  144. this.MOUSE_X_Y_DIFF_MIN = 5;
  145. this.MOUSE_PATH_MIN = 3;
  146. this.SPEED_ALIEN = 400;
  147. };
  148. GameManager.prototype = Object.create(Jok.JokState.prototype);
  149. GameManager.prototype.constructor = GameManager;
  150. GameManager.prototype.initAnimData = function () {
  151. this.ANIM_ALIEN_IDLE_DATA = [];
  152. for (var i = 0; i <= 4; i++) {
  153. this.ANIM_ALIEN_IDLE_DATA.push([]);
  154. }
  155. for (var i = 1; i <= 2; i++) {
  156. var dataOne = {};
  157. dataOne.name = "alien_" + i + "_idle_1_mc";
  158. dataOne.numMin = 2;
  159. dataOne.numMax = 3;
  160. this.ANIM_ALIEN_IDLE_DATA[i].push(dataOne);
  161. var dataOne = {};
  162. dataOne.name = "alien_" + i + "_idle_2_mc";
  163. dataOne.numMin = 1;
  164. dataOne.numMax = 2;
  165. this.ANIM_ALIEN_IDLE_DATA[i].push(dataOne);
  166. var dataOne = {};
  167. dataOne.name = "alien_" + i + "_idle_3_mc";
  168. dataOne.numMin = 1;
  169. dataOne.numMax = 1;
  170. this.ANIM_ALIEN_IDLE_DATA[i].push(dataOne);
  171. var dataOne = {};
  172. dataOne.name = "alien_" + i + "_idle_4_mc";
  173. dataOne.numMin = 1;
  174. dataOne.numMax = 1;
  175. this.ANIM_ALIEN_IDLE_DATA[i].push(dataOne);
  176. }
  177. var dataOne = {};
  178. dataOne.name = "alien_3_idle_1_mc";
  179. dataOne.numMin = 2;
  180. dataOne.numMax = 3;
  181. this.ANIM_ALIEN_IDLE_DATA[3].push(dataOne);
  182. var dataOne = {};
  183. dataOne.name = "alien_3_idle_2_mc";
  184. dataOne.numMin = 1;
  185. dataOne.numMax = 2;
  186. this.ANIM_ALIEN_IDLE_DATA[3].push(dataOne);
  187. var dataOne = {};
  188. dataOne.name = "alien_3_idle_3_mc";
  189. dataOne.numMin = 1;
  190. dataOne.numMax = 1;
  191. this.ANIM_ALIEN_IDLE_DATA[3].push(dataOne);
  192. var dataOne = {};
  193. dataOne.name = "alien_4_idle_1_mc";
  194. dataOne.numMin = 3;
  195. dataOne.numMax = 5;
  196. this.ANIM_ALIEN_IDLE_DATA[4].push(dataOne);
  197. var dataOne = {};
  198. dataOne.name = "alien_4_idle_2_mc";
  199. dataOne.numMin = 1;
  200. dataOne.numMax = 1;
  201. this.ANIM_ALIEN_IDLE_DATA[4].push(dataOne);
  202. };
  203. GameManager.prototype.create = function () {
  204. this.work = true;
  205. this.field = new Array;
  206. for (var i = 0; i < this.CELL_W; i++) {
  207. this.field.push(new Array);
  208. for (var j = 0; j < this.CELL_H; j++) {
  209. this.field[i].push(0);
  210. }
  211. }
  212. this.backround = new BackgroundManager(this, this.field);
  213. this.addChild(this.backround);
  214. this.loadLevel();
  215. this.gui = new GuiBlock(this);
  216. this.addChild(this.gui);
  217. this.onWork();
  218. if (this.levelId == 0) {
  219. this.addChild(new HelpDialog(this));
  220. }
  221. };
  222. GameManager.prototype.dispose = function () {
  223. this.offWork();
  224. };
  225. GameManager.prototype.offWork = function () {
  226. this._step = this.mouseDown = false;
  227. this.stage.off("stagemousemove", this.eventMove);
  228. this.stage.off("stagemousedown", this.eventMouseDown);
  229. this.stage.off("stagemouseup", this.eventMouseUp);
  230. this._oldPosX = this._oldPosY = this._oldCellX = this._oldCellY = -999;
  231. this.gui.offButton();
  232. };
  233. GameManager.prototype.onWork = function () {
  234. this._step = this.mouseDown = false;
  235. this.eventMove = this.stage.on("stagemousemove", createjs.proxy(this.cccMouseMove, this));
  236. this.eventMouseDown = this.stage.on("stagemousedown", createjs.proxy(this.cccMouseDown, this));
  237. this.eventMouseUp = this.stage.on("stagemouseup", createjs.proxy(this.cccMouseUp, this));
  238. this._oldPosX = this._oldPosY = this._oldCellX = this._oldCellY = -999;
  239. this.gui.onButton();
  240. };
  241. GameManager.prototype.cccMouseDown = function (evt) {
  242. this._step = this.mouseDown = true;
  243. this._oldPosX = this.stage.mouseX;
  244. this._oldPosY = this.stage.mouseY;
  245. this._oldCellX = this.globalPosXtoCellX(this._oldPosX);
  246. this._oldCellY = this.globalPosYtoCellY(this._oldPosY);
  247. this.aeObjectManager.tapToMap(this._oldCellX, this._oldCellY);
  248. };
  249. GameManager.prototype.cccMouseMove = function (evt) {
  250. if (this.mouseDown && this._step) {
  251. var nowMouseX = this.stage.mouseX;
  252. var nowMouseY = this.stage.mouseY;
  253. var pathX = Math.abs(nowMouseX - this._oldPosX);
  254. var pathY = Math.abs(nowMouseY - this._oldPosY);
  255. var newCellX = this.globalPosXtoCellX(nowMouseX);
  256. var newCellY = this.globalPosYtoCellY(nowMouseY);
  257. if (this._oldCellX != newCellX || this._oldCellY != newCellY) {
  258. this._oldCellX = newCellX;
  259. this._oldCellY = newCellY;
  260. this.aeObjectManager.tapMove(this._oldCellX, this._oldCellY);
  261. }
  262. if (Math.abs(pathX - pathY) < this.MOUSE_X_Y_DIFF_MIN || pathX < this.MOUSE_PATH_MIN && pathY < this.MOUSE_PATH_MIN) {
  263. this._oldPosX = nowMouseX;
  264. this._oldPosY = nowMouseY;
  265. return;
  266. }
  267. if (this.aeObjectManager.activeObject != null) {
  268. this._step = false;
  269. if (pathX > pathY) {
  270. if (nowMouseX > this._oldPosX) {
  271. this.aeObjectManager.stepActiveObject(1, 0);
  272. } else {
  273. this.aeObjectManager.stepActiveObject(-1, 0);
  274. }
  275. } else {
  276. if (nowMouseY > this._oldPosY) {
  277. this.aeObjectManager.stepActiveObject(0, 1);
  278. } else {
  279. this.aeObjectManager.stepActiveObject(0, -1);
  280. }
  281. }
  282. }
  283. this._oldPosX = nowMouseX;
  284. this._oldPosY = nowMouseY;
  285. }
  286. };
  287. GameManager.prototype.cccMouseUp = function (evt) {
  288. this._oldCellX = this._oldCellY = -999;
  289. this.mouseDown = false;
  290. this.aeObjectManager.activeObject = null;
  291. };
  292. GameManager.prototype.restart = function () {
  293. this.backround.unccccccache();
  294. var gameManager = new GameManager;
  295. gameManager.levelId = this.levelId;
  296. (new Jok.JokG).jokEngine.transitionScreen(gameManager, null, null);
  297. };
  298. GameManager.prototype.setPause = function () {
  299. this.addChild(new PauseDialog(this));
  300. };
  301. GameManager.prototype.toLevelSelect = function () {
  302. this.backround.unccccccache();
  303. (new Jok.JokG).jokEngine.transitionScreen(new LevelSelectMenu, null, null);
  304. };
  305. GameManager.prototype.setGameOver = function () {
  306. this.addChild(new GameOverDialog(this));
  307. };
  308. GameManager.prototype.update = function () {
  309. if (this.work) {
  310. this.aeObjectManager.update();
  311. }
  312. };
  313. GameManager.prototype.loadLevel = function () {
  314. console.log("loadLevel");
  315. var idLevelsTT = [];
  316. idLevelsTT.push(1);
  317. idLevelsTT.push(2);
  318. idLevelsTT.push(4);
  319. idLevelsTT.push(5);
  320. idLevelsTT.push(8);
  321. idLevelsTT.push(28);
  322. idLevelsTT.push(6);
  323. idLevelsTT.push(23);
  324. idLevelsTT.push(7);
  325. idLevelsTT.push(3);
  326. idLevelsTT.push(18);
  327. idLevelsTT.push(16);
  328. idLevelsTT.push(20);
  329. idLevelsTT.push(30);
  330. idLevelsTT.push(14);
  331. idLevelsTT.push(22);
  332. idLevelsTT.push(31);
  333. idLevelsTT.push(21);
  334. idLevelsTT.push(13);
  335. idLevelsTT.push(15);
  336. idLevelsTT.push(17);
  337. idLevelsTT.push(35);
  338. idLevelsTT.push(19);
  339. idLevelsTT.push(26);
  340. idLevelsTT.push(25);
  341. idLevelsTT.push(24);
  342. idLevelsTT.push(36);
  343. idLevelsTT.push(34);
  344. idLevelsTT.push(40);
  345. idLevelsTT.push(27);
  346. idLevelsTT.push(9);
  347. idLevelsTT.push(29);
  348. idLevelsTT.push(37);
  349. idLevelsTT.push(39);
  350. idLevelsTT.push(32);
  351. idLevelsTT.push(38);
  352. idLevelsTT.push(33);
  353. idLevelsTT.push(32);
  354. idLevelsTT.push(31);
  355. idLevelsTT.push(26);
  356. idLevelsTT.push(37);
  357. idLevelsTT.push(33);
  358. idLevelsTT.push(29);
  359. idLevelsTT.push(45);
  360. idLevelsTT.push(28);
  361. idLevelsTT.push(44);
  362. idLevelsTT.push(18);
  363. idLevelsTT.push(42);
  364. idLevelsTT.push(9);
  365. idLevelsTT.push(24);
  366. idLevelsTT.push(46);
  367. idLevelsTT.push(41);
  368. var levelId = idLevelsTT[this.levelId] - 1;
  369. var xmlLevels = (new Jok.JokG).queue.getResult("gameLevels_1");
  370. var level = xmlLevels.getElementsByTagName("Level")[levelId].getElementsByTagName("tiles")[0].getAttribute("id");
  371. this.numStar = parseInt(xmlLevels.getElementsByTagName("Level")[levelId].getAttribute("numStar"));
  372. var idNow = 0;
  373. for (var i = 0; i < this.CELL_W; i++) {
  374. for (var j = 0; j < this.CELL_H; j++) {
  375. this.field[i][j] = parseInt(level[idNow]);
  376. idNow++;
  377. }
  378. }
  379. this.backround.init();
  380. var objectI = 0;
  381. var backContainer = new createjs.Container;
  382. this.addChild(backContainer);
  383. this.aeObjectManager = new AEObjectManager(this, this.field, backContainer);
  384. this.addChild(this.aeObjectManager);
  385. while (true) {
  386. var objectData = xmlLevels.getElementsByTagName("Level")[levelId].getElementsByTagName("baseObject")[objectI];
  387. if (objectData) {
  388. var xTT = parseInt(objectData.getAttribute("x"));
  389. var yTT = parseInt(objectData.getAttribute("y"));
  390. var strMc = objectData.getAttribute("str");
  391. if (strMc == "alien_1_mc") {
  392. this.aeObjectManager.addAlien(xTT, yTT, 1);
  393. } else {
  394. if (strMc == "alien_2_mc") {
  395. this.aeObjectManager.addAlien(xTT, yTT, 2);
  396. } else {
  397. if (strMc == "alien_3_mc") {
  398. this.aeObjectManager.addAlien(xTT, yTT, 3);
  399. } else {
  400. if (strMc == "alien_4_mc") {
  401. this.aeObjectManager.addAlien(xTT, yTT, 4);
  402. } else {
  403. if (strMc == "Exit_1_mc") {
  404. this.aeObjectManager.addExit(xTT, yTT, 1);
  405. } else {
  406. if (strMc == "Exit_2_mc") {
  407. this.aeObjectManager.addExit(xTT, yTT, 2);
  408. } else {
  409. if (strMc == "Exit_3_mc") {
  410. this.aeObjectManager.addExit(xTT, yTT, 3);
  411. } else {
  412. if (strMc == "Exit_4_mc") {
  413. this.aeObjectManager.addExit(xTT, yTT, 4);
  414. } else {
  415. if (strMc == "arrow_1_mc") {
  416. this.aeObjectManager.addArrow(xTT, yTT, 1);
  417. } else {
  418. if (strMc == "arrow_2_mc") {
  419. this.aeObjectManager.addArrow(xTT, yTT, 2);
  420. } else {
  421. if (strMc == "arrow_3_mc") {
  422. this.aeObjectManager.addArrow(xTT, yTT, 3);
  423. } else {
  424. if (strMc == "arrow_4_mc") {
  425. this.aeObjectManager.addArrow(xTT, yTT, 4);
  426. } else {
  427. if (strMc == "spring_1_mc") {
  428. this.aeObjectManager.addSpring(xTT, yTT);
  429. } else {
  430. if (strMc == "ice_1_mc") {
  431. this.aeObjectManager.addIce(xTT, yTT);
  432. } else {
  433. if (strMc == "Teleport_1_mc") {
  434. this.aeObjectManager.addTeleport(xTT, yTT, 1);
  435. } else {
  436. if (strMc == "Teleport_2_mc") {
  437. this.aeObjectManager.addTeleport(xTT, yTT, 2);
  438. } else {
  439. if (strMc == "Teleport_3_mc") {
  440. this.aeObjectManager.addTeleport(xTT, yTT, 3);
  441. } else {
  442. if (strMc == "Teleport_4_mc") {
  443. this.aeObjectManager.addTeleport(xTT, yTT, 4);
  444. } else {
  445. if (strMc == "decor_8_mc") {
  446. var decorSpr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "decor_8_mc");
  447. backContainer.addChild(decorSpr);
  448. decorSpr.x = xTT;
  449. decorSpr.y = yTT;
  450. } else {
  451. this.backround.addDecor(xTT, yTT, strMc);
  452. }
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. }
  470. }
  471. } else {
  472. break;
  473. }
  474. objectI++;
  475. }
  476. this.aeObjectManager.postInit();
  477. this.backround.ccccccache();
  478. };
  479. GameManager.prototype.cellYtoPosY = function (cellY) {
  480. return this.CELL_Y_BEGIN + this.CELL_WIDTH * cellY - this.CELL_WIDTH / 2;
  481. };
  482. GameManager.prototype.cellXtoPosX = function (cellX) {
  483. return -(this.CELL_W / 2) * this.CELL_WIDTH + this.CELL_WIDTH * cellX + this.CELL_WIDTH / 2;
  484. };
  485. GameManager.prototype.globalPosXtoCellX = function (posX) {
  486. posX = posX - ((new Jok.JokG).GAME_WIDTH - this.CELL_WIDTH * this.CELL_W) / 2;
  487. var cellX = Math.floor(posX / this.CELL_WIDTH);
  488. if (cellX < 0) {
  489. cellX = 0;
  490. }
  491. if (cellX >= this.CELL_W) {
  492. cellX = this.CELL_W - 1;
  493. }
  494. return cellX;
  495. };
  496. GameManager.prototype.globalPosYtoCellY = function (posY) {
  497. posY += -(new Jok.JokG).height / 2 - this.CELL_Y_BEGIN + this.CELL_HEIGHT;
  498. var cellY = Math.floor(posY / this.CELL_WIDTH);
  499. if (cellY < 0) {
  500. cellY = 0;
  501. }
  502. return cellY;
  503. };
  504. MusicManager = function () {
  505. var callee = arguments.callee;
  506. if (callee.instance) {
  507. return callee.instance;
  508. }
  509. this._mute = false;
  510. this._globalMute = false;
  511. this._paused = false;
  512. var isWebAudio = createjs.Sound.activePlugin instanceof createjs.WebAudioPlugin;
  513. console.log("this.isWebAudio = " + createjs.Sound.activePlugin);
  514. this._soundSupport = isWebAudio || !isWebAudio && (!createjs.Sound.BrowserDetect.isIOS && !createjs.Sound.BrowserDetect.isAndroid);
  515. console.log("this._soundSupport = " + this._soundSupport);
  516. this.musicInstance = createjs.Sound.createInstance("mus_1");
  517. this.musicInstance.setVolume(1);
  518. this.enableSound = false;
  519. this.eventMouseDown = (new Jok.JokG).stage.on("stagemousedown", createjs.proxy(this.cccMouseDown, this));
  520. var hidden = "hidden";
  521. var eventVisable = createjs.proxy(this.onchangeVisable, this);
  522. if (hidden in document) {
  523. console.log("mus_1 = " + document.hidden);
  524. if (document.hidden == true) {
  525. this._globalMute = true;
  526. }
  527. document.addEventListener("visibilitychange", eventVisable);
  528. } else {
  529. if ((hidden = "mozHidden") in document) {
  530. console.log("mus_2 = " + document.mozHidden);
  531. if (document.mozHidden == true) {
  532. this._globalMute = true;
  533. }
  534. document.addEventListener("mozvisibilitychange", eventVisable);
  535. } else {
  536. if ((hidden = "webkitHidden") in document) {
  537. console.log("mus_3 = " + document.webkitHidden);
  538. if (document.webkitHidden == true) {
  539. this._globalMute = true;
  540. }
  541. document.addEventListener("webkitvisibilitychange", eventVisable);
  542. } else {
  543. if ((hidden = "msHidden") in document) {
  544. console.log("mus_4 = " + document.msHidden);
  545. if (document.hidden == true) {
  546. this._globalMute = true;
  547. }
  548. document.addEventListener("msvisibilitychange", eventVisable);
  549. } else {
  550. if ("onfocusin" in document) {
  551. console.log("mus_5 = " + document.onfocusin);
  552. document.onfocusin = document.onfocusout = eventVisable;
  553. } else {
  554. console.log("mus_6");
  555. window.onpageshow = window.onpagehide = window.onfocus = window.onblur = eventVisable;
  556. }
  557. }
  558. }
  559. }
  560. }
  561. callee.instance = this;
  562. };
  563. MusicManager.prototype.constructor = MusicManager;
  564. MusicManager.prototype.onchangeVisable = function (evt) {
  565. this._globalMute = !this._globalMute;
  566. console.log("onchangeVisable this._globalMute = " + this._globalMute);
  567. if (this._globalMute) {
  568. if (!this._mute && this.enableSound) {
  569. this._paused = true;
  570. this.musicInstance.pause();
  571. }
  572. } else {
  573. if (!this._mute && this.enableSound) {
  574. this.playMusic();
  575. }
  576. }
  577. };
  578. MusicManager.prototype.cccMouseDown = function (evt) {
  579. console.log("this.enableSound = " + this._globalMute);
  580. this.enableSound = true;
  581. (new Jok.JokG).stage.off("stagemousedown", this.eventMouseDown);
  582. this.playMusic();
  583. };
  584. MusicManager.prototype.playMusic = function () {
  585. if (!this._mute && (this.enableSound && !this._globalMute)) {
  586. if (this._paused) {
  587. this.musicInstance.resume();
  588. } else {
  589. this.musicInstance.play({ loop: -1, interrupt: createjs.Sound.INTERRUPT_ANY });
  590. }
  591. }
  592. };
  593. MusicManager.prototype.playSound = function (name, volume) {
  594. if (!this._mute && (this.enableSound && (this._soundSupport && !this._globalMute))) {
  595. createjs.Sound.play(name, { volume: volume });
  596. }
  597. };
  598. MusicManager.prototype.getMute = function () {
  599. return this._mute;
  600. };
  601. MusicManager.prototype.setMute = function (value) {
  602. this._mute = value;
  603. if (this._mute) {
  604. this._paused = true;
  605. this.musicInstance.pause();
  606. } else {
  607. this.playMusic();
  608. }
  609. };
  610. MusicManager.prototype.playMouse = function () {
  611. this.playSound("mouseClick", 1);
  612. };
  613. MusicManager.prototype.playGameOver = function () {
  614. this.playSound("gameOver", 0.6);
  615. };
  616. MusicManager.prototype.playAlienGo = function () {
  617. this.playSound("alienGo_" + +Jok.JokMath.getRandomInt(1, 2), 0.25);
  618. };
  619. MusicManager.prototype.playAlienTap = function () {
  620. this.playSound("alienTap_" + Jok.JokMath.getRandomInt(1, 3), 0.4);
  621. };
  622. MusicManager.prototype.playIce = function () {
  623. this.playSound("ice", 0.4);
  624. };
  625. MusicManager.prototype.playSpring = function () {
  626. this.playSound("spring", 0.21);
  627. };
  628. MusicManager.prototype.playStarGameOver = function () {
  629. this.playSound("star", 1);
  630. };
  631. MusicManager.prototype.playTeleportBegin = function () {
  632. this.playSound("teleportBegin", 0.4);
  633. };
  634. MusicManager.prototype.playTeleportEnd = function () {
  635. this.playSound("teleportEnd", 0.4);
  636. };
  637. PreloadState = function () {
  638. Jok.JokState.call(this);
  639. };
  640. PreloadState.prototype = Object.create(Jok.JokState.prototype);
  641. PreloadState.prototype.constructor = PreloadState;
  642. PreloadState.prototype.create = function () {
  643. console.log("PreloadState.create");
  644. this.queue = (new Jok.JokG).queue;
  645. var manifest = [{ src: "soft/logo_ingame.png", id: "logo_ingame" }];
  646. this.initAllEvent = this.queue.on("complete", createjs.proxy(this.initAll, this));
  647. this.queue.setMaxConnections(5);
  648. this.queue.loadManifest(manifest);
  649. };
  650. PreloadState.prototype.initAll = function () {
  651. console.log("PreloadState.initAll");
  652. this.queue.off("complete", this.initAllEvent);
  653. this.initCookie();
  654. (new Jok.JokG).MAX_LEVEL = 37;
  655. (new Jok.JokG).text.setLang(SG.lang);
  656. (new Jok.JokG).text.fontName["default"] = "Seymour One";
  657. this.addPreloadText();
  658. var registeTT = [createjs.WebAudioPlugin, createjs.HTMLAudioPlugin];
  659. if (createjs.Sound.BrowserDetect.isFirefox) {
  660. registeTT = [createjs.HTMLAudioPlugin];
  661. }
  662. createjs.Sound.registerPlugins(registeTT);
  663. console.log("createjs.Sound.isReady() = " + createjs.Sound.isReady());
  664. this.queue = (new Jok.JokG).queue;
  665. createjs.Sound.alternateExtensions = ["m4a"];
  666. this.queue.installPlugin(createjs.Sound);
  667. var manifest = [{
  668. src: "imagesPack/AlienEscapeGame_1.png",
  669. id: "gameImg_1"
  670. }, {
  671. src: "imagesPack/AlienEscapeGame_1.json",
  672. id: "gameImgJson_1",
  673. type: createjs.LoadQueue.JSON
  674. }, { src: "imagesPack/AlienEscapeGame_2.png", id: "gameImg_2" }, {
  675. src: "imagesPack/AlienEscapeGame_2.json",
  676. id: "gameImgJson_2",
  677. type: createjs.LoadQueue.JSON
  678. }, { src: "imagesPack/AlienEscapeGame_3.png", id: "gameImg_3" }, {
  679. src: "imagesPack/AlienEscapeGame_3.json",
  680. id: "gameImgJson_3",
  681. type: createjs.LoadQueue.JSON
  682. }, { src: "font/Animated/font.png", id: "fontImg_1" }, {
  683. src: "font/Animated/font.fnt",
  684. id: "fontDataXml_1",
  685. type: createjs.LoadQueue.XML
  686. }, { src: "text.json", id: "text_1", type: createjs.LoadQueue.JSON }, {
  687. src: "HelpAnim/allAnim.xml",
  688. id: "gameImgXml_1",
  689. type: createjs.LoadQueue.XML
  690. }, {
  691. src: "levels/xml/levels.xml",
  692. id: "gameLevels_1",
  693. type: createjs.LoadQueue.XML
  694. }, {
  695. src: "audio/music/gameMus_1.ogg",
  696. id: "mus_1",
  697. type: createjs.LoadQueue.SOUND
  698. }, {
  699. src: "audio/sound/mouseClick.ogg",
  700. id: "mouseClick",
  701. type: createjs.LoadQueue.SOUND
  702. }, {
  703. src: "audio/sound/alienGo_1.ogg",
  704. id: "alienGo_1",
  705. type: createjs.LoadQueue.SOUND
  706. }, {
  707. src: "audio/sound/alienGo_2.ogg",
  708. id: "alienGo_2",
  709. type: createjs.LoadQueue.SOUND
  710. }, {
  711. src: "audio/sound/alienTap_1.ogg",
  712. id: "alienTap_1",
  713. type: createjs.LoadQueue.SOUND
  714. }, {
  715. src: "audio/sound/alienTap_2.ogg",
  716. id: "alienTap_2",
  717. type: createjs.LoadQueue.SOUND
  718. }, {
  719. src: "audio/sound/alienTap_3.ogg",
  720. id: "alienTap_3",
  721. type: createjs.LoadQueue.SOUND
  722. }, { src: "audio/sound/ice.ogg", id: "ice", type: createjs.LoadQueue.SOUND }, {
  723. src: "audio/sound/spring.ogg",
  724. id: "spring",
  725. type: createjs.LoadQueue.SOUND
  726. }, { src: "audio/sound/star.ogg", id: "star", type: createjs.LoadQueue.SOUND }, {
  727. src: "audio/sound/teleportBegin.ogg",
  728. id: "teleportBegin",
  729. type: createjs.LoadQueue.SOUND
  730. }, {
  731. src: "audio/sound/teleportEnd.ogg",
  732. id: "teleportEnd",
  733. type: createjs.LoadQueue.SOUND
  734. }, { src: "audio/sound/gameOver.ogg", id: "gameOver", type: createjs.LoadQueue.SOUND }];
  735. this.queue.on("progress", createjs.proxy(this.handleProgress, this));
  736. this.queue.on("complete", createjs.proxy(this.handleComplete, this));
  737. this.queue.on("fileload", createjs.proxy(this.handleFileLoad, this));
  738. this.queue.setMaxConnections(5);
  739. this.queue.loadManifest(manifest);
  740. };
  741. PreloadState.prototype.addPreloadText = function () {
  742. var txt = new createjs.Text("logo", "26px " + (new Jok.JokG).text.fontName["default"], "#FFE054");
  743. txt.x = -txt.getBounds().width * txt.scaleX;
  744. txt.y = -txt.getBounds().height / 2 * txt.scaleX;
  745. this.addChild(txt);
  746. var shape = new createjs.Shape;
  747. var shapeWidth = 960;
  748. shape.x = -shapeWidth / 2;
  749. shape.y = -shapeWidth / 2;
  750. shape.graphics.beginFill("rgba(75,164,194,1)").rect(0, 0, shapeWidth, shapeWidth);
  751. this.addChild(shape);
  752. this.progressTxt = new createjs.Text("0%", "30px Arial", "#fff");
  753. this.progressTxt.y = -this.progressTxt.getBounds().height / 2 + 120;
  754. this.addChild(this.progressTxt);
  755. var bmp = new createjs.Bitmap((new Jok.JokG).queue.getResult("logo_ingame"));
  756. bmp.scaleX = bmp.scaleY = 0.65;
  757. bmp.x = -bmp.getBounds().width / 2 * bmp.scaleX;
  758. bmp.y = -bmp.getBounds().height / 2 * bmp.scaleX;
  759. bmp.cursor = "pointer";
  760. if (showSGLinks) {
  761. this.addChild(bmp);
  762. bmp.on("click", createjs.proxy(this.openUrl, this));
  763. }
  764. };
  765. PreloadState.prototype.openUrl = function () {
  766. (new Jok.JokG).openUrl("http://m.softgames.de/");
  767. };
  768. PreloadState.prototype.initCookie = function () {
  769. if (typeof window.localStorage != "undefined") {
  770. if (window.localStorage.getItem("levelComplete") == null) {
  771. window.localStorage.setItem("levelComplete", 1);
  772. }
  773. }
  774. };
  775. PreloadState.prototype.handleProgress = function (event) {
  776. console.log("handleProgress = " + event.progress);
  777. this.progressTxt.text = "" + Math.ceil(event.progress * 100) + "%";
  778. this.progressTxt.x = -this.progressTxt.getBounds().width / 2;
  779. };
  780. PreloadState.prototype.handleFileLoad = function (event) {
  781. };
  782. PreloadState.prototype.handleComplete = function (event) {
  783. this._loadGame = true;
  784. if (this._loadGame) {
  785. this.allLoadComplete();
  786. }
  787. };
  788. PreloadState.prototype.initAnim = function () {
  789. (new Jok.JokG).animLoader.loadAnimStep_1_images([this.queue.getResult("gameImgJson_1"), this.queue.getResult("gameImgJson_2"), this.queue.getResult("gameImgJson_3")], [this.queue.getResult("gameImg_1"), this.queue.getResult("gameImg_2"), this.queue.getResult("gameImg_3")]);
  790. (new Jok.JokG).animLoader.setFramePivotXY("helpHand_mc_000", -32, -71);
  791. (new Jok.JokG).animLoader.setFramePivotXY("helpHand_mc_001", -57, -71);
  792. for (var i = 1; i <= 4; i++) {
  793. (new Jok.JokG).animLoader.addAnimation_step_1("alien_" + i + "_mc");
  794. (new Jok.JokG).animLoader.addAnimation_step_1("alien_" + i + "_idle_1_mc");
  795. (new Jok.JokG).animLoader.addAnimation_step_1("alien_" + i + "_idle_2_mc");
  796. (new Jok.JokG).animLoader.addAnimation_step_1("alien_" + i + "_idle_3_mc");
  797. (new Jok.JokG).animLoader.addAnimation_step_1("alien_" + i + "_idle_4_mc");
  798. }
  799. (new Jok.JokG).animLoader.endLoadAnim();
  800. (new Jok.JokG).animLoader.loadAnimStep_2_images();
  801. for (var i = 1; i <= 4; i++) {
  802. (new Jok.JokG).animLoader.addAnimation_step_2("alien_" + i + "_mc", ["mini_0" + i + "_02"]);
  803. (new Jok.JokG).animLoader.addAnimation_step_2("alien_" + i + "_idle_1_mc", ["mini_0" + i + "_01", "mini_0" + i + "_01", "mini_0" + i + "_02", "mini_0" + i + "_03", "mini_0" + i + "_03", "mini_0" + i + "_02"]);
  804. (new Jok.JokG).animLoader.addAnimation_step_2("alien_" + i + "_idle_2_mc", ["mini_0" + i + "_04", "mini_0" + i + "_05", "mini_0" + i + "_06", "mini_0" + i + "_07", "mini_0" + i + "_07", "mini_0" + i + "_06", "mini_0" + i + "_05", "mini_0" + i + "_04", "mini_0" + i + "_02"]);
  805. (new Jok.JokG).animLoader.addAnimation_step_2("alien_" + i + "_idle_3_mc", ["mini_0" + i + "_08", "mini_0" + i + "_08", "mini_0" + i + "_08", "mini_0" + i + "_02"]);
  806. (new Jok.JokG).animLoader.addAnimation_step_2("alien_" + i + "_idle_4_mc", ["mini_0" + i + "_09", "mini_0" + i + "_09", "mini_0" + i + "_09", "mini_0" + i + "_02"]);
  807. }
  808. (new Jok.JokG).animLoader.addAnimation_step_2("alien_3_idle_3_mc", ["mini_03_08", "mini_03_09", "mini_03_08", "mini_03_09", "mini_03_08", "mini_03_09", "mini_03_08", "mini_03_09", "mini_03_02"]);
  809. (new Jok.JokG).animLoader.addAnimation_step_2("alien_4_mc", ["mini_04_01"]);
  810. (new Jok.JokG).animLoader.addAnimation_step_2("alien_4_idle_1_mc", ["mini_04_01", "mini_04_02", "mini_04_03", "mini_04_04", "mini_04_03", "mini_04_02", "mini_04_01"]);
  811. (new Jok.JokG).animLoader.addAnimation_step_2("alien_4_idle_2_mc", ["mini_04_05", "mini_04_06", "mini_04_07", "mini_04_08", "mini_04_05", "mini_04_06", "mini_04_07", "mini_04_08", "mini_04_05", "mini_04_06", "mini_04_07", "mini_04_08", "mini_04_01"]);
  812. for (var i = 1; i <= 4; i++) {
  813. (new Jok.JokG).animLoader.spriteSheet.getAnimation("alien_" + i + "_idle_1_mc").speed = 0.55;
  814. (new Jok.JokG).animLoader.spriteSheet.getAnimation("alien_" + i + "_idle_2_mc").speed = 0.75;
  815. (new Jok.JokG).animLoader.spriteSheet.getAnimation("alien_" + i + "_idle_3_mc").speed = 0.1;
  816. (new Jok.JokG).animLoader.spriteSheet.getAnimation("alien_" + i + "_idle_4_mc").speed = 0.1;
  817. (new Jok.JokG).animLoader.spriteSheet.getAnimation("Teleport_" + i + "_mc").speed = 0.5;
  818. }
  819. (new Jok.JokG).animLoader.spriteSheet.getAnimation("ice_1_mc").speed = 0.2;
  820. (new Jok.JokG).animLoader.spriteSheet.getAnimation("iceDetaills_1_mc").speed = 0.8;
  821. (new Jok.JokG).animLoader.spriteSheet.getAnimation("alien_3_idle_3_mc").speed = 0.75;
  822. (new Jok.JokG).animLoader.spriteSheet.getAnimation("alien_4_idle_1_mc").speed = 0.45;
  823. (new Jok.JokG).animLoader.spriteSheet.getAnimation("alien_4_idle_2_mc").speed = 0.4;
  824. (new Jok.JokG).animLoader.spriteSheet.getAnimation("arrow_1_mc").speed = 0.4;
  825. (new Jok.JokG).animLoader.spriteSheet.getAnimation("spring_1_mc").speed = 1;
  826. (new Jok.JokG).animLoader.spriteSheet.getAnimation("decor_8_mc").speed = 0.75;
  827. };
  828. PreloadState.prototype.allLoadComplete = function () {
  829. if (typeof window.localStorage != "undefined") {
  830. if (window.localStorage.getItem("bestScore") == null) {
  831. window.localStorage.setItem("bestScore", 0);
  832. }
  833. }
  834. (new Jok.JokG).totalScore = 0;
  835. new MusicManager;
  836. (new Jok.JokG).text.init(this.queue.getResult("text_1"));
  837. this.initAnim();
  838. (new Jok.JokG).animLoader.loadBitmapFont(this.queue.getResult("fontDataXml_1"), this.queue.getResult("fontImg_1"), "default");
  839. (new Jok.JokG).jokEngine.switchState(new MainMenu);
  840. };
  841. BackgroundManager = function (gameManager, field) {
  842. createjs.Container.call(this);
  843. this.field = field;
  844. this.gameManager = gameManager;
  845. this.CELL_W_MAX = 14;
  846. this.CELL_H_MAX = 20;
  847. this.DELTA_X_TT = -2;
  848. this.DELTA_Y_TT = -5;
  849. this.tilesData = {};
  850. this.tilesData["0000"] = {};
  851. this.tilesData["0001"] = {};
  852. this.tilesData["0010"] = {};
  853. this.tilesData["0100"] = {};
  854. this.tilesData["1000"] = {};
  855. this.tilesData["0011"] = {};
  856. this.tilesData["0101"] = {};
  857. this.tilesData["1001"] = {};
  858. this.tilesData["0110"] = {};
  859. this.tilesData["1010"] = {};
  860. this.tilesData["1100"] = {};
  861. this.tilesData["1110"] = {};
  862. this.tilesData["1101"] = {};
  863. this.tilesData["1011"] = {};
  864. this.tilesData["0111"] = {};
  865. this.tilesData["1111"] = {};
  866. this.tilesData["0000"].name = "";
  867. this.tilesData["0001"].name = "tileTT_1";
  868. this.tilesData["0010"].name = "tileTT_1";
  869. this.tilesData["0100"].name = "tileTT_1";
  870. this.tilesData["1000"].name = "tileTT_1";
  871. this.tilesData["0011"].name = "tileTT_5";
  872. this.tilesData["0101"].name = "tileTT_3";
  873. this.tilesData["1001"].name = "tileTT_5";
  874. this.tilesData["0110"].name = "tileTT_5";
  875. this.tilesData["1010"].name = "tileTT_3";
  876. this.tilesData["1100"].name = "tileTT_5";
  877. this.tilesData["1110"].name = "tileTT_2";
  878. this.tilesData["1101"].name = "tileTT_2";
  879. this.tilesData["1011"].name = "tileTT_2";
  880. this.tilesData["0111"].name = "tileTT_2";
  881. this.tilesData["1111"].name = "";
  882. this.tilesData["0000"].rot = 0;
  883. this.tilesData["0001"].rot = 180;
  884. this.tilesData["0010"].rot = 90;
  885. this.tilesData["0100"].rot = 0;
  886. this.tilesData["1000"].rot = -90;
  887. this.tilesData["0011"].rot = 90;
  888. this.tilesData["0101"].rot = 0;
  889. this.tilesData["1001"].rot = 180;
  890. this.tilesData["0110"].rot = 0;
  891. this.tilesData["1010"].rot = 90;
  892. this.tilesData["1100"].rot = -90;
  893. this.tilesData["1110"].rot = 0;
  894. this.tilesData["1101"].rot = -90;
  895. this.tilesData["1011"].rot = 180;
  896. this.tilesData["0111"].rot = 90;
  897. this.tilesData["1111"].rot = 0;
  898. };
  899. BackgroundManager.prototype = Object.create(createjs.Container.prototype);
  900. BackgroundManager.prototype.constructor = BackgroundManager;
  901. BackgroundManager.prototype.init = function () {
  902. for (var x = -1; x < this.gameManager.CELL_W + 1; x++) {
  903. for (var y = -5; y < this.gameManager.CELL_H + 3; y++) {
  904. var spr = this.getSprTile(x, y);
  905. if (spr != null) {
  906. spr.x = this.gameManager.cellXtoPosX(x);
  907. spr.y = this.gameManager.cellYtoPosY(y);
  908. spr.rotation = 90 * Jok.JokMath.getRandomInt(0, 3);
  909. this.addChild(spr);
  910. }
  911. }
  912. }
  913. var tt = 1;
  914. for (var x = -1; x < this.gameManager.CELL_W + 1; x++) {
  915. tt = x;
  916. for (var y = -1; y < this.gameManager.CELL_H + 1; y++) {
  917. var XY = this.getTileId(x, y);
  918. if (XY == 0) {
  919. var tileBack = null;
  920. if (tt % 2 == 0) {
  921. tileBack = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "Cell_1_mc");
  922. } else {
  923. tileBack = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "Cell_2_mc");
  924. }
  925. tileBack.x = this.gameManager.cellXtoPosX(x);
  926. tileBack.y = this.gameManager.cellYtoPosY(y);
  927. tileBack.rotation = 90 * Jok.JokMath.getRandomInt(0, 3);
  928. this.addChild(tileBack);
  929. tileBack.stop();
  930. }
  931. tt++;
  932. }
  933. }
  934. for (var x = -1; x < this.gameManager.CELL_W + 1; x++) {
  935. tt = x;
  936. for (var y = -1; y < this.gameManager.CELL_H + 1; y++) {
  937. this.addCorner_0(x, y, tt % 2);
  938. tt++;
  939. }
  940. }
  941. for (var x = -1; x < this.gameManager.CELL_W + 1; x++) {
  942. for (var y = -5; y < this.gameManager.CELL_H + 3; y++) {
  943. var spr = this.addCorner_2(x, y);
  944. if (spr != null) {
  945. spr.x = this.gameManager.cellXtoPosX(x) + this.gameManager.CELL_WIDTH / 2;
  946. spr.y = this.gameManager.cellYtoPosY(y) + this.gameManager.CELL_WIDTH / 2;
  947. this.addChild(spr);
  948. }
  949. }
  950. }
  951. tileBack = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "shadowMenu");
  952. this.addChild(tileBack);
  953. };
  954. BackgroundManager.prototype.addCorner_0 = function (x, y, numTT) {
  955. var XY = this.getTileId(x, y);
  956. if (XY == 1) {
  957. var X1Y = this.getTileId(x + 1, y);
  958. var X_1Y = this.getTileId(x - 1, y);
  959. var XY1 = this.getTileId(x, y + 1);
  960. var XY_1 = this.getTileId(x, y - 1);
  961. var X1Y1 = this.getTileId(x + 1, y + 1);
  962. var X1Y_1 = this.getTileId(x + 1, y - 1);
  963. var X_1Y1 = this.getTileId(x - 1, y + 1);
  964. var X_1Y_1 = this.getTileId(x - 1, y - 1);
  965. if (X1Y == 0) {
  966. this.addTileBack("CellDelta_mc", x, y, 180, numTT);
  967. }
  968. if (X_1Y == 0) {
  969. this.addTileBack("CellDelta_mc", x, y, 0, numTT);
  970. }
  971. if (XY1 == 0) {
  972. this.addTileBack("CellDelta_mc", x, y, 270, numTT);
  973. }
  974. if (XY_1 == 0) {
  975. this.addTileBack("CellDelta_mc", x, y, 90, numTT);
  976. }
  977. if (X1Y1 == 0 && (XY1 == 1 && X1Y == 1)) {
  978. this.addTileBack("CellDelta1_mc", x, y, 270);
  979. }
  980. if (X1Y_1 == 0 && (X1Y == 1 && XY_1 == 1)) {
  981. this.addTileBack("CellDelta1_mc", x, y, 180);
  982. }
  983. if (X_1Y1 == 0 && (X_1Y == 1 && XY1 == 1)) {
  984. this.addTileBack("CellDelta1_mc", x, y, 0);
  985. }
  986. if (X_1Y_1 == 0 && (X_1Y == 1 && XY_1 == 1)) {
  987. this.addTileBack("CellDelta1_mc", x, y, 90);
  988. }
  989. }
  990. };
  991. BackgroundManager.prototype.addCorner_1 = function (x, y) {
  992. var XY = this.getTileId(x, y);
  993. if (XY == 1) {
  994. var X1Y = this.getTileId(x + 1, y);
  995. var X_1Y = this.getTileId(x - 1, y);
  996. var XY1 = this.getTileId(x, y + 1);
  997. var XY_1 = this.getTileId(x, y - 1);
  998. var X1Y1 = this.getTileId(x + 1, y + 1);
  999. var X1Y_1 = this.getTileId(x + 1, y - 1);
  1000. var X_1Y1 = this.getTileId(x - 1, y + 1);
  1001. var X_1Y_1 = this.getTileId(x - 1, y - 1);
  1002. if (X1Y == 0 && (XY1 == 1 && XY_1 == 1)) {
  1003. this.addTileBack("tile_01_site", x, y, 180);
  1004. }
  1005. if (X_1Y == 0 && (XY1 == 1 && XY_1 == 1)) {
  1006. this.addTileBack("tile_01_site", x, y, 0);
  1007. }
  1008. if (XY1 == 0 && (X1Y == 1 && X_1Y == 1)) {
  1009. this.addTileBack("tile_01_site", x, y, 270);
  1010. }
  1011. if (XY_1 == 0 && (X1Y == 1 && X_1Y == 1)) {
  1012. this.addTileBack("tile_01_site", x, y, 90);
  1013. }
  1014. if (X1Y1 == 0 && (XY1 == 1 && X1Y == 1)) {
  1015. this.addTileBack("tile_01_corner", x, y, 270);
  1016. }
  1017. if (X1Y_1 == 0 && (X1Y == 1 && XY_1 == 1)) {
  1018. this.addTileBack("tile_01_corner", x, y, 180);
  1019. }
  1020. if (X_1Y1 == 0 && (X_1Y == 1 && XY1 == 1)) {
  1021. this.addTileBack("tile_01_corner", x, y, 0);
  1022. }
  1023. if (X_1Y_1 == 0 && (X_1Y == 1 && XY_1 == 1)) {
  1024. this.addTileBack("tile_01_corner", x, y, 90);
  1025. }
  1026. if (X1Y1 == 0 && (XY1 == 0 && X1Y == 0)) {
  1027. this.addTileBack("tile_01_corner_1", x, y, 270);
  1028. }
  1029. if (X1Y_1 == 0 && (X1Y == 0 && XY_1 == 0)) {
  1030. this.addTileBack("tile_01_corner_1", x, y, 180);
  1031. }
  1032. if (X_1Y1 == 0 && (X_1Y == 0 && XY1 == 0)) {
  1033. this.addTileBack("tile_01_corner_1", x, y, 0);
  1034. }
  1035. if (X_1Y_1 == 0 && (X_1Y == 0 && XY_1 == 0)) {
  1036. this.addTileBack("tile_01_corner_1", x, y, 90);
  1037. }
  1038. }
  1039. };
  1040. BackgroundManager.prototype.addCorner_2 = function (x, y) {
  1041. var XY = this.getTileId(x, y);
  1042. var X1Y = this.getTileId(x + 1, y);
  1043. var X1Y1 = this.getTileId(x + 1, y + 1);
  1044. var XY1 = this.getTileId(x, y + 1);
  1045. var name = this.tilesData["" + XY + "" + X1Y + "" + X1Y1 + "" + XY1].name;
  1046. if (name.length == 0) {
  1047. return null;
  1048. }
  1049. var spr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, name);
  1050. spr.rotation = this.tilesData["" + XY + "" + X1Y + "" + X1Y1 + "" + XY1].rot;
  1051. spr.stop();
  1052. return spr;
  1053. };
  1054. BackgroundManager.prototype.addTileBack = function (nameAnim, x, y, rot, frameNum) {
  1055. frameNum = frameNum || 0;
  1056. var tileBack = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, nameAnim);
  1057. tileBack.x = this.gameManager.cellXtoPosX(x);
  1058. tileBack.y = this.gameManager.cellYtoPosY(y);
  1059. tileBack.rotation = rot;
  1060. tileBack.currentAnimationFrame = frameNum;
  1061. this.addChild(tileBack);
  1062. tileBack.stop();
  1063. };
  1064. BackgroundManager.prototype.unccccccache = function () {
  1065. this.uncache();
  1066. };
  1067. BackgroundManager.prototype.ccccccache = function () {
  1068. this.cache(-640 / 2, -960 / 2, 640, 960);
  1069. this.removeAllChildren();
  1070. };
  1071. BackgroundManager.prototype.addUp = function (fieldUP, deltaX, deltaY) {
  1072. for (var x = -1; x < this.CELL_W_MAX; x++) {
  1073. for (var y = -5; y < this.CELL_H_MAX + 2; y++) {
  1074. var spr = this.getSprTileUp(x, y, fieldUP);
  1075. if (spr != null) {
  1076. spr.x = this.gameManager.cellXtoPosX(x + this.DELTA_X_TT) + this.gameManager.CELL_WIDTH / 2 + deltaX;
  1077. spr.y = this.gameManager.cellYtoPosY(y + this.DELTA_Y_TT) + this.gameManager.CELL_WIDTH / 2 + deltaY;
  1078. this.addChild(spr);
  1079. }
  1080. }
  1081. }
  1082. };
  1083. BackgroundManager.prototype.getSprTile = function (x, y) {
  1084. var XY = this.getTileId(x, y);
  1085. var X1Y = this.getTileId(x + 1, y);
  1086. var X1Y1 = this.getTileId(x + 1, y + 1);
  1087. var XY1 = this.getTileId(x, y + 1);
  1088. if (XY == 0) {
  1089. return null;
  1090. }
  1091. var spr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "tile_black_1_1_1_1");
  1092. spr.stop();
  1093. return spr;
  1094. };
  1095. BackgroundManager.prototype.getTileId = function (x, y) {
  1096. if (x <= -1 || (y <= -1 || (x >= this.gameManager.CELL_W || y >= this.gameManager.CELL_H))) {
  1097. return 1;
  1098. }
  1099. return this.field[x][y];
  1100. };
  1101. BackgroundManager.prototype.addDecor = function (x, y, nameDecor) {
  1102. var decorSpr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, nameDecor);
  1103. this.addChild(decorSpr);
  1104. decorSpr.x = x;
  1105. decorSpr.y = y;
  1106. decorSpr.stop();
  1107. };
  1108. GuiBlock = function (gameManager) {
  1109. createjs.Container.call(this);
  1110. this.y = -316;
  1111. this.gameManager = gameManager;
  1112. var back = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "guiFrameDown_mc");
  1113. this.addChild(back);
  1114. back.y = -20;
  1115. back.scaleY = 1.5;
  1116. back.y += back.scaleY * 286 / 2 - 286 / 2;
  1117. back.stop();
  1118. this.buttonPause = new MyButtonBase(createjs.proxy(this.pauseAction, this), new createjs.Point(-277, 2), new createjs.Point(1, 1), "buttonBase_mc");
  1119. this.buttonPause.initUp("buttonStop_mc");
  1120. this.addChild(this.buttonPause);
  1121. this.buttonRestart = new MyButtonBase(createjs.proxy(this.restartAction, this), new createjs.Point(-192, this.buttonPause.y), new createjs.Point(this.buttonPause.scaleX, this.buttonPause.scaleY), "buttonBase_mc");
  1122. this.buttonRestart.initUp("buttonRestart_mc");
  1123. this.addChild(this.buttonRestart);
  1124. this.starBar = new StarBar(this.gameManager.numStar);
  1125. this.addChild(this.starBar);
  1126. var txt = new createjs.Text((new Jok.JokG).text.getText("level") + " " + (gameManager.levelId + 1), "26px " + (new Jok.JokG).text.fontName["default"], "#FFE054");
  1127. txt.x = (new Jok.JokG).width / 2 - txt.getBounds().width * txt.scaleX - 5;
  1128. txt.y = -txt.getBounds().height / 2 * txt.scaleX;
  1129. this.addChild(txt);
  1130. };
  1131. GuiBlock.prototype = Object.create(createjs.Container.prototype);
  1132. GuiBlock.prototype.constructor = GuiBlock;
  1133. GuiBlock.prototype.offButton = function () {
  1134. this.buttonPause.offWork();
  1135. this.buttonRestart.offWork();
  1136. };
  1137. GuiBlock.prototype.onButton = function () {
  1138. this.buttonPause.onWork();
  1139. this.buttonRestart.onWork();
  1140. };
  1141. GuiBlock.prototype.pauseAction = function () {
  1142. this.gameManager.setPause();
  1143. };
  1144. GuiBlock.prototype.restartAction = function () {
  1145. this.gameManager.restart();
  1146. };
  1147. LevelButton = function (pos, scaleBegin, idLevel, open) {
  1148. MyButtonBase.call(this, null, pos, scaleBegin, "LevelSelectButton_mc");
  1149. this.idLevel = idLevel;
  1150. this._open = open;
  1151. if (!open) {
  1152. this.sprDown.currentAnimationFrame = 1;
  1153. }
  1154. this.initStar();
  1155. var levelText = new createjs.BitmapText("" + this.idLevel, (new Jok.JokG).animLoader.fontSheet["default"]);
  1156. levelText.scaleX = levelText.scaleY = 0.8;
  1157. levelText.y = -levelText.getBounds().height / 2 * levelText.scaleX - 15;
  1158. levelText.x = -levelText.getBounds().width / 2 * levelText.scaleX;
  1159. this.addChild(levelText);
  1160. this.actionFunc = createjs.proxy(this.levelAction, this);
  1161. };
  1162. LevelButton.prototype = Object.create(MyButtonBase.prototype);
  1163. LevelButton.prototype.constructor = LevelButton;
  1164. LevelButton.prototype.initStar = function () {
  1165. this.sprDown.stop();
  1166. var numStar = 0;
  1167. if (typeof window.localStorage != "undefined") {
  1168. if (window.localStorage.getItem("levelStar" + this.idLevel) == null) {
  1169. window.localStorage.setItem("levelStar" + this.idLevel, 0);
  1170. }
  1171. numStar = window.localStorage.getItem("levelStar" + this.idLevel);
  1172. }
  1173. var ttPos = 30;
  1174. for (var i = 0; i < 3; i++) {
  1175. var spr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "LevelMenuStar_mc");
  1176. spr.x = -ttPos + ttPos * i;
  1177. spr.y = 30;
  1178. spr.stop();
  1179. if (i < numStar) {
  1180. spr.currentAnimationFrame = 1;
  1181. } else {
  1182. spr.currentAnimationFrame = 0;
  1183. }
  1184. this.addChild(spr);
  1185. }
  1186. };
  1187. LevelButton.prototype.levelAction = function () {
  1188. if (this._open) {
  1189. SG_Hooks.start();
  1190. var gameManager = new GameManager;
  1191. gameManager.levelId = this.idLevel - 1;
  1192. (new Jok.JokG).jokEngine.transitionScreen(gameManager, null, null);
  1193. }
  1194. };
  1195. SoundButton = function (pos, scaleBegin) {
  1196. MyButtonBase.call(this, null, pos, scaleBegin, "buttonBase_mc");
  1197. this.initUp("ButtonMusic_mc");
  1198. if ((new MusicManager).getMute()) {
  1199. this.sprUp.currentAnimationFrame = 1;
  1200. }
  1201. this.actionFunc = createjs.proxy(this.soundAction, this);
  1202. };
  1203. SoundButton.prototype = Object.create(MyButtonBase.prototype);
  1204. SoundButton.prototype.constructor = SoundButton;
  1205. SoundButton.prototype.soundAction = function () {
  1206. (new MusicManager).setMute(!(new MusicManager).getMute());
  1207. if ((new MusicManager).getMute()) {
  1208. this.sprUp.currentAnimationFrame = 1;
  1209. } else {
  1210. this.sprUp.currentAnimationFrame = 0;
  1211. }
  1212. };
  1213. StarBar = function (numStar) {
  1214. createjs.Container.call(this);
  1215. this.x = -12;
  1216. this.y = 5;
  1217. this.MASK_SIZE = 237.15;
  1218. this.barMask = new createjs.Shape;
  1219. this.barMask.x = -this.MASK_SIZE / 2;
  1220. this.barMask.y = -25 / 2;
  1221. this.barMask.graphics.beginFill("rgba(255,255,255,1)").rect(0, 0, this.MASK_SIZE, 25);
  1222. this.starNum = 3;
  1223. this.stepNow = 0;
  1224. this.numStarThree = numStar;
  1225. this.numStarTwo = Math.ceil(this.numStarThree * 0.4) + numStar;
  1226. this.numStarOne = Math.ceil(this.numStarTwo * 0.5) + this.numStarTwo;
  1227. this.numStarAll = this.numStarOne + 1;
  1228. this.initStars();
  1229. var sprDown = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "scoreBar_1_mc");
  1230. this.addChild(sprDown);
  1231. this.barSpr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "scoreBar_2_mc");
  1232. this.barSpr.mask = this.barMask;
  1233. this.addChild(this.barSpr);
  1234. var sprUp = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "scoreBar_3_mc");
  1235. this.addChild(sprUp);
  1236. this.stepTxt = new createjs.BitmapText("0", (new Jok.JokG).animLoader.fontSheet["default"]);
  1237. this.stepTxt.scaleX = this.stepTxt.scaleY = 0.3;
  1238. this.stepTxt.x = -this.stepTxt.getBounds().width / 2 * this.stepTxt.scaleX;
  1239. this.stepTxt.y = -this.stepTxt.getBounds().height / 2 * this.stepTxt.scaleX + 0;
  1240. this.addChild(this.stepTxt);
  1241. };
  1242. StarBar.prototype = Object.create(createjs.Container.prototype);
  1243. StarBar.prototype.constructor = StarBar;
  1244. StarBar.prototype.initStars = function () {
  1245. var addX = 0;
  1246. this.starTree = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "star_3_mc");
  1247. this.starTree.stop();
  1248. this.starTree.y = -27;
  1249. this.starTree.x = -this.MASK_SIZE / 2 + this.MASK_SIZE * (this.numStarThree / this.numStarAll) + addX;
  1250. this.addChild(this.starTree);
  1251. this.starTwoo = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "star_2_mc");
  1252. this.starTwoo.y = this.starTree.y;
  1253. this.starTwoo.stop();
  1254. this.starTwoo.x = -this.MASK_SIZE / 2 + this.MASK_SIZE * (this.numStarTwo / this.numStarAll) + addX;
  1255. this.addChild(this.starTwoo);
  1256. this.starOne = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "star_1_mc");
  1257. this.starOne.y = this.starTree.y;
  1258. this.starOne.stop();
  1259. this.starOne.x = -this.MASK_SIZE / 2 + this.MASK_SIZE * (this.numStarOne / this.numStarAll) + addX;
  1260. this.addChild(this.starOne);
  1261. this.initStarsText(this.numStarThree);
  1262. this.initStarsText(this.numStarTwo);
  1263. this.initStarsText(this.numStarOne);
  1264. };
  1265. StarBar.prototype.initStarsText = function (numb) {
  1266. var addX = 0;
  1267. var posY = 28;
  1268. var starTreeText = new createjs.BitmapText("" + numb, (new Jok.JokG).animLoader.fontSheet["default"]);
  1269. starTreeText.scaleX = starTreeText.scaleY = 0.4;
  1270. starTreeText.y = posY - starTreeText.getBounds().height / 2 * starTreeText.scaleX;
  1271. starTreeText.x = -this.MASK_SIZE / 2 + this.MASK_SIZE * (numb / this.numStarAll) - starTreeText.getBounds().width / 2 * starTreeText.scaleX + addX;
  1272. this.addChild(starTreeText);
  1273. };
  1274. StarBar.prototype.addStep = function () {
  1275. if (this.stepNow == this.numStarThree) {
  1276. this.starTree.currentAnimationFrame = 1;
  1277. this.starNum--;
  1278. } else {
  1279. if (this.stepNow == this.numStarTwo) {
  1280. this.starTwoo.currentAnimationFrame = 1;
  1281. this.starNum--;
  1282. } else {
  1283. if (this.stepNow == this.numStarOne) {
  1284. this.starOne.currentAnimationFrame = 1;
  1285. this.starNum--;
  1286. }
  1287. }
  1288. }
  1289. this.stepNow++;
  1290. this.stepTxt.text = "" + this.stepNow;
  1291. this.stepTxt.x = -this.stepTxt.getBounds().width / 2 * this.stepTxt.scaleX;
  1292. if (this.stepNow >= this.numStarAll) {
  1293. this.barMask.x = 9999;
  1294. } else {
  1295. this.barMask.x = -this.MASK_SIZE / 2 + this.MASK_SIZE * (this.stepNow / this.numStarAll);
  1296. }
  1297. };
  1298. CreditsDialog = function (mainMenu) {
  1299. createjs.Container.call(this);
  1300. this.mainMenu = mainMenu;
  1301. this.mainMenu.offButton();
  1302. var color = "#000";
  1303. var font = " Verdana";
  1304. var shapeRect = new createjs.Shape;
  1305. shapeRect.x = -(new Jok.JokG).width / 2;
  1306. shapeRect.y = -(new Jok.JokG).height / 2;
  1307. shapeRect.graphics.beginFill("rgba(255,255,255,0.5)").rect(0, 0, (new Jok.JokG).width, (new Jok.JokG).height);
  1308. this.addChild(shapeRect);
  1309. var txt = new createjs.Text((new Jok.JokG).text.getText("developed"), "36px" + font, color);
  1310. txt.x = -txt.getBounds().width / 2;
  1311. txt.y = -260;
  1312. this.addChild(txt);
  1313. var txt_1 = new createjs.Text((new Jok.JokG).text.getText("aizat"), "36px" + font, color);
  1314. txt_1.x = -txt_1.getBounds().width / 2;
  1315. txt_1.y = txt.y + 55;
  1316. this.addChild(txt_1);
  1317. var txt_2 = new createjs.Text((new Jok.JokG).text.getText("email"), "36px" + font, color);
  1318. txt_2.x = -txt_2.getBounds().width / 2;
  1319. txt_2.y = txt_1.y + 80;
  1320. this.addChild(txt_2);
  1321. this.alpha = 0;
  1322. createjs.Tween.get(this).to({ alpha: 1 }, 400, createjs.Ease.quadOut);
  1323. this.eventMouseDown = (new Jok.JokG).stage.on("stagemousedown", createjs.proxy(this.cccMouseDown, this));
  1324. };
  1325. CreditsDialog.prototype = Object.create(createjs.Container.prototype);
  1326. CreditsDialog.prototype.constructor = CreditsDialog;
  1327. CreditsDialog.prototype.cccMouseDown = function (evt) {
  1328. (new Jok.JokG).stage.off("stagemousedown", this.eventMouseDown);
  1329. this.mainMenu.onButton();
  1330. if (this.parent) {
  1331. this.parent.removeChild(this);
  1332. }
  1333. };
  1334. AEObjectBase = function (gameManger, aeObjectManager, cellX, cellY, idObject, animName) {
  1335. createjs.Container.call(this);
  1336. this.gameManager = gameManger;
  1337. this.fgid = (new Jok.JokG).getNewid();
  1338. this.aeObjectManager = aeObjectManager;
  1339. this.cellX = cellX;
  1340. this.cellY = cellY;
  1341. this.idObject = idObject;
  1342. this.tag = 0;
  1343. this.selectable = false;
  1344. console.log("animName = " + animName);
  1345. this.baseSpr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, animName);
  1346. this.baseSpr.stop();
  1347. this.addChild(this.baseSpr);
  1348. this.x = this.gameManager.cellXtoPosX(this.cellX);
  1349. this.y = this.gameManager.cellYtoPosY(this.cellY);
  1350. };
  1351. AEObjectBase.prototype = Object.create(createjs.Container.prototype);
  1352. AEObjectBase.prototype.constructor = AEObjectBase;
  1353. AEObjectBase.prototype.postInit = function () {
  1354. };
  1355. AEObjectBase.prototype.tapToObject = function () {
  1356. };
  1357. AEObjectBase.prototype.step = function (dirX, dirY) {
  1358. return false;
  1359. };
  1360. AEObjectBase.prototype.alienPreActivateCell = function (alien) {
  1361. };
  1362. AEObjectBase.prototype.alienActivateCell = function (alien) {
  1363. };
  1364. AEObjectBase.prototype.alienActivateNextCell = function (alien) {
  1365. return false;
  1366. };
  1367. AEObjectBase.prototype.alienGoBegin = function (alien) {
  1368. };
  1369. AEObjectAlien = function (gameManger, aeObjectManager, cellX, cellY, idAlien) {
  1370. AEObjectBase.call(this, gameManger, aeObjectManager, cellX, cellY, gameManger.AEOBJECT_ALIEN_ID, "alien_" + idAlien + "_mc");
  1371. this.selectable = true;
  1372. this.numAnim = 0;
  1373. this.idAlien = idAlien;
  1374. this.funcEndAnim = createjs.proxy(this.endAnim, this);
  1375. this.onFuncEndAnim = this.baseSpr.on("animationend", this.funcEndAnim);
  1376. this.setIdleAnim();
  1377. this.setBeginAnimTime();
  1378. this.isCellHappy = false;
  1379. this.dirX = 0;
  1380. this.dirY = 0;
  1381. this.shadowSpr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "shadow");
  1382. this.addChildAt(this.shadowSpr, 0);
  1383. this.baseSprYBegin = -10;
  1384. this.baseSpr.y = this.baseSprYBegin;
  1385. this.shadowSpr.y = 18;
  1386. };
  1387. AEObjectAlien.prototype = Object.create(AEObjectBase.prototype);
  1388. AEObjectAlien.prototype.constructor = AEObjectAlien;
  1389. AEObjectAlien.prototype.setIdleAnim = function () {
  1390. this.idleData = this.gameManager.ANIM_ALIEN_IDLE_DATA[this.idAlien][Jok.JokMath.getRandomInt(0, this.gameManager.ANIM_ALIEN_IDLE_DATA[this.idAlien].length - 1)];
  1391. this.baseSpr.gotoAndStop(this.idleData.name);
  1392. this.baseSpr.currentAnimationFrame = this.baseSpr.spriteSheet.getAnimation(this.baseSpr.currentAnimation).frames.length - 1;
  1393. };
  1394. AEObjectAlien.prototype.setHappy = function (happy) {
  1395. if (happy == this.isCellHappy) {
  1396. return;
  1397. }
  1398. this.isCellHappy = happy;
  1399. if (this.isCellHappy) {
  1400. this.aeObjectManager.checkWin();
  1401. this.setHappyAnim();
  1402. (new MusicManager).playAlienTap();
  1403. } else {
  1404. createjs.Tween.removeTweens(this.baseSpr);
  1405. createjs.Tween.removeTweens(this.shadowSpr);
  1406. this.baseSpr.y = this.baseSprYBegin;
  1407. this.shadowSpr.scaleX = this.shadowSpr.scaleY = 1;
  1408. this.setTimeWait();
  1409. }
  1410. };
  1411. AEObjectAlien.prototype.setHappyAnim = function () {
  1412. createjs.Tween.removeTweens(this);
  1413. this.numAnim = 9999;
  1414. this.baseSpr.stop();
  1415. this.baseSpr.currentAnimationFrame = this.baseSpr.spriteSheet.getAnimation(this.baseSpr.currentAnimation).frames.length - 1;
  1416. var time = 200;
  1417. createjs.Tween.get(this.baseSpr, { loop: true }).to({ y: this.baseSprYBegin - 20 }, time, createjs.Ease.linear).to({ y: this.baseSprYBegin }, time, createjs.Ease.linear);
  1418. var scaleEnd = 0.8;
  1419. createjs.Tween.get(this.shadowSpr, { loop: true }).to({
  1420. scaleX: scaleEnd,
  1421. scaleY: scaleEnd
  1422. }, time, createjs.Ease.linear).to({ scaleX: 1, scaleY: 1 }, time, createjs.Ease.linear);
  1423. };
  1424. AEObjectAlien.prototype.setBeginAnimTime = function () {
  1425. this.baseSpr.off("animationend", this.onFuncEndAnim);
  1426. this.onFuncEndAnim = this.baseSpr.on("animationend", this.funcEndAnim);
  1427. this.baseSpr.stop();
  1428. this.setTimeWait();
  1429. };
  1430. AEObjectAlien.prototype.setTimeWait = function () {
  1431. if (!this.isCellHappy) {
  1432. createjs.Tween.get(this).wait(Jok.JokMath.getRandomNumber(2000, 4000)).call(createjs.proxy(this.endWait, this));
  1433. } else {
  1434. this.setHappyAnim();
  1435. }
  1436. };
  1437. AEObjectAlien.prototype.endWait = function () {
  1438. if (!this.isCellHappy) {
  1439. this.setIdleAnim();
  1440. this.numAnim = Jok.JokMath.getRandomInt(this.idleData.numMin, this.idleData.numMax) + 1;
  1441. this.baseSpr.play();
  1442. }
  1443. };
  1444. AEObjectAlien.prototype.endAnim = function () {
  1445. this.numAnim--;
  1446. if (this.numAnim <= 0) {
  1447. this.baseSpr.stop();
  1448. this.setTimeWait();
  1449. }
  1450. };
  1451. AEObjectAlien.prototype.setWIn = function () {
  1452. this.setHappyAnim();
  1453. this.numAnim = 999;
  1454. createjs.Tween.removeTweens(this);
  1455. };
  1456. AEObjectAlien.prototype.tapToObject = function () {
  1457. };
  1458. AEObjectBase.prototype.step = function (dirX, dirY) {
  1459. this.stepAnimNow = 0;
  1460. var toCell = this.aeObjectManager.getCellStopByDir(this.cellX + dirX, this.cellY + dirY, dirX, dirY, this);
  1461. if (this.cellX == toCell.cellX && this.cellY == toCell.cellY) {
  1462. return false;
  1463. }
  1464. this.aeObjectManager.alienGoBegin(this.cellX, this.cellY, this);
  1465. this.setHappy(false);
  1466. (new MusicManager).playAlienGo();
  1467. this.dirX = dirX;
  1468. this.dirY = dirY;
  1469. this.cellX = toCell.cellX;
  1470. this.cellY = toCell.cellY;
  1471. this.aeObjectManager.setAlienSelectable(false);
  1472. var lenght = Math.abs(this.gameManager.cellXtoPosX(this.cellX) - this.x) + Math.abs(this.gameManager.cellYtoPosY(this.cellY) - this.y);
  1473. var time = lenght / this.gameManager.SPEED_ALIEN * 1000;
  1474. createjs.Tween.get(this).to({
  1475. x: this.gameManager.cellXtoPosX(this.cellX),
  1476. y: this.gameManager.cellYtoPosY(this.cellY)
  1477. }, time, createjs.Ease.quadInOut).call(createjs.proxy(this.goAnimStep_2, this));
  1478. if (dirY == 0) {
  1479. var timeTo = 100;
  1480. this.timeEndRot = 100;
  1481. if (time > timeTo + this.timeEndRot) {
  1482. createjs.Tween.get(this.baseSpr).to({ rotation: -15 * dirX }, timeTo, createjs.Ease.linear).wait(time - this.timeEndRot - timeTo).call(createjs.proxy(this.endRot, this));
  1483. }
  1484. }
  1485. return true;
  1486. };
  1487. AEObjectAlien.prototype.endRot = function () {
  1488. createjs.Tween.get(this.baseSpr).to({ rotation: 0 }, this.timeEndRot, createjs.Ease.linear);
  1489. };
  1490. AEObjectAlien.prototype.goAnimStep_2 = function () {
  1491. this.goAnimStep_3();
  1492. };
  1493. AEObjectAlien.prototype.goAnimStep_3 = function () {
  1494. this.stepAnimNow = 3;
  1495. this.aeObjectManager.setAlienSelectable(true);
  1496. if (!this.aeObjectManager.alienActivateNextCell(this.cellX + this.dirX, this.cellY + this.dirY, this)) {
  1497. this.aeObjectManager.alienActivateCell(this.cellX, this.cellY, this);
  1498. }
  1499. };
  1500. AEObjectAlien.prototype.teleportActivate = function (newCellX, newCellY) {
  1501. (new MusicManager).playTeleportBegin();
  1502. this.aeObjectManager.setAlienSelectable(false);
  1503. this.cellX = newCellX;
  1504. this.cellY = newCellY;
  1505. this.stepAnimNow = 0;
  1506. var scaleX_1 = 0.5;
  1507. var scaleY_1 = 1.5;
  1508. var time_1 = 200;
  1509. var scaleX_2 = 0.2;
  1510. var scaleY_2 = 0.3;
  1511. var time_2 = 100;
  1512. createjs.Tween.get(this).to({
  1513. scaleX: scaleX_1,
  1514. scaleY: scaleY_1,
  1515. y: this.y - 30
  1516. }, time_1, createjs.Ease.linear).to({
  1517. scaleX: scaleX_2,
  1518. scaleY: scaleY_2,
  1519. y: this.y + 10
  1520. }, time_2, createjs.Ease.linear).call(createjs.proxy(this.teleportActivateBegin, this));
  1521. };
  1522. AEObjectAlien.prototype.teleportActivateBegin = function () {
  1523. this.x = this.gameManager.cellXtoPosX(this.cellX);
  1524. this.y = this.gameManager.cellYtoPosY(this.cellY);
  1525. this.y += 10;
  1526. var scaleX_1 = 0.5;
  1527. var scaleY_1 = 1.5;
  1528. var time_1 = 100;
  1529. createjs.Tween.get(this).to({
  1530. scaleX: scaleX_1,
  1531. scaleY: scaleY_1,
  1532. y: this.y - 40
  1533. }, time_1, createjs.Ease.linear).to({
  1534. scaleX: 1,
  1535. scaleY: 1,
  1536. y: this.y - 10
  1537. }, 200, createjs.Ease.linear).call(createjs.proxy(this.teleportActivateEnd, this));
  1538. };
  1539. AEObjectAlien.prototype.teleportActivateEnd = function () {
  1540. this.aeObjectManager.setAlienSelectable(true);
  1541. this.step(this.dirX, this.dirY);
  1542. };
  1543. AEObjectArrow = function (gameManger, aeObjectManager, cellX, cellY, idArrow) {
  1544. AEObjectBase.call(this, gameManger, aeObjectManager, cellX, cellY, gameManger.AEOBJECT_ARROW_ID, "arrow_1_mc");
  1545. this.idArrow = idArrow;
  1546. this.rotation = (idArrow + 1) * 90;
  1547. this.baseSpr.play();
  1548. this.stepX = 0;
  1549. this.stepY = 0;
  1550. if (this.idArrow == 1) {
  1551. this.stepY = -1;
  1552. } else {
  1553. if (this.idArrow == 2) {
  1554. this.stepX = 1;
  1555. } else {
  1556. if (this.idArrow == 3) {
  1557. this.stepY = 1;
  1558. } else {
  1559. if (this.idArrow == 4) {
  1560. this.stepX = -1;
  1561. }
  1562. }
  1563. }
  1564. }
  1565. };
  1566. AEObjectArrow.prototype = Object.create(AEObjectBase.prototype);
  1567. AEObjectArrow.prototype.constructor = AEObjectArrow;
  1568. AEObjectArrow.prototype.alienActivateCell = function (alien) {
  1569. alien.step(this.stepX, this.stepY);
  1570. };
  1571. AEObjectExit = function (gameManger, aeObjectManager, cellX, cellY, idExit) {
  1572. AEObjectBase.call(this, gameManger, aeObjectManager, cellX, cellY, gameManger.AEOBJECT_EXIT_ID, "Exit_" + idExit + "_mc");
  1573. this.baseSpr.y = 3;
  1574. this.baseSpr.currentAnimationFrame = 0;
  1575. this.idExit = idExit;
  1576. };
  1577. AEObjectExit.prototype = Object.create(AEObjectBase.prototype);
  1578. AEObjectExit.prototype.constructor = AEObjectExit;
  1579. AEObjectExit.prototype.alienActivateCell = function (alien) {
  1580. if (this.idExit == alien.idAlien) {
  1581. alien.setHappy(true);
  1582. this.baseSpr.currentAnimationFrame = 1;
  1583. }
  1584. };
  1585. AEObjectExit.prototype.alienGoBegin = function (alien) {
  1586. this.baseSpr.currentAnimationFrame = 0;
  1587. };
  1588. AEObjectIce = function (gameManger, aeObjectManager, cellX, cellY) {
  1589. AEObjectBase.call(this, gameManger, aeObjectManager, cellX, cellY, gameManger.AEOBJECT_ICE_ID, "ice_1_mc");
  1590. this.baseSpr.currentAnimationFrame = 1;
  1591. };
  1592. AEObjectIce.prototype = Object.create(AEObjectBase.prototype);
  1593. AEObjectIce.prototype.constructor = AEObjectIce;
  1594. AEObjectIce.prototype.stopAnim = function () {
  1595. this.baseSpr.stop();
  1596. if (this.parent) {
  1597. this.parent.removeChild(this);
  1598. }
  1599. };
  1600. AEObjectIce.prototype.alienActivateNextCell = function (alien) {
  1601. console.log("alienActivateNextCell");
  1602. this.aeObjectManager.deleteAEObject(this.fgid);
  1603. this.baseSpr.gotoAndPlay("iceDetaills_1_mc");
  1604. this.onFuncStopAnim = this.baseSpr.on("animationend", createjs.proxy(this.stopAnim, this));
  1605. (new MusicManager).playIce();
  1606. return false;
  1607. };
  1608. AEObjectSpring = function (gameManger, aeObjectManager, cellX, cellY) {
  1609. AEObjectBase.call(this, gameManger, aeObjectManager, cellX, cellY, gameManger.AEOBJECT_SPRING_ID, "spring_1_mc");
  1610. this.baseSpr.play();
  1611. };
  1612. AEObjectSpring.prototype = Object.create(AEObjectBase.prototype);
  1613. AEObjectSpring.prototype.constructor = AEObjectSpring;
  1614. AEObjectSpring.prototype.stopAnim = function () {
  1615. this.baseSpr.stop();
  1616. };
  1617. AEObjectSpring.prototype.alienActivateNextCell = function (alien) {
  1618. console.log("alienActivateNextCell");
  1619. alien.step(-alien.dirX, -alien.dirY);
  1620. (new MusicManager).playSpring();
  1621. return true;
  1622. };
  1623. AEObjectTeleport = function (gameManger, aeObjectManager, cellX, cellY, idTeleport) {
  1624. AEObjectBase.call(this, gameManger, aeObjectManager, cellX, cellY, gameManger.AEOBJECT_TELEPORT_ID, "Teleport_" + idTeleport + "_mc");
  1625. this.baseSpr.play();
  1626. this.idTeleport = idTeleport;
  1627. this.teleportEnd = null;
  1628. };
  1629. AEObjectTeleport.prototype = Object.create(AEObjectBase.prototype);
  1630. AEObjectTeleport.prototype.constructor = AEObjectTeleport;
  1631. AEObjectTeleport.prototype.postInit = function () {
  1632. var aeObj = this.aeObjectManager.aeObjects;
  1633. for (var i = 0; i < aeObj.length; i++) {
  1634. if (aeObj[i].idObject == this.gameManager.AEOBJECT_TELEPORT_ID) {
  1635. if (aeObj[i].idTeleport == this.idTeleport) {
  1636. if (aeObj[i].fgid != this.fgid) {
  1637. this.teleportEnd = aeObj[i];
  1638. return;
  1639. }
  1640. }
  1641. }
  1642. }
  1643. };
  1644. AEObjectTeleport.prototype.alienActivateCell = function (alien) {
  1645. if (this.idTeleport == alien.idAlien) {
  1646. var obj = this.aeObjectManager.getObjectsByCell(this.teleportEnd.cellX, this.teleportEnd.cellY);
  1647. var toEnd = true;
  1648. for (var i = 0; i < obj.length; i++) {
  1649. if (obj[i].idObject == this.gameManager.AEOBJECT_ALIEN_ID) {
  1650. toEnd = false;
  1651. }
  1652. }
  1653. if (toEnd) {
  1654. alien.teleportActivate(this.teleportEnd.cellX, this.teleportEnd.cellY);
  1655. } else {
  1656. alien.teleportActivate(this.cellX, this.cellY);
  1657. }
  1658. }
  1659. };
  1660. AEObjectManager = function (gameManager, field, backgroundManager) {
  1661. createjs.Container.call(this);
  1662. this.field = field;
  1663. this.gameManager = gameManager;
  1664. this.aeObjects = [];
  1665. this.backgroundManager = backgroundManager;
  1666. this.activeObject = null;
  1667. this.sortFun = createjs.proxy(this.sortFunction, this);
  1668. this.sort = false;
  1669. this.ALIEN_STEP_CELL_TRUE = 0;
  1670. this.ALIEN_STEP_CELL_NOW_FALSE = 1;
  1671. this.ALIEN_STEP_CELL_NEXT_FALSE = 2;
  1672. };
  1673. AEObjectManager.prototype = Object.create(createjs.Container.prototype);
  1674. AEObjectManager.prototype.constructor = AEObjectManager;
  1675. AEObjectManager.prototype.postInit = function () {
  1676. for (var i = 0; i < this.aeObjects.length; i++) {
  1677. this.aeObjects[i].postInit();
  1678. }
  1679. };
  1680. AEObjectManager.prototype.sortFunction = function (obj1, obj2, options) {
  1681. if (obj1.y > obj2.y) {
  1682. return 1;
  1683. }
  1684. if (obj1.y < obj2.y) {
  1685. return -1;
  1686. }
  1687. return 0;
  1688. };
  1689. AEObjectManager.prototype.update = function () {
  1690. if (this.sort) {
  1691. this.sortChildren(this.sortFun);
  1692. }
  1693. };
  1694. AEObjectManager.prototype.addAlien = function (cellX, cellY, idAlien) {
  1695. var alien = new AEObjectAlien(this.gameManager, this, cellX, cellY, idAlien);
  1696. this._addAEObject(alien, false);
  1697. };
  1698. AEObjectManager.prototype.addIce = function (cellX, cellY) {
  1699. var obj = new AEObjectIce(this.gameManager, this, cellX, cellY);
  1700. this._addAEObject(obj, false);
  1701. };
  1702. AEObjectManager.prototype.addSpring = function (cellX, cellY) {
  1703. var obj = new AEObjectSpring(this.gameManager, this, cellX, cellY);
  1704. this._addAEObject(obj, true);
  1705. };
  1706. AEObjectManager.prototype.addExit = function (cellX, cellY, idExit) {
  1707. var obj = new AEObjectExit(this.gameManager, this, cellX, cellY, idExit);
  1708. this._addAEObject(obj, true);
  1709. };
  1710. AEObjectManager.prototype.addTeleport = function (cellX, cellY, idTeleport) {
  1711. var obj = new AEObjectTeleport(this.gameManager, this, cellX, cellY, idTeleport);
  1712. this._addAEObject(obj, true);
  1713. };
  1714. AEObjectManager.prototype.addArrow = function (cellX, cellY, idArrow) {
  1715. var obj = new AEObjectArrow(this.gameManager, this, cellX, cellY, idArrow);
  1716. this._addAEObject(obj, true);
  1717. };
  1718. AEObjectManager.prototype._addAEObject = function (aeObject, back) {
  1719. if (back) {
  1720. this.backgroundManager.addChild(aeObject);
  1721. } else {
  1722. this.addChild(aeObject);
  1723. }
  1724. this.aeObjects.push(aeObject);
  1725. };
  1726. AEObjectManager.prototype.deleteAEObject = function (id) {
  1727. for (var i = 0; i < this.aeObjects.length; i++) {
  1728. if (this.aeObjects[i].fgid == id) {
  1729. console.log("deleteAEObject");
  1730. this.aeObjects.splice(i, 1);
  1731. return;
  1732. }
  1733. }
  1734. };
  1735. AEObjectManager.prototype.tapToMap = function (cellX, cellY) {
  1736. this.activeObject = this.getSelectableObjectbyCell(cellX, cellY);
  1737. if (this.activeObject != null) {
  1738. this.activeObject.tapToObject();
  1739. }
  1740. };
  1741. AEObjectManager.prototype.tapMove = function (cellX, cellY) {
  1742. if (this.activeObject == null) {
  1743. this.activeObject = this.getSelectableObjectbyCell(cellX, cellY);
  1744. if (this.activeObject != null) {
  1745. this.activeObject.tapToObject();
  1746. }
  1747. }
  1748. };
  1749. AEObjectManager.prototype.stepActiveObject = function (dirX, dirY) {
  1750. if (this.activeObject != null) {
  1751. if (this.activeObject.step(dirX, dirY)) {
  1752. this.gameManager.gui.starBar.addStep();
  1753. }
  1754. }
  1755. };
  1756. AEObjectManager.prototype.alienPreActivateCell = function (cellX, cellY, alien) {
  1757. var objects = this.getObjectsByCell(cellX, cellY);
  1758. alien.setHappy(false);
  1759. for (var i = 0; i < objects.length; i++) {
  1760. objects[i].alienPreActivateCell(alien);
  1761. }
  1762. };
  1763. AEObjectManager.prototype.alienActivateCell = function (cellX, cellY, alien) {
  1764. var objects = this.getObjectsByCell(cellX, cellY);
  1765. alien.setHappy(false);
  1766. for (var i = 0; i < objects.length; i++) {
  1767. objects[i].alienActivateCell(alien);
  1768. }
  1769. };
  1770. AEObjectManager.prototype.alienGoBegin = function (cellX, cellY, alien) {
  1771. var objects = this.getObjectsByCell(cellX, cellY);
  1772. for (var i = 0; i < objects.length; i++) {
  1773. objects[i].alienGoBegin(alien);
  1774. }
  1775. };
  1776. AEObjectManager.prototype.alienActivateNextCell = function (cellX, cellY, alien) {
  1777. var objects = this.getObjectsByCell(cellX, cellY);
  1778. for (var i = 0; i < objects.length; i++) {
  1779. if (objects[i].alienActivateNextCell(alien)) {
  1780. return true;
  1781. }
  1782. }
  1783. return false;
  1784. };
  1785. AEObjectManager.prototype.getCellStopByDir = function (cellX, cellY, dirX, dirY, alien) {
  1786. while (true) {
  1787. if (cellX < 0 || (cellY < 0 || (cellX >= this.gameManager.CELL_W || cellY >= this.gameManager.CELL_H))) {
  1788. break;
  1789. }
  1790. if (this.field[cellX][cellY] == 1) {
  1791. break;
  1792. }
  1793. var objects = this.getObjectsByCell(cellX, cellY);
  1794. var stepCEll = this.isObjectsStop(objects, alien);
  1795. if (stepCEll == this.ALIEN_STEP_CELL_NEXT_FALSE) {
  1796. break;
  1797. }
  1798. if (stepCEll == this.ALIEN_STEP_CELL_NOW_FALSE) {
  1799. cellX += dirX;
  1800. cellY += dirY;
  1801. break;
  1802. }
  1803. cellX += dirX;
  1804. cellY += dirY;
  1805. }
  1806. return { cellX: cellX - dirX, cellY: cellY - dirY };
  1807. };
  1808. AEObjectManager.prototype.getObjectsByCell = function (cellX, cellY) {
  1809. var objects = [];
  1810. if (cellX < 0 || (cellY < 0 || (cellX >= this.gameManager.CELL_W || cellY >= this.gameManager.CELL_H))) {
  1811. return objects;
  1812. }
  1813. for (var i = 0; i < this.aeObjects.length; i++) {
  1814. if (this.aeObjects[i].cellX == cellX && this.aeObjects[i].cellY == cellY) {
  1815. objects.push(this.aeObjects[i]);
  1816. }
  1817. }
  1818. return objects;
  1819. };
  1820. AEObjectManager.prototype.isObjectsStop = function (objects, alien) {
  1821. for (var i = 0; i < objects.length; i++) {
  1822. if (objects[i].idObject == this.gameManager.AEOBJECT_ALIEN_ID) {
  1823. return this.ALIEN_STEP_CELL_NEXT_FALSE;
  1824. }
  1825. if (objects[i].idObject == this.gameManager.AEOBJECT_SPRING_ID) {
  1826. return this.ALIEN_STEP_CELL_NEXT_FALSE;
  1827. }
  1828. if (objects[i].idObject == this.gameManager.AEOBJECT_ICE_ID) {
  1829. return this.ALIEN_STEP_CELL_NEXT_FALSE;
  1830. }
  1831. }
  1832. for (i = 0; i < objects.length; i++) {
  1833. if (objects[i].idObject == this.gameManager.AEOBJECT_ARROW_ID) {
  1834. return this.ALIEN_STEP_CELL_NOW_FALSE;
  1835. }
  1836. if (objects[i].idObject == this.gameManager.AEOBJECT_TELEPORT_ID) {
  1837. if (alien.idAlien == objects[i].idTeleport) {
  1838. return this.ALIEN_STEP_CELL_NOW_FALSE;
  1839. }
  1840. }
  1841. }
  1842. return this.ALIEN_STEP_CELL_TRUE;
  1843. };
  1844. AEObjectManager.prototype.getSelectableObjectbyCell = function (cellX, cellY) {
  1845. if (cellX < 0 || (cellY < 0 || (cellX >= this.gameManager.CELL_W || cellY >= this.gameManager.CELL_H))) {
  1846. return null;
  1847. }
  1848. for (var i = 0; i < this.aeObjects.length; i++) {
  1849. if (this.aeObjects[i].selectable && (this.aeObjects[i].cellX == cellX && this.aeObjects[i].cellY == cellY)) {
  1850. return this.aeObjects[i];
  1851. }
  1852. }
  1853. return null;
  1854. };
  1855. AEObjectManager.prototype.setAlienSelectable = function (selectable) {
  1856. this.sort = !selectable;
  1857. for (var i = 0; i < this.aeObjects.length; i++) {
  1858. if (this.aeObjects[i].idObject == this.gameManager.AEOBJECT_ALIEN_ID) {
  1859. this.aeObjects[i].selectable = selectable;
  1860. }
  1861. }
  1862. };
  1863. AEObjectManager.prototype.checkWin = function () {
  1864. for (var i = 0; i < this.aeObjects.length; i++) {
  1865. if (this.aeObjects[i].idObject == this.gameManager.AEOBJECT_ALIEN_ID) {
  1866. if (!this.aeObjects[i].isCellHappy) {
  1867. return;
  1868. }
  1869. }
  1870. }
  1871. this.gameManager.setGameOver();
  1872. };
  1873. GameDialogBase = function (gameManager) {
  1874. createjs.Container.call(this);
  1875. console.log("GameDialogBase");
  1876. this.gameManager = gameManager;
  1877. gameManager.offWork();
  1878. gameManager.work = false;
  1879. var shapeRect = new createjs.Shape;
  1880. shapeRect.x = -(new Jok.JokG).width / 2;
  1881. shapeRect.y = -(new Jok.JokG).height / 2;
  1882. shapeRect.graphics.beginFill("rgba(0,0,0,0.65)").rect(0, 0, (new Jok.JokG).width, (new Jok.JokG).height);
  1883. this.addChild(shapeRect);
  1884. this.alpha = 0;
  1885. createjs.Tween.get(this).to({ alpha: 1 }, 400, createjs.Ease.quadOut).call(createjs.proxy(this.alphaEnd, this));
  1886. };
  1887. GameDialogBase.prototype = Object.create(createjs.Container.prototype);
  1888. GameDialogBase.prototype.constructor = GameDialogBase;
  1889. GameDialogBase.prototype.restartAction = function () {
  1890. this.gameManager.restart();
  1891. };
  1892. GameDialogBase.prototype.backAction = function () {
  1893. this.gameManager.toLevelSelect();
  1894. };
  1895. GameDialogBase.prototype.onAll = function () {
  1896. this.gameManager.onWork();
  1897. };
  1898. GameDialogBase.prototype.alphaEnd = function () {
  1899. };
  1900. GameOverDialog = function (gameManager) {
  1901. GameDialogBase.call(this, gameManager);
  1902. this.idAdd = 0;
  1903. (new MusicManager).playGameOver();
  1904. var txt = new createjs.Text((new Jok.JokG).text.getText("levelComplete"), "45px " + (new Jok.JokG).text.fontName["default"], "#FFE054");
  1905. txt.scaleX = txt.scaleY = 1;
  1906. txt.x = -txt.getBounds().width / 2 * txt.scaleX;
  1907. txt.y = -250 - txt.getBounds().height / 2 * txt.scaleX;
  1908. this.addChild(txt);
  1909. var button = new MyButtonBase(createjs.proxy(this.playAction, this), new createjs.Point(0, 70), new createjs.Point(0.8, 0.8), "MainMenuButton_1_mc");
  1910. button.initUp("ButtonPlay_mc");
  1911. this.addChild(button);
  1912. var scaleTT = 1.2;
  1913. var posY = 190;
  1914. var posX = 100;
  1915. button = new MyButtonBase(createjs.proxy(this.backAction, this), new createjs.Point(-posX * 2, posY), new createjs.Point(scaleTT, scaleTT), "buttonBase_mc");
  1916. button.initUp("ButtonBack_mc");
  1917. this.addChild(button);
  1918. var tttttttt = 0.85;
  1919. button = new MyButtonBase(createjs.proxy(this.restartAction, this), new createjs.Point(-posX * tttttttt, posY + 90), new createjs.Point(scaleTT, scaleTT), "buttonBase_mc");
  1920. button.initUp("buttonRestart_mc");
  1921. this.addChild(button);
  1922. button = new MyButtonBase(btMoreGame, new createjs.Point(posX * tttttttt, posY + 90), new createjs.Point(scaleTT, scaleTT), "buttonBase_mc");
  1923. button.initUp("ButtonMoreGames_mc");
  1924. if (showSGLinks) {
  1925. this.addChild(button);
  1926. }
  1927. button = new SoundButton(new createjs.Point(2 * posX, posY), new createjs.Point(scaleTT, scaleTT));
  1928. this.addChild(button);
  1929. (new MusicManager).musicInstance.setVolume(0);
  1930. SG_Hooks.levelUp(this.gameManager.levelId + 1, this.gameManager.gui.starBar.starNum, function () {
  1931. (new MusicManager).musicInstance.setVolume(1);
  1932. });
  1933. this.saveProgress();
  1934. // Play68.setRankingLevelScoreDesc(this.gameManager.levelId+1,this.gameManager.gui.starBar.starNum);
  1935. // updateShare(this.gameManager.levelId+1,this.gameManager.gui.starBar.starNum);
  1936. };
  1937. GameOverDialog.prototype = Object.create(GameDialogBase.prototype);
  1938. GameOverDialog.prototype.constructor = GameOverDialog;
  1939. GameOverDialog.prototype.saveProgress = function () {
  1940. var thisLevel = this.gameManager.levelId + 1;
  1941. if (typeof window.localStorage != "undefined") {
  1942. var numLevelComplete = window.localStorage.getItem("levelComplete");
  1943. if (this.gameManager.levelId + 1 >= numLevelComplete) {
  1944. window.localStorage.setItem("levelComplete", this.gameManager.levelId + 2);
  1945. }
  1946. numLevelComplete = window.localStorage.getItem("levelStar" + (this.gameManager.levelId + 1));
  1947. if (this.gameManager.gui.starBar.starNum > numLevelComplete) {
  1948. window.localStorage.setItem("levelStar" + (this.gameManager.levelId + 1), this.gameManager.gui.starBar.starNum);
  1949. }
  1950. }
  1951. };
  1952. GameOverDialog.prototype.playAction = function (evt) {
  1953. this.gameManager.backround.unccccccache();
  1954. if (this.gameManager.levelId + 1 < (new Jok.JokG).MAX_LEVEL) {
  1955. var gameManager = new GameManager;
  1956. gameManager.levelId = this.gameManager.levelId + 1;
  1957. (new Jok.JokG).jokEngine.transitionScreen(gameManager, null, null);
  1958. } else {
  1959. this.gameManager.toLevelSelect();
  1960. }
  1961. };
  1962. GameOverDialog.prototype.alphaEnd = function () {
  1963. var starX = 200;
  1964. var starY = -110;
  1965. var delltaY = 40;
  1966. var numStar = this.gameManager.gui.starBar.starNum;
  1967. for (var i = 0; i < 3; i++) {
  1968. if (this.idAdd == i) {
  1969. var spr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "StarLevelComplete_mc");
  1970. spr.x = -starX + starX * i;
  1971. spr.y = starY;
  1972. if (i == 0 || i == 2) {
  1973. spr.y += delltaY;
  1974. }
  1975. spr.stop();
  1976. if (i < numStar) {
  1977. spr.currentAnimationFrame = 0;
  1978. spr.scaleX = spr.scaleY = 0;
  1979. createjs.Tween.get(spr).to({ scaleX: 1, scaleY: 1 }, 1500, createjs.Ease.elasticOut);
  1980. console.log("new MusicManager().playStarGameOver();");
  1981. } else {
  1982. spr.currentAnimationFrame = 1;
  1983. spr.alpha = 0;
  1984. createjs.Tween.get(spr).to({ alpha: 1 }, 800, createjs.Ease.quadOut);
  1985. }
  1986. this.addChild(spr);
  1987. }
  1988. }
  1989. this.idAdd++;
  1990. if (this.idAdd < 3) {
  1991. createjs.Tween.get(this).to({ x: this.x }, 500, createjs.Ease.linear).call(createjs.proxy(this.alphaEnd, this));
  1992. }
  1993. };
  1994. HelpDialog = function (gameManager) {
  1995. createjs.Container.call(this);
  1996. this.gameManager = gameManager;
  1997. this.finger = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "helpHand_mc");
  1998. this.addChild(this.finger);
  1999. this.SCALE_BEGIN = 1.5;
  2000. this.Y_BEGIN = 200;
  2001. this.Y_END = 75;
  2002. this.X_END = 200;
  2003. this.finger.y = this.Y_BEGIN;
  2004. this.finger.stop();
  2005. this.finger.scaleX = this.finger.scaleY = this.SCALE_BEGIN;
  2006. this.ALIEN_X_BEGIN = 1;
  2007. this.ALIEN_Y_BEGIN = 4;
  2008. this.alienHelp = this.gameManager.aeObjectManager.getObjectsByCell(this.ALIEN_X_BEGIN, this.ALIEN_Y_BEGIN)[0];
  2009. this.finger.alpha = 0;
  2010. this.tween = createjs.Tween.get(this.finger, { loop: true }).to({
  2011. x: -this.X_END,
  2012. y: this.Y_END,
  2013. alpha: 1,
  2014. scaleX: 1,
  2015. scaleY: 1
  2016. }, 500, createjs.Ease.quadOut).call(createjs.proxy(this.stepHelp_1, this)).wait(750).to({ x: this.X_END }, 900, createjs.Ease.quadInOut).wait(750).call(createjs.proxy(this.stepHelp_2, this)).to({
  2017. scaleX: this.SCALE_BEGIN,
  2018. scaleY: this.SCALE_BEGIN,
  2019. y: this.Y_END + 50,
  2020. alpha: 0
  2021. }, 500, createjs.Ease.quadInOut).to({ x: 0, y: this.Y_BEGIN }, 1500, createjs.Ease.quadInOut);
  2022. };
  2023. HelpDialog.prototype = Object.create(createjs.Container.prototype);
  2024. HelpDialog.prototype.constructor = HelpDialog;
  2025. HelpDialog.prototype.stepHelp_1 = function () {
  2026. this.finger.currentAnimationFrame = 1;
  2027. this.checkDelete();
  2028. };
  2029. HelpDialog.prototype.stepHelp_2 = function () {
  2030. this.finger.currentAnimationFrame = 0;
  2031. this.checkDelete();
  2032. };
  2033. HelpDialog.prototype.checkDelete = function () {
  2034. var ttttttt = false;
  2035. if (this.alienHelp.cellX != this.ALIEN_X_BEGIN) {
  2036. ttttttt = true;
  2037. }
  2038. if (this.gameManager.parent == null) {
  2039. ttttttt = true;
  2040. }
  2041. if (ttttttt) {
  2042. if (this.parent) {
  2043. this.parent.removeChild(this);
  2044. }
  2045. createjs.Tween.removeTweens(this.finger);
  2046. }
  2047. };
  2048. LevelSelectMenu = function () {
  2049. Jok.JokState.call(this);
  2050. };
  2051. LevelSelectMenu.prototype = Object.create(Jok.JokState.prototype);
  2052. LevelSelectMenu.prototype.constructor = LevelSelectMenu;
  2053. LevelSelectMenu.prototype.create = function () {
  2054. this.MAX_LEVEL_ID = Math.floor(((new Jok.JokG).MAX_LEVEL - 1) / 20);
  2055. this._nowLevelId = 0;
  2056. var background = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "MenuBack_1_mc");
  2057. this.addChild(background);
  2058. this.buttonBack = new MyButtonBase(createjs.proxy(this.backsAction, this), new createjs.Point(-(new Jok.JokG).width / 2 + 64, 290), new createjs.Point(1, 1), "buttonBase_mc");
  2059. this.buttonBack.initUp("ButtonBack_mc");
  2060. this.addChild(this.buttonBack);
  2061. this.buttonLevelBack = new MyButtonBase(createjs.proxy(this.buttonLevelBackAction, this), new createjs.Point(-(new Jok.JokG).width / 2 + 40, 0), new createjs.Point(1, 1), "ButtonLevel_mc");
  2062. this.buttonLevelBack.sprDown.stop();
  2063. this.buttonLevelBack.sprDown.currentAnimationFrame = 1;
  2064. this.addChild(this.buttonLevelBack);
  2065. this.buttonLevelNext = new MyButtonBase(createjs.proxy(this.buttonLevelNextAction, this), new createjs.Point(-this.buttonLevelBack.x, 0), new createjs.Point(-1, 1), "ButtonLevel_mc");
  2066. this.buttonLevelNext.sprDown.stop();
  2067. this.addChild(this.buttonLevelNext);
  2068. this.drawLevelButtons();
  2069. };
  2070. LevelSelectMenu.prototype.buttonLevelBackAction = function (evt) {
  2071. if (this._nowLevelId <= 0) {
  2072. return;
  2073. }
  2074. this.buttonLevelNext.sprDown.currentAnimationFrame = 0;
  2075. this._nowLevelId--;
  2076. if (this._nowLevelId == 0) {
  2077. this.buttonLevelBack.sprDown.currentAnimationFrame = 1;
  2078. }
  2079. this.drawLevelButtons();
  2080. };
  2081. LevelSelectMenu.prototype.buttonLevelNextAction = function (evt) {
  2082. if (this._nowLevelId >= this.MAX_LEVEL_ID) {
  2083. return;
  2084. }
  2085. this.buttonLevelBack.sprDown.currentAnimationFrame = 0;
  2086. this._nowLevelId++;
  2087. if (this._nowLevelId == this.MAX_LEVEL_ID) {
  2088. this.buttonLevelNext.sprDown.currentAnimationFrame = 1;
  2089. }
  2090. this.drawLevelButtons();
  2091. };
  2092. LevelSelectMenu.prototype.backsAction = function (evt) {
  2093. (new Jok.JokG).jokEngine.transitionScreen(new MainMenu, null, null);
  2094. };
  2095. LevelSelectMenu.prototype.drawLevelButtons = function () {
  2096. if (this._levelButtonsContainer) {
  2097. this._levelButtonsContainer.removeAllChildren();
  2098. } else {
  2099. this._levelButtonsContainer = new createjs.Container;
  2100. this.addChild(this._levelButtonsContainer);
  2101. }
  2102. var yBegin = 80;
  2103. var yTo = 712 - yBegin - 170;
  2104. yTo = yTo / 4;
  2105. var xBegin = 140;
  2106. var xTo = ((new Jok.JokG).width - xBegin - xBegin) / 3;
  2107. xBegin -= (new Jok.JokG).width / 2;
  2108. yBegin -= 712 / 2;
  2109. var levelAdd = this._nowLevelId * 20 + 1;
  2110. var numLevelComplete = 1;
  2111. if (typeof window.localStorage != "undefined") {
  2112. numLevelComplete = window.localStorage.getItem("levelComplete");
  2113. }
  2114. for (var i = 0; i < 5; i++) {
  2115. for (var j = 0; j < 4; j++) {
  2116. if ((new Jok.JokG).MAX_LEVEL >= levelAdd) {
  2117. var levelButton = new LevelButton(new createjs.Point(xBegin + xTo * j, yBegin + yTo * i), new createjs.Point(1, 1), levelAdd, numLevelComplete >= levelAdd);
  2118. this._levelButtonsContainer.addChild(levelButton);
  2119. }
  2120. levelAdd++;
  2121. }
  2122. }
  2123. };
  2124. LevelSelectMenu.prototype.drawTotalScore = function () {
  2125. if (typeof window.localStorage != "undefined") {
  2126. } else {
  2127. return;
  2128. }
  2129. var allScore = 0;
  2130. for (var i = 0; i < (new Jok.JokG).MAX_LEVEL; i++) {
  2131. allScore += parseInt(window.localStorage.getItem("levelScore" + i));
  2132. }
  2133. if (allScore > 0) {
  2134. var levelText = new createjs.BitmapText((new Jok.JokG).text.getText("totalScore") + " " + allScore, (new Jok.JokG).animLoader.fontSheet);
  2135. levelText.scaleX = levelText.scaleY = 0.5;
  2136. levelText.y = -340;
  2137. levelText.x = -levelText.getBounds().width / 2 * levelText.scaleX;
  2138. this.addChild(levelText);
  2139. }
  2140. };
  2141. MainMenu = function () {
  2142. Jok.JokState.call(this);
  2143. };
  2144. MainMenu.prototype = Object.create(Jok.JokState.prototype);
  2145. MainMenu.prototype.constructor = MainMenu;
  2146. MainMenu.prototype.create = function () {
  2147. var background = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "MenuBack_1_mc");
  2148. this.addChild(background);
  2149. this.buttonMusic = new SoundButton(new createjs.Point(245, 288), new createjs.Point(1, 1));
  2150. this.addChild(this.buttonMusic);
  2151. this.buttonMore = new MyButtonBase(btMoreGame, new createjs.Point(-this.buttonMusic.x, this.buttonMusic.y), new createjs.Point(1, 1), "buttonBase_mc");
  2152. this.buttonMore.initUp("ButtonMoreGames_mc");
  2153. if (showSGLinks) {
  2154. this.addChild(this.buttonMore);
  2155. }
  2156. var titleSpr = new createjs.Sprite(Jok.JokG().animLoader.spriteSheet, "MenuTitle_1_mc");
  2157. titleSpr.y = -208;
  2158. this.addChild(titleSpr);
  2159. titleSpr.scaleX = titleSpr.scaleY = 0;
  2160. createjs.Tween.get(titleSpr).to({ scaleX: 1, scaleY: 1 }, 2500, createjs.Ease.elasticOut);
  2161. this.eventPlay = createjs.proxy(this.playAction, this);
  2162. this.buttonPlay = new MyButtonBase(this.eventPlay, new createjs.Point(0, 27), new createjs.Point(1, 1), "MainMenuButton_1_mc");
  2163. this.buttonPlay.initUp("ButtonPlay_mc");
  2164. this.addChild(this.buttonPlay);
  2165. this.buttonPlay.scaleX = this.buttonPlay.scaleY = 0;
  2166. createjs.Tween.get(this.buttonPlay).to({ scaleX: 1, scaleY: 1 }, 1800, createjs.Ease.elasticOut);
  2167. };
  2168. MainMenu.prototype.onButton = function () {
  2169. this.buttonCredits.onWork();
  2170. this.buttonPlay.onWork();
  2171. this.buttonMusic.onWork();
  2172. this.buttonMore.onWork();
  2173. };
  2174. MainMenu.prototype.offButton = function () {
  2175. this.buttonCredits.offWork();
  2176. this.buttonPlay.offWork();
  2177. this.buttonMusic.offWork();
  2178. this.buttonMore.offWork();
  2179. };
  2180. MainMenu.prototype.moreAction = function (evt) {
  2181. (new Jok.JokG).openUrl();
  2182. };
  2183. MainMenu.prototype.creditsAction = function (evt) {
  2184. this.addChild(new CreditsDialog(this));
  2185. };
  2186. MainMenu.prototype.playAction = function (evt) {
  2187. (new Jok.JokG).jokEngine.transitionScreen(new LevelSelectMenu, null, null);
  2188. };
  2189. PauseDialog = function (gameManager) {
  2190. GameDialogBase.call(this, gameManager);
  2191. var button = new MyButtonBase(createjs.proxy(this.playAction, this), new createjs.Point(0, -81), new createjs.Point(0.8, 0.8), "MainMenuButton_1_mc");
  2192. button.initUp("ButtonPlay_mc");
  2193. this.addChild(button);
  2194. var scaleTT = 1.2;
  2195. var posY = 100;
  2196. var posX = 100;
  2197. button = new MyButtonBase(createjs.proxy(this.backAction, this), new createjs.Point(-posX * 2, posY), new createjs.Point(scaleTT, scaleTT), "buttonBase_mc");
  2198. button.initUp("ButtonBack_mc");
  2199. this.addChild(button);
  2200. var tttttttt = 0.85;
  2201. button = new MyButtonBase(createjs.proxy(this.restartAction, this), new createjs.Point(-posX * tttttttt, posY + 90), new createjs.Point(scaleTT, scaleTT), "buttonBase_mc");
  2202. button.initUp("buttonRestart_mc");
  2203. this.addChild(button);
  2204. button = new MyButtonBase(btMoreGame, new createjs.Point(posX * tttttttt, posY + 90), new createjs.Point(scaleTT, scaleTT), "buttonBase_mc");
  2205. button.initUp("ButtonMoreGames_mc");
  2206. if (showSGLinks) {
  2207. this.addChild(button);
  2208. }
  2209. button = new SoundButton(new createjs.Point(2 * posX, posY), new createjs.Point(scaleTT, scaleTT));
  2210. this.addChild(button);
  2211. };
  2212. PauseDialog.prototype = Object.create(GameDialogBase.prototype);
  2213. PauseDialog.prototype.constructor = PauseDialog;
  2214. PauseDialog.prototype.playAction = function (evt) {
  2215. createjs.Tween.get(this).to({ alpha: 0 }, 400, createjs.Ease.quadOut).call(createjs.proxy(this.playActionEnd, this));
  2216. };
  2217. PauseDialog.prototype.playActionEnd = function (evt) {
  2218. if (this.parent) {
  2219. this.parent.removeChild(this);
  2220. }
  2221. this.onAll();
  2222. this.gameManager.work = true;
  2223. };
  2224. Jok.JokAnimLoader = function () {
  2225. this.data = null;
  2226. this.fontSheet = {};
  2227. };
  2228. Jok.JokAnimLoader.prototype.constructor = Jok.JokAnimLoader;
  2229. Jok.JokAnimLoader.prototype.loadAnimStep_1_images = function (jsonFrameDatas, images) {
  2230. this.spriteSheetData = { framerate: 24, images: [], frames: [], animations: {} };
  2231. for (var i = 0; i < images.length; i++) {
  2232. this.spriteSheetData.images.push(images[i]);
  2233. }
  2234. this.namesFrames = {};
  2235. for (i = 0; i < jsonFrameDatas.length; i++) {
  2236. var id = 0;
  2237. while (true) {
  2238. var rect = this.getFrameDataJson(jsonFrameDatas[i], id);
  2239. if (rect != null) {
  2240. this.spriteSheetData.frames.push([rect.x, rect.y, rect.w, rect.h, i, rect.w * 0.5, rect.h * 0.5]);
  2241. rect.name = rect.name.substr(0, rect.name.length - 4);
  2242. this.namesFrames[rect.name] = this.spriteSheetData.frames.length - 1;
  2243. } else {
  2244. break;
  2245. }
  2246. id++;
  2247. }
  2248. }
  2249. for (var nameFrame in this.namesFrames) {
  2250. var nameAnim = this.getNameAnim(nameFrame);
  2251. if (!this.spriteSheetData.animations[nameAnim]) {
  2252. var numAdd = nameFrame.lastIndexOf("_");
  2253. this.spriteSheetData.animations[nameAnim] = [this.namesFrames[nameFrame]];
  2254. }
  2255. }
  2256. };
  2257. Jok.JokAnimLoader.prototype.loadAnimStep_2_images = function () {
  2258. var xynta = {};
  2259. for (var nameFrame in this.namesFrames) {
  2260. var nameAnim = this.getNameAnim(nameFrame);
  2261. if (!xynta[nameAnim]) {
  2262. var numAdd = nameFrame.lastIndexOf("_");
  2263. xynta[nameAnim] = 0;
  2264. if (numAdd < 0) {
  2265. } else {
  2266. this.addAnimFromName(nameAnim, nameFrame.length - numAdd - 1);
  2267. }
  2268. }
  2269. }
  2270. };
  2271. Jok.JokAnimLoader.prototype.addAnimation_step_1 = function (animName) {
  2272. this.spriteSheetData.animations[animName] = [3];
  2273. };
  2274. Jok.JokAnimLoader.prototype.addAnimation_step_2 = function (animName, frames) {
  2275. var framesTT = [];
  2276. for (var i = 0; i < frames.length; i++) {
  2277. framesTT.push(this.namesFrames[frames[i]]);
  2278. }
  2279. this.spriteSheet.getAnimation(animName).frames = framesTT;
  2280. };
  2281. Jok.JokAnimLoader.prototype.setFramePivotXY = function (nameFrame, x, y) {
  2282. x = -x;
  2283. y = -y;
  2284. this.spriteSheetData.frames[this.namesFrames[nameFrame]][5] = x;
  2285. this.spriteSheetData.frames[this.namesFrames[nameFrame]][6] = this.spriteSheetData.frames[this.namesFrames[nameFrame]][3] - y;
  2286. };
  2287. Jok.JokAnimLoader.prototype.endLoadAnim = function () {
  2288. this.spriteSheet = new createjs.SpriteSheet(this.spriteSheetData);
  2289. };
  2290. Jok.JokAnimLoader.prototype.getNameAnim = function (nameFrame) {
  2291. var nameTT = nameFrame.lastIndexOf("_");
  2292. if (nameTT < 0) {
  2293. return nameFrame;
  2294. }
  2295. return nameFrame.substr(0, nameTT);
  2296. };
  2297. Jok.JokAnimLoader.prototype.addAnimFromName = function (nameAnim, numAdd) {
  2298. var framesTT = [];
  2299. var idFrame = 0;
  2300. while (true) {
  2301. var nameFrame = this.getFrameName_1(nameAnim, idFrame, numAdd);
  2302. if (this.namesFrames[nameFrame] != null) {
  2303. framesTT.push(this.namesFrames[nameFrame]);
  2304. } else {
  2305. if (idFrame > 3) {
  2306. break;
  2307. }
  2308. }
  2309. idFrame++;
  2310. }
  2311. if (framesTT.length == 0) {
  2312. console.log("error name anim 0 frame = " + nameAnim);
  2313. }
  2314. this.spriteSheet.getAnimation(nameAnim).frames = framesTT;
  2315. };
  2316. Jok.JokAnimLoader.prototype.getFrameName_1 = function (nameFrame, numFrame, len) {
  2317. var name = "000" + numFrame;
  2318. name = name.substr(name.length - len, len);
  2319. return nameFrame + "_" + name + "";
  2320. };
  2321. Jok.JokAnimLoader.prototype.getFrameDataJson = function (jsonFrameData, idFrame) {
  2322. if (jsonFrameData.frames[idFrame]) {
  2323. return {
  2324. x: parseInt(jsonFrameData.frames[idFrame].frame.x),
  2325. y: parseInt(jsonFrameData.frames[idFrame].frame.y),
  2326. w: parseInt(jsonFrameData.frames[idFrame].frame.w),
  2327. h: parseInt(jsonFrameData.frames[idFrame].frame.h),
  2328. name: jsonFrameData.frames[idFrame].filename
  2329. };
  2330. }
  2331. return null;
  2332. };
  2333. Jok.JokAnimLoader.prototype.loadAnim = function (xmlArchorData, jsonFrameDatas, images) {
  2334. console.log("xmlArchorData = " + xmlArchorData);
  2335. console.log("jsonFrameData = " + jsonFrameDatas);
  2336. console.log("image = " + images);
  2337. var allNode = 0;
  2338. var lastName;
  2339. console.log("Jok.JokAnimLoader.prototype.loadAnim 1");
  2340. this.spriteSheetData = { framerate: 24, images: [], frames: [], animations: {} };
  2341. for (var i = 0; i < images.length; i++) {
  2342. this.spriteSheetData.images.push(images[i]);
  2343. }
  2344. var idFrame = 0;
  2345. console.log("Jok.JokAnimLoader.prototype.loadAnim 2");
  2346. while (true) {
  2347. var parametr = xmlArchorData.getElementsByTagName("Parametr")[allNode];
  2348. if (parametr) {
  2349. lastName = parametr.getAttribute("n");
  2350. var oneFrameNum = 0;
  2351. while (true) {
  2352. var oneFrame = parametr.getElementsByTagName("info")[oneFrameNum];
  2353. if (oneFrame) {
  2354. var xStr = -parseInt(oneFrame.getAttribute("x"));
  2355. var yStr = -parseInt(oneFrame.getAttribute("y"));
  2356. for (var i = 0; i < jsonFrameDatas.length; i++) {
  2357. var rect = this.getFrameData(jsonFrameDatas[i], this.getFrameName(lastName, oneFrameNum));
  2358. if (rect != null) {
  2359. this.spriteSheetData.frames.push([rect.x, rect.y, rect.w, rect.h, i, xStr, rect.h - yStr]);
  2360. }
  2361. }
  2362. oneFrameNum++;
  2363. idFrame++;
  2364. } else {
  2365. break;
  2366. }
  2367. }
  2368. this.spriteSheetData.animations[lastName] = [idFrame - oneFrameNum, idFrame - 1];
  2369. allNode++;
  2370. } else {
  2371. break;
  2372. }
  2373. }
  2374. console.log("Jok.JokAnimLoader.prototype.loadAnim 3");
  2375. this.spriteSheet = new createjs.SpriteSheet(this.spriteSheetData);
  2376. console.log("Jok.JokAnimLoader.prototype.loadAnim 4");
  2377. };
  2378. Jok.JokAnimLoader.prototype.getFrameName = function (nameFrame, numFrame) {
  2379. var name = "000" + numFrame;
  2380. name = name.substr(name.length - 3, 3);
  2381. return nameFrame + "_" + name + ".png";
  2382. };
  2383. Jok.JokAnimLoader.prototype.getFrameData = function (jsonFrameData, nameFrame) {
  2384. var i = 0;
  2385. while (jsonFrameData.frames[i]) {
  2386. if (jsonFrameData.frames[i].filename == nameFrame) {
  2387. return {
  2388. x: parseInt(jsonFrameData.frames[i].frame.x),
  2389. y: parseInt(jsonFrameData.frames[i].frame.y),
  2390. w: parseInt(jsonFrameData.frames[i].frame.w),
  2391. h: parseInt(jsonFrameData.frames[i].frame.h)
  2392. };
  2393. }
  2394. i++;
  2395. }
  2396. return null;
  2397. };
  2398. Jok.JokAnimLoader.prototype.loadBitmapFont = function (xmlFontData, image, nameFont) {
  2399. var dataCharId = {};
  2400. dataCharId[65] = "A";
  2401. dataCharId[66] = "B";
  2402. dataCharId[67] = "C";
  2403. dataCharId[68] = "D";
  2404. dataCharId[69] = "E";
  2405. dataCharId[70] = "F";
  2406. dataCharId[71] = "G";
  2407. dataCharId[72] = "H";
  2408. dataCharId[73] = "I";
  2409. dataCharId[74] = "J";
  2410. dataCharId[75] = "K";
  2411. dataCharId[76] = "L";
  2412. dataCharId[77] = "M";
  2413. dataCharId[78] = "N";
  2414. dataCharId[79] = "O";
  2415. dataCharId[80] = "P";
  2416. dataCharId[81] = "Q";
  2417. dataCharId[82] = "R";
  2418. dataCharId[83] = "S";
  2419. dataCharId[84] = "T";
  2420. dataCharId[85] = "U";
  2421. dataCharId[86] = "V";
  2422. dataCharId[87] = "W";
  2423. dataCharId[88] = "X";
  2424. dataCharId[89] = "Y";
  2425. dataCharId[90] = "Z";
  2426. dataCharId[47] = "/";
  2427. dataCharId[48] = "0";
  2428. dataCharId[49] = "1";
  2429. dataCharId[50] = "2";
  2430. dataCharId[51] = "3";
  2431. dataCharId[52] = "4";
  2432. dataCharId[53] = "5";
  2433. dataCharId[54] = "6";
  2434. dataCharId[55] = "7";
  2435. dataCharId[56] = "8";
  2436. dataCharId[57] = "9";
  2437. var allNode = 0;
  2438. this.fontData = { images: [image], frames: [], animations: {} };
  2439. var idFrame = 0;
  2440. while (true) {
  2441. var parametr = xmlFontData.getElementsByTagName("chars")[0];
  2442. parametr = parametr.getElementsByTagName("char")[allNode];
  2443. if (parametr) {
  2444. var id = parseInt(parametr.getAttribute("id"));
  2445. var x = parseInt(parametr.getAttribute("x"));
  2446. var y = parseInt(parametr.getAttribute("y"));
  2447. var width = parseInt(parametr.getAttribute("width"));
  2448. var height = parseInt(parametr.getAttribute("height"));
  2449. var xoffset = parseInt(parametr.getAttribute("xoffset"));
  2450. var yoffset = parseInt(parametr.getAttribute("yoffset"));
  2451. if (width > 0 && height > 0) {
  2452. xoffset = yoffset = 0;
  2453. this.fontData.frames.push([x, y, width, height, 0, xoffset, yoffset]);
  2454. this.fontData.animations[dataCharId[id]] = { "frames": [idFrame] };
  2455. idFrame++;
  2456. }
  2457. allNode++;
  2458. } else {
  2459. break;
  2460. }
  2461. }
  2462. console.log("allNode = " + allNode);
  2463. this.fontSheet[nameFont] = new createjs.SpriteSheet(this.fontData);
  2464. };
  2465. Jok.JokEngine = function (nameCanvas) {
  2466. this.state = null;
  2467. (new Jok.JokG).init(nameCanvas, this);
  2468. this.stage = (new Jok.JokG).stage;
  2469. this.fpsLabel = new createjs.Text("-- fps", "bold 14px Arial", "#000");
  2470. this.fpsLabel.x = 10 - (new Jok.JokG).width / 2;
  2471. this.fpsLabel.y = 20 - 712 / 2;
  2472. this.delta = 0;
  2473. };
  2474. Jok.JokEngine.prototype.constructor = Jok.JokEngine;
  2475. Jok.JokEngine.prototype.initState = function (aState) {
  2476. this.switchState(aState);
  2477. if (!createjs.Ticker.hasEventListener("tick")) {
  2478. this.tickEvent = createjs.proxy(this.tick, this);
  2479. createjs.Ticker.on("tick", this.tickEvent);
  2480. }
  2481. };
  2482. Jok.JokEngine.prototype.transitionScreen = function (aState, funcBegin, funcEnd) {
  2483. (new Jok.JokTransitionScreenBase).init(funcBegin, funcEnd, aState, 1000);
  2484. };
  2485. Jok.JokEngine.prototype.switchState = function (aState) {
  2486. if (this.state) {
  2487. this.stage.removeChild(this.state);
  2488. this.state.dispose();
  2489. }
  2490. this.state = aState;
  2491. this.state.create();
  2492. this.stage.addChildAt(this.state, 0);
  2493. };
  2494. Jok.JokEngine.prototype.tick = function (event) {
  2495. this.delta = event.delta / 1000;
  2496. this.state.update();
  2497. this.fpsLabel.text = Math.round(createjs.Ticker.getMeasuredFPS()) + " fps";
  2498. this.stage.update(event);
  2499. };
  2500. Jok.JokG = function () {
  2501. var callee = arguments.callee;
  2502. if (callee.instance) {
  2503. return callee.instance;
  2504. }
  2505. this.queue = new createjs.LoadQueue(true, "assets/");
  2506. this.animLoader = new Jok.JokAnimLoader;
  2507. this._idNow = 0;
  2508. this.text = new Jok.JokTextData;
  2509. callee.instance = this;
  2510. };
  2511. Jok.JokG.prototype.constructor = Jok.JokG;
  2512. Jok.JokG.prototype.getNewid = function () {
  2513. return this._idNow++;
  2514. };
  2515. Jok.JokG.prototype.init = function (nameCanvas, jokEngine) {
  2516. this.canvas = this.createGameCanvas(nameCanvas);
  2517. this.stage = new createjs.Stage(this.canvas);
  2518. this.stage.autoClear = false;
  2519. this.stage.enableMouseOver(10);
  2520. this.jokEngine = jokEngine;
  2521. this.resize();
  2522. var resizeFunc = createjs.proxy(this.resize, this);
  2523. window.addEventListener("resize", resizeFunc, false);
  2524. window.addEventListener("viewportchange", resizeFunc, false);
  2525. window.addEventListener("viewportready", resizeFunc, false);
  2526. SG_Hooks.setOrientationHandler(resizeFunc);
  2527. SG_Hooks.setResizeHandler(resizeFunc);
  2528. createjs.Touch.enable(this.stage);
  2529. createjs.Ticker.setFPS(30);
  2530. this.fonts = {};
  2531. console.log("this.jokEngine = " + this.jokEngine);
  2532. this.GAME_WIDTH = 640;
  2533. this.GAME_HEIGHT = 712;
  2534. };
  2535. Jok.JokG.prototype.createGameCanvas = function (nameCanvas) {
  2536. var container = document.getElementById(nameCanvas);
  2537. return container;
  2538. };
  2539. Jok.JokG.prototype.addFont = function (nameIdFont, nameFont) {
  2540. this.fonts[nameIdFont] = nameFont;
  2541. };
  2542. Jok.JokG.prototype.resize = function () {
  2543. var GAME_WIDTH = 640;
  2544. var GAME_MIN_HEIGHT = 712;
  2545. var GAME_MAX_HEIGHT = 960;
  2546. if (this.isPC()) {
  2547. GAME_MIN_HEIGHT = 960;
  2548. }
  2549. var widthWindow = window.innerWidth;
  2550. var heightWindow = window.innerHeight;
  2551. var portainLockCanvas = document.getElementById("portraitLock");
  2552. if (!this.isLandscape()) {
  2553. portainLockCanvas.style.display = "none";
  2554. (new Jok.JokG).canvas.style.display = "block";
  2555. } else {
  2556. portainLockCanvas.style.display = "block";
  2557. (new Jok.JokG).canvas.style.display = "none";
  2558. }
  2559. var scale = Math.min(widthWindow / GAME_WIDTH, heightWindow / GAME_MIN_HEIGHT);
  2560. var canvas = (new Jok.JokG).canvas;
  2561. canvas.width = GAME_WIDTH;
  2562. canvas.height = Math.min(Math.floor(heightWindow / scale), GAME_MAX_HEIGHT);
  2563. var scaleWidth = Math.floor(canvas.width * scale);
  2564. var scaleHeight = Math.floor(canvas.height * scale);
  2565. canvas.style.width = scaleWidth + "px";
  2566. canvas.style.height = scaleHeight + "px";
  2567. this.width = this.canvas.width;
  2568. this.height = this.canvas.height;
  2569. this.stage.x = this.width / 2;
  2570. this.stage.y = this.height / 2;
  2571. var parent = canvas.parentElement;
  2572. parent.style.width = scaleWidth + "px";
  2573. parent.style.height = scaleHeight + "px";
  2574. var v = (widthWindow - scaleWidth) / 2;
  2575. parent.style.left = v + "px";
  2576. var w = (heightWindow - scaleHeight) / 2;
  2577. parent.style.top = w + "px";
  2578. };
  2579. Jok.JokG.prototype.isPC = function () {
  2580. return !(createjs.Sound.BrowserDetect.isIOS || (createjs.Sound.BrowserDetect.isAndroid || createjs.Sound.BrowserDetect.isBlackberry));
  2581. };
  2582. Jok.JokG.prototype.isLandscape = function () {
  2583. if (createjs.Sound.BrowserDetect.isIOS || (createjs.Sound.BrowserDetect.isAndroid || createjs.Sound.BrowserDetect.isBlackberry)) {
  2584. return window.innerWidth > window.innerHeight && window.innerWidth <= 640;
  2585. }
  2586. return false;
  2587. };
  2588. Jok.JokG.prototype.openUrl = function (url) {
  2589. SG.redirectToPortal();
  2590. };
  2591. Jok.JokTextData = function () {
  2592. this.text = null;
  2593. this._noText = "textNotFound";
  2594. this.setLang("fr");
  2595. this.fontName = {};
  2596. };
  2597. Jok.JokTextData.prototype.constructor = Jok.JokTextData;
  2598. Jok.JokTextData.prototype.init = function (jsonText) {
  2599. this.text = jsonText;
  2600. console.log(this.text);
  2601. };
  2602. Jok.JokTextData.prototype.setLang = function (lang) {
  2603. console.log("ok.JokTextData.prototype.setLang = " + lang);
  2604. this._lang = lang;
  2605. this.textsJson = "texts_" + this._lang;
  2606. };
  2607. Jok.JokTextData.prototype.getText = function (idText) {
  2608. if (this.text != null) {
  2609. var i = 0;
  2610. while (true) {
  2611. var textTT = this.text[this.textsJson][i];
  2612. if (textTT) {
  2613. if (textTT.id == idText) {
  2614. return textTT.text;
  2615. }
  2616. } else {
  2617. break;
  2618. }
  2619. i++;
  2620. }
  2621. return this._noText;
  2622. }
  2623. return "this.text=null";
  2624. };
  2625. Jok.JokMath = function () {
  2626. };
  2627. Jok.JokMath.prototype.constructor = Jok.JokMath;
  2628. Jok.JokMath.getRandomNumber = function (min, max) {
  2629. return Math.random() * (max - min) + min;
  2630. };
  2631. Jok.JokMath.getRandomInt = function (min, max) {
  2632. return Math.floor(Math.random() * (max - min + 1)) + min;
  2633. };
  2634. Jok.JokMath.getRandomInt = function (min, max) {
  2635. return Math.floor(Math.random() * (max - min + 1)) + min;
  2636. };
  2637. Jok.JokMath.linesCross = function (aLineX1, aLineY1, aLineX2, aLineY2, bLineX1, bLineY1, bLineX2, bLineY2) {
  2638. var d = (aLineX2 - aLineX1) * (bLineY1 - bLineY2) - (bLineX1 - bLineX2) * (aLineY2 - aLineY1);
  2639. if (d == 0) {
  2640. return false;
  2641. }
  2642. var d1 = (bLineX1 - aLineX1) * (bLineY1 - bLineY2) - (bLineX1 - bLineX2) * (bLineY1 - aLineY1);
  2643. var d2 = (aLineX2 - aLineX1) * (bLineY1 - aLineY1) - (bLineX1 - aLineX1) * (aLineY2 - aLineY1);
  2644. var t1 = d1 / d;
  2645. var t2 = d2 / d;
  2646. return t1 >= 0 && (t1 <= 1 && (t2 >= 0 && t2 <= 1)) ? true : false;
  2647. };
  2648. Jok.JokMath.distanceSQR = function (x1, y1, x2, y2) {
  2649. var dx = x2 - x1;
  2650. var dy = y2 - y1;
  2651. return dx * dx + dy * dy;
  2652. };
  2653. Jok.JokMath.distance = function (x1, y1, x2, y2) {
  2654. var dx = x2 - x1;
  2655. var dy = y2 - y1;
  2656. return Math.sqrt(dx * dx + dy * dy);
  2657. };
  2658. Jok.JokTransitionScreenBase = function () {
  2659. createjs.Container.call(this);
  2660. this.shape = new createjs.Shape;
  2661. this.shape.x = -(new Jok.JokG).width / 2;
  2662. this.shape.y = -(new Jok.JokG).height / 2;
  2663. this.shape.graphics.beginFill("rgba(255,255,255,1)").rect(0, 0, (new Jok.JokG).width, (new Jok.JokG).height);
  2664. this.addChild(this.shape);
  2665. this.eventTween = createjs.proxy(this.endTeen, this);
  2666. };
  2667. Jok.JokTransitionScreenBase.prototype = Object.create(createjs.Container.prototype);
  2668. Jok.JokTransitionScreenBase.prototype.constructor = Jok.JokTransitionScreenBase;
  2669. Jok.JokTransitionScreenBase.prototype.init = function (FBegin, FEnd, state, time) {
  2670. this._state = state;
  2671. this._funcBegin = FBegin;
  2672. this._funcEnd = FEnd;
  2673. (new Jok.JokG).stage.addChild(this);
  2674. this.alpha = 0;
  2675. this._time = time / 2;
  2676. createjs.Tween.get(this).to({ alpha: 1 }, this._time, createjs.Ease.quadOut).call(this.eventTween);
  2677. };
  2678. Jok.JokTransitionScreenBase.prototype.endTeen = function (evt) {
  2679. if (this.alpha > 0.9) {
  2680. createjs.Tween.get(this).to({ alpha: 0 }, this._time, createjs.Ease.quadOut).call(this.eventTween);
  2681. if (this._funcBegin != null) {
  2682. this._funcBegin();
  2683. }
  2684. (new Jok.JokG).jokEngine.switchState(this._state);
  2685. } else {
  2686. (new Jok.JokG).stage.removeChild(this);
  2687. if (this._funcEnd != null) {
  2688. this._funcEnd();
  2689. }
  2690. }
  2691. };