game.js 171 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035
  1. var CRENDER_DEBUG = !1;
  2. "undefined" == typeof window.console && (window.console = {
  3. log: function() {}
  4. });
  5. window.Utils || (window.Utils = {});
  6. var Utils = Utils;
  7. Utils.detectMobileBrowser = function() {
  8. return navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)
  9. };
  10. Utils.getTouchStartEvent = function() {
  11. return Utils.isWindowsPhone() ? "mspointerdown" : "touchstart"
  12. };
  13. Utils.getTouchMoveEvent = function() {
  14. return Utils.isWindowsPhone() ? "mspointermove" : "touchmove"
  15. };
  16. Utils.getTouchEndEvent = function() {
  17. return Utils.isWindowsPhone() ? "mspointerup" : "touchend"
  18. };
  19. Utils.touchScreen = Utils.detectMobileBrowser();
  20. Utils.globalScale = 1;
  21. Utils.globalPixelScale = 1;
  22. Utils.isWindowHidden = !1;
  23. Utils.DOMMainContainerId = "main_container";
  24. Utils.DOMProgressContainerId = "progress_container";
  25. Utils.DOMProgressId = "progress";
  26. Utils.DOMScreenBackgroundContainerId = "screen_background_container";
  27. Utils.DOMScreenBackgroundWrapperId = "screen_background_wrapper";
  28. Utils.DOMScreenBackgroundId = "screen_background";
  29. Utils.DOMScreenContainerId = "screen_container";
  30. Utils.DOMScreenWrapperId = "screen_wrapper";
  31. Utils.DOMScreenId = "screen";
  32. Utils.DOMP2lContainerId = "p2l_container";
  33. Utils.DOMP2lId = "p2l";
  34. Utils.DOMMarkId = "mark";
  35. Utils.setCookie = function(a, c) {
  36. try {
  37. window.localStorage.setItem(a, c)
  38. } catch (d) {
  39. var e = new Date;
  40. e.setDate(e.getDate() + 3650);
  41. document.cookie = a + "=" + c + "; expires=" + e.toUTCString()
  42. }
  43. };
  44. Utils.getCookie = function(a) {
  45. var c;
  46. try {
  47. c = window.localStorage.getItem(a)
  48. } catch (d) {
  49. a += "=";
  50. c = document.cookie.indexOf(a);
  51. if (-1 == c) return null;
  52. var e = document.cookie.indexOf(";", c + a.length); - 1 == e && (e = document.cookie.length);
  53. c = unescape(document.cookie.substring(c + a.length, e))
  54. }
  55. return c
  56. };
  57. Utils.bindEvent = function(a, c, d) {
  58. a.addEventListener ? a.addEventListener(c, d, !1) : a.attachEvent && a.attachEvent("on" + c, d)
  59. };
  60. Utils.unbindEvent = function(a, c, d) {
  61. a.removeEventListener ? a.removeEventListener(c, d, !1) : a.detachEvent && a.detachEvent("on" + c, d)
  62. };
  63. Utils.getObjectLeft = function(a) {
  64. var c = a.offsetLeft;
  65. a.offsetParent && (c += Utils.getObjectLeft(a.offsetParent));
  66. return c
  67. };
  68. Utils.getObjectTop = function(a) {
  69. var c = a.offsetTop;
  70. a.offsetParent && (c += Utils.getObjectTop(a.offsetParent));
  71. return c
  72. };
  73. Utils.parseGet = function() {
  74. var a = {},
  75. c = window.location.toString(),
  76. d = window.location.toString().indexOf("?");
  77. if (0 <= d)
  78. for (var c = c.substr(d + 1, c.length), d = c.split("&"), e = 0; e < d.length; e++) c = d[e].split("="), a[c[0]] = c[1];
  79. return a
  80. };
  81. Utils.getMouseCoord = function(a, c) {
  82. var d = a || window.event;
  83. d.touches && (d = d.touches[0]);
  84. if (!d) return {
  85. x: 0,
  86. y: 0
  87. };
  88. var e = 0,
  89. f = 0,
  90. g = 0,
  91. h = 0;
  92. c && (e = Utils.getObjectLeft(c), f = Utils.getObjectTop(c));
  93. if (d.pageX || d.pageY) g = d.pageX, h = d.pageY;
  94. else if (d.clientX || d.clientY) g = d.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft, h = d.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  95. return {
  96. x: g - e,
  97. y: h - f
  98. }
  99. };
  100. Utils.removeFromArray = function(a, c) {
  101. for (var d = [], e = 0; e < a.length; e++) a[e] != c && d.push(a[e]);
  102. return d
  103. };
  104. Utils.showLoadProgress = function(a) {
  105. var c = Utils.globalScale,
  106. d;
  107. d = "Loading: " + a + "%<br><br>";
  108. d += '<div style="display: block; background: #000; width: ' + a * c * 2 + "px; height: " + 10 * c + 'px;">&nbsp;</div>';
  109. document.getElementById(Utils.DOMProgressId).innerHTML = d
  110. };
  111. Utils.hideAddressBarLock = !1;
  112. Utils.mobileHideAddressBar = function() {
  113. Utils.hideAddressBarLock || window.scrollTo(0, 1)
  114. };
  115. Utils.mobileCheckIphone4 = function() {
  116. return Utils.touchScreen && 0 <= navigator.userAgent.indexOf("iPhone") && 2 == window.devicePixelRatio
  117. };
  118. Utils.mobileCheckBrokenAndroid = function() {
  119. return Utils.touchScreen && Utils.isAndroid() && !Utils.isChrome() && !Utils.isFirefox()
  120. };
  121. Utils.mobileCheckSlowDevice = function() {
  122. return Utils.mobileCheckBrokenAndroid() && 0 <= navigator.userAgent.toLowerCase().indexOf("sm-t310") || Utils.touchScreen && Utils.isAndroid() && Utils.isFirefox() && 0 <= navigator.userAgent.toLowerCase().indexOf("sm-t310")
  123. };
  124. Utils.isChrome = function() {
  125. var a = !1;
  126. 0 <= navigator.userAgent.toLowerCase().indexOf("chrome") && (a = !0, Utils.isAndroid() && 22 > (parseInt((/Chrome\/([0-9]+)/.exec(navigator.appVersion) || 0)[1], 10) || 0) && (a = !1));
  127. return a
  128. };
  129. Utils.isAndroid = function() {
  130. return 0 <= navigator.userAgent.toLowerCase().indexOf("android")
  131. };
  132. Utils.isIOS = function() {
  133. return navigator.userAgent.toLowerCase().match(/(ipad|iphone|ipod)/g) ? !0 : !1
  134. };
  135. Utils.isPlayFreeBrowser = function() {
  136. return 0 <= navigator.userAgent.toLowerCase().indexOf("playfreebrowser")
  137. };
  138. Utils.isFirefox = function() {
  139. return 0 <= navigator.userAgent.toLowerCase().indexOf("firefox")
  140. };
  141. Utils.isWindowsPhone = function() {
  142. return 0 <= navigator.userAgent.toLowerCase().indexOf("windows phone")
  143. };
  144. Utils.disableCorrectPixelRatio = !1;
  145. Utils.mobileCorrectPixelRatio = function() {
  146. for (var a = document.getElementsByTagName("head")[0].getElementsByTagName("meta"), c = !0, d = null, e = "", f = 0; f < a.length; f++)
  147. if ("viewport" == a[f].name) {
  148. d = a[f];
  149. c = !1;
  150. break
  151. }
  152. c && (d = document.createElement("meta"), d.name = "viewport");
  153. e += "target-densitydpi=device-dpi, user-scalable=0";
  154. Utils.isPlayFreeBrowser() && (e += ", width=device-width, height=device-height");
  155. a = 1 / (window.devicePixelRatio ? window.devicePixelRatio : 1);
  156. a = a.toFixed(2);
  157. Utils.disableCorrectPixelRatio && (a = 1);
  158. d.content =
  159. e + (", initial-scale=" + a + ", maximum-scale=" + a + ", minimum-scale=" + a);
  160. c && document.getElementsByTagName("head")[0].appendChild(d)
  161. };
  162. Utils.getMobileScreenResolution = function(a) {
  163. var c = 1,
  164. d = window.innerWidth,
  165. e = window.innerHeight;
  166. d && e || (d = screen.width, e = screen.height);
  167. c = 1;
  168. Utils.disableCorrectPixelRatio && (c = window.devicePixelRatio ? window.devicePixelRatio : 1);
  169. var d = d * c,
  170. e = e * c,
  171. f = [{
  172. scale: 1,
  173. width: 320,
  174. height: 480
  175. }, {
  176. scale: 1.5,
  177. width: 480,
  178. height: 720
  179. }, {
  180. scale: 2,
  181. width: 640,
  182. height: 960
  183. }],
  184. g = {
  185. width: 0,
  186. height: 0
  187. },
  188. h = "";
  189. Utils.touchScreen ? (g.width = Math.min(d, e), g.height = Math.max(d, e)) : (a && (f = [{
  190. scale: 1,
  191. width: 480,
  192. height: 320
  193. }, {
  194. scale: 1.5,
  195. width: 720,
  196. height: 480
  197. }, {
  198. scale: 2,
  199. width: 960,
  200. height: 640
  201. }]), g.width = d, g.height = e);
  202. h = "height";
  203. d = Number.MAX_VALUE;
  204. for (e = 0; e < f.length; e++) {
  205. var l = Math.abs(g[h] - f[e][h]);
  206. d > l && (d = l, c = f[e].scale)
  207. }
  208. return Utils.getScaleScreenResolution(c, a)
  209. };
  210. Utils.getScaleScreenResolution = function(a, c) {
  211. var d = Math.round(320 * a),
  212. e = Math.round(480 * a);
  213. return {
  214. width: c ? e : d,
  215. height: c ? d : e,
  216. scale: a
  217. }
  218. };
  219. Utils.imagesRoot = "images";
  220. Utils.initialResolution = {
  221. width: 320,
  222. height: 480,
  223. scale: 1
  224. };
  225. Utils.ignoreMobileHeightCorrection = !1;
  226. Utils.createLayout = function(a, c, d, e) {
  227. var f = Utils.globalScale;
  228. Utils.initialResolution = c;
  229. d = window.innerHeight;
  230. document.body.style.overflow = "hidden";
  231. var g;
  232. g = "" + ('<div id="' + Utils.DOMProgressContainerId + '" align="center" style="width: 100%; height: ' + d + 'px; display: block; width: 100%; position: absolute; left: 0px; top: 0px;">');
  233. g += '<table cellspacing="0" cellpadding="0" border="0"><tr><td id="' + Utils.DOMProgressId + '" align="center" valign="middle" style="width: ' + c.width + "px; height: " + c.height + "px; color: #000; background: #fff; font-weight: bold; font-family: Verdana; font-size: " +
  234. 12 * f + 'px; vertical-align: middle; box-sizing: border-box"></td></tr></table>';
  235. g = g + "</div>" + ('<div id="' + Utils.DOMScreenBackgroundContainerId + '" style="width: 100%; height: ' + d + 'px; position: absolute; left: 0px; top: 0px; display: none; z-index: 2;">');
  236. g += '<div id="' + Utils.DOMScreenBackgroundWrapperId + '" style="width: ' + c.width + "px; height: " + c.height + 'px; position: relative; left: 0px; overflow: hidden;">';
  237. e || (g += '<canvas id="' + Utils.DOMScreenBackgroundId + '" width="' + c.width + '" height="' + c.height +
  238. '" style="transform: translateZ(0)"></canvas>');
  239. g += "</div>";
  240. g += "</div>";
  241. g += '<div id="' + Utils.DOMScreenContainerId + '" style="width: 100%; height: ' + d + 'px; position: absolute; left: 0px; top: 0px; display: none; z-index: 3;">';
  242. g += '<div id="' + Utils.DOMScreenWrapperId + '" width="' + c.width + '" height="' + c.height + '" style="width: ' + c.width + "px; height: " + c.height + 'px; position: relative; left: 0px; overflow: hidden;">';
  243. e || (g += '<canvas id="' + Utils.DOMScreenId + '" style="position: absolute; left: 0px; top: 0px;" width="' +
  244. c.width + '" height="' + c.height + '">You browser does not support this application :(</canvas>');
  245. g += "</div>";
  246. g += "</div>";
  247. a.innerHTML = g;
  248. a = document.createElement("div");
  249. a.setAttribute("id", Utils.DOMP2lContainerId);
  250. a.setAttribute("align", "center");
  251. a.setAttribute("style", "width: 100%; height: " + d + "px; position: absolute; left: 0px; top: 0px; visibility: hidden; z-index: 1000; background-color: #fff; background-image: url(" + Utils.imagesRoot + "/p2l.jpg); background-repeat: no-repeat; background-position: center center");
  252. c = document.createElement("img");
  253. c.setAttribute("id", Utils.DOMP2lId);
  254. c.width = 1;
  255. c.height = 1;
  256. c.style.display = "none";
  257. a.appendChild(c);
  258. document.body.appendChild(a);
  259. a = document.createElement("div");
  260. a.setAttribute("id", Utils.DOMMarkId);
  261. a.style.position = "fixed";
  262. a.style.right = "0px";
  263. a.style.bottom = "0px";
  264. a.style.width = "1px";
  265. a.style.height = "1px";
  266. a.style.background = "";
  267. a.style.zIndex = "100000";
  268. document.body.appendChild(a);
  269. Utils.fitLayoutToScreen()
  270. };
  271. Utils.showMainLayoutContent = function() {
  272. document.getElementById(Utils.DOMProgressContainerId).style.display = "none";
  273. document.getElementById(Utils.DOMScreenContainerId).style.display = "block";
  274. document.getElementById(Utils.DOMScreenBackgroundContainerId).style.display = "block"
  275. };
  276. Utils.preventEvent = function(a) {
  277. a.preventDefault();
  278. a.stopPropagation();
  279. a.cancelBubble = !0;
  280. return a.returnValue = !1
  281. };
  282. Utils.touchStartEventDisabled = !1;
  283. Utils.preventTouchStart = function() {
  284. Utils.touchStartEventDisabled && Utils.bindEvent(document.body, Utils.getTouchStartEvent(), Utils.preventEvent)
  285. };
  286. Utils.removePreventTouchStart = function() {
  287. Utils.touchStartEventDisabled && Utils.unbindEvent(document.body, Utils.getTouchStartEvent(), Utils.preventEvent)
  288. };
  289. Utils.addMobileListeners = function(a, c) {
  290. if (c || !navigator.userAgent.match(/(iPad|iPhone|iPod).*CPU.*OS 7_\d/i)) Utils.touchStartEventDisabled = !0, Utils.preventTouchStart();
  291. Utils.isPlayFreeBrowser() || Utils.bindEvent(window, "scroll", function(a) {
  292. setTimeout(Utils.mobileHideAddressBar, 300)
  293. });
  294. document.addEventListener(Utils.getVisibiltyProps().visibilityChange, Utils.handleVisibilityChange, !1);
  295. setInterval("Utils.checkOrientation(" + (a ? "true" : "false") + ")", 500);
  296. setTimeout(Utils.mobileHideAddressBar, 500)
  297. };
  298. Utils.handleVisibilityChange = function() {
  299. Utils.isWindowHidden = document[Utils.getVisibiltyProps().hidden];
  300. Utils.dispatchEvent(Utils.isWindowHidden ? "hidewindow" : "showwindow")
  301. };
  302. Utils.getVisibiltyProps = function() {
  303. var a, c;
  304. "undefined" !== typeof document.hidden ? (a = "hidden", c = "visibilitychange") : "undefined" !== typeof document.mozHidden ? (a = "mozHidden", c = "mozvisibilitychange") : "undefined" !== typeof document.msHidden ? (a = "msHidden", c = "msvisibilitychange") : "undefined" !== typeof document.webkitHidden && (a = "webkitHidden", c = "webkitvisibilitychange");
  305. return {
  306. hidden: a,
  307. visibilityChange: c
  308. }
  309. };
  310. Utils.staticWindowRect = null;
  311. Utils.setWindowRect = function(a, c) {
  312. Utils.staticWindowRect = {
  313. width: a,
  314. height: c
  315. }
  316. };
  317. Utils.getWindowRect = function() {
  318. var a = document.getElementById(Utils.DOMMarkId);
  319. return Utils.isAndroid() && a ? {
  320. width: window.innerWidth,
  321. height: a.offsetTop + 1
  322. } : {
  323. width: window.innerWidth,
  324. height: window.innerHeight
  325. }
  326. };
  327. Utils.storeOrient = null;
  328. Utils.noCheckOrient = !1;
  329. Utils.checkOrientation = function(a) {
  330. if (Utils.touchScreen && document.getElementById(Utils.DOMScreenContainerId) && !Utils.noCheckOrient && 1 != Utils.parseGet().nocheckorient) {
  331. var c = Utils.getWindowRect(),
  332. c = c.width > c.height;
  333. Utils.storeOrient !== c && (Utils.storeOrient = c, c != a ? (Utils.dispatchEvent("lockscreen"), document.getElementById(Utils.DOMP2lContainerId).style.visibility = "visible", document.getElementById(Utils.DOMProgressContainerId).style.visibility = "hidden", document.getElementById(Utils.DOMScreenBackgroundContainerId).style.display =
  334. "none", document.getElementById(Utils.DOMScreenContainerId).style.display = "none") : (Utils.dispatchEvent("unlockscreen"), document.getElementById(Utils.DOMP2lContainerId).style.visibility = "hidden", document.getElementById(Utils.DOMProgressContainerId).style.visibility = "visible", document.getElementById(Utils.DOMScreenBackgroundContainerId).style.display = "block", document.getElementById(Utils.DOMScreenContainerId).style.display = "block"), setTimeout(Utils.mobileHideAddressBar, 900), setTimeout(Utils.fitLayoutToScreen,
  335. 1E3))
  336. }
  337. };
  338. Utils.fitLayoutTimer = null;
  339. Utils.addFitLayoutListeners = function() {
  340. Utils.fitLayoutTimer = setInterval(Utils.fitLayoutToScreen, 500)
  341. };
  342. Utils.removeFitLayoutListeners = function() {
  343. clearInterval(Utils.fitLayoutTimer)
  344. };
  345. Utils.fitLayoutLock = !1;
  346. Utils.fitLayoutCorrectHeight = 0;
  347. Utils.fitLayoutAlign = "center";
  348. Utils.fitLayoutVerticalAlign = "top";
  349. Utils.layoutMargin = {
  350. left: 0,
  351. right: 0,
  352. top: 0,
  353. bottom: 0
  354. };
  355. Utils.fitLayoutToScreen = function(a) {
  356. if (!Utils.fitLayoutLock) {
  357. var c, d, e, f, g;
  358. g = Utils.getWindowRect();
  359. "object" == typeof a && a.width || (f = Utils.staticWindowRect ? Utils.staticWindowRect : g, d = f.width, e = f.height, e += Utils.fitLayoutCorrectHeight, e -= Utils.layoutMargin.top, e -= Utils.layoutMargin.bottom, d -= Utils.layoutMargin.left, d -= Utils.layoutMargin.right, a = {
  360. width: d,
  361. height: e
  362. });
  363. if (a.width && a.height && (c = document.getElementById(Utils.DOMScreenWrapperId))) {
  364. c.initWidth || (c.initWidth = Utils.initialResolution.width, c.initHeight =
  365. Utils.initialResolution.height);
  366. d = c.initWidth;
  367. e = c.initHeight;
  368. var h = 1,
  369. h = a.width / d,
  370. l = a.height / e,
  371. h = h < l ? h : l;
  372. Utils.globalPixelScale = h;
  373. d = Math.floor(d * h);
  374. e = Math.floor(e * h);
  375. if (c.lastWidth != a.width || c.lastHeight != a.height || c.lastRealWidth != g.width || c.lastRealHeight != g.height) c.lastWidth = a.width, c.lastHeight = a.height, c.lastRealWidth = g.width, c.lastRealHeight = g.height, Utils.resizeElement(Utils.DOMScreenId, d, e), Utils.resizeElement(Utils.DOMScreenBackgroundId, d, e), Utils.resizeElement(Utils.DOMProgressContainerId,
  376. f.width, f.height), Utils.resizeElement(Utils.DOMProgressId, d, e), c = Utils.resizeElement(Utils.DOMScreenWrapperId, d, e), Utils.alignElement(c, g, d, e), c = Utils.resizeElement(Utils.DOMScreenBackgroundWrapperId, d, e), Utils.alignElement(c, g, d, e), Utils.resizeElement(Utils.DOMP2lContainerId, f.width, f.height), Utils.resizeElement(Utils.DOMScreenContainerId, f.width, f.height), Utils.resizeElement(Utils.DOMScreenBackgroundContainerId, f.width, f.height), Utils.dispatchEvent("fitlayout"), Utils.isPlayFreeBrowser() && window.scrollTo(1,
  377. 2), setTimeout(Utils.mobileHideAddressBar, 10)
  378. }
  379. }
  380. };
  381. Utils.alignElement = function(a, c, d, e) {
  382. a && (a.style.left = "left" == Utils.fitLayoutAlign ? Utils.layoutMargin.left + "px" : "right" == Utils.fitLayoutAlign ? Math.floor(c.width - d - Utils.layoutMargin.right) + "px" : Math.floor((c.width - d - Utils.layoutMargin.left - Utils.layoutMargin.right) / 2) + "px", a.style.top = "top" == Utils.fitLayoutVerticalAlign ? Utils.layoutMargin.top + "px" : "bottom" == Utils.fitLayoutVerticalAlign ? Math.floor(c.height - e - Utils.layoutMargin.bottom) + "px" : Math.floor((c.height - e - Utils.layoutMargin.top - Utils.layoutMargin.bottom) /
  383. 2) + "px")
  384. };
  385. Utils.resizeElement = function(a, c, d) {
  386. a = document.getElementById(a);
  387. if (!a) return null;
  388. a.style.width = Math.floor(c) + "px";
  389. a.style.height = Math.floor(d) + "px";
  390. return a
  391. };
  392. Utils.drawIphoneLimiter = function(a, c) {
  393. c ? a.drawRectangle(240, 295, 480, 54, "#f00", !0, .5, !0) : a.drawRectangle(160, 448, 320, 64, "#f00", !0, .5, !0)
  394. };
  395. Utils.drawGrid = function(a, c, d) {
  396. "undefined" == typeof c && (c = !1);
  397. "undefined" == typeof d && (d = "#FFF");
  398. var e = c ? 480 : 320;
  399. c = c ? 320 : 480;
  400. for (var f = 10; f < e; f += 10) {
  401. var g = .1 + (f - 10) / 10 % 10 * .1;
  402. a.drawLine(f, 0, f, c, 1, d, g)
  403. }
  404. for (f = 10; f < c; f += 10) g = .1 + (f - 10) / 10 % 10 * .1, a.drawLine(0, f, e, f, 1, d, g)
  405. };
  406. Utils.drawScaleFix = function(a, c) {.75 == Utils.globalScale && (c ? a.drawRectangle(507, 160, 54, 320, "#000", !0, 1, !0) : a.drawRectangle(160, 507, 320, 54, "#000", !0, 1, !0));
  407. 1.5 == Utils.globalScale && (c ? a.drawRectangle(510, 160, 60, 320, "#000", !0, 1, !0) : a.drawRectangle(160, 510, 320, 60, "#000", !0, 1, !0))
  408. };
  409. Utils.grad2radian = function(a) {
  410. return a / (180 / Math.PI)
  411. };
  412. Utils.radian2grad = function(a) {
  413. return 180 / Math.PI * a
  414. };
  415. Utils.eventsListeners = [];
  416. Utils.onlockscreen = null;
  417. Utils.onunlockscreen = null;
  418. Utils.onhidewindow = null;
  419. Utils.onshowwindow = null;
  420. Utils.onfitlayout = null;
  421. Utils.addEventListener = function(a, c) {
  422. EventsManager.addEvent(Utils, a, c)
  423. };
  424. Utils.removeEventListener = function(a, c) {
  425. EventsManager.removeEvent(Utils, a, c)
  426. };
  427. Utils.dispatchEvent = function(a, c) {
  428. return EventsManager.dispatchEvent(Utils, a, c)
  429. };
  430. Utils.isArray = function(a) {
  431. return "[object Array]" === Object.prototype.toString.call(a)
  432. };
  433. Utils.isPlainObject = function(a) {
  434. return a && a.constructor ? a.constructor === Object : !1
  435. };
  436. Utils.getFunctionArguments = function(a, c) {
  437. "undefined" == typeof c && (c = 0);
  438. return [].slice.call(a, c)
  439. };
  440. Utils.proxy = function(a, c) {
  441. var d = Utils.getFunctionArguments(arguments, 2);
  442. return function() {
  443. return a.apply(c || this, Utils.getFunctionArguments(arguments, 0).concat(d))
  444. }
  445. };
  446. Utils.extend = function(a, c) {
  447. var d = function() {};
  448. d.prototype = c.prototype;
  449. a.prototype = new d;
  450. a.prototype.constructor = a;
  451. a.superclass = c.prototype
  452. };
  453. Utils.callSuperConstructor = function(a, c) {
  454. a.superclass.constructor.apply(c, Utils.getFunctionArguments(arguments, 2))
  455. };
  456. Utils.callSuperMethod = function(a, c, d) {
  457. return a.superclass[d].apply(c, Utils.getFunctionArguments(arguments, 3))
  458. };
  459. Utils.copyObjectProps = function(a, c) {
  460. for (var d in a)
  461. if (a.hasOwnProperty(d))
  462. if (Utils.isArray(a[d])) {
  463. c[d] = [];
  464. for (var e = 0; e < a[d].length; e++) "object" == typeof a[d][e] && (c[d][e] = Utils.cloneEmptyObject(a[d][e])), Utils.copyObjectProps(a[d][e], c[d][e])
  465. } else Utils.isPlainObject(a[d]) ? (c[d] = {}, Utils.copyObjectProps(a[d], c[d])) : c[d] = a[d]
  466. };
  467. Utils.cloneEmptyObject = function(a) {
  468. return a.constructor ? new a.constructor : {}
  469. };
  470. Utils.clone = function(a) {
  471. if (!a || "object" != typeof a) return a;
  472. var c = Utils.cloneEmptyObject(a);
  473. Utils.copyObjectProps(a, c);
  474. return c
  475. };
  476. Utils.switchToTimeMode = function(a) {
  477. Tween.STEP_TYPE = Tween.STEP_BY_TIME;
  478. StageTimer.TIMEOUT_TYPE = StageTimer.TIMEOUT_BY_TIME;
  479. Sprite.CHANGE_FRAME_TYPE = Sprite.CHANGE_FRAME_BY_TIME;
  480. Sprite.CHANGE_FRAME_DELAY = a
  481. };
  482. Utils.getGameID = function() {
  483. if (window.GAME_ID && "my_game" != window.GAME_ID) return window.GAME_ID;
  484. for (var a = window.location.toString().split("/"), c = ""; !c;) c = a.pop(), 1 < c.split(".").length && (c = ""), 0 == a.length && (c = "my_game");
  485. return c
  486. };
  487. Utils.ajax = function(a, c, d, e, f, g) {
  488. var h;
  489. h = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
  490. h.onreadystatechange = function() {
  491. if (4 == h.readyState)
  492. if (200 == h.status) {
  493. var a = h.responseText;
  494. "json" == e && (a = JSON.parse(a));
  495. "xml" == e && (a = Utils.parseXMLString(a));
  496. f && f(a, h)
  497. } else g && g(h.status, h)
  498. };
  499. if (d) {
  500. var l = [],
  501. k;
  502. for (k in d) l.push(encodeURIComponent(k) + "=" + encodeURIComponent(d[k]));
  503. d = l.join("&")
  504. } else d = "";
  505. c || (c = "GET");
  506. h.open(c, a + ("GET" == c ? "?" + d : ""), !0);
  507. "POST" == c && h.setRequestHeader("Content-type",
  508. "application/x-www-form-urlencoded");
  509. h.send("GET" != c ? d : null)
  510. };
  511. Utils.get = function(a, c, d, e, f) {
  512. Utils.ajax(a, "GET", c, d, e, f)
  513. };
  514. Utils.post = function(a, c, d, e, f) {
  515. Utils.ajax(a, "POST", c, d, e, f)
  516. };
  517. Utils.getBezierBasis = function(a, c, d) {
  518. function e(a) {
  519. return 1 >= a ? 1 : a * e(a - 1)
  520. }
  521. return e(c) / (e(a) * e(c - a)) * Math.pow(d, a) * Math.pow(1 - d, c - a)
  522. };
  523. Utils.getBezierCurve = function(a, c) {
  524. "undefined" == typeof c && (c = .1);
  525. var d = [];
  526. c /= a.length;
  527. for (var e = 0; e < 1 + c; e += c) {
  528. 1 < e && (e = 1);
  529. var f = d.length;
  530. d[f] = {
  531. x: 0,
  532. y: 0
  533. };
  534. for (var g = 0; g < a.length; g++) {
  535. var h = Utils.getBezierBasis(g, a.length - 1, e);
  536. d[f].x += a[g].x * h;
  537. d[f].y += a[g].y * h
  538. }
  539. }
  540. return d
  541. };
  542. Utils.parseXMLString = function(a) {
  543. var c = null;
  544. if ("undefined" != typeof window.DOMParser) c = (new window.DOMParser).parseFromString(a, "text/xml");
  545. else if ("undefined" != typeof window.ActiveXObject && new window.ActiveXObject("Microsoft.XMLDOM")) c = new window.ActiveXObject("Microsoft.XMLDOM"), c.async = "false", c.loadXML(a);
  546. else throw Error("No XML parser found");
  547. return c
  548. };
  549. Utils.gotoFullScreen = function() {
  550. var a = document.documentElement;
  551. a.requestFullscreen && a.requestFullscreen();
  552. a.webkitRequestFullscreen && a.webkitRequestFullscreen();
  553. a.mozRequestFullscreen && a.mozRequestFullscreen();
  554. a.msRequestFullscreen && a.msRequestFullscreen()
  555. };
  556. Utils.cancelFullScreen = function() {
  557. document.cancelFullScreen && document.cancelFullScreen();
  558. document.webkitCancelFullScreen && document.webkitCancelFullScreen();
  559. document.mozCancelFullScreen && document.mozCancelFullScreen();
  560. document.msExitFullscreen && document.msExitFullscreen()
  561. };
  562. Utils.isFullScreen = function() {
  563. return !!(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)
  564. };
  565. Utils.isFullScreenEnabled = function() {
  566. return !!(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullscreenEnabled || document.msFullscreenEnabled)
  567. };
  568. Utils.toggleFullScreen = function() {
  569. Utils.isFullScreen() ? Utils.cancelFullScreen() : Utils.gotoFullScreen()
  570. };
  571. Utils.sign = function(a) {
  572. return 0 == a ? 0 : 0 < a ? 1 : -1
  573. };
  574. function ImagesPreloader() {
  575. this.curItem = -1;
  576. this.loadedImages = {};
  577. this.processCallback = this.endCallback = this.data = null;
  578. this.minProgressVal = 0;
  579. this.maxProgressVal = 100;
  580. this.wait = Utils.proxy(this.wait, this)
  581. }
  582. ImagesPreloader.prototype.load = function(a, c, d) {
  583. this.data = a;
  584. this.endCallback = c;
  585. this.processCallback = d;
  586. for (a = 0; a < this.data.length; a++) c = this.data[a], d = new Image, d.src = c.src, this.loadedImages[c.name] = d;
  587. this.wait()
  588. };
  589. ImagesPreloader.prototype.wait = function() {
  590. var a = 0,
  591. c = 0,
  592. d;
  593. for (d in this.loadedImages) this.loadedImages[d].complete && a++, c++;
  594. a >= c ? this.endCallback && this.endCallback(this.loadedImages) : (this.processCallback && this.processCallback(Math.floor(a / c * this.maxProgressVal + this.minProgressVal)), setTimeout(this.wait, 50))
  595. };
  596. function SoundsPreloader(a, c, d) {
  597. this.sounds = a;
  598. this.endCallback = c;
  599. this.progressCallback = d;
  600. this.minProgressVal = this.loadedCount = 0;
  601. this.maxProgressVal = 100
  602. }
  603. SoundsPreloader.prototype.isMp3Support = function() {
  604. return "" != document.createElement("audio").canPlayType("audio/mpeg")
  605. };
  606. SoundsPreloader.prototype.isWebAudio = function() {
  607. return Boolean(window.AudioMixer) && AudioMixer.isWebAudioSupport()
  608. };
  609. SoundsPreloader.prototype.load = function(a, c, d) {
  610. a && (this.sounds = a);
  611. c && (this.endCallback = c);
  612. d && (this.progressCallback = d);
  613. if (!this.sounds || 1 > this.sounds.length || !this.isWebAudio()) this.endCallback && this.endCallback();
  614. else {
  615. a = this.isMp3Support() ? "mp3" : "ogg";
  616. var e;
  617. this.loadedCount = 0;
  618. var f = this;
  619. for (d = 0; d < this.sounds.length; d++) c = this.sounds[d] + "." + a, this.isWebAudio() ? (e = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"), e.open("GET", c, !0), e.responseType = "arraybuffer", e.onreadystatechange =
  620. function() {
  621. if (4 == this.readyState && 200 == this.status) {
  622. var a = this.soundSrc;
  623. AudioMixer.waContext || (AudioMixer.waContext = new AudioContext);
  624. AudioMixer.waContext.decodeAudioData(this.response, function(c) {
  625. AudioMixer.buffer[a] = c;
  626. f.soundIsLoaded(null, f)
  627. }, function(a) {
  628. f.soundIsLoaded(null, f)
  629. })
  630. }
  631. }, e.soundSrc = c, e.send()) : (e = document.createElement("audio"), e.src = c, e.type = "mp3" == a ? "audio/mpeg" : "audio/ogg", e.preload = "auto", e.load(), e.addEventListener("canplay", Utils.proxy(this.soundIsLoaded, e, this)), e.addEventListener("canplaythrough",
  632. Utils.proxy(this.soundIsLoaded, e, this)))
  633. }
  634. };
  635. SoundsPreloader.prototype.soundIsLoaded = function(a, c) {
  636. if (this.nodeName && "audio" == this.nodeName.toLowerCase()) {
  637. if (this.alreadyLoaded) return;
  638. this.alreadyLoaded = !0
  639. }
  640. c.loadedCount++;
  641. c.progressCallback && c.progressCallback(Math.floor(c.loadedCount / c.sounds.length * c.maxProgressVal + c.minProgressVal));
  642. c.loadedCount >= c.sounds.length && c.endCallback && c.endCallback()
  643. };
  644. function Asset(a, c, d, e, f, g) {
  645. this.name = a + "";
  646. this.src = c + "";
  647. this.width = d;
  648. this.height = e;
  649. this.frames = f;
  650. this.layers = g;
  651. this.object = this.bitmap = null;
  652. this.ready = !(!this.width || !this.height);
  653. this.spriteClass = null
  654. }
  655. Asset.prototype.detectSize = function() {
  656. if (!this.bitmap) return !1;
  657. try {
  658. isNaN(this.width) && (this.width = this.bitmap.width ? parseInt(this.bitmap.width) : 0), isNaN(this.height) && (this.height = this.bitmap.height ? parseInt(this.bitmap.height) : 0)
  659. } catch (a) {
  660. CRENDER_DEBUG && console.log(a)
  661. }
  662. return !isNaN(this.width) && !isNaN(this.height)
  663. };
  664. Asset.prototype.normalize = function(a) {
  665. if (!this.ready && this.detectSize()) {
  666. if (isNaN(this.frames) || 1 > this.frames) this.frames = 1;
  667. if (isNaN(this.layers) || 1 > this.layers) this.layers = 1;
  668. this.width = Math.ceil(this.width / this.layers / a);
  669. this.height = Math.ceil(this.height / this.frames / a);
  670. this.ready = !0
  671. }
  672. };
  673. function AssetsLibrary(a, c, d) {
  674. this.path = "images";
  675. this.scale = 1;
  676. this.items = {};
  677. this.bitmaps = {};
  678. this.loaded = !1;
  679. this.onloadprogress = this.onload = null;
  680. this.spriteClass = Sprite;
  681. this.onLoadHandler = Utils.proxy(this.onLoadHandler, this);
  682. this.onLoadProgressHandler = Utils.proxy(this.onLoadProgressHandler, this);
  683. this.init(a, c);
  684. this.addAssets(d)
  685. }
  686. AssetsLibrary.prototype.init = function(a, c) {
  687. "undefined" != typeof a && (this.path = a + "");
  688. "undefined" != typeof c && (this.scale = parseFloat(c), isNaN(this.scale) && (this.scale = 1))
  689. };
  690. AssetsLibrary.prototype.load = function(a, c, d, e) {
  691. this.onload = a;
  692. this.onloadprogress = c;
  693. a = new ImagesPreloader;
  694. c = [];
  695. for (var f in this.items) c.push(this.items[f]);
  696. "undefined" != typeof d && (a.minProgressVal = d);
  697. "undefined" != typeof e && (a.maxProgressVal = e);
  698. a.load(c, this.onLoadHandler, this.onLoadProgressHandler)
  699. };
  700. AssetsLibrary.prototype.onLoadProgressHandler = function(a) {
  701. if ("function" == typeof this.onloadprogress) this.onloadprogress(a)
  702. };
  703. AssetsLibrary.prototype.onLoadHandler = function(a) {
  704. this.loaded = !0;
  705. for (var c in a) {
  706. var d = this.items[c];
  707. d.bitmap = a[c];
  708. d.normalize(this.scale)
  709. }
  710. if ("function" == typeof this.onload) this.onload(this.items)
  711. };
  712. AssetsLibrary.prototype.addAssets = function(a) {
  713. if ("undefined" != typeof a && "object" == typeof a)
  714. for (var c = 0; c < a.length; c++) {
  715. var d = a[c];
  716. d.noscale = "undefined" == typeof d.noscale ? !1 : d.noscale;
  717. d.noscale || (d.src = "%SCALE%/" + d.src);
  718. this.addAsset(d)
  719. }
  720. };
  721. AssetsLibrary.prototype.addAsset = function(a, c, d, e, f, g) {
  722. var h = null,
  723. l = null;
  724. "object" == typeof a && 1 == arguments.length && (c = a.name, d = a.width || NaN, e = a.height || NaN, f = a.frames || 1, g = a.layers || 1, h = a.spriteClass || null, l = a.properties || null, a = a.src);
  725. a = a.replace("%SCALE%", "%PATH%/" + this.scale);
  726. a = a.replace("%PATH%", this.path);
  727. if ("undefined" == typeof c) {
  728. var k = a.split("/"),
  729. k = k.pop(),
  730. k = k.split(".");
  731. c = k = k.shift() + ""
  732. }
  733. k = new Asset(c, a, d, e, f, g);
  734. k.spriteClass = h;
  735. if (l)
  736. for (var m in l) "undefined" == typeof k[m] && (k[m] = l[m]);
  737. return this.items[c] =
  738. k
  739. };
  740. AssetsLibrary.prototype.addObject = function(a) {
  741. var c = this.addAsset("%SCALE%/" + a.image, a.name, a.width * this.scale, a.height * this.scale, a.frames, a.layers);
  742. c && (c.object = a);
  743. return c
  744. };
  745. AssetsLibrary.prototype.getAsset = function(a, c) {
  746. var d = null;
  747. "undefined" != typeof this.items[a] && this.items[a].bitmap && (d = "undefined" != typeof c && !c || this.items[a].ready ? this.items[a] : null);
  748. if (!d) throw Error('Trying to get undefined asset "' + a + '"');
  749. return d
  750. };
  751. AssetsLibrary.prototype.getSprite = function(a, c, d) {
  752. var e = null,
  753. e = null;
  754. try {
  755. e = this.getAsset(a, !0)
  756. } catch (f) {
  757. e = new Asset
  758. }
  759. if ((d = d || e.spriteClass || this.spriteClass || window.Sprite) && "function" == typeof d || "function" == typeof window[d]) d = "function" == typeof d ? d : window[d];
  760. e = d.create && "function" == typeof d.create ? d.create(e, this) : new d(e.bitmap, e.width, e.height, e.frames, e.layers);
  761. if (c && "object" == typeof c)
  762. for (var g in c) e[g] = c[g];
  763. return e
  764. };
  765. AssetsLibrary.prototype.getBitmap = function(a) {
  766. try {
  767. return this.getAsset(a, !0).bitmap
  768. } catch (c) {
  769. return null
  770. }
  771. };
  772. function Vector(a, c) {
  773. "undefined" == typeof a && (a = 0);
  774. this.x = a;
  775. "undefined" == typeof c && (c = 0);
  776. this.y = c
  777. }
  778. Vector.prototype.isZero = function() {
  779. return 0 == this.x && 0 == this.y
  780. };
  781. Vector.prototype.clone = function() {
  782. return new Vector(this.x, this.y)
  783. };
  784. Vector.prototype.add = function(a) {
  785. this.x += a.x;
  786. this.y += a.y;
  787. return this
  788. };
  789. Vector.prototype.subtract = function(a) {
  790. this.x -= a.x;
  791. this.y -= a.y;
  792. return this
  793. };
  794. Vector.prototype.mult = function(a) {
  795. this.x *= a;
  796. this.y *= a;
  797. return this
  798. };
  799. Vector.prototype.invert = function() {
  800. this.mult(-1);
  801. return this
  802. };
  803. Vector.prototype.rotate = function(a, c) {
  804. "undefined" == typeof c && (c = new Vector(0, 0));
  805. var d = this.clone();
  806. d.subtract(c);
  807. d.x = this.x * Math.cos(a) + this.y * Math.sin(a);
  808. d.y = this.x * -Math.sin(a) + this.y * Math.cos(a);
  809. d.add(c);
  810. this.x = d.x;
  811. this.y = d.y;
  812. return this
  813. };
  814. Vector.prototype.normalize = function(a, c) {
  815. "undefined" == typeof c && (c = new Vector(0, 0));
  816. this.subtract(c);
  817. this.rotate(-a);
  818. return this
  819. };
  820. Vector.prototype.getLength = function() {
  821. return Math.sqrt(this.x * this.x + this.y * this.y)
  822. };
  823. Vector.prototype.distanceTo = function(a) {
  824. p2 = this.clone();
  825. p2.subtract(a);
  826. return p2.getLength()
  827. };
  828. function Rectangle(a, c, d, e, f) {
  829. this.center = new Vector(a, c);
  830. this.width = d;
  831. this.height = e;
  832. this.angle = f;
  833. this.vertices = [];
  834. this.AABB = [];
  835. this.refreshVertices()
  836. }
  837. Rectangle.prototype.clone = function() {
  838. return new Rectangle(this.center.x, this.center.y, this.width, this.height, this.angle)
  839. };
  840. Rectangle.prototype.refreshVertices = function() {
  841. var a = this.width / 2,
  842. c = this.height / 2;
  843. this.vertices = [];
  844. this.vertices.push(new Vector(-a, c));
  845. this.vertices.push(new Vector(a, c));
  846. this.vertices.push(new Vector(a, -c));
  847. this.vertices.push(new Vector(-a, -c));
  848. this.AABB = [this.center.clone(), this.center.clone()];
  849. for (a = 0; 4 > a; a++) this.vertices[a].rotate(-this.angle, this.center), this.vertices[a].x < this.AABB[0].x && (this.AABB[0].x = this.vertices[a].x), this.vertices[a].x > this.AABB[1].x && (this.AABB[1].x = this.vertices[a].x),
  850. this.vertices[a].y < this.AABB[0].y && (this.AABB[0].y = this.vertices[a].y), this.vertices[a].y > this.AABB[1].y && (this.AABB[1].y = this.vertices[a].y)
  851. };
  852. Rectangle.prototype.move = function(a, c) {
  853. this.center.add(new Vector(a, c));
  854. this.refreshVertices()
  855. };
  856. Rectangle.prototype.rotate = function(a) {
  857. this.angle += a;
  858. this.refreshVertices()
  859. };
  860. Rectangle.prototype.hitTestPoint = function(a) {
  861. a = a.clone();
  862. a.normalize(-this.angle, this.center);
  863. return Math.abs(a.x) <= this.width / 2 && Math.abs(a.y) <= this.height / 2
  864. };
  865. Rectangle.prototype.hitTestRectangle = function(a) {
  866. var c = this.clone();
  867. a = a.clone();
  868. var d, e, f;
  869. c.move(-this.center.x, -this.center.y);
  870. a.move(-this.center.x, -this.center.y);
  871. a.center.rotate(this.angle);
  872. c.rotate(-this.angle);
  873. a.rotate(-this.angle);
  874. d = Math.max(c.AABB[0].x, c.AABB[1].x, a.AABB[0].x, a.AABB[1].x) - Math.min(c.AABB[0].x, c.AABB[1].x, a.AABB[0].x, a.AABB[1].x);
  875. e = c.AABB[1].x - c.AABB[0].x;
  876. f = a.AABB[1].x - a.AABB[0].x;
  877. if (d > e + f) return !1;
  878. d = Math.max(c.AABB[0].y, c.AABB[1].y, a.AABB[0].y, a.AABB[1].y) - Math.min(c.AABB[0].y,
  879. c.AABB[1].y, a.AABB[0].y, a.AABB[1].y);
  880. e = c.AABB[1].y - c.AABB[0].y;
  881. f = a.AABB[1].y - a.AABB[0].y;
  882. if (d > e + f) return !1;
  883. c.move(-a.center.x, -a.center.y);
  884. a.move(-a.center.x, -a.center.y);
  885. c.center.rotate(a.angle);
  886. c.refreshVertices();
  887. c.rotate(-a.angle);
  888. a.rotate(-a.angle);
  889. d = Math.max(c.AABB[0].x, c.AABB[1].x, a.AABB[0].x, a.AABB[1].x) - Math.min(c.AABB[0].x, c.AABB[1].x, a.AABB[0].x, a.AABB[1].x);
  890. e = c.AABB[1].x - c.AABB[0].x;
  891. f = a.AABB[1].x - a.AABB[0].x;
  892. if (d > e + f) return !1;
  893. d = Math.max(c.AABB[0].y, c.AABB[1].y, a.AABB[0].y, a.AABB[1].y) -
  894. Math.min(c.AABB[0].y, c.AABB[1].y, a.AABB[0].y, a.AABB[1].y);
  895. e = c.AABB[1].y - c.AABB[0].y;
  896. f = a.AABB[1].y - a.AABB[0].y;
  897. return d > e + f ? !1 : !0
  898. };
  899. var EventsManager = {
  900. addEvent: function(a, c, d) {
  901. if (a.eventsListeners) {
  902. for (var e = 0; e < a.eventsListeners.length; e++)
  903. if (a.eventsListeners[e].type === c && a.eventsListeners[e].callback === d) return;
  904. a.eventsListeners.push({
  905. type: c,
  906. callback: d
  907. })
  908. }
  909. },
  910. removeEvent: function(a, c, d) {
  911. if (a.eventsListeners)
  912. for (var e = 0; e < a.eventsListeners.length; e++)
  913. if (a.eventsListeners[e].type === c && a.eventsListeners[e].callback === d) {
  914. a.eventsListeners = Utils.removeFromArray(a.eventsListeners, a.eventsListeners[e]);
  915. break
  916. }
  917. },
  918. dispatchEvent: function(a,
  919. c, d) {
  920. if (a.eventsListeners) {
  921. var e;
  922. if ("function" == typeof a["on" + c] && (e = a["on" + c](d), !1 === e)) return !1;
  923. for (var f = 0; f < a.eventsListeners.length; f++)
  924. if (a.eventsListeners[f].type === c && (e = a.eventsListeners[f].callback(d), !1 === e)) return !1
  925. }
  926. },
  927. hasEventListener: function(a, c) {
  928. if (a.eventsListeners) {
  929. for (var d = 0; d < a.eventsListeners.length; d++)
  930. if (a.eventsListeners[d].type === c) return !0;
  931. return !1
  932. }
  933. },
  934. removeAllEventListeners: function(a, c) {
  935. if (a.eventsListeners) {
  936. "undefined" == typeof c && (a.eventsListeners = []);
  937. for (var d = [], e =
  938. 0; e < a.eventsListeners.length; e++) a.eventsListeners[e].type !== c && d.push(a.eventsListeners[e]);
  939. a.eventsListeners = d
  940. }
  941. }
  942. };
  943. function EventsProxy() {
  944. this.eventsListeners = []
  945. }
  946. EventsProxy.prototype.addEventListener = function(a, c) {
  947. EventsManager.addEvent(this, a, c)
  948. };
  949. EventsProxy.prototype.removeEventListener = function(a, c) {
  950. EventsManager.removeEvent(this, a, c)
  951. };
  952. EventsProxy.prototype.dispatchEvent = function(a, c) {
  953. return EventsManager.dispatchEvent(this, a, c)
  954. };
  955. EventsProxy.prototype.hasEventListener = function(a) {
  956. return EventsManager.hasEventListener(this, a)
  957. };
  958. EventsProxy.prototype.removeAllEventListeners = function(a) {
  959. EventsManager.removeAllEventListeners(this, a)
  960. };
  961. var Easing = {
  962. back: {
  963. easeIn: function(a, c, d, e) {
  964. return d * (a /= e) * a * (2.70158 * a - 1.70158) + c
  965. },
  966. easeOut: function(a, c, d, e) {
  967. return d * ((a = a / e - 1) * a * (2.70158 * a + 1.70158) + 1) + c
  968. },
  969. easeInOut: function(a, c, d, e) {
  970. var f = 1.70158;
  971. return 1 > (a /= e / 2) ? d / 2 * a * a * (((f *= 1.525) + 1) * a - f) + c : d / 2 * ((a -= 2) * a * (((f *= 1.525) + 1) * a + f) + 2) + c
  972. }
  973. },
  974. bounce: {
  975. easeIn: function(a, c, d, e) {
  976. return d - Easing.bounce.easeOut(e - a, 0, d, e) + c
  977. },
  978. easeOut: function(a, c, d, e) {
  979. return (a /= e) < 1 / 2.75 ? 7.5625 * d * a * a + c : a < 2 / 2.75 ? d * (7.5625 * (a -= 1.5 / 2.75) * a + .75) + c : a < 2.5 / 2.75 ? d * (7.5625 * (a -= 2.25 /
  980. 2.75) * a + .9375) + c : d * (7.5625 * (a -= 2.625 / 2.75) * a + .984375) + c
  981. },
  982. easeInOut: function(a, c, d, e) {
  983. return a < e / 2 ? .5 * Easing.bounce.easeIn(2 * a, 0, d, e) + c : .5 * Easing.bounce.easeOut(2 * a - e, 0, d, e) + .5 * d + c
  984. }
  985. },
  986. circular: {
  987. easeIn: function(a, c, d, e) {
  988. return -d * (Math.sqrt(1 - (a /= e) * a) - 1) + c
  989. },
  990. easeOut: function(a, c, d, e) {
  991. return d * Math.sqrt(1 - (a = a / e - 1) * a) + c
  992. },
  993. easeInOut: function(a, c, d, e) {
  994. return 1 > (a /= e / 2) ? -d / 2 * (Math.sqrt(1 - a * a) - 1) + c : d / 2 * (Math.sqrt(1 - (a -= 2) * a) + 1) + c
  995. }
  996. },
  997. cubic: {
  998. easeIn: function(a, c, d, e) {
  999. return d * (a /= e) * a * a + c
  1000. },
  1001. easeOut: function(a, c,
  1002. d, e) {
  1003. return d * ((a = a / e - 1) * a * a + 1) + c
  1004. },
  1005. easeInOut: function(a, c, d, e) {
  1006. return 1 > (a /= e / 2) ? d / 2 * a * a * a + c : d / 2 * ((a -= 2) * a * a + 2) + c
  1007. }
  1008. },
  1009. exponential: {
  1010. easeIn: function(a, c, d, e) {
  1011. return 0 == a ? c : d * Math.pow(2, 10 * (a / e - 1)) + c
  1012. },
  1013. easeOut: function(a, c, d, e) {
  1014. return a == e ? c + d : d * (-Math.pow(2, -10 * a / e) + 1) + c
  1015. },
  1016. easeInOut: function(a, c, d, e) {
  1017. return 0 == a ? c : a == e ? c + d : 1 > (a /= e / 2) ? d / 2 * Math.pow(2, 10 * (a - 1)) + c : d / 2 * (-Math.pow(2, -10 * --a) + 2) + c
  1018. }
  1019. },
  1020. linear: {
  1021. easeIn: function(a, c, d, e) {
  1022. return d * a / e + c
  1023. },
  1024. easeOut: function(a, c, d, e) {
  1025. return d * a / e + c
  1026. },
  1027. easeInOut: function(a,
  1028. c, d, e) {
  1029. return d * a / e + c
  1030. }
  1031. },
  1032. quadratic: {
  1033. easeIn: function(a, c, d, e) {
  1034. return d * (a /= e) * a + c
  1035. },
  1036. easeOut: function(a, c, d, e) {
  1037. return -d * (a /= e) * (a - 2) + c
  1038. },
  1039. easeInOut: function(a, c, d, e) {
  1040. return 1 > (a /= e / 2) ? d / 2 * a * a + c : -d / 2 * (--a * (a - 2) - 1) + c
  1041. }
  1042. },
  1043. quartic: {
  1044. easeIn: function(a, c, d, e) {
  1045. return d * (a /= e) * a * a * a + c
  1046. },
  1047. easeOut: function(a, c, d, e) {
  1048. return -d * ((a = a / e - 1) * a * a * a - 1) + c
  1049. },
  1050. easeInOut: function(a, c, d, e) {
  1051. return 1 > (a /= e / 2) ? d / 2 * a * a * a * a + c : -d / 2 * ((a -= 2) * a * a * a - 2) + c
  1052. }
  1053. },
  1054. quintic: {
  1055. easeIn: function(a, c, d, e) {
  1056. return d * (a /= e) * a * a * a * a + c
  1057. },
  1058. easeOut: function(a, c, d, e) {
  1059. return d *
  1060. ((a = a / e - 1) * a * a * a * a + 1) + c
  1061. },
  1062. easeInOut: function(a, c, d, e) {
  1063. return 1 > (a /= e / 2) ? d / 2 * a * a * a * a * a + c : d / 2 * ((a -= 2) * a * a * a * a + 2) + c
  1064. }
  1065. },
  1066. sine: {
  1067. easeIn: function(a, c, d, e) {
  1068. return -d * Math.cos(a / e * (Math.PI / 2)) + d + c
  1069. },
  1070. easeOut: function(a, c, d, e) {
  1071. return d * Math.sin(a / e * (Math.PI / 2)) + c
  1072. },
  1073. easeInOut: function(a, c, d, e) {
  1074. return -d / 2 * (Math.cos(Math.PI * a / e) - 1) + c
  1075. }
  1076. },
  1077. smoothstep: {
  1078. easeIn: function(a, c, d, e) {
  1079. a = a / e / 2;
  1080. return 2 * a * a * (3 - 2 * a) * d + c
  1081. },
  1082. easeOut: function(a, c, d, e) {
  1083. a = (a / e + 1) / 2;
  1084. return (2 * a * a * (3 - 2 * a) - 1) * d + c
  1085. },
  1086. easeInOut: function(a, c, d, e) {
  1087. a /= e;
  1088. return a * a * (3 -
  1089. 2 * a) * d + c
  1090. }
  1091. }
  1092. };
  1093. function Tween(a, c, d, e, f, g) {
  1094. Utils.callSuperConstructor(Tween, this);
  1095. "object" != typeof a && (a = null);
  1096. if (a) {
  1097. if ("undefined" == typeof a[c]) throw Error('Trying to tween undefined property "' + c + '"');
  1098. if (isNaN(a[c])) throw Error("Tweened value can not be " + typeof a[c]);
  1099. } else if (isNaN(c)) throw Error("Tweened value can not be " + typeof c);
  1100. "function" != typeof g && (g = Easing.linear.easeIn);
  1101. this.obj = a;
  1102. this.prop = c;
  1103. this.onfinish = this.onchange = null;
  1104. this.start = d;
  1105. this.end = e;
  1106. this.duration = ~~f;
  1107. this.callback = g;
  1108. this.playing = !1;
  1109. this._pos = -1;
  1110. this.newly = !0;
  1111. this.eventsListeners = []
  1112. }
  1113. Utils.extend(Tween, EventsProxy);
  1114. Tween.prototype.play = function() {
  1115. this.playing = !0;
  1116. this.tick(0)
  1117. };
  1118. Tween.prototype.pause = function() {
  1119. this.playing = !1
  1120. };
  1121. Tween.prototype.rewind = function() {
  1122. this._pos = -1
  1123. };
  1124. Tween.prototype.forward = function() {
  1125. this._pos = this.duration
  1126. };
  1127. Tween.prototype.stop = function() {
  1128. this.pause();
  1129. this.rewind()
  1130. };
  1131. Tween.prototype.updateValue = function(a) {
  1132. this.obj ? this.obj[this.prop] = a : this.prop = a
  1133. };
  1134. Tween.prototype.tick = function(a) {
  1135. if (!this.playing) return !1;
  1136. a || (a = 0);
  1137. Tween.STEP_TYPE == Tween.STEP_BY_FRAME ? this._pos++ : this._pos += a;
  1138. if (0 > this._pos) return !1;
  1139. if (this._pos > this.duration) return this.finish();
  1140. a = this.callback;
  1141. a = a(this._pos, this.start, this.end - this.start, this.duration);
  1142. this.updateValue(a);
  1143. this.dispatchEvent("change", {
  1144. target: this,
  1145. value: a
  1146. });
  1147. return !1
  1148. };
  1149. Tween.prototype.finish = function() {
  1150. this.stop();
  1151. this.updateValue(this.end);
  1152. return !1 === this.dispatchEvent("finish", {
  1153. target: this,
  1154. value: this.end
  1155. }) ? !1 : !0
  1156. };
  1157. Tween.STEP_BY_FRAME = 0;
  1158. Tween.STEP_BY_TIME = 1;
  1159. Tween.STEP_TYPE = Tween.STEP_BY_FRAME;
  1160. function DisplayObjectContainer() {
  1161. Utils.callSuperConstructor(DisplayObjectContainer, this);
  1162. this.objects = [];
  1163. this.anchor = {
  1164. x: 0,
  1165. y: 0
  1166. }
  1167. }
  1168. Utils.extend(DisplayObjectContainer, EventsProxy);
  1169. DisplayObjectContainer.prototype.objectsCounter = 0;
  1170. DisplayObjectContainer.prototype.scaleX = 1;
  1171. DisplayObjectContainer.prototype.scaleY = 1;
  1172. DisplayObjectContainer.prototype.opacity = 1;
  1173. DisplayObjectContainer.prototype.x = 0;
  1174. DisplayObjectContainer.prototype.y = 0;
  1175. DisplayObjectContainer.prototype.width = 0;
  1176. DisplayObjectContainer.prototype.height = 0;
  1177. DisplayObjectContainer.prototype.skewX = 0;
  1178. DisplayObjectContainer.prototype.skewY = 0;
  1179. DisplayObjectContainer.prototype.rotation = 0;
  1180. DisplayObjectContainer.prototype.parent = null;
  1181. DisplayObjectContainer.prototype.hitArea = null;
  1182. DisplayObjectContainer.prototype.fillColor = null;
  1183. DisplayObjectContainer.prototype.fillLinearGradient = null;
  1184. DisplayObjectContainer.prototype.fillRadialGradient = null;
  1185. DisplayObjectContainer.prototype.fillPattern = null;
  1186. DisplayObjectContainer.prototype.getAbsoluteRotation = function() {
  1187. return this.rotation + (this.parent ? this.parent.getAbsoluteRotation() : 0)
  1188. };
  1189. DisplayObjectContainer.prototype.getAbsoluteOpacity = function() {
  1190. return this.opacity * (this.parent ? this.parent.getAbsoluteOpacity() : 1)
  1191. };
  1192. DisplayObjectContainer.prototype.getAbsoluteScaleX = function() {
  1193. return this.scaleX * (this.parent ? this.parent.getAbsoluteScaleX() : 1)
  1194. };
  1195. DisplayObjectContainer.prototype.getAbsoluteScaleY = function() {
  1196. return this.scaleY * (this.parent ? this.parent.getAbsoluteScaleY() : 1)
  1197. };
  1198. DisplayObjectContainer.prototype.getAbsoluteSkewX = function() {
  1199. return this.skewX + (this.parent ? this.parent.getAbsoluteSkewX() : 0)
  1200. };
  1201. DisplayObjectContainer.prototype.getAbsoluteSkewY = function() {
  1202. return this.skewY + (this.parent ? this.parent.getAbsoluteSkewY() : 0)
  1203. };
  1204. DisplayObjectContainer.prototype.render = function(a, c, d) {
  1205. for (var e = 0; e < this.objects.length; e++) obj = this.objects[e], obj.destroy ? (this.removeChild(obj), e--) : obj.visible && obj.render(a, c, d)
  1206. };
  1207. DisplayObjectContainer.prototype.getX = function() {
  1208. return Math.round(this.x * Utils.globalScale)
  1209. };
  1210. DisplayObjectContainer.prototype.getY = function() {
  1211. return Math.round(this.y * Utils.globalScale)
  1212. };
  1213. DisplayObjectContainer.prototype.getWidth = function() {
  1214. return this.width * Math.abs(this.getAbsoluteScaleX()) * Utils.globalScale
  1215. };
  1216. DisplayObjectContainer.prototype.getHeight = function() {
  1217. return this.height * Math.abs(this.getAbsoluteScaleY()) * Utils.globalScale
  1218. };
  1219. DisplayObjectContainer.prototype.getPosition = function() {
  1220. return {
  1221. x: this.x,
  1222. y: this.y
  1223. }
  1224. };
  1225. DisplayObjectContainer.prototype.setPosition = function(a, c) {
  1226. if ("undefined" == typeof c && "undefined" != typeof a.x && "undefined" != typeof a.y) return this.setPosition(a.x, a.y);
  1227. this.x = parseFloat(a);
  1228. this.y = parseFloat(c)
  1229. };
  1230. DisplayObjectContainer.prototype.setPropScale = function(a) {
  1231. this.scaleX = this.scaleY = 1 * a
  1232. };
  1233. DisplayObjectContainer.prototype.getAnchor = function() {
  1234. return this.anchor
  1235. };
  1236. DisplayObjectContainer.prototype.setAnchor = function(a, c) {
  1237. if ("undefined" == typeof c && "undefined" != typeof a.x && "undefined" != typeof a.y) return this.setAnchor(a.x, a.y);
  1238. this.anchor.x = parseFloat(a);
  1239. this.anchor.y = parseFloat(c)
  1240. };
  1241. DisplayObjectContainer.prototype.alignAnchor = function(a, c) {
  1242. a = parseInt(a);
  1243. isNaN(a) && (a = DisplayObjectContainer.ANCHOR_ALIGN_CENTER);
  1244. 0 > a && (a = DisplayObjectContainer.ANCHOR_ALIGN_LEFT);
  1245. 0 < a && (a = DisplayObjectContainer.ANCHOR_ALIGN_RIGHT);
  1246. c = parseInt(c);
  1247. isNaN(c) && (c = DisplayObjectContainer.ANCHOR_VALIGN_MIDDLE);
  1248. 0 > c && (c = DisplayObjectContainer.ANCHOR_VALIGN_TOP);
  1249. 0 < c && (c = DisplayObjectContainer.ANCHOR_VALIGN_BOTTOM);
  1250. this.anchor.x = this.width * a / 2;
  1251. this.anchor.y = this.height * c / 2;
  1252. return this.getAnchor()
  1253. };
  1254. DisplayObjectContainer.prototype.getAbsoluteAnchor = function() {
  1255. return this.getPosition()
  1256. };
  1257. DisplayObjectContainer.prototype.getRelativeCenter = function() {
  1258. var a = this.getAnchor(),
  1259. c = this.getAbsoluteRotation(),
  1260. a = {
  1261. x: a.x,
  1262. y: a.y
  1263. };
  1264. 0 != c ? (a = new Vector(-a.x * this.getAbsoluteScaleX(), -a.y * this.getAbsoluteScaleY()), a.rotate(-c)) : (a.x = -(a.x * this.getAbsoluteScaleX()), a.y = -(a.y * this.getAbsoluteScaleY()));
  1265. return a
  1266. };
  1267. DisplayObjectContainer.prototype.getAbsolutePosition = function() {
  1268. var a = {
  1269. x: this.x,
  1270. y: this.y
  1271. };
  1272. if (this.parent) {
  1273. var c = this.parent.getAbsolutePosition(),
  1274. d = this.parent.getAbsoluteRotation();
  1275. if (0 != d) {
  1276. var e = new Vector(a.x * this.parent.getAbsoluteScaleX(), a.y * this.parent.getAbsoluteScaleY());
  1277. e.rotate(-d);
  1278. a.x = c.x + e.x;
  1279. a.y = c.y + e.y
  1280. } else a.x = c.x + a.x * this.parent.getAbsoluteScaleX(), a.y = c.y + a.y * this.parent.getAbsoluteScaleY()
  1281. }
  1282. return a
  1283. };
  1284. DisplayObjectContainer.prototype.getAbsoluteCenter = function() {
  1285. var a = this.getAbsolutePosition(),
  1286. c = this.getRelativeCenter();
  1287. a.x += c.x;
  1288. a.y += c.y;
  1289. return a
  1290. };
  1291. DisplayObjectContainer.prototype.getCenter = function() {
  1292. return this.getAbsoluteCenter()
  1293. };
  1294. DisplayObjectContainer.prototype.getIgnoreViewport = function() {
  1295. return this.ignoreViewport || this.parent && this.parent.getIgnoreViewport()
  1296. };
  1297. DisplayObjectContainer.prototype.getHitAreaRectangle = function() {
  1298. if (!this.hitArea) return this.getDrawRectangle();
  1299. var a = this.getAbsoluteRotation(),
  1300. c = this.getAbsoluteScaleX(),
  1301. d = this.getAbsoluteScaleY(),
  1302. e = this.getCenter(),
  1303. f = new Rectangle(0, 0, this.hitArea.width * Math.abs(c), this.hitArea.height * Math.abs(d), a);
  1304. 0 != a ? (c = new Vector(this.hitArea.x * c, this.hitArea.y * d), c.rotate(-a), f.move(e.x + c.x, e.y + c.y)) : f.move(e.x + this.hitArea.x * c, e.y + this.hitArea.x * d);
  1305. return f
  1306. };
  1307. DisplayObjectContainer.prototype.getDrawRectangle = function() {
  1308. var a = this.getCenter(),
  1309. c = new Rectangle(0, 0, this.width * Math.abs(this.getAbsoluteScaleX()), this.height * Math.abs(this.getAbsoluteScaleY()), this.getAbsoluteRotation());
  1310. c.move(a.x, a.y);
  1311. return c
  1312. };
  1313. DisplayObjectContainer.prototype.getAABBRectangle = function() {
  1314. var a = this.getDrawRectangle(),
  1315. c = a.AABB[1].x - a.AABB[0].x,
  1316. d = a.AABB[1].y - a.AABB[0].y;
  1317. return new Rectangle(a.AABB[0].x + c / 2, a.AABB[0].y + d / 2, c, d, 0)
  1318. };
  1319. DisplayObjectContainer.prototype.getFullAABBRectangle = function() {
  1320. for (var a = [this.getAABBRectangle()], c = 0; c < this.objects.length; c++) a.push(this.objects[c].getFullAABBRectangle());
  1321. for (var d = [{
  1322. x: Number.MAX_VALUE,
  1323. y: Number.MAX_VALUE
  1324. }, {
  1325. x: Number.MIN_VALUE,
  1326. y: Number.MIN_VALUE
  1327. }], c = 0; c < a.length; c++) r = a[c], d[0].x = Math.min(d[0].x, r.AABB[0].x), d[0].y = Math.min(d[0].y, r.AABB[0].y), d[1].x = Math.max(d[1].x, r.AABB[1].x), d[1].y = Math.max(d[1].y, r.AABB[1].y);
  1328. a = d[1].x - d[0].x;
  1329. c = d[1].y - d[0].y;
  1330. return new Rectangle(d[0].x + a /
  1331. 2, d[0].y + c / 2, a, c, 0)
  1332. };
  1333. DisplayObjectContainer.prototype.cacheAsBitmap = function() {
  1334. var a = this.x,
  1335. c = this.y,
  1336. d = this.rotation,
  1337. e = this.parent;
  1338. this.rotation = 0;
  1339. this.parent = null;
  1340. var f = this.getAABBRectangle(),
  1341. g = this.getFullAABBRectangle();
  1342. this.getCenter();
  1343. this.x = f.AABB[0].x - g.AABB[0].x + (this.width / 2 + this.anchor.x) * this.scaleX;
  1344. this.y = f.AABB[0].y - g.AABB[0].y + (this.height / 2 + this.anchor.y) * this.scaleY;
  1345. f = document.createElement("canvas");
  1346. f.width = g.width * Utils.globalScale;
  1347. f.height = g.height * Utils.globalScale;
  1348. f.ctx = f.getContext("2d");
  1349. this.render(f, !0, 0);
  1350. this.render(f, !1, 0);
  1351. this.parent = e;
  1352. this.x = a;
  1353. this.y = c;
  1354. this.rotation = d;
  1355. return f
  1356. };
  1357. DisplayObjectContainer.prototype.localToGlobal = function(a, c) {
  1358. var d = "object" == typeof a && "undefined" != typeof a.x && "undefined" != typeof a.y ? new Vector(a.x + 0, a.y + 0) : new Vector(a, c);
  1359. d.rotate(this.getAbsoluteRotation()).add(this.getAbsolutePosition());
  1360. return d
  1361. };
  1362. DisplayObjectContainer.prototype.globalToLocal = function(a, c) {
  1363. var d = "object" == typeof a && "undefined" != typeof a.x && "undefined" != typeof a.y ? new Vector(a.x + 0, a.y + 0) : new Vector(a, c);
  1364. d.subtract(this.getAbsolutePosition()).rotate(this.getAbsoluteRotation());
  1365. return d
  1366. };
  1367. DisplayObjectContainer.prototype.findMaxZIndex = function() {
  1368. for (var a = -1, c = !1, d = 0; d < this.objects.length; d++) this.objects[d].zIndex > a && (a = this.objects[d].zIndex, c = d);
  1369. return {
  1370. index: c,
  1371. zIndex: a
  1372. }
  1373. };
  1374. DisplayObjectContainer.prototype.findMinZIndex = function() {
  1375. for (var a = -1, c = !1, d = 0; d < this.objects.length; d++) 0 == d && (a = this.objects[d].zIndex, c = 0), this.objects[d].zIndex < a && (a = this.objects[d].zIndex, c = d);
  1376. return {
  1377. index: c,
  1378. zIndex: a
  1379. }
  1380. };
  1381. DisplayObjectContainer.prototype.addChild = function(a) {
  1382. var c = this.findMaxZIndex(),
  1383. d = a.zIndex;
  1384. a.zIndex = !1 !== c.index ? c.zIndex + 1 : 0;
  1385. this.objectsCounter++;
  1386. a.uid = this.objectsCounter;
  1387. a.parent = this;
  1388. a.setStage(this.stage);
  1389. this.objects.push(a);
  1390. 0 != d && this.setChildZIndex(a, ~~d);
  1391. a.dispatchEvent("add", {
  1392. target: a
  1393. });
  1394. return a
  1395. };
  1396. DisplayObjectContainer.prototype.setStage = function(a) {
  1397. this.stage = a;
  1398. for (var c = 0; c < this.objects.length; c++) this.objects[c].setStage(a)
  1399. };
  1400. DisplayObjectContainer.prototype.removeChild = function(a) {
  1401. a && 0 <= this.objects.indexOf(a) && (a.stage && a.stage.clearObjectTweens(a), a.clear(), a.dispatchEvent("remove", {
  1402. target: a
  1403. }), a.removeAllEventListeners(), a.parent = null, a.stage = null, this.objects = Utils.removeFromArray(this.objects, a))
  1404. };
  1405. DisplayObjectContainer.prototype.setChildZIndex = function(a, c) {
  1406. a.zIndex = c;
  1407. this.objects = this.objects.sort(function(a, c) {
  1408. return a.zIndex == c.zIndex ? a.uid > c.uid ? 1 : -1 : a.zIndex > c.zIndex ? 1 : -1
  1409. })
  1410. };
  1411. DisplayObjectContainer.prototype.getHitArea = function() {
  1412. return this.hitArea ? this.hitArea : {
  1413. x: 0,
  1414. y: 0,
  1415. width: this.width,
  1416. height: this.height
  1417. }
  1418. };
  1419. DisplayObjectContainer.prototype.hitTest = function(a, c) {
  1420. c || (c = this);
  1421. if (0 == a.getAbsoluteRotation() && 0 == c.getAbsoluteRotation()) {
  1422. var d = a.getCenter(),
  1423. e = c.getCenter(),
  1424. f = a.width * Math.abs(a.getAbsoluteScaleX()),
  1425. g = a.height * Math.abs(a.getAbsoluteScaleY()),
  1426. h = c.width * Math.abs(c.getAbsoluteScaleX()),
  1427. l = c.height * Math.abs(c.getAbsoluteScaleY()),
  1428. k = d.x - f / 2,
  1429. d = d.y - g / 2,
  1430. m = e.x - h / 2,
  1431. n = e.y - l / 2,
  1432. p = Math.max(d, n),
  1433. e = Math.max(k, m),
  1434. f = Math.min(k + f, m + h),
  1435. g = Math.min(d + g, n + l) - p;
  1436. return 0 < f - e && 0 < g
  1437. }
  1438. g = a.getDrawRectangle();
  1439. l = c.getDrawRectangle();
  1440. return g.hitTestRectangle(l)
  1441. };
  1442. DisplayObjectContainer.prototype.hitTestPointObject = function(a, c, d, e, f) {
  1443. var g, h, l, k, m, n, p;
  1444. "boolean" == typeof a.pixelCheck && (e = a.pixelCheck);
  1445. p = a.getHitArea();
  1446. l = p.width * Math.abs(a.getAbsoluteScaleX());
  1447. k = p.height * Math.abs(a.getAbsoluteScaleY());
  1448. m = a.getAbsoluteCenter();
  1449. g = m.x + p.x - l / 2;
  1450. h = m.y + p.y - k / 2;
  1451. m = c;
  1452. n = d;
  1453. a.ignoreViewport || (m += this.stage.viewport.x, n += this.stage.viewport.y);
  1454. p = !1;
  1455. 0 == a.getAbsoluteRotation() ? g <= m && h <= n && g + l >= m && h + k >= n && (p = !0) : (g = a.getHitAreaRectangle(), g.hitTestPoint(new Vector(m, n)) && (p = !0));
  1456. p && e && (this.stage.buffer.width = this.stage.canvas.width, this.stage.buffer.height = this.stage.canvas.height, this.stage.clearScreen(this.stage.buffer), a.render(this.stage.buffer, a.static, 0), c = this.stage.buffer.ctx.getImageData(Math.floor(c * Utils.globalScale), Math.floor(d * Utils.globalScale), 1, 1), 0 == c.data[3] && (p = !1));
  1457. !p && f && a.dragged && (p = !0);
  1458. return p
  1459. };
  1460. DisplayObjectContainer.prototype.getObjectsStackByCoord = function(a, c, d, e) {
  1461. for (var f, g = [], h = this.objects.length - 1; 0 <= h; h--) this.objects[h].visible && (f = this.objects[h], f.objects && f.objects.length && (g = g.concat(f.getObjectsStackByCoord(a, c, d, e))), this.hitTestPointObject(f, a, c, d, e) && g.push(f));
  1462. return g
  1463. };
  1464. DisplayObjectContainer.prototype.doDrag = function(a, c) {
  1465. for (var d = 0; d < this.objects.length; d++) this.objects[d].doDrag(a, c);
  1466. if (this.dragged) {
  1467. var d = a,
  1468. e = c;
  1469. this.ignoreViewport || (d += this.stage.viewport.x, e += this.stage.viewport.y);
  1470. d -= this.dragX;
  1471. e -= this.dragY;
  1472. d = this.parent.globalToLocal(d, e);
  1473. this.x = d.x;
  1474. this.y = d.y
  1475. }
  1476. };
  1477. DisplayObjectContainer.prototype.checkMouseOut = function(a, c) {
  1478. for (var d = this.objects.length - 1; 0 <= d; d--)
  1479. if (!1 === this.objects[d].checkMouseOut(a, c)) return;
  1480. if (this.mouseOn && 0 > a.indexOf(this)) return this.mouseOn = !1, d = this.stage.finalizeMouseCoords(this, c), this.dispatchEvent("mouseout", {
  1481. target: this,
  1482. x: d.x,
  1483. y: d.y
  1484. })
  1485. };
  1486. DisplayObjectContainer.prototype.getMaxZIndexInStack = function(a) {
  1487. for (var c = -1, d = 0, e = 0; e < a.length; e++) a[e].zIndex > c && (c = a[e].zIndex, d = e);
  1488. return d
  1489. };
  1490. DisplayObjectContainer.prototype.sortStack = function(a, c) {
  1491. return a.sort(function(a, e) {
  1492. a.zIndex == e.zIndex ? c ? a.uid < e.uid ? 1 : -1 : a.uid > e.uid ? 1 : -1 : c ? a.zIndex < e.zIndex ? 1 : -1 : a.zIndex > e.zIndex ? 1 : -1
  1493. })
  1494. };
  1495. DisplayObjectContainer.prototype.clear = function() {
  1496. for (; this.objects.length;) this.removeChild(this.objects[0])
  1497. };
  1498. DisplayObjectContainer.prototype.getFillStyle = function(a) {
  1499. var c = null;
  1500. if (this.fillLinearGradient) {
  1501. a = a.ctx.createLinearGradient(this.fillLinearGradient.x0 * Utils.globalScale, this.fillLinearGradient.y0 * Utils.globalScale, this.fillLinearGradient.x1 * Utils.globalScale, this.fillLinearGradient.y1 * Utils.globalScale);
  1502. for (c = 0; c < this.fillLinearGradient.points.length; c++) a.addColorStop(this.fillLinearGradient.points[c].point, this.fillLinearGradient.points[c].color);
  1503. c = a
  1504. } else if (this.fillRadialGradient) {
  1505. a = a.ctx.createRadialGradient(this.fillRadialGradient.x0 *
  1506. Utils.globalScale, this.fillRadialGradient.y0 * Utils.globalScale, this.fillRadialGradient.r0 * Utils.globalScale, this.fillRadialGradient.x1 * Utils.globalScale, this.fillRadialGradient.y1 * Utils.globalScale, this.fillRadialGradient.r1 * Utils.globalScale);
  1507. for (c = 0; c < this.fillRadialGradient.points.length; c++) a.addColorStop(this.fillRadialGradient.points[c].point, this.fillRadialGradient.points[c].color);
  1508. c = a
  1509. } else c = this.fillPattern ? a.ctx.createPattern(this.fillPattern.img, this.fillPattern.repeat) : this.fillColor;
  1510. return c
  1511. };
  1512. DisplayObjectContainer.ANCHOR_ALIGN_LEFT = -1;
  1513. DisplayObjectContainer.ANCHOR_ALIGN_CENTER = 0;
  1514. DisplayObjectContainer.ANCHOR_ALIGN_RIGHT = 1;
  1515. DisplayObjectContainer.ANCHOR_VALIGN_TOP = -1;
  1516. DisplayObjectContainer.ANCHOR_VALIGN_MIDDLE = 0;
  1517. DisplayObjectContainer.ANCHOR_VALIGN_BOTTOM = 1;
  1518. var ANCHOR_ALIGN_LEFT = DisplayObjectContainer.ANCHOR_ALIGN_LEFT,
  1519. ANCHOR_ALIGN_CENTER = DisplayObjectContainer.ANCHOR_ALIGN_CENTER,
  1520. ANCHOR_ALIGN_RIGHT = DisplayObjectContainer.ANCHOR_ALIGN_RIGHT,
  1521. ANCHOR_VALIGN_TOP = DisplayObjectContainer.ANCHOR_VALIGN_TOP,
  1522. ANCHOR_VALIGN_MIDDLE = DisplayObjectContainer.ANCHOR_VALIGN_MIDDLE,
  1523. ANCHOR_VALIGN_BOTTOM = DisplayObjectContainer.ANCHOR_VALIGN_BOTTOM;
  1524. function DisplayObject() {
  1525. Utils.callSuperConstructor(DisplayObject, this)
  1526. }
  1527. Utils.extend(DisplayObject, DisplayObjectContainer);
  1528. DisplayObject.prototype.uid = 0;
  1529. DisplayObject.prototype.stage = null;
  1530. DisplayObject.prototype.shadowColor = null;
  1531. DisplayObject.prototype.shadowOffsetX = 0;
  1532. DisplayObject.prototype.shadowOffsetY = 0;
  1533. DisplayObject.prototype.shadowBlur = 0;
  1534. DisplayObject.prototype.zIndex = 0;
  1535. DisplayObject.prototype.visible = !0;
  1536. DisplayObject.prototype.static = !1;
  1537. DisplayObject.prototype.ignoreViewport = !1;
  1538. DisplayObject.prototype.destroy = !1;
  1539. DisplayObject.prototype.dragged = !1;
  1540. DisplayObject.prototype.dragX = 0;
  1541. DisplayObject.prototype.dragY = 0;
  1542. DisplayObject.prototype.mouseOn = !1;
  1543. DisplayObject.prototype.allowDebugDrawing = !0;
  1544. DisplayObject.prototype.pixelCheck = null;
  1545. DisplayObject.prototype.onmouseover = null;
  1546. DisplayObject.prototype.onmouseout = null;
  1547. DisplayObject.prototype.onmousedown = null;
  1548. DisplayObject.prototype.onmouseup = null;
  1549. DisplayObject.prototype.onclick = null;
  1550. DisplayObject.prototype.oncontextmenu = null;
  1551. DisplayObject.prototype.onmousemove = null;
  1552. DisplayObject.prototype.onprerender = null;
  1553. DisplayObject.prototype.onenterframe = null;
  1554. DisplayObject.prototype.onrender = null;
  1555. DisplayObject.prototype.onadd = null;
  1556. DisplayObject.prototype.onremove = null;
  1557. DisplayObject.prototype.onbox2dsync = null;
  1558. DisplayObject.prototype.setStatic = function(a, c) {
  1559. a = Boolean(a);
  1560. if (!c)
  1561. for (var d = 0; d < this.objects.length; d++) this.objects[d].setStatic(a);
  1562. return this.static != a ? (this.static = a, this.stage && this.stage.refreshBackground(), !0) : !1
  1563. };
  1564. DisplayObject.prototype.startDrag = function(a, c) {
  1565. this.dragged = !0;
  1566. this.dragX = a;
  1567. this.dragY = c
  1568. };
  1569. DisplayObject.prototype.stopDrag = function() {
  1570. this.dragged = !1;
  1571. this.dragY = this.dragX = 0
  1572. };
  1573. DisplayObject.prototype.removeTweens = function() {
  1574. this.stage && this.stage.clearObjectTweens(this)
  1575. };
  1576. DisplayObject.prototype.addTween = function(a, c, d, e, f, g) {
  1577. if (this.stage) {
  1578. var h = this[a];
  1579. if (!isNaN(h)) return a = this.stage.createTween(this, a, h, c, d, e), a.onchange = g, a.onfinish = f, a
  1580. }
  1581. };
  1582. DisplayObject.prototype.moveTo = function(a, c, d, e, f, g) {
  1583. d = ~~d;
  1584. 0 >= d ? this.setPosition(a, c) : ((a = this.addTween("x", a, d, e)) && a.play(), (c = this.addTween("y", c, d, e, f, g)) && c.play());
  1585. return this
  1586. };
  1587. DisplayObject.prototype.moveBy = function(a, c, d, e, f, g) {
  1588. return this.moveTo(this.x + a, this.y + c, d, e, f, g)
  1589. };
  1590. DisplayObject.prototype.fadeTo = function(a, c, d, e, f) {
  1591. c = ~~c;
  1592. 0 >= c ? this.opacity = a : (a = this.addTween("opacity", a, c, d, e, f)) && a.play();
  1593. return this
  1594. };
  1595. DisplayObject.prototype.fadeBy = function(a, c, d, e, f) {
  1596. a = Math.max(0, Math.min(1, this.opacity + a));
  1597. return this.fadeTo(a, c, d, e, f)
  1598. };
  1599. DisplayObject.prototype.rotateTo = function(a, c, d, e, f) {
  1600. c = ~~c;
  1601. 0 >= c ? this.rotation = a : (a = this.addTween("rotation", a, c, d, e, f)) && a.play();
  1602. return this
  1603. };
  1604. DisplayObject.prototype.rotateBy = function(a, c, d, e, f) {
  1605. return this.rotateTo(this.rotation + a, c, d, e, f)
  1606. };
  1607. DisplayObject.prototype.skewXTo = function(a, c, d, e, f) {
  1608. c = ~~c;
  1609. 0 >= c ? this.skewX = a : (a = this.addTween("skewX", a, c, d, e, f)) && a.play();
  1610. return this
  1611. };
  1612. DisplayObject.prototype.skewXBy = function(a, c, d, e, f) {
  1613. return this.skewXTo(this.skewX + a, c, d, e, f)
  1614. };
  1615. DisplayObject.prototype.skewYTo = function(a, c, d, e, f) {
  1616. c = ~~c;
  1617. 0 >= c ? this.skewY = a : (a = this.addTween("skewY", a, c, d, e, f)) && a.play();
  1618. return this
  1619. };
  1620. DisplayObject.prototype.skewYBy = function(a, c, d, e, f) {
  1621. return this.skewYTo(this.skewY + a, c, d, e, f)
  1622. };
  1623. DisplayObject.prototype.scaleTo = function(a, c, d, e, f) {
  1624. c = ~~c;
  1625. if (0 >= c) this.scaleX = this.scaleY = a;
  1626. else {
  1627. var g = this.addTween("scaleX", a, c, d, e, f);
  1628. g && g.play();
  1629. (a = this.addTween("scaleY", a, c, d, g ? null : e, g ? null : f)) && a.play()
  1630. }
  1631. return this
  1632. };
  1633. DisplayObject.prototype.setZIndex = function(a) {
  1634. this.zIndex = ~~a;
  1635. this.parent && this.parent.setChildZIndex(this, this.zIndex)
  1636. };
  1637. DisplayObject.prototype.hitTestPoint = function(a, c, d, e, f) {
  1638. return this.stage ? this.stage.hitTestPointObject(this, a, c, d, e, f) : !1
  1639. };
  1640. DisplayObject.prototype.setRelativePosition = function(a, c, d, e) {
  1641. switch (d) {
  1642. case "right":
  1643. a = this.stage.screenWidth - a;
  1644. break;
  1645. case "left":
  1646. break;
  1647. default:
  1648. a = this.stage.screenWidth / 2 + a
  1649. }
  1650. switch (e) {
  1651. case "bottom":
  1652. c = this.stage.screenHeight - c;
  1653. break;
  1654. case "top":
  1655. break;
  1656. default:
  1657. c = this.stage.screenHeight / 2 + c
  1658. }
  1659. this.setPosition(a, c)
  1660. };
  1661. DisplayObject.prototype.debugDraw = function() {
  1662. if (this.visible && this.allowDebugDrawing) {
  1663. var a = this.getAbsolutePosition(),
  1664. c = this.getCenter(),
  1665. d = this.getDrawRectangle(),
  1666. e = this.getAABBRectangle();
  1667. stage.drawCircle(a.x, a.y, 1, 1, "rgba(255,0,0,0.9)");
  1668. stage.drawCircle(c.x, c.y, 1, 1, "rgba(0,255,0,0.9)");
  1669. stage.drawLine(a.x, a.y, c.x, c.y, 1, "rgba(255,255,255,0.5)");
  1670. stage.drawPolygon(d.vertices, .5, "rgba(255,0,255,0.5)", 1);
  1671. stage.drawLine(e.vertices[0].x, e.vertices[0].y, e.vertices[2].x, e.vertices[2].y, 1, "rgba(255,255,255,0.5)");
  1672. stage.drawLine(e.vertices[2].x, e.vertices[0].y, e.vertices[0].x, e.vertices[2].y, 1, "rgba(255,255,255,0.5)");
  1673. stage.drawPolygon(e.vertices, .5, "rgba(255,255,255,0.5)")
  1674. }
  1675. };
  1676. DisplayObject.prototype.fixChildrenParent = function(a) {
  1677. for (a = 0; a < this.objects.length; a++) this.objects[a].parent = this, this.objects[a].fixChildrenParent()
  1678. };
  1679. DisplayObject.prototype.clone = function() {
  1680. var a = Utils.clone(this);
  1681. a.fixChildrenParent();
  1682. return a
  1683. };
  1684. function Graphics() {
  1685. Utils.callSuperConstructor(Graphics, this)
  1686. }
  1687. Utils.extend(Graphics, DisplayObject);
  1688. Graphics.prototype.x = 0;
  1689. Graphics.prototype.y = 0;
  1690. Graphics.prototype.color = "#000";
  1691. Graphics.prototype.lineWidth = 1;
  1692. Graphics.prototype.render = function(a, c, d) {
  1693. !!this.static == !!c && this.dispatchEvent("render", {
  1694. target: this,
  1695. canvas: a,
  1696. delta: d
  1697. });
  1698. Utils.callSuperMethod(Graphics, this, "render", a, c, d)
  1699. };
  1700. Graphics.prototype.prepareCanvas = function(a, c) {
  1701. c.ctx.save();
  1702. this.getIgnoreViewport() || (a.x -= this.stage.viewport.x, a.y -= this.stage.viewport.y);
  1703. a.x *= Utils.globalScale;
  1704. a.y *= Utils.globalScale;
  1705. c.ctx.translate(a.x, a.y);
  1706. var d = this.getAbsoluteRotation();
  1707. c.ctx.rotate(d);
  1708. c.ctx.scale(this.getAbsoluteScaleX(), this.getAbsoluteScaleY());
  1709. var e = this.getAbsoluteSkewX(),
  1710. f = this.getAbsoluteSkewY();
  1711. 0 == e && 0 == f || c.ctx.transform(1, e, f, 1, 0, 0);
  1712. this.shadowColor && (c.ctx.shadowColor = this.shadowColor, 0 != d ? (e = new Vector(this.shadowOffsetX *
  1713. Utils.globalScale, this.shadowOffsetY * Utils.globalScale), e.rotate(-d), c.ctx.shadowOffsetX = e.x, c.ctx.shadowOffsetY = e.y) : (c.ctx.shadowOffsetX = this.shadowOffsetX * Utils.globalScale, c.ctx.shadowOffsetY = this.shadowOffsetY * Utils.globalScale), c.ctx.shadowBlur = this.shadowBlur * Utils.globalScale)
  1714. };
  1715. Graphics.prototype.preparePath = function(a) {
  1716. a.ctx.beginPath();
  1717. a.ctx.strokeStyle = 0 < this.lineWidth ? this.color : "transparent";
  1718. a.ctx.lineWidth = this.lineWidth * Utils.globalScale;
  1719. a.ctx.globalAlpha = this.getAbsoluteOpacity();
  1720. a.ctx.fillStyle = this.getFillStyle(a)
  1721. };
  1722. Graphics.prototype.finalizeCanvas = function(a) {
  1723. (this.fillColor || this.fillLinearGradient || this.fillRadialGradient || this.fillPattern) && a.ctx.fill();
  1724. a.ctx.stroke()
  1725. };
  1726. Graphics.prototype.restoreCanvas = function(a) {
  1727. a.ctx.restore()
  1728. };
  1729. Graphics.prototype.resetView = function() {
  1730. this.color = "transparent";
  1731. this.fillPattern = this.fillRadialGradient = this.fillLinearGradient = this.fillColor = null
  1732. };
  1733. Graphics.circle = function(a, c, d) {
  1734. Utils.callSuperConstructor(Graphics.circle, this);
  1735. this.x = a;
  1736. this.y = c;
  1737. this.radius = d;
  1738. this.width = 2 * d;
  1739. this.height = 2 * d
  1740. };
  1741. Utils.extend(Graphics.circle, Graphics);
  1742. Graphics.circle.prototype.render = function(a, c, d) {
  1743. !!this.static == !!c && 0 != this.opacity && (this.prepareCanvas(this.getAbsoluteCenter(), a), this.preparePath(a), a.ctx.arc(0, 0, this.radius * Utils.globalScale, 0, 2 * Math.PI), this.finalizeCanvas(a), this.restoreCanvas(a));
  1744. Utils.callSuperMethod(Graphics.circle, this, "render", a, c, d)
  1745. };
  1746. Graphics.line = function(a, c, d, e) {
  1747. Utils.callSuperConstructor(Graphics.line, this);
  1748. this.x1 = a;
  1749. this.x2 = d;
  1750. this.y1 = c;
  1751. this.y2 = e
  1752. };
  1753. Utils.extend(Graphics.line, Graphics);
  1754. Graphics.line.prototype.render = function(a, c, d) {
  1755. !!this.static == !!c && 0 != this.opacity && (this.prepareCanvas(this.getAbsoluteCenter(), a), this.preparePath(a), a.ctx.moveTo(this.x1 * Utils.globalScale, this.y1 * Utils.globalScale), a.ctx.lineTo(this.x2 * Utils.globalScale, this.y2 * Utils.globalScale), this.finalizeCanvas(a), this.restoreCanvas(a));
  1756. Utils.callSuperMethod(Graphics.line, this, "render", a, c, d)
  1757. };
  1758. Graphics.rectangle = function(a, c, d, e) {
  1759. Utils.callSuperConstructor(Graphics.rectangle, this);
  1760. this.x = a;
  1761. this.y = c;
  1762. this.width = d;
  1763. this.height = e
  1764. };
  1765. Utils.extend(Graphics.rectangle, Graphics);
  1766. Graphics.rectangle.prototype.render = function(a, c, d) {
  1767. !!this.static == !!c && 0 != this.opacity && (this.prepareCanvas(this.getAbsoluteCenter(), a), this.preparePath(a), a.ctx.rect(-this.width / 2 * Utils.globalScale, -this.height / 2 * Utils.globalScale, this.width * Utils.globalScale, this.height * Utils.globalScale), this.finalizeCanvas(a), this.restoreCanvas(a));
  1768. Utils.callSuperMethod(Graphics.rectangle, this, "render", a, c, d)
  1769. };
  1770. Graphics.arc = function(a, c, d, e, f, g) {
  1771. Utils.callSuperConstructor(Graphics.arc, this);
  1772. this.x = a;
  1773. this.y = c;
  1774. this.radius = d;
  1775. this.startAngle = e;
  1776. this.endAngle = f;
  1777. this.antiClockWise = g;
  1778. this.width = 2 * d;
  1779. this.height = 2 * d
  1780. };
  1781. Utils.extend(Graphics.arc, Graphics);
  1782. Graphics.arc.prototype.render = function(a, c, d) {
  1783. !!this.static == !!c && 0 != this.opacity && (this.prepareCanvas(this.getAbsoluteCenter(), a), this.preparePath(a), a.ctx.arc(0, 0, this.radius * Utils.globalScale, this.startAngle, this.endAngle, this.antiClockWise), this.finalizeCanvas(a), this.restoreCanvas(a));
  1784. Utils.callSuperMethod(Graphics.arc, this, "render", a, c, d)
  1785. };
  1786. Graphics.polygon = function(a) {
  1787. if (!a || 2 > a.length) throw Error("Invalid parameters");
  1788. Utils.callSuperConstructor(Graphics.polygon, this);
  1789. this.points = a;
  1790. for (var c = Number.MAX_VALUE, d = Number.MAX_VALUE, e = Number.MIN_VALUE, f = Number.MIN_VALUE, g = 0; g < a.length; g++) a[g].x < c && (c = a[g].x), a[g].y < d && (d = a[g].y), a[g].x > e && (e = a[g].x), a[g].y > f && (f = a[g].y);
  1791. this.width = e - c;
  1792. this.height = f - d
  1793. };
  1794. Utils.extend(Graphics.polygon, Graphics);
  1795. Graphics.polygon.prototype.render = function(a, c, d) {
  1796. if (!!this.static == !!c && 0 != this.opacity) {
  1797. this.prepareCanvas(this.getAbsoluteCenter(), a);
  1798. this.preparePath(a);
  1799. a.ctx.moveTo(this.points[0].x * Utils.globalScale, this.points[0].y * Utils.globalScale);
  1800. for (var e = 1; e < this.points.length; e++) a.ctx.lineTo(this.points[e].x * Utils.globalScale, this.points[e].y * Utils.globalScale);
  1801. a.ctx.lineTo(this.points[0].x * Utils.globalScale, this.points[0].y * Utils.globalScale);
  1802. this.finalizeCanvas(a);
  1803. this.restoreCanvas(a)
  1804. }
  1805. Utils.callSuperMethod(Graphics.polygon,
  1806. this, "render", a, c, d)
  1807. };
  1808. Graphics.text = function(a, c, d) {
  1809. Utils.callSuperConstructor(Graphics.text, this);
  1810. this.x = a;
  1811. this.y = c;
  1812. this.text = d;
  1813. this.align = Graphics.text.ALIGN_LEFT;
  1814. this.valign = Graphics.text.VALIGN_MIDDLE;
  1815. this.style = "normal";
  1816. this.size = 10;
  1817. this.font = "sans-serif"
  1818. };
  1819. Utils.extend(Graphics.text, Graphics);
  1820. Graphics.text.ALIGN_LEFT = "left";
  1821. Graphics.text.ALIGN_CENTER = "center";
  1822. Graphics.text.ALIGN_RIGHT = "right";
  1823. Graphics.text.VALIGN_TOP = "top";
  1824. Graphics.text.VALIGN_MIDDLE = "middle";
  1825. Graphics.text.VALIGN_BOTTOM = "bottom";
  1826. Graphics.text.prototype.getRect = function(a) {
  1827. return a.ctx.measureText(this.text)
  1828. };
  1829. Graphics.text.prototype.render = function(a, c, d) {
  1830. !!this.static == !!c && 0 != this.opacity && (this.prepareCanvas(this.getAbsoluteCenter(), a), this.preparePath(a), a.ctx.font = this.style + " " + Math.floor(this.size * Utils.globalScale) + "px " + this.font, a.ctx.textAlign = this.align, a.ctx.textBaseline = this.valign, this.fillColor && a.ctx.fillText(this.text, 0, 0), a.ctx.strokeText(this.text, 0, 0), this.finalizeCanvas(a), this.restoreCanvas(a));
  1831. Utils.callSuperMethod(Graphics.text, this, "render", a, c, d)
  1832. };
  1833. Graphics.free = function() {
  1834. this.commands = [];
  1835. Utils.callSuperConstructor(Graphics.free, this)
  1836. };
  1837. Utils.extend(Graphics.free, Graphics);
  1838. Graphics.free.prototype.clear = function() {
  1839. this.commands = [];
  1840. Utils.callSuperMethod(Graphics.free, this, "clear")
  1841. };
  1842. Graphics.free.prototype.beginPath = function() {
  1843. this.commands.push({
  1844. command: "beginPath"
  1845. });
  1846. return this
  1847. };
  1848. Graphics.free.prototype.stroke = function() {
  1849. this.commands.push({
  1850. command: "stroke"
  1851. });
  1852. return this
  1853. };
  1854. Graphics.free.prototype.setStrokeStyle = function(a) {
  1855. this.commands.push({
  1856. command: "setStrokeStyle",
  1857. style: a
  1858. });
  1859. return this
  1860. };
  1861. Graphics.free.prototype.setFillStyle = function(a) {
  1862. this.commands.push({
  1863. command: "setFillStyle",
  1864. style: a
  1865. });
  1866. return this
  1867. };
  1868. Graphics.free.prototype.fill = function() {
  1869. this.commands.push({
  1870. command: "fill"
  1871. });
  1872. return this
  1873. };
  1874. Graphics.free.prototype.moveTo = function(a, c) {
  1875. this.commands.push({
  1876. command: "moveTo",
  1877. x: a,
  1878. y: c
  1879. });
  1880. return this
  1881. };
  1882. Graphics.free.prototype.lineTo = function(a, c) {
  1883. this.commands.push({
  1884. command: "lineTo",
  1885. x: a,
  1886. y: c
  1887. });
  1888. return this
  1889. };
  1890. Graphics.free.prototype.arc = function(a, c, d, e, f, g) {
  1891. this.commands.push({
  1892. command: "arc",
  1893. x: a,
  1894. y: c,
  1895. radius: d,
  1896. startAngle: e,
  1897. endAngle: f,
  1898. antiClockWise: g
  1899. });
  1900. return this
  1901. };
  1902. Graphics.free.prototype.circle = function(a, c, d) {
  1903. this.commands.push({
  1904. command: "circle",
  1905. x: a,
  1906. y: c,
  1907. radius: d
  1908. });
  1909. return this
  1910. };
  1911. Graphics.free.prototype.rect = function(a, c, d, e) {
  1912. this.commands.push({
  1913. command: "circle",
  1914. x: a,
  1915. y: c,
  1916. width: d,
  1917. height: e
  1918. });
  1919. return this
  1920. };
  1921. Graphics.free.prototype.polygon = function(a) {
  1922. this.commands.push({
  1923. command: "polygon",
  1924. points: a
  1925. });
  1926. return this
  1927. };
  1928. Graphics.free.prototype.executeCommand = function(a, c) {
  1929. switch (c.command) {
  1930. case "beginPath":
  1931. a.ctx.beginPath();
  1932. break;
  1933. case "stroke":
  1934. a.ctx.stroke();
  1935. break;
  1936. case "fill":
  1937. a.ctx.fill();
  1938. break;
  1939. case "setStrokeStyle":
  1940. a.ctx.strokeStyle = 0 < this.lineWidth ? c.style : "transparent";
  1941. break;
  1942. case "setFillStyle":
  1943. a.ctx.fillStyle = c.style;
  1944. break;
  1945. case "moveTo":
  1946. a.ctx.moveTo(c.x * Utils.globalScale, c.y * Utils.globalScale);
  1947. break;
  1948. case "lineTo":
  1949. a.ctx.lineTo(c.x * Utils.globalScale, c.y * Utils.globalScale);
  1950. break;
  1951. case "arc":
  1952. a.ctx.arc(c.x * Utils.globalScale,
  1953. c.y * Utils.globalScale, c.radius * Utils.globalScale, c.startAngle, c.endAngle, c.antiClockWise);
  1954. break;
  1955. case "circle":
  1956. a.ctx.arc(c.x * Utils.globalScale, c.y * Utils.globalScale, c.radius * Utils.globalScale, 0, 2 * Math.PI);
  1957. break;
  1958. case "rect":
  1959. a.ctx.rect((c.x - c.width / 2) * Utils.globalScale, (c.y - c.height / 2) * Utils.globalScale, c.width * Utils.globalScale, \u0441.height * Utils.globalScale);
  1960. break;
  1961. case "polygon":
  1962. a.ctx.moveTo(c.points[0].x * Utils.globalScale, c.points[0].y * Utils.globalScale);
  1963. for (var d = 1; d < c.points.length; d++) a.ctx.lineTo(c.points[d].x *
  1964. Utils.globalScale, c.points[d].y * Utils.globalScale);
  1965. a.ctx.lineTo(c.points[0].x * Utils.globalScale, c.points[0].y * Utils.globalScale)
  1966. }
  1967. };
  1968. Graphics.free.prototype.executeCommands = function(a) {
  1969. for (var c = 0; c < this.commands.length; c++) this.executeCommand(a, this.commands[c])
  1970. };
  1971. Graphics.free.prototype.render = function(a, c, d) {
  1972. !!this.static == !!c && 0 != this.opacity && (this.prepareCanvas(this.getAbsoluteCenter(), a), this.preparePath(a), this.executeCommands(a), this.finalizeCanvas(a), this.restoreCanvas(a));
  1973. Utils.callSuperMethod(Graphics.free, this, "render", a, c, d)
  1974. };
  1975. var BitmapsCache = {
  1976. bitmaps: {},
  1977. cache: function(a) {
  1978. if (!(a && a instanceof Image)) return a;
  1979. if (BitmapsCache.bitmaps[a.src]) return BitmapsCache.bitmaps[a.src];
  1980. cns = document.createElement("canvas");
  1981. cns.width = a.width;
  1982. cns.height = a.height;
  1983. ctx = cns.getContext("2d");
  1984. ctx.drawImage(a, 0, 0, a.width, a.height, 0, 0, a.width, a.height);
  1985. return BitmapsCache.bitmaps[a.src] = cns
  1986. }
  1987. };
  1988. function Sprite(a, c, d, e, f) {
  1989. Utils.callSuperConstructor(Sprite, this);
  1990. this.offset = {
  1991. left: 0,
  1992. top: 0
  1993. };
  1994. this.width = c;
  1995. this.height = d;
  1996. this.totalFrames = Math.max(1, ~~e);
  1997. 1 >= this.totalFrames && (this.animated = !1);
  1998. this.totalLayers = Math.max(1, ~~f);
  1999. this.bitmap = a;
  2000. this.changeFrameDelay = Sprite.CHANGE_FRAME_DELAY;
  2001. this.cacheBitmap = Sprite.CACHE_BITMAPS
  2002. }
  2003. Utils.extend(Sprite, DisplayObject);
  2004. Sprite.prototype.animated = !0;
  2005. Sprite.prototype.animDirection = 1;
  2006. Sprite.prototype.currentFrame = 0;
  2007. Sprite.prototype.totalFrames = 1;
  2008. Sprite.prototype.currentLayer = 0;
  2009. Sprite.prototype.totalLayers = 1;
  2010. Sprite.prototype.bitmap = null;
  2011. Sprite.prototype.mask = null;
  2012. Sprite.prototype.isMask = !1;
  2013. Sprite.prototype.maskParent = null;
  2014. Sprite.prototype.maskInvert = !1;
  2015. Sprite.prototype.animStep = 0;
  2016. Sprite.prototype.animDelay = 1;
  2017. Sprite.prototype.changeFrameDelay = 1E3 / 24;
  2018. Sprite.prototype.changeFrameTime = 0;
  2019. Sprite.prototype.onchangeframe = null;
  2020. Sprite.prototype.cacheBitmap = !1;
  2021. Sprite.create = function(a, c) {
  2022. if ("string" == typeof a) {
  2023. c = c || window.library;
  2024. if (!c) throw Error("Could not create sprite from asset '%s'. Library not found.", a);
  2025. a = c.getAsset(a)
  2026. }
  2027. return new Sprite(a.bitmap, a.width || 1, a.height || 1, a.frames || 1, a.layers || 1)
  2028. };
  2029. Sprite.prototype.play = function() {
  2030. this.animated = !0
  2031. };
  2032. Sprite.prototype.stop = function() {
  2033. this.animated = !1
  2034. };
  2035. Sprite.prototype.gotoAndStop = function(a) {
  2036. this.currentFrame = a;
  2037. this.stop()
  2038. };
  2039. Sprite.prototype.gotoAndPlay = function(a) {
  2040. this.currentFrame = a;
  2041. this.play()
  2042. };
  2043. Sprite.prototype.nextFrame = function(a) {
  2044. this.dispatchEvent("enterframe", {
  2045. target: this,
  2046. delta: a
  2047. });
  2048. var c = 1;
  2049. if (Sprite.CHANGE_FRAME_TYPE == Sprite.CHANGE_FRAME_BY_TIME)
  2050. if (this.changeFrameTime += a, this.changeFrameTime >= this.changeFrameDelay * this.animDelay) c = Math.floor(this.changeFrameTime / (this.changeFrameDelay * this.animDelay)), this.changeFrameTime -= Math.abs(c) * this.changeFrameDelay * this.animDelay;
  2051. else return;
  2052. else this.animStep++;
  2053. if (this.animStep >= this.animDelay || Sprite.CHANGE_FRAME_TYPE == Sprite.CHANGE_FRAME_BY_TIME) {
  2054. for (var d =
  2055. 0; d < c; d++) this.animated && (this.currentFrame += this.animDirection), 0 < this.animDirection && this.currentFrame >= this.totalFrames && (this.currentFrame = 0), 0 > this.animDirection && 0 > this.currentFrame && (this.currentFrame = this.totalFrames - 1), this.dispatchEvent("changeframe", {
  2056. target: this,
  2057. delta: a
  2058. });
  2059. this.animStep = 0
  2060. }
  2061. };
  2062. Sprite.prototype.setMask = function(a) {
  2063. this.mask = a;
  2064. this.mask.isMask = !0;
  2065. this.mask.stage = this.stage;
  2066. this.mask.maskParent = this
  2067. };
  2068. Sprite.prototype.renderBack = function(a, c, d, e, f, g) {
  2069. c && (a.ctx.save(), a.ctx.translate(-(f / 2), -(g / 2)), a.ctx.fillStyle = c, a.ctx.strokeStyle = c, a.ctx.fillRect(0, 0, f, g), a.ctx.restore())
  2070. };
  2071. Sprite.prototype.renderBitmap = function(a, c, d, e, f) {
  2072. var g = {
  2073. x: 0,
  2074. y: 0,
  2075. width: e,
  2076. height: f
  2077. };
  2078. if (this.bitmap) {
  2079. var h = this.bitmap.width,
  2080. l = this.bitmap.height,
  2081. k = this.currentLayer * e + this.offset.left * Utils.globalScale,
  2082. m = this.currentFrame * f + this.offset.top * Utils.globalScale;
  2083. if (k < h && m < l) {
  2084. var n = e,
  2085. p = f;
  2086. k + n > h && (n = h - k);
  2087. m + p > l && (p = l - m);
  2088. Sprite.FLOOR_VALUES_ON_RENDER && (k = ~~k, m = ~~m, n = ~~n, p = ~~p, c = ~~c, d = ~~d, e = ~~e, f = ~~f);
  2089. 0 < n && 0 < p && 0 < e && 0 < f && a.ctx.drawImage(this.cacheBitmap ? BitmapsCache.cache(this.bitmap) : this.bitmap, k, m, n, p, c, d,
  2090. e, f);
  2091. g.x = k;
  2092. g.y = m;
  2093. g.width = n;
  2094. g.height = p
  2095. }
  2096. }
  2097. return g
  2098. };
  2099. Sprite.prototype.render = function(a, c, d, e) {
  2100. if (!this.isMask || e) {
  2101. if (!!this.static == !!c) {
  2102. d || (d = 0);
  2103. this.nextFrame(d);
  2104. if (!this.visible || !1 === this.dispatchEvent("prerender", {
  2105. target: this,
  2106. canvas: a,
  2107. delta: d
  2108. }) || !this.stage || 0 == this.opacity) return;
  2109. var f = this.getAbsoluteCenter();
  2110. if (e) {
  2111. var f = {
  2112. x: this.x - this.getAnchor().x,
  2113. y: this.y - this.getAnchor().y
  2114. },
  2115. g = this.parent ? this.parent : this.maskParent;
  2116. g && (f.x += g.getAnchor().x + g.width / 2, f.y += g.getAnchor().y + g.height / 2)
  2117. }
  2118. e = this.width * Utils.globalScale;
  2119. var h = this.height * Utils.globalScale,
  2120. l = f.x * Utils.globalScale - e / 2,
  2121. f = f.y * Utils.globalScale - h / 2,
  2122. k = this.getAbsoluteRotation(),
  2123. g = this.getAbsoluteScaleX(),
  2124. m = this.getAbsoluteScaleY(),
  2125. n = this.getAbsoluteSkewX(),
  2126. p = this.getAbsoluteSkewY(),
  2127. q = this.getFillStyle(a),
  2128. u = Boolean(0 != k || 1 != g || 1 != m || this.shadowColor || q || 0 != n || 0 != p);
  2129. this.getIgnoreViewport() || (l -= this.stage.viewport.x * Utils.globalScale, f -= this.stage.viewport.y * Utils.globalScale);
  2130. u && (a.ctx.save(), a.ctx.translate(l + e / 2, f + h / 2), a.ctx.rotate(k), a.ctx.scale(g, m), 0 == n && 0 == p || a.ctx.transform(1, n, p,
  2131. 1, 0, 0), l = -(e / 2), f = -(h / 2), this.shadowColor && (0 != k ? (g = new Vector(this.shadowOffsetX * Utils.globalScale, this.shadowOffsetY * Utils.globalScale), g.rotate(-k), a.ctx.shadowOffsetX = g.x, a.ctx.shadowOffsetY = g.y) : (a.ctx.shadowOffsetX = this.shadowOffsetX * Utils.globalScale, a.ctx.shadowOffsetY = this.shadowOffsetY * Utils.globalScale), a.ctx.shadowColor = this.shadowColor, a.ctx.shadowBlur = this.shadowBlur * Utils.globalScale));
  2132. a.ctx.globalAlpha = this.getAbsoluteOpacity();
  2133. this.ceilSizes && (e = Math.ceil(e), h = Math.ceil(h));
  2134. this.mask ?
  2135. (this.stage.buffer.ctx.save(), this.stage.buffer.ctx.clearRect(0, 0, e, h), this.renderBack(this.stage.buffer, q, 0, 0, e, h), k = this.renderBitmap(this.stage.buffer, 0, 0, e, h), this.stage.buffer.ctx.globalCompositeOperation = this.maskInvert ? "destination-out" : "destination-in", this.mask.render ? this.mask.render(this.stage.buffer, c, d, !0) : this.stage.buffer.ctx.drawImage(this.mask, this.mask.x ? this.mask.x : 0, this.mask.y ? this.mask.y : 0), Sprite.FLOOR_VALUES_ON_RENDER ? a.ctx.drawImage(this.stage.buffer, 0, 0, k.width, k.height, ~~l, ~~f, ~~e, ~~h) : a.ctx.drawImage(this.stage.buffer, 0, 0, k.width, k.height, l, f, e, h), this.stage.buffer.ctx.restore()) : (this.renderBack(a, q, l, f, e, h), this.renderBitmap(a, l, f, e, h));
  2136. u && a.ctx.restore();
  2137. this.stage.allowDebugDrawing && this.allowDebugDrawing && (!this.stage.allowStaticDebugDrawing && this.static || this.debugDraw());
  2138. this.dispatchEvent("render", {
  2139. target: this,
  2140. canvas: a,
  2141. delta: d
  2142. })
  2143. }
  2144. Utils.callSuperMethod(Sprite, this, "render", a, c, d)
  2145. }
  2146. };
  2147. Sprite.prototype.resetView = function() {
  2148. this.fillPattern = this.fillRadialGradient = this.fillLinearGradient = this.fillColor = this.bitmap = null;
  2149. for (var a = 0; a < this.objects.length; a++) this.objects[a].resetView && this.objects[a].resetView()
  2150. };
  2151. Sprite.CHANGE_FRAME_BY_FRAME = 0;
  2152. Sprite.CHANGE_FRAME_BY_TIME = 1;
  2153. Sprite.CHANGE_FRAME_DELAY = 1E3 / 24;
  2154. Sprite.CHANGE_FRAME_TYPE = Sprite.CHANGE_FRAME_BY_FRAME;
  2155. Sprite.FLOOR_VALUES_ON_RENDER = !0;
  2156. Sprite.CACHE_BITMAPS = Utils.isIOS();
  2157. function StageTimer(a, c, d) {
  2158. Utils.callSuperConstructor(StageTimer, this);
  2159. this.repeat = d;
  2160. this.timeout = this.initialTimeout = c;
  2161. this.onend = a;
  2162. this.ontick = null;
  2163. this.destroy = !1;
  2164. this.newly = !0;
  2165. this.paused = !1
  2166. }
  2167. Utils.extend(StageTimer, EventsProxy);
  2168. StageTimer.prototype.update = function(a) {
  2169. if (this.destroy) return !0;
  2170. if (this.paused) return !1;
  2171. StageTimer.TIMEOUT_TYPE == StageTimer.TIMEOUT_BY_FRAME ? this.timeout-- : this.timeout -= a;
  2172. if (0 >= this.timeout)
  2173. if ("string" == typeof this.onend ? eval(this.onend) : this.dispatchEvent("end", {
  2174. target: this
  2175. }), this.repeat) this.rewind();
  2176. else return !0;
  2177. this.dispatchEvent("tick", {
  2178. target: this,
  2179. delta: a
  2180. });
  2181. return !1
  2182. };
  2183. StageTimer.prototype.rewind = function() {
  2184. this.timeout = this.initialTimeout
  2185. };
  2186. StageTimer.prototype.resume = function() {
  2187. this.paused = !1
  2188. };
  2189. StageTimer.prototype.pause = function() {
  2190. this.paused = !0
  2191. };
  2192. StageTimer.TIMEOUT_BY_FRAME = 0;
  2193. StageTimer.TIMEOUT_BY_TIME = 1;
  2194. StageTimer.TIMEOUT_TYPE = StageTimer.TIMEOUT_BY_FRAME;
  2195. function Stage(a, c, d) {
  2196. Utils.callSuperConstructor(Stage, this);
  2197. this.canvas = null;
  2198. a && (this.canvas = "string" == typeof a ? document.getElementById(a) : a, this.canvas.ctx = this.canvas.getContext("2d"));
  2199. this.backgroundCanvas = null;
  2200. this.needToRebuildBack = !1;
  2201. this.screenWidth = c;
  2202. this.screenHeight = d;
  2203. this.viewport = {
  2204. x: 0,
  2205. y: 0
  2206. };
  2207. this.buffer = null;
  2208. try {
  2209. this.buffer = document.createElement("canvas"), this.buffer.width = c * Utils.globalScale, this.buffer.height = d * Utils.globalScale, this.buffer.ctx = this.buffer.getContext("2d")
  2210. } catch (e) {
  2211. this.buffer =
  2212. this.canvas
  2213. }
  2214. this.delay = 40;
  2215. this.started = !1;
  2216. this.lastFPS = this.fps = 0;
  2217. this.ceilSizes = this.pixelMouseMoveEvent = this.pixelMouseDownEvent = this.pixelMouseUpEvent = this.pixelClickEvent = this.showFPS = !1;
  2218. this.tmFPS = this.tmMain = null;
  2219. this.allowStaticDebugDrawing = this.allowDebugDrawing = this.clearLock = !1;
  2220. this.drawBackAlways = Utils.mobileCheckBrokenAndroid();
  2221. this.tweens = [];
  2222. this.timers = [];
  2223. this.eventsListeners = [];
  2224. this.lastTick = 0;
  2225. this.onmousemove = this.oncontextmenu = this.onclick = this.onmouseup = this.onmousedown = this.onposttick =
  2226. this.prerender = this.onpretick = this.inputController = null;
  2227. this.canvas && this.addInputListeners(this.canvas);
  2228. this.tick = Utils.proxy(this.tick, this);
  2229. this.clearFPS = Utils.proxy(this.clearFPS, this);
  2230. this.stage = this;
  2231. this.drawScene = this.render
  2232. }
  2233. Utils.extend(Stage, DisplayObjectContainer);
  2234. Stage.prototype.refreshBackground = function() {
  2235. this.needToRebuildBack = !0
  2236. };
  2237. Stage.prototype.setBackgroundCanvas = function(a) {
  2238. a && (this.backgroundCanvas = "string" == typeof a ? document.getElementById(a) : a, this.backgroundCanvas.ctx = this.backgroundCanvas.getContext("2d"))
  2239. };
  2240. Stage.prototype.destroy = function() {
  2241. clearTimeout(this.tmMain);
  2242. clearTimeout(this.tmFPS);
  2243. this.stop();
  2244. this.clear();
  2245. this.clearScreen(this.canvas);
  2246. this.backgroundCanvas && this.clearScreen(this.backgroundCanvas);
  2247. this.removeInputListeners(this.stage)
  2248. };
  2249. Stage.prototype.clearScreen = function(a) {
  2250. this.clearLock || a.ctx.clearRect(0, 0, Math.floor(a.width), Math.floor(a.height))
  2251. };
  2252. Stage.prototype.addChild = function(a) {
  2253. a.stage = this;
  2254. return Utils.callSuperMethod(Stage, this, "addChild", a)
  2255. };
  2256. Stage.prototype.setZIndex = function(a, c) {
  2257. this.setChildZIndex(a, c)
  2258. };
  2259. Stage.prototype.finalizeMouseCoords = function(a, c) {
  2260. if (!a) return c;
  2261. var d = this.prepareMouseCoord(c.x),
  2262. e = this.prepareMouseCoord(c.y);
  2263. a.getIgnoreViewport() || (d += this.viewport.x, e += this.viewport.y);
  2264. var f = a.getAbsolutePosition(),
  2265. d = d - f.x,
  2266. e = e - f.y;
  2267. return {
  2268. x: d,
  2269. y: e
  2270. }
  2271. };
  2272. Stage.prototype.prepareMouseCoord = function(a) {
  2273. return a / Utils.globalScale / Utils.globalPixelScale
  2274. };
  2275. Stage.prototype.processMouseEvent = function(a, c, d) {
  2276. a = Utils.getMouseCoord(a, this.inputController);
  2277. d = this.getObjectsStackByCoord(this.prepareMouseCoord(a.x), this.prepareMouseCoord(a.y), d, !1);
  2278. for (var e, f = 0; f < d.length; f++)
  2279. if (e = this.finalizeMouseCoords(d[f], a), e = d[f].dispatchEvent(c, {
  2280. target: d[f],
  2281. x: e.x,
  2282. y: e.y
  2283. }), !1 === e) return;
  2284. this.dispatchEvent(c, {
  2285. target: this,
  2286. x: Math.floor(this.prepareMouseCoord(a.x)),
  2287. y: Math.floor(this.prepareMouseCoord(a.y))
  2288. })
  2289. };
  2290. Stage.prototype.checkClick = function(a) {
  2291. this.processMouseEvent(a, "click", this.pixelClickEvent)
  2292. };
  2293. Stage.prototype.checkContextMenu = function(a) {
  2294. this.processMouseEvent(a, "contextmenu", this.pixelClickEvent)
  2295. };
  2296. Stage.prototype.checkMouseMove = function(a) {
  2297. a = Utils.getMouseCoord(a, this.inputController);
  2298. this.doDrag(this.prepareMouseCoord(a.x), this.prepareMouseCoord(a.y));
  2299. var c = this.getObjectsStackByCoord(this.prepareMouseCoord(a.x), this.prepareMouseCoord(a.y), this.pixelMouseMoveEvent),
  2300. d, e, f, g = [];
  2301. if (0 < c.length) {
  2302. for (d = 0; d < c.length && (g.push(c[d]), f = this.finalizeMouseCoords(c[d], a), c[d].mouseOn || (e = c[d].dispatchEvent("mouseover", {
  2303. target: c[d],
  2304. x: f.x,
  2305. y: f.y
  2306. })), c[d].mouseOn = !0, !1 !== e); d++);
  2307. e = !0;
  2308. for (d = 0; d < c.length && (f =
  2309. this.finalizeMouseCoords(c[d], a), e = c[d].dispatchEvent("mousemove", {
  2310. target: c[d],
  2311. x: f.x,
  2312. y: f.y
  2313. }), !1 !== e); d++);
  2314. !1 !== e && this.dispatchEvent("mousemove", {
  2315. target: this,
  2316. x: Math.floor(this.prepareMouseCoord(a.x)),
  2317. y: Math.floor(this.prepareMouseCoord(a.y))
  2318. })
  2319. }
  2320. this.checkMouseOut(g, a)
  2321. };
  2322. Stage.prototype.checkMouseDown = function(a) {
  2323. this.processMouseEvent(a, "mousedown", this.pixelMouseDownEvent)
  2324. };
  2325. Stage.prototype.checkMouseUp = function(a) {
  2326. this.processMouseEvent(a, "mouseup", this.pixelMouseUpEvent)
  2327. };
  2328. Stage.prototype.clear = function() {
  2329. this.tweens = [];
  2330. this.timers = [];
  2331. this.eventsListeners = [];
  2332. this.objectsCounter = 0;
  2333. Utils.callSuperMethod(Stage, this, "clear")
  2334. };
  2335. Stage.prototype.getCenter = function() {
  2336. return {
  2337. x: this.screenWidth / 2,
  2338. y: this.screenHeight / 2
  2339. }
  2340. };
  2341. Stage.prototype.drawRectangle = function(a, c, d, e, f, g, h, l) {
  2342. var k = this.canvas;
  2343. k.ctx.globalAlpha = "undefined" != typeof h ? h : 1;
  2344. k.ctx.fillStyle = f;
  2345. k.ctx.strokeStyle = f;
  2346. l || (a -= this.viewport.x, c -= this.viewport.y);
  2347. a *= Utils.globalScale;
  2348. c *= Utils.globalScale;
  2349. d *= Utils.globalScale;
  2350. e *= Utils.globalScale;
  2351. g ? k.ctx.fillRect(a - d / 2, c - e / 2, d, e) : k.ctx.strokeRect(a - d / 2, c - e / 2, d, e)
  2352. };
  2353. Stage.prototype.drawCircle = function(a, c, d, e, f, g, h) {
  2354. this.drawArc(a, c, d, 0, 2 * Math.PI, !1, e, f, g, h)
  2355. };
  2356. Stage.prototype.drawArc = function(a, c, d, e, f, g, h, l, k, m) {
  2357. var n = this.canvas,
  2358. p = n.ctx.lineWidth;
  2359. "undefined" == typeof l && (l = "#000");
  2360. n.ctx.strokeStyle = l;
  2361. "undefined" == typeof h && (h = 1);
  2362. n.ctx.lineWidth = h * Utils.globalScale;
  2363. "undefined" == typeof k && (k = 1);
  2364. n.ctx.globalAlpha = k;
  2365. m || (a -= this.viewport.x, c -= this.viewport.y);
  2366. a *= Utils.globalScale;
  2367. c *= Utils.globalScale;
  2368. d *= Utils.globalScale;
  2369. n.ctx.beginPath();
  2370. n.ctx.arc(a, c, d, e, f, g);
  2371. n.ctx.stroke();
  2372. n.ctx.lineWidth = p
  2373. };
  2374. Stage.prototype.drawPolygon = function(a, c, d, e, f) {
  2375. if ("object" == typeof a && a instanceof Array && !(2 > a.length)) {
  2376. for (var g = 0; g < a.length - 1; g++) this.drawLine(a[g].x, a[g].y, a[g + 1].x, a[g + 1].y, c, d, e, f);
  2377. this.drawLine(a[g].x, a[g].y, a[0].x, a[0].y, c, d, e, f)
  2378. }
  2379. };
  2380. Stage.prototype.drawLine = function(a, c, d, e, f, g, h, l) {
  2381. var k = this.canvas,
  2382. m = k.ctx.lineWidth;
  2383. k.ctx.strokeStyle = g ? g : "#000";
  2384. k.ctx.lineWidth = f ? f * Utils.globalScale : 1 * Utils.globalScale;
  2385. k.ctx.globalAlpha = h ? h : 1;
  2386. l || (a -= this.viewport.x, c -= this.viewport.y, d -= this.viewport.x, e -= this.viewport.y);
  2387. a *= Utils.globalScale;
  2388. c *= Utils.globalScale;
  2389. d *= Utils.globalScale;
  2390. e *= Utils.globalScale;
  2391. k.ctx.beginPath();
  2392. k.ctx.moveTo(a, c);
  2393. k.ctx.lineTo(d, e);
  2394. k.ctx.stroke();
  2395. k.ctx.lineWidth = m
  2396. };
  2397. Stage.prototype.start = function() {
  2398. this.started || (this.started = !0, this.clearFPS(), this.tick())
  2399. };
  2400. Stage.prototype.forceRender = function() {
  2401. this.started && this.tick()
  2402. };
  2403. Stage.prototype.stop = function() {
  2404. this.started = !1
  2405. };
  2406. Stage.prototype.clearFPS = function() {
  2407. this.lastFPS = this.fps;
  2408. this.fps = 0;
  2409. this.started && (this.tmFPS = setTimeout(this.clearFPS, 1E3))
  2410. };
  2411. Stage.prototype.setTextStyle = function(a, c, d, e, f, g) {
  2412. g = g ? g : this.canvas;
  2413. g.ctx.fillStyle = e;
  2414. g.ctx.strokeStyle = f;
  2415. e = "";
  2416. d && (e += d + " ");
  2417. c && (e += Math.floor(c * Utils.globalScale) + "px ");
  2418. a && (e += a);
  2419. g.ctx.font = e
  2420. };
  2421. Stage.prototype.drawText = function(a, c, d, e, f, g, h) {
  2422. h = h ? h : this.canvas;
  2423. h.ctx.globalAlpha = "undefined" == typeof e ? 1 : e;
  2424. f || (c -= this.viewport.x, d -= this.viewport.y);
  2425. c *= Utils.globalScale;
  2426. d *= Utils.globalScale;
  2427. g && (c -= this.getTextWidth(a) / 2);
  2428. h.ctx.fillText(a, c, d)
  2429. };
  2430. Stage.prototype.strokeText = function(a, c, d, e, f, g, h) {
  2431. h = h ? h : this.canvas;
  2432. h.ctx.globalAlpha = "undefined" == typeof e ? 1 : e;
  2433. f || (c -= this.viewport.x, d -= this.viewport.y);
  2434. c *= Utils.globalScale;
  2435. d *= Utils.globalScale;
  2436. g && (c -= this.getTextWidth(a) / 2);
  2437. h.ctx.strokeText(a, c, d)
  2438. };
  2439. Stage.prototype.getTextWidth = function(a, c) {
  2440. return (c ? c : this.canvas).ctx.measureText(a).width
  2441. };
  2442. Stage.prototype.render = function(a, c, d, e) {
  2443. a && (e || (e = 0), a && !a.ctx && (a.ctx = a.getContext("2d")), d || ((d = this.getFillStyle(a)) ? (a.ctx.fillStyle = d, a.ctx.fillRect(0, 0, a.width, a.height)) : this.clearLock || this.clearScreen(a)), Utils.callSuperMethod(Stage, this, "render", a, c, e))
  2444. };
  2445. Stage.prototype.createTween = function(a, c, d, e, f, g) {
  2446. a = new Tween(a, c, d, e, f, g);
  2447. this.tweens.push(a);
  2448. return a
  2449. };
  2450. Stage.prototype.removeTween = function(a) {
  2451. var c = null;
  2452. if (isNaN(a))
  2453. for (var d = 0; d < this.tweens.length; d++) {
  2454. if (this.tweens[d] === a) {
  2455. c = d;
  2456. break
  2457. }
  2458. } else c = a;
  2459. isNaN(c) || (this.tweens[c] && this.tweens[c].pause(), this.tweens.splice(c, 1));
  2460. return c
  2461. };
  2462. Stage.prototype.clearObjectTweens = function(a) {
  2463. for (var c = 0; c < this.tweens.length; c++) this.tweens[c].obj === a && (this.tweens[c].destroy = !0)
  2464. };
  2465. Stage.prototype.updateTweens = function(a) {
  2466. for (var c, d = 0; d < this.tweens.length; d++) c = this.tweens[d], c.destroy && (d = this.removeTween(d), d--);
  2467. for (d = 0; d < this.tweens.length; d++) c = this.tweens[d], !c.newly && c.tick(a) && (c.destroy = !0), c.newly = !1
  2468. };
  2469. Stage.prototype.setTimeout = function(a, c) {
  2470. var d = new StageTimer(a, c);
  2471. this.timers.push(d);
  2472. return d
  2473. };
  2474. Stage.prototype.clearTimeout = function(a) {
  2475. a && (a.destroy = !0)
  2476. };
  2477. Stage.prototype.setInterval = function(a, c) {
  2478. var d = new StageTimer(a, c, !0);
  2479. this.timers.push(d);
  2480. return d
  2481. };
  2482. Stage.prototype.clearInterval = function(a) {
  2483. this.clearTimeout(a)
  2484. };
  2485. Stage.prototype.removeTimer = function(a) {
  2486. this.timers = Utils.removeFromArray(this.timers, a)
  2487. };
  2488. Stage.prototype.updateTimers = function(a) {
  2489. for (var c, d = 0; d < this.timers.length; d++) c = this.timers[d], c.destroy && (this.removeTimer(c), d--);
  2490. for (d = 0; d < this.timers.length; d++) c = this.timers[d], !c.newly && c.update(a) && (c.destroy = !0), c.newly = !1
  2491. };
  2492. Stage.prototype.tick = function() {
  2493. clearTimeout(this.tmMain);
  2494. var a;
  2495. if (Utils.isWindowHidden) this.lastTick = 0, a = this.delay;
  2496. else {
  2497. a = (new Date).getTime();
  2498. var c = Math.min(Stage.MIN_DELTA, a - this.lastTick);
  2499. this.lastTick = a;
  2500. this.dispatchEvent("pretick", {
  2501. target: this,
  2502. delta: c
  2503. });
  2504. if (!this.started) {
  2505. this.lastTick = 0;
  2506. return
  2507. }
  2508. this.updateTweens(c);
  2509. if (!this.started) {
  2510. this.lastTick = 0;
  2511. return
  2512. }
  2513. this.updateTimers(c);
  2514. if (!this.started) {
  2515. this.lastTick = 0;
  2516. return
  2517. }
  2518. this.dispatchEvent("prerender", {
  2519. target: this,
  2520. delta: c
  2521. });
  2522. var d = !1;
  2523. this.drawBackAlways ?
  2524. (this.render(this.canvas, !0, !1, c), d = !0) : this.needToRebuildBack && (this.needToRebuildBack = !1, this.backgroundCanvas && this.render(this.backgroundCanvas, !0));
  2525. this.render(this.canvas, !1, d, c);
  2526. this.showFPS && (this.setTextStyle("sans-serif", 10, "bold", "#fff", "#000"), this.drawText("FPS: " + this.lastFPS, 2, 10, 1, !0));
  2527. this.dispatchEvent("posttick", {
  2528. target: this,
  2529. delta: c
  2530. });
  2531. a = (new Date).getTime() - a;
  2532. a = this.delay - a;
  2533. 1 > a && (a = 1);
  2534. this.fps++
  2535. }
  2536. this.started ? this.tmMain = setTimeout(this.tick, a) : this.lastTick = 0
  2537. };
  2538. Stage.prototype.box2dSync = function(a) {
  2539. for (b = a.m_bodyList; b; b = b.m_next) b.sprite && (b.sprite.rotation = b.GetRotation(), a = b.GetPosition(), b.sprite.x = a.x, b.sprite.y = a.y, b.sprite.dispatchEvent("box2dsync", {
  2540. target: b.sprite
  2541. }))
  2542. };
  2543. Stage.prototype.processTouchEvent = function(a, c) {
  2544. for (var d = 0; d < a.length; d++) this[c]({
  2545. clientX: a[d].clientX,
  2546. clientY: a[d].clientY
  2547. })
  2548. };
  2549. Stage.prototype.prepareEventTouches = function(a, c) {
  2550. a[c] || (a[c] = [{
  2551. clientX: a.clientX,
  2552. clientY: a.clientY
  2553. }]);
  2554. return a[c]
  2555. };
  2556. Stage.prototype.addInputListeners = function(a) {
  2557. this.inputController = a;
  2558. Utils.touchScreen ? (a["on" + Utils.getTouchStartEvent()] = Utils.proxy(function(a) {
  2559. this.processTouchEvent(this.prepareEventTouches(a, "changedTouches"), "checkMouseDown");
  2560. this.processTouchEvent(this.prepareEventTouches(a, "changedTouches"), "checkClick");
  2561. a.preventDefault()
  2562. }, this), a["on" + Utils.getTouchMoveEvent()] = Utils.proxy(function(a) {
  2563. this.processTouchEvent(this.prepareEventTouches(a, "changedTouches"), "checkMouseMove");
  2564. a.preventDefault()
  2565. },
  2566. this), a["on" + Utils.getTouchEndEvent()] = Utils.proxy(function(a) {
  2567. this.processTouchEvent(this.prepareEventTouches(a, "changedTouches"), "checkMouseUp");
  2568. a.preventDefault()
  2569. }, this)) : (a.onclick = Utils.proxy(function(a) {
  2570. this.checkClick(a)
  2571. }, this), a.onmousemove = Utils.proxy(function(a) {
  2572. this.checkMouseMove(a)
  2573. }, this), a.onmousedown = Utils.proxy(function(a) {
  2574. 0 == a.button && this.checkMouseDown(a)
  2575. }, this), a.onmouseup = Utils.proxy(function(a) {
  2576. 0 == a.button && this.checkMouseUp(a)
  2577. }, this), a.oncontextmenu = Utils.proxy(function(a) {
  2578. this.checkContextMenu(a)
  2579. },
  2580. this))
  2581. };
  2582. Stage.prototype.removeInputListeners = function(a) {
  2583. a.ontouchstart = null;
  2584. a.ontouchmove = null;
  2585. a.ontouchend = null;
  2586. a.onmspointerdown = null;
  2587. a.onmspointermove = null;
  2588. a.onmspointerup = null;
  2589. a.onclick = null;
  2590. a.onmousemove = null;
  2591. a.onmousedown = null;
  2592. a.onmouseup = null;
  2593. a.oncontextmenu = null
  2594. };
  2595. Stage.MIN_DELTA = 500;
  2596. var ExternalAPI = {
  2597. type: "default",
  2598. init: function() {},
  2599. exec: function() {
  2600. var a = arguments[0];
  2601. if ("exec" != a && "function" == typeof ExternalAPI[a]) return ExternalAPI[a].apply(ExternalAPI, Utils.getFunctionArguments(arguments, 1))
  2602. },
  2603. check: function() {
  2604. return !1
  2605. },
  2606. openWidget: function() {},
  2607. closeWidget: function() {},
  2608. getMoreGamesURL: function(a, c) {
  2609. return "http://playtomax.com/"
  2610. },
  2611. getPreloaderURL: function() {
  2612. return "http://playtomax.com/"
  2613. },
  2614. showCopyright: function() {},
  2615. isPortalEnvironment: function() {
  2616. var a = window.location.href;
  2617. return 0 ==
  2618. a.indexOf("http://playtomax.com") || 0 == a.indexOf("https://playtomax.com")
  2619. },
  2620. isPlainPortalEnvironment: function() {
  2621. return ExternalAPI.isPortalEnvironment() ? "whitelabel" != Utils.parseGet().external : !1
  2622. },
  2623. showAds: function() {
  2624. // ExternalAPI.isPortalEnvironment() && (window.GoogleIMA ? GoogleIMA.show() : window.Leadbolt && Leadbolt.show())
  2625. },
  2626. sendGAEvent: function(a, c, d, e) {
  2627. // ExternalAPI.isPlainPortalEnvironment() && window.ga && (e || (e = 0), ga("send", "event", a, c, d, e))
  2628. },
  2629. openPlayMarket: function(a, c, d) {
  2630. /*a = "https://play.google.com/store/apps/details?id=" +
  2631. a + ("&referrer=utm_source%3D" + c);
  2632. a += "%26utm_medium%3Dbutton%26utm_campaign%3D" + d;
  2633. window.open(a, "_blank")*/
  2634. },
  2635. shareTwitter: function(a, c) {
  2636. /*c || (c = "en");
  2637. var d = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(a) + "&lang=" + c,
  2638. e = window.open(d, "_blank");
  2639. e ? e.focus() : window.location.href = d*/
  2640. },
  2641. trackGameEvent: function(a, c) {
  2642. var d = window._gameEventCounter || {};
  2643. "undefined" == typeof d[a] && (d[a] = {});
  2644. "undefined" == typeof d[a][c] && (d[a][c] = 1);
  2645. ExternalAPI.exec("sendGAEvent", GAME_ID || "Unknown_Game", a, c, d[a][c]++);
  2646. window._gameEventCounter =
  2647. d
  2648. }
  2649. },
  2650. TTLoader = {
  2651. endCallback: null,
  2652. loadedData: null,
  2653. landscapeMode: !1,
  2654. skipPlayButton: !1,
  2655. create: function(a, c, d, e) {
  2656. TTLoader.endCallback = a;
  2657. TTLoader.landscapeMode = c;
  2658. TTLoader.skipPlayButton = d;
  2659. document.getElementById("progress_container").style.background = "#fff";
  2660. document.getElementById("progress_container").style.zIndex = "1000";
  2661. a = document.getElementById("progress");
  2662. a.setAttribute("valign", "top");
  2663. a.style.verticalAlign = "top";
  2664. a.style.background = "#fff";
  2665. c = document.createElement("div");
  2666. d = document.createElement("a");
  2667. d.setAttribute("id", "tt_load_logo_c");
  2668. /*var f = window.ExternalAPI ? ExternalAPI.exec("getPreloaderURL") : "http://playtomax.com/",
  2669. g = "_blank";
  2670. if (e || !f) f = "javascript:void(0)", g = "";
  2671. d.setAttribute("href", f);
  2672. d.setAttribute("target", g);*/
  2673. e = new Image;
  2674. e.setAttribute("id", "tt_load_logo");
  2675. e.setAttribute("border", "");
  2676. e.src = TTLoader.logoSrc;
  2677. e.style.cursor = "pointer";
  2678. d.appendChild(e);
  2679. c.appendChild(d);
  2680. a.appendChild(c);
  2681. c = document.createElement("div");
  2682. c.setAttribute("id", "tt_load_progress_cont");
  2683. c.setAttribute("align", "left");
  2684. c.setAttribute("style", "padding: 1px; border: 2px solid #e44d26; background: #fff");
  2685. e = document.createElement("div");
  2686. e.setAttribute("id", "tt_load_progress");
  2687. e.setAttribute("style", "width: 0px; background: #e44d26;");
  2688. e.innerHTML = "&nbsp;";
  2689. c.appendChild(e);
  2690. a.appendChild(c);
  2691. c = document.createElement("div");
  2692. c.setAttribute("id", "tt_load_play");
  2693. e = new Image;
  2694. e.setAttribute("id", "tt_load_button");
  2695. e.src = TTLoader.buttonDisabledSrc;
  2696. e.style.visibility = TTLoader.skipPlayButton ? "hidden" : "hidden";
  2697. c.appendChild(e);
  2698. a.appendChild(c);
  2699. Utils.addEventListener("fitlayout", TTLoader.setSizes);
  2700. TTLoader.setSizes()
  2701. },
  2702. setSizes: function() {
  2703. var a = Utils.getWindowRect();
  2704. document.getElementById("progress_container").style.width = a.width + "px";
  2705. document.getElementById("progress_container").style.height = a.height + "px";
  2706. a = Utils.globalScale * Utils.globalPixelScale;
  2707. TTLoader.landscapeMode || (document.getElementById("progress").style.paddingTop = Math.floor(80 * a) + "px");
  2708. document.getElementById("tt_load_progress_cont").style.width = Math.floor(200 * a) + "px";
  2709. document.getElementById("tt_load_progress").style.height =
  2710. Math.floor(12 * a) + "px";
  2711. document.getElementById("tt_load_progress").style.width = a * TTLoader.progressVal * 2 + "px";
  2712. document.getElementById("tt_load_logo").style.marginTop = Math.floor(80) + "px";
  2713. document.getElementById("tt_load_logo").setAttribute("width", Math.floor(300) + "px");
  2714. document.getElementById("tt_load_logo").setAttribute("height", Math.floor(304) + "px");
  2715. document.getElementById("tt_load_button").setAttribute("width", Math.floor(65 * a) + "px");
  2716. document.getElementById("tt_load_button").setAttribute("height",
  2717. Math.floor(29 * a) + "px");
  2718. document.getElementById("tt_load_button").style.marginTop = Math.floor(30 * a) + "px"
  2719. },
  2720. progressVal: 0,
  2721. showLoadProgress: function(a) {
  2722. 0 > a && (a = 0);
  2723. 100 < a && (a = 100);
  2724. TTLoader.progressVal = a;
  2725. TTLoader.setSizes()
  2726. },
  2727. loadComplete: function(a) {
  2728. TTLoader.showLoadProgress(100);
  2729. TTLoader.loadedData = a;
  2730. a = document.getElementById("tt_load_button");
  2731. var c = "click";
  2732. Utils.touchScreen && !Utils.isWindowsPhone() && (c = Utils.getTouchStartEvent());
  2733. Utils.bindEvent(a, c, TTLoader.close);
  2734. Utils.bindEvent(a, "click", TTLoader.close);
  2735. a.style.cursor = "pointer";
  2736. a.src = TTLoader.buttonSrc;
  2737. a = document.getElementById("tt_load_progress");
  2738. a.style.background = "transparent";
  2739. a = document.getElementById("tt_load_progress_cont");
  2740. a.style.border = "2px solid transparent";
  2741. a.style.background = "transparent";
  2742. // document.getElementById("tt_load_button").style.display = "block";
  2743. /*TTLoader.skipPlayButton &&*/ TTLoader.close()
  2744. },
  2745. close: function(a) {
  2746. clearTimeout(TTLoader.animateTimeout);
  2747. TTLoader.endCallback(TTLoader.loadedData)
  2748. },
  2749. logoSrc: "images/68_logo.png",
  2750. buttonDisabledSrc: "",
  2751. buttonSrc: ""
  2752. };
  2753. function Animation(a, c, d) {
  2754. this.obj = a;
  2755. this.sequence = c;
  2756. this.currentAnimation = -1;
  2757. this.currentTweens = [];
  2758. this.ended = !1;
  2759. this.endTimer = this.startTimer = null;
  2760. this.playNext = Utils.proxy(this.playNext, this);
  2761. this.play = Utils.proxy(this.play, this);
  2762. this.onfinish = d
  2763. }
  2764. Animation.prototype.play = function() {
  2765. this.playNext()
  2766. };
  2767. Animation.prototype.playNext = function() {
  2768. if (0 <= this.currentAnimation) {
  2769. var a = this.sequence[this.currentAnimation];
  2770. if (a.onfinish) a.onfinish({
  2771. target: this
  2772. });
  2773. "undefined" != typeof a.loop && 0 <= a.loop && (this.currentAnimation = a.loop - 1)
  2774. }
  2775. this.currentAnimation++;
  2776. if (this.currentAnimation >= this.sequence.length) {
  2777. if (this.ended = !0, "function" == typeof this.onfinish) this.onfinish({
  2778. target: this
  2779. })
  2780. } else {
  2781. var a = this.sequence[this.currentAnimation],
  2782. c, d, e, f, g, h, l;
  2783. e = a.tweens;
  2784. Utils.isArray(e) || (e = [e]);
  2785. c = a.duration || 0;
  2786. this.currentTweens =
  2787. [];
  2788. for (var k = null, m = 0; m < e.length; m++) f = e[m], d = f.duration, "undefined" == typeof d && (d = c), g = f.from, "undefined" == typeof g && (g = this.obj[f.prop]), h = f.to, "undefined" == typeof h && (h = this.obj[f.prop]), l = f.ease || a.ease || null, g = Animation.stage.createTween(this.obj, f.prop, g, h, d, l), "undefined" != typeof f.onchange && (g.onchange = f.onchange), "undefined" != typeof f.onfinish && (g.onfinish = f.onfinish), g.play(), this.currentTweens.push(g), d == c && (k = g);
  2789. if (k) {
  2790. var n = this,
  2791. p = k.onfinish;
  2792. k.onfinish = function(a) {
  2793. "function" == typeof p &&
  2794. p(a);
  2795. n.playNext()
  2796. }
  2797. } else this.endTimer = Animation.stage.setTimeout(this.playNext, c)
  2798. }
  2799. };
  2800. Animation.prototype.executeTweensMethod = function(a) {
  2801. for (var c = 0; c < this.currentTweens.length; c++) this.currentTweens[c][a]()
  2802. };
  2803. Animation.prototype.clearTweens = function() {
  2804. for (var a = 0; a < this.currentTweens.length; a++) this.currentTweens[a].destroy = !0;
  2805. this.currentTweens = []
  2806. };
  2807. Animation.prototype.stop = function() {
  2808. this.ended || (this.executeTweensMethod("stop"), this.startTimer && Animation.stage.clearTimeout(this.startTimer), this.endTimer && Animation.stage.clearTimeout(this.endTimer))
  2809. };
  2810. Animation.prototype.pause = function() {
  2811. this.ended || (this.executeTweensMethod("pause"), this.startTimer && this.startTimer.pause(), this.endTimer && this.endTimer.pause())
  2812. };
  2813. Animation.prototype.resume = function() {
  2814. this.ended || (this.executeTweensMethod("play"), this.startTimer && this.startTimer.resume(), this.endTimer && this.endTimer.resume())
  2815. };
  2816. Animation.stage = null;
  2817. Animation.play = function(a, c, d, e) {
  2818. if (a && c) return a.stage && (Animation.stage = a.stage), Animation.stage || (Animation.stage = window.stage), a = new Animation(a, c, d), e ? a.startTimer = Animation.stage.setTimeout(a.play, e) : a.play(), a
  2819. };
  2820. function AudioPlayer() {
  2821. this.disabled = !1;
  2822. this.basePath = "";
  2823. this.mp3Support = !0;
  2824. this.delayPlay = !1;
  2825. this.audioWrapper = null;
  2826. this.busy = this.locked = !1;
  2827. this.startPlayTime = 0;
  2828. this.onend = null;
  2829. this.controlPlay = Utils.proxy(this.controlPlay, this)
  2830. }
  2831. AudioPlayer.prototype.createNewAudio = function() {
  2832. if (AudioMixer.isWebAudioSupport()) {
  2833. var a = AudioMixer.waContext.createBufferSource();
  2834. a.connect(AudioMixer.waContext.destination);
  2835. return a
  2836. }
  2837. return document.createElement("audio")
  2838. };
  2839. AudioPlayer.prototype.init = function(a) {
  2840. this.basePath = a ? a : "";
  2841. this.delayPlay = "ontouchstart" in window;
  2842. this.audioWrapper = this.createNewAudio();
  2843. a = document.createElement("audio");
  2844. a.canPlayType ? this.mp3Support = "" != a.canPlayType("audio/mpeg") : this.disabled = !0;
  2845. return !this.disabled
  2846. };
  2847. AudioPlayer.prototype.play = function(a, c) {
  2848. if (this.disabled) return !1;
  2849. var d = this.basePath + "/" + a + (this.mp3Support ? ".mp3" : ".ogg");
  2850. this.stop();
  2851. this.audioWrapper = this.createNewAudio();
  2852. this.audioWrapper.doLoop = c ? !0 : !1;
  2853. this.audioWrapper.fileName = a;
  2854. if (AudioMixer.isWebAudioSupport()) {
  2855. var e = this;
  2856. this.loadSound(d, function(a) {
  2857. e.audioWrapper.buffer = a;
  2858. e.audioWrapper.noteOn ? e.audioWrapper.noteOn(0) : e.audioWrapper.start(0);
  2859. e.startPlayTime = (new Date).getTime();
  2860. e.audioWrapper.loop = c;
  2861. "undefined" != typeof e.audioWrapper.playbackState ?
  2862. e.waCheckInterval = setInterval(function() {
  2863. e.audioWrapper ? e.audioWrapper.playbackState == e.audioWrapper.FINISHED_STATE && e.controlPlay() : clearInterval(e.waCheckInterval)
  2864. }, 100) : e.audioWrapper.onended = e.controlPlay
  2865. })
  2866. } else this.audioWrapper.src = d, this.audioWrapper.type = this.mp3Support ? "audio/mpeg" : "audio/ogg", this.audioWrapper.loop = !1, this.audioWrapper.preload = "auto", this.audioWrapper.load(), this.delayPlay ? (this.audioWrapper.addEventListener("canplay", this.readyToPlay), this.audioWrapper.addEventListener("canplaythrough",
  2867. this.readyToPlay)) : this.audioWrapper.play(), this.audioWrapper.addEventListener("ended", this.controlPlay, !1);
  2868. this.busy = !0;
  2869. this.startPlayTime = (new Date).getTime()
  2870. };
  2871. AudioPlayer.prototype.loadSound = function(a, c) {
  2872. if (AudioMixer.buffer[a]) c && c(AudioMixer.buffer[a]);
  2873. else {
  2874. var d = new XMLHttpRequest;
  2875. d.open("GET", a, !0);
  2876. d.responseType = "arraybuffer";
  2877. d.onload = function() {
  2878. AudioMixer.waContext.decodeAudioData(this.response, function(d) {
  2879. AudioMixer.buffer[a] = d;
  2880. c && c(d)
  2881. })
  2882. };
  2883. d.send()
  2884. }
  2885. };
  2886. AudioPlayer.prototype.readyToPlay = function(a) {
  2887. a.currentTarget.alreadyLoaded || (a.currentTarget.alreadyLoaded = !0, a.currentTarget.play())
  2888. };
  2889. AudioPlayer.prototype.stop = function() {
  2890. this.busy = !1;
  2891. try {
  2892. AudioMixer.isWebAudioSupport() ? this.audioWrapper.noteOff ? this.audioWrapper.noteOff(0) : this.audioWrapper.stop(0) : (this.audioWrapper.removeEventListener("canplay", this.readyToPlay), this.audioWrapper.removeEventListener("canplaythrough", this.readyToPlay), this.audioWrapper.pause(), this.audioWrapper.currentTime = 0), this.audioWrapper = null
  2893. } catch (a) {}
  2894. };
  2895. AudioPlayer.prototype.pause = function() {
  2896. AudioMixer.isWebAudioSupport() ? this.audioWrapper && this.audioWrapper.disconnect() : this.audioWrapper.pause()
  2897. };
  2898. AudioPlayer.prototype.resume = function() {
  2899. if (AudioMixer.isWebAudioSupport()) {
  2900. if (this.audioWrapper) try {
  2901. this.audioWrapper.connect(AudioMixer.waContext.destination)
  2902. } catch (a) {}
  2903. } else this.audioWrapper.play()
  2904. };
  2905. AudioPlayer.prototype.controlPlay = function() {
  2906. if (this.audioWrapper)
  2907. if (this.audioWrapper.doLoop) AudioMixer.isWebAudioSupport() || (Utils.isFirefox() ? this.play(this.audioWrapper.fileName, !0) : (this.audioWrapper.currentTime = 0, this.audioWrapper.play()));
  2908. else {
  2909. this.busy = !1;
  2910. if ("function" == typeof this.onend) this.onend();
  2911. this.waCheckInterval && clearInterval(this.waCheckInterval)
  2912. }
  2913. };
  2914. AudioPlayer.prototype.getPosition = function() {
  2915. if (AudioMixer.isWebAudioSupport()) {
  2916. if (!this.startPlayTime) return 0;
  2917. var a = this.getDuration();
  2918. if (!a) return 0;
  2919. var c = ((new Date).getTime() - this.startPlayTime) / 1E3;
  2920. return c <= a ? c : this.audioWrapper.doLoop ? c - Math.floor(c / a) * a : a
  2921. }
  2922. return this.audioWrapper.currentTime ? this.audioWrapper.currentTime : 0
  2923. };
  2924. AudioPlayer.prototype.getDuration = function() {
  2925. return AudioMixer.isWebAudioSupport() ? this.audioWrapper.buffer ? this.audioWrapper.buffer.duration : 0 : this.audioWrapper.duration ? this.audioWrapper.duration : 0
  2926. };
  2927. function AudioMixer(a, c) {
  2928. this.singleChannelMode = !1;
  2929. this.channels = [];
  2930. this.init(a, c)
  2931. }
  2932. AudioMixer.prototype.init = function(a, c) {
  2933. if (AudioMixer.isWebAudioSupport()) {
  2934. AudioMixer.waContext = new window.AudioContext;
  2935. var d = AudioMixer.waContext.createBuffer(1, 1, 22050),
  2936. e = AudioMixer.waContext.createBufferSource();
  2937. e.buffer = d;
  2938. e.connect(AudioMixer.waContext.destination);
  2939. e.noteOn ? e.noteOn(0) : e.start(0)
  2940. }
  2941. AudioMixer.isWebAudioSupport() || -1 == navigator.userAgent.toLowerCase().indexOf("mac") || (this.singleChannelMode = !0, c = 1);
  2942. this.path = a;
  2943. this.channels = [];
  2944. for (d = 0; d < c; d++) this.channels[d] = new AudioPlayer, this.channels[d].init(a);
  2945. Utils.addEventListener("hidewindow", Utils.proxy(this.pauseOnHide, this));
  2946. Utils.addEventListener("showwindow", Utils.proxy(this.resumeOnShow, this))
  2947. };
  2948. AudioMixer.prototype.pauseOnHide = function() {
  2949. for (var a = 0; a < this.channels.length; a++) this.channels[a].pause()
  2950. };
  2951. AudioMixer.prototype.resumeOnShow = function() {
  2952. for (var a = 0; a < this.channels.length; a++) this.channels[a].resume()
  2953. };
  2954. AudioMixer.prototype.play = function(a, c, d, e) {
  2955. var f = -1,
  2956. f = "number" == typeof e ? e : this.getFreeChannel(d);
  2957. 0 <= f && f < this.channels.length && (this.channels[f].stop(), this.channels[f].play(a, c));
  2958. return this.channels[f]
  2959. };
  2960. AudioMixer.prototype.stop = function(a) {
  2961. 0 <= a && a < this.channels.length && this.channels[a].stop()
  2962. };
  2963. AudioMixer.prototype.getFreeChannel = function(a) {
  2964. for (var c = -1, d = [], e = -1, f = -1, g = 0, h = 0; h < this.channels.length; h++) this.channels[h].locked || (this.channels[h].busy ? (g = (new Date).getTime(), g -= this.channels[h].startPlayTime, g > f && (f = g, e = h)) : d.push(h));
  2965. 0 == d.length ? !a && 0 <= e && (c = e) : c = d[0];
  2966. return c
  2967. };
  2968. AudioMixer.isWebAudioSupport = function() {
  2969. return Boolean(window.AudioContext)
  2970. };
  2971. window.AudioContext = window.AudioContext || window.webkitAudioContext;
  2972. AudioMixer.buffer = {};
  2973. AudioMixer.waContext = null;
  2974. function PathTween(a, c, d, e) {
  2975. this.obj = a;
  2976. this.path = c;
  2977. this.loop = !!e;
  2978. d && (this.path = Utils.getBezierCurve(c));
  2979. this.pathLen = this.getPathLen();
  2980. this.position = 0;
  2981. this.startTimer = this.tween = null
  2982. }
  2983. PathTween.prototype.getPathLen = function() {
  2984. for (var a, c, d = 0, e = 0; e < this.path.length - 1; e++) a = this.path[e].x - this.path[e + 1].x, c = this.path[e].y - this.path[e + 1].y, d += Math.sqrt(a * a + c * c);
  2985. return d
  2986. };
  2987. PathTween.prototype.getPoint = function(a) {
  2988. for (var c, d, e = c = 0, f = 0, g = this.path[0].x, h = this.path[0].y;;) {
  2989. f++;
  2990. if (f >= this.path.length) return {
  2991. x: this.path[this.path.length - 1].x,
  2992. y: this.path[this.path.length - 1].y
  2993. };
  2994. c = g - this.path[f].x;
  2995. d = h - this.path[f].y;
  2996. c = Math.sqrt(c * c + d * d);
  2997. if (e + c >= a) return f = Math.atan2(this.path[f].y - h, this.path[f].x - g), c = a - e, g += Math.cos(f) * c, h += Math.sin(f) * c, {
  2998. x: g,
  2999. y: h
  3000. };
  3001. e += c;
  3002. g = this.path[f].x;
  3003. h = this.path[f].y
  3004. }
  3005. };
  3006. PathTween.prototype.start = function(a, c, d, e, f) {
  3007. function g() {
  3008. h.position = 0;
  3009. h.tween && (h.tween.stop(), h.tween.destroy = !0);
  3010. h.tween = h.obj.stage.createTween(h, "position", 0, h.pathLen, a, c);
  3011. h.tween.addEventListener("finish", h.updateOnFinish);
  3012. h.tween.addEventListener("change", h.updateOnTween);
  3013. d && h.tween.addEventListener("finish", d);
  3014. e && h.tween.addEventListener("change", e);
  3015. h.tween.play();
  3016. h.startTimer = null
  3017. }
  3018. var h = this;
  3019. f ? this.startTimer = this.obj.stage.setTimeout(g, f) : g()
  3020. };
  3021. PathTween.prototype.pause = function() {
  3022. this.tween && this.tween.pause();
  3023. this.startTimer && this.startTimer.pause()
  3024. };
  3025. PathTween.prototype.play = function() {
  3026. this.tween && this.tween.play();
  3027. this.startTimer && this.startTimer.pause()
  3028. };
  3029. PathTween.prototype.rewind = function() {
  3030. this.tween && this.tween.rewind();
  3031. this.startTimer && this.startTimer.rewind()
  3032. };
  3033. PathTween.prototype.forward = function() {
  3034. this.tween && this.tween.forward();
  3035. this.startTimer && (this.startTimer.pause(), this.startTimer.destroy = !0)
  3036. };
  3037. PathTween.prototype.stop = function() {
  3038. this.tween && this.tween.stop();
  3039. this.startTimer && (this.startTimer.pause(), this.startTimer.destroy = !0)
  3040. };
  3041. PathTween.prototype.updateOnFinish = function(a) {
  3042. a = a.target.obj;
  3043. var c = a.path[a.path.length - 1];
  3044. a.obj.x = c.x;
  3045. a.obj.y = c.y;
  3046. if (a.loop) return a.rewind(), a.play(), !1
  3047. };
  3048. PathTween.prototype.updateOnTween = function(a) {
  3049. a = a.target.obj;
  3050. var c = a.getPoint(a.position);
  3051. a.obj.x = c.x;
  3052. a.obj.y = c.y
  3053. };
  3054. function SimpleText(a, c, d, e) {
  3055. this.font = a;
  3056. this.y = this.x = 0;
  3057. this.width = c;
  3058. this.height = d;
  3059. this.align = SimpleText.ALIGN_LEFT;
  3060. this.charSpacing = this.rotation = 0;
  3061. this.opacity = this.scale = 1;
  3062. this.static = !1;
  3063. this.charMap = "0123456789".split("");
  3064. this.charWidth = [];
  3065. this.sprites = [];
  3066. this.text = "";
  3067. this.parent = this.stage = window.stage;
  3068. this.ALIGN_LEFT = SimpleText.ALIGN_LEFT;
  3069. this.ALIGN_RIGHT = SimpleText.ALIGN_RIGHT;
  3070. this.ALIGN_CENTER = SimpleText.ALIGN_CENTER;
  3071. this.ignoreViewport = e
  3072. }
  3073. SimpleText.prototype.manageSprites = function(a) {
  3074. var c, d = a.length,
  3075. e = this.sprites.length;
  3076. if (e < d)
  3077. for (a = 0; a < d - e; a++) c = new window[SimpleText.spriteClass](this.font, this.width, this.height, this.charMap.length), this.sprites.push(c), this.parent.addChild(c);
  3078. if (e > d) {
  3079. for (a = 0; a < e - d; a++) this.parent.removeChild(this.sprites[a]);
  3080. this.sprites.splice(0, e - d)
  3081. }
  3082. };
  3083. SimpleText.prototype.getCharIx = function(a) {
  3084. for (var c = 0; c < this.charMap.length; c++)
  3085. if (this.charMap[c] == a) return c;
  3086. return -1
  3087. };
  3088. SimpleText.prototype.getCharWidth = function(a) {
  3089. a = this.getCharIx(a);
  3090. return 0 <= a ? this.charWidth[a] ? this.charWidth[a] : this.width : this.width
  3091. };
  3092. SimpleText.prototype.getWidth = function() {
  3093. for (var a = 0, c = 0; c < this.text.length; c++) a += this.getCharWidth(this.text.substr(c, 1)) + this.charSpacing;
  3094. return a
  3095. };
  3096. SimpleText.prototype.write = function(a) {
  3097. var c, d, e, f;
  3098. this.text = a += "";
  3099. this.manageSprites(a);
  3100. c = this.x;
  3101. this.align == SimpleText.ALIGN_CENTER && (c = this.x - this.getWidth() / 2 * this.scale + this.getCharWidth(this.text.substr(0, 1)) / 2 * this.scale);
  3102. this.align == SimpleText.ALIGN_RIGHT && (c = this.x - this.getWidth() * this.scale);
  3103. e = new Vector(c - this.x, 0);
  3104. e.rotate(-this.rotation);
  3105. c = e.x + this.x;
  3106. d = e.y + this.y;
  3107. e = new Vector(0, 0);
  3108. for (var g = 0; g < a.length; g++)
  3109. if (this.sprites[g].visible = !0, f = this.charMap.indexOf(a.substr(g, 1)), 0 > f) this.sprites[g].visible = !1;
  3110. else {
  3111. var h = this.getCharWidth(this.text.substr(g, 1));
  3112. this.sprites[g].scaleX = this.sprites[g].scaleY = this.scale;
  3113. this.sprites[g].gotoAndStop(f);
  3114. f = e.clone();
  3115. f.x *= this.scale;
  3116. f.rotate(-this.rotation);
  3117. this.sprites[g].x = f.x + ("," == this.text.substr(g, 1) ? c - h / 2 : c);
  3118. this.sprites[g].y = f.y + d;
  3119. this.sprites[g].rotation = this.rotation;
  3120. this.sprites[g].static = this.static;
  3121. this.sprites[g].opacity = this.opacity;
  3122. this.sprites[g].ignoreViewport = this.ignoreViewport;
  3123. this.sprites[g].gx = this.sprites[g].x;
  3124. this.sprites[g].gy = this.sprites[g].y;
  3125. this.sprites[g].gscaleX = this.sprites[g].scaleX;
  3126. this.sprites[g].gscaleY = this.sprites[g].scaleY;
  3127. this.sprites[g].grotation = this.sprites[g].rotation;
  3128. this.sprites[g].gopacity = this.sprites[g].opacity;
  3129. e.x += h + this.charSpacing
  3130. }
  3131. };
  3132. SimpleText.prototype.refresh = function() {
  3133. this.write(this.text)
  3134. };
  3135. SimpleText.prototype.addToGroup = function(a) {
  3136. for (var c = 0; c < this.sprites.length; c++) this.sprites[c].gx = this.sprites[c].x / 2, this.sprites[c].gy = this.sprites[c].y, a.addChild(this.sprites[c], !1)
  3137. };
  3138. SimpleText.prototype.putToGroup = function(a) {
  3139. for (var c = 0; c < this.sprites.length; c++) this.sprites[c].gx = this.sprites[c].x, this.sprites[c].gy = this.sprites[c].y, a.addChild(this.sprites[c], !1)
  3140. };
  3141. SimpleText.prototype.refreshOnTween = function(a) {
  3142. a.target.obj.refresh()
  3143. };
  3144. SimpleText.prototype.setPosition = function(a, c) {
  3145. this.x = a;
  3146. this.y = c;
  3147. this.refresh()
  3148. };
  3149. SimpleText.prototype.removeTweens = function() {
  3150. this.stage && this.stage.clearObjectTweens(this)
  3151. };
  3152. SimpleText.prototype.addTween = function(a, c, d, e, f, g) {
  3153. if (this.stage) {
  3154. var h = this[a];
  3155. if (!isNaN(h)) return a = this.stage.createTween(this, a, h, c, d, e), a.onchange = g, a.onfinish = f, a
  3156. }
  3157. };
  3158. SimpleText.prototype.moveTo = function(a, c, d, e, f, g) {
  3159. d = ~~d;
  3160. if (0 >= d) this.setPosition(a, c);
  3161. else {
  3162. if (a = this.addTween("x", a, d, e, f, g)) a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween), a.play();
  3163. if (c = this.addTween("y", c, d, e, a ? null : f, a ? null : g)) c.addEventListener("change", this.refreshOnTween), c.addEventListener("finish", this.refreshOnTween), c.play()
  3164. }
  3165. return this
  3166. };
  3167. SimpleText.prototype.moveBy = function(a, c, d, e, f, g) {
  3168. return this.moveTo(this.x + a, this.y + c, d, e, f, g)
  3169. };
  3170. SimpleText.prototype.fadeTo = function(a, c, d, e, f) {
  3171. c = ~~c;
  3172. if (0 >= c) this.opacity = a;
  3173. else if (a = this.addTween("opacity", a, c, d, e, f)) a.play(), a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween);
  3174. return this
  3175. };
  3176. SimpleText.prototype.fadeBy = function(a, c, d, e, f) {
  3177. a = Math.max(0, Math.min(1, this.opacity + a));
  3178. return this.fadeTo(a, c, d, e, f)
  3179. };
  3180. SimpleText.prototype.rotateTo = function(a, c, d, e, f) {
  3181. c = ~~c;
  3182. if (0 >= c) this.rotation = a;
  3183. else if (a = this.addTween("rotation", a, c, d, e, f)) a.play(), a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween);
  3184. return this
  3185. };
  3186. SimpleText.prototype.rotateBy = function(a, c, d, e, f) {
  3187. return this.rotateTo(this.rotation + a, c, d, e, f)
  3188. };
  3189. SimpleText.prototype.scaleTo = function(a, c, d, e, f) {
  3190. c = ~~c;
  3191. if (0 >= c) this.scale = a;
  3192. else if (a = this.addTween("scale", a, c, d, e, f)) a.play(), a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween);
  3193. return this
  3194. };
  3195. SimpleText.spriteClass = "Sprite";
  3196. SimpleText.ALIGN_LEFT = 0;
  3197. SimpleText.ALIGN_RIGHT = 1;
  3198. SimpleText.ALIGN_CENTER = 2;
  3199. function BitmapText(a, c) {
  3200. this.font = Utils.isArray(a) ? a : [a];
  3201. this.charMap = c;
  3202. this.sprites = [];
  3203. this.lines = [];
  3204. this.parent = this.stage = window.stage
  3205. }
  3206. BitmapText.ALIGN_LEFT = 0;
  3207. BitmapText.ALIGN_RIGHT = 1;
  3208. BitmapText.ALIGN_CENTER = 2;
  3209. BitmapText.VALIGN_TOP = 0;
  3210. BitmapText.VALIGN_MIDDLE = 1;
  3211. BitmapText.VALIGN_BOTTOM = 2;
  3212. BitmapText.spriteClass = "Sprite";
  3213. BitmapText.LINES_DELIMITER = "\n";
  3214. BitmapText.prototype.x = 0;
  3215. BitmapText.prototype.y = 0;
  3216. BitmapText.prototype.align = BitmapText.ALIGN_LEFT;
  3217. BitmapText.prototype.valign = BitmapText.VALIGN_TOP;
  3218. BitmapText.prototype.rotation = 0;
  3219. BitmapText.prototype.charSpacing = 0;
  3220. BitmapText.prototype.lineSpacing = 0;
  3221. BitmapText.prototype.maxWidth = 0;
  3222. BitmapText.prototype.scale = 1;
  3223. BitmapText.prototype.opacity = 1;
  3224. BitmapText.prototype.static = !1;
  3225. BitmapText.prototype.text = "";
  3226. this.ignoreViewport = !1;
  3227. this.zIndex = void 0;
  3228. BitmapText.prototype.manageSprites = function(a) {
  3229. if (this.parent) {
  3230. var c, d = a.length,
  3231. e = this.sprites.length;
  3232. if (e < d)
  3233. for (a = 0; a < d - e; a++) c = new window[BitmapText.spriteClass](null, 0, 0), this.sprites.push(c), this.parent.addChild(c);
  3234. if (e > d) {
  3235. for (a = 0; a < e - d; a++) this.parent.removeChild(this.sprites[a]);
  3236. this.sprites.splice(0, e - d)
  3237. }
  3238. }
  3239. };
  3240. BitmapText.prototype.getChar = function(a) {
  3241. for (var c = a.charCodeAt(0), d = 0; d < this.charMap.length; d++)
  3242. if (this.charMap[d].id == c) return this.charMap[d];
  3243. console.log("Char not found", a, c, this.text);
  3244. return {
  3245. id: 0,
  3246. x: 0,
  3247. y: 0,
  3248. width: 0,
  3249. height: 0,
  3250. xoffset: 0,
  3251. yoffset: 0,
  3252. page: 0,
  3253. xadvance: 0
  3254. }
  3255. };
  3256. BitmapText.prototype.getWidth = function() {
  3257. for (var a = 0, c = 0; c < this.lines.length; c++) {
  3258. for (var d = 0, e, f = 0; f < this.lines[c].length; f++) e = this.getChar(this.lines[c].substr(f, 1)), d += e.xadvance + this.charSpacing;
  3259. d > a && (a = d)
  3260. }
  3261. return a
  3262. };
  3263. BitmapText.prototype.getWidthOfLine = function(a) {
  3264. for (var c = 0, d, e = 0; e < this.lines[a].length; e++) d = this.getChar(this.lines[a].substr(e, 1)), c += d.xadvance + this.charSpacing;
  3265. return c
  3266. };
  3267. BitmapText.prototype.getHeight = function() {
  3268. for (var a = 0, c = 0; c < this.lines.length; c++) a += this.getHeightOfLine(c) + this.lineSpacing;
  3269. return a
  3270. };
  3271. BitmapText.prototype.getHeightOfLine = function(a) {
  3272. for (var c = 0, d, e = 0; e < this.lines[a].length; e++) d = this.getChar(this.lines[a].substr(e, 1)), d.height + d.yoffset > c && (c = d.height + d.yoffset);
  3273. return c
  3274. };
  3275. BitmapText.prototype.write = function(a) {
  3276. var c, d, e, f, g, h, l, k;
  3277. a += "";
  3278. if (0 < this.maxWidth) {
  3279. f = a.split(BitmapText.LINES_DELIMITER);
  3280. c = [];
  3281. for (e = 0; e < f.length; e++) {
  3282. d = f[e].split(" ");
  3283. a = "";
  3284. for (l = 0; l < d.length; l++) this.lines = [a + d[l]], this.getWidthOfLine(0) > this.maxWidth ? (c.push(a), a = d[l] + " ") : a += d[l] + " ";
  3285. c.push(a)
  3286. }
  3287. a = c.join(BitmapText.LINES_DELIMITER)
  3288. }
  3289. this.text = a;
  3290. this.lines = a.split(BitmapText.LINES_DELIMITER);
  3291. this.manageSprites(a);
  3292. a = this.x;
  3293. f = this.y;
  3294. l = this.getHeight();
  3295. this.valign == BitmapText.VALIGN_MIDDLE && (f = this.y -
  3296. l / 2 * this.scale);
  3297. this.valign == BitmapText.VALIGN_BOTTOM && (f = this.y - l * this.scale);
  3298. var m = 0,
  3299. n = 0;
  3300. for (l = 0; l < this.lines.length; l++) {
  3301. k = this.getHeightOfLine(l);
  3302. this.align == BitmapText.ALIGN_CENTER && (a = this.x - this.getWidthOfLine(l) / 2 * this.scale);
  3303. this.align == BitmapText.ALIGN_RIGHT && (a = this.x - this.getWidthOfLine(l) * this.scale);
  3304. g = new Vector(a - this.x, f - this.y + n);
  3305. g.rotate(-this.rotation);
  3306. a = g.x + this.x;
  3307. e = g.y + this.y;
  3308. n += (k + this.lineSpacing) * this.scale;
  3309. g = new Vector(0, 0);
  3310. for (var p = 0; p < this.lines[l].length; p++) d = this.sprites[m],
  3311. m++, d.visible = !0, (c = this.getChar(this.lines[l].substr(p, 1))) ? (d.bitmap = this.font[c.page ? c.page : 0], d.width = c.width, d.height = c.height, d.offset.left = c.x, d.offset.top = c.y, d.anchor.x = -c.width / 2, d.anchor.y = -c.height / 2, h = g.clone(), h.x += c.xoffset * this.scale, h.y += (c.yoffset - k / 2) * this.scale, h.rotate(-this.rotation), d.x = h.x + a, d.y = h.y + e, d.scaleX = d.scaleY = this.scale, d.rotation = this.rotation, d.setStatic(this.static), d.ignoreViewport = this.ignoreViewport, d.opacity = this.opacity, d.gx = d.x, d.gy = d.y, d.gscaleX = d.scaleX,
  3312. d.gscaleY = d.scaleY, d.grotation = d.rotation, d.gopacity = d.opacity, g.x += (c.xadvance + this.charSpacing) * this.scale, "number" == typeof this.zIndex && d.zIndex != this.zIndex && d.setZIndex(this.zIndex)) : d.visible = !1
  3313. }
  3314. };
  3315. BitmapText.prototype.setStatic = function(a) {
  3316. a = !!a;
  3317. this.static != a && (this.static = a, this.refresh())
  3318. };
  3319. BitmapText.prototype.setZIndex = function(a) {
  3320. this.zIndex = a;
  3321. for (var c = 0; c < this.sprites.length; c++) this.sprites[c].setZIndex(a)
  3322. };
  3323. BitmapText.prototype.addToGroup = function(a) {
  3324. for (var c = 0; c < this.sprites.length; c++) this.sprites[c].gx = this.sprites[c].x / 2, this.sprites[c].gy = this.sprites[c].y, a.addChild(this.sprites[c], !1)
  3325. };
  3326. BitmapText.prototype.putToGroup = function(a) {
  3327. for (var c = 0; c < this.sprites.length; c++) this.sprites[c].gx = this.sprites[c].x, this.sprites[c].gy = this.sprites[c].y, a.addChild(this.sprites[c], !1)
  3328. };
  3329. BitmapText.prototype.refresh = function() {
  3330. this.write(this.text)
  3331. };
  3332. BitmapText.prototype.refreshOnTween = function(a) {
  3333. a.target.obj.refresh()
  3334. };
  3335. BitmapText.prototype.setPosition = function(a, c) {
  3336. this.x = a;
  3337. this.y = c;
  3338. this.refresh()
  3339. };
  3340. BitmapText.prototype.removeTweens = function() {
  3341. this.stage && this.stage.clearObjectTweens(this)
  3342. };
  3343. BitmapText.prototype.addTween = function(a, c, d, e, f, g) {
  3344. if (this.stage) {
  3345. var h = this[a];
  3346. if (!isNaN(h)) return a = stage.createTween(this, a, h, c, d, e), a.onchange = g, a.onfinish = f, a
  3347. }
  3348. };
  3349. BitmapText.prototype.moveTo = function(a, c, d, e, f, g) {
  3350. d = ~~d;
  3351. if (0 >= d) this.setPosition(a, c);
  3352. else {
  3353. if (a = this.addTween("x", a, d, e, f, g)) a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween), a.play();
  3354. if (c = this.addTween("y", c, d, e, a ? null : f, a ? null : g)) c.addEventListener("change", this.refreshOnTween), c.addEventListener("finish", this.refreshOnTween), c.play()
  3355. }
  3356. return this
  3357. };
  3358. BitmapText.prototype.moveBy = function(a, c, d, e, f, g) {
  3359. return this.moveTo(this.x + a, this.y + c, d, e, f, g)
  3360. };
  3361. BitmapText.prototype.fadeTo = function(a, c, d, e, f) {
  3362. c = ~~c;
  3363. if (0 >= c) this.opacity = a;
  3364. else if (a = this.addTween("opacity", a, c, d, e, f)) a.play(), a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween);
  3365. return this
  3366. };
  3367. BitmapText.prototype.fadeBy = function(a, c, d, e, f) {
  3368. a = Math.max(0, Math.min(1, this.opacity + a));
  3369. return this.fadeTo(a, c, d, e, f)
  3370. };
  3371. BitmapText.prototype.rotateTo = function(a, c, d, e, f) {
  3372. c = ~~c;
  3373. if (0 >= c) this.rotation = a;
  3374. else if (a = this.addTween("rotation", a, c, d, e, f)) a.play(), a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween);
  3375. return this
  3376. };
  3377. BitmapText.prototype.rotateBy = function(a, c, d, e, f) {
  3378. return this.rotateTo(this.rotation + a, c, d, e, f)
  3379. };
  3380. BitmapText.prototype.scaleTo = function(a, c, d, e, f) {
  3381. c = ~~c;
  3382. if (0 >= c) this.scale = a;
  3383. else if (a = this.addTween("scale", a, c, d, e, f)) a.play(), a.addEventListener("change", this.refreshOnTween), a.addEventListener("finish", this.refreshOnTween);
  3384. return this
  3385. };
  3386. function TilesSprite(a, c, d, e, f, g) {
  3387. TilesSprite.superclass.constructor.call(this, a, c, d, f, g);
  3388. this.framesCount = e;
  3389. this.animated = 1 < e;
  3390. this.addEventListener("changeframe", TilesSprite.changeStep);
  3391. this.addEventListener("prerender", TilesSprite.sync)
  3392. }
  3393. Utils.extend(TilesSprite, Sprite);
  3394. TilesSprite.prototype.currentFrameX = 0;
  3395. TilesSprite.create = function(a, c) {
  3396. if ("string" == typeof a) {
  3397. c = c || window.library;
  3398. if (!c) throw Error("Could not create sprite from asset '%s'. Library not found.", a);
  3399. a = c.getAsset(a)
  3400. }
  3401. return new TilesSprite(a.bitmap, a.width || 1, a.height || 1, a.framesCount || (a.frames || 1) * (a.layers || 1), a.frames || 1, a.layers || 1)
  3402. };
  3403. TilesSprite.prototype.gotoAndStop = function(a) {
  3404. this.currentFrameX = a;
  3405. this.stop()
  3406. };
  3407. TilesSprite.prototype.gotoAndPlay = function(a) {
  3408. this.currentFrameX = a;
  3409. this.play()
  3410. };
  3411. TilesSprite.changeStep = function(a) {
  3412. a = a.target;
  3413. a.animated && (a.currentFrameX += a.animDirection, 0 < a.animDirection && a.currentFrameX >= a.framesCount && (a.currentFrameX = 0), 0 > a.animDirection && 0 > a.currentFrameX && (a.currentFrameX = a.framesCount - 1))
  3414. };
  3415. TilesSprite.sync = function(a) {
  3416. a = a.target;
  3417. a.currentLayer = Math.floor(a.currentFrameX / a.totalFrames);
  3418. a.currentFrame = a.currentFrameX - a.currentLayer * a.totalFrames
  3419. };
  3420. var assets = [{
  3421. name: "char_jump",
  3422. src: "anim/char_jump.png",
  3423. frames: 13,
  3424. layers: 2,
  3425. width: 54,
  3426. height: 48
  3427. }, {
  3428. name: "char_walk",
  3429. src: "anim/char_walk.png",
  3430. frames: 17,
  3431. layers: 2,
  3432. width: 56,
  3433. height: 44
  3434. }, {
  3435. name: "enemy_1",
  3436. src: "anim/enemy_1.png",
  3437. frames: 17,
  3438. layers: 2,
  3439. width: 60,
  3440. height: 48
  3441. }, {
  3442. name: "enemy_2",
  3443. src: "anim/enemy_2.png",
  3444. frames: 17,
  3445. layers: 2,
  3446. width: 60,
  3447. height: 48
  3448. }, {
  3449. name: "enemy_3",
  3450. src: "anim/enemy_3.png",
  3451. frames: 17,
  3452. layers: 2,
  3453. width: 60,
  3454. height: 48
  3455. }, {
  3456. name: "enemy_4",
  3457. src: "anim/enemy_4.png",
  3458. frames: 8,
  3459. layers: 1,
  3460. width: 42,
  3461. height: 40
  3462. }, {
  3463. name: "background_preview",
  3464. src: "background/background_preview.png",
  3465. frames: 1,
  3466. layers: 1,
  3467. width: 320,
  3468. height: 480
  3469. }, {
  3470. name: "bushes",
  3471. src: "background/bushes.png",
  3472. frames: 1,
  3473. layers: 1,
  3474. width: 320,
  3475. height: 156
  3476. }, {
  3477. name: "cloud_1",
  3478. src: "background/clouds/cloud_1.png",
  3479. frames: 1,
  3480. layers: 1,
  3481. width: 130,
  3482. height: 62
  3483. }, {
  3484. name: "cloud_2",
  3485. src: "background/clouds/cloud_2.png",
  3486. frames: 1,
  3487. layers: 1,
  3488. width: 98,
  3489. height: 44
  3490. }, {
  3491. name: "cloud_3",
  3492. src: "background/clouds/cloud_3.png",
  3493. frames: 1,
  3494. layers: 1,
  3495. width: 122,
  3496. height: 50
  3497. }, {
  3498. name: "cloud_4",
  3499. src: "background/clouds/cloud_4.png",
  3500. frames: 1,
  3501. layers: 1,
  3502. width: 80,
  3503. height: 48
  3504. }, {
  3505. name: "cloud_5",
  3506. src: "background/clouds/cloud_5.png",
  3507. frames: 1,
  3508. layers: 1,
  3509. width: 84,
  3510. height: 30
  3511. }, {
  3512. name: "crass",
  3513. src: "background/crass.png",
  3514. frames: 1,
  3515. layers: 1,
  3516. width: 320,
  3517. height: 96
  3518. }, {
  3519. name: "lvl_1",
  3520. src: "background/lvl_1.png",
  3521. frames: 1,
  3522. layers: 1,
  3523. width: 320,
  3524. height: 50
  3525. }, {
  3526. name: "lvl_2",
  3527. src: "background/lvl_2.png",
  3528. frames: 1,
  3529. layers: 1,
  3530. width: 320,
  3531. height: 50
  3532. }, {
  3533. name: "lvl_3",
  3534. src: "background/lvl_3.png",
  3535. frames: 1,
  3536. layers: 1,
  3537. width: 320,
  3538. height: 50
  3539. }, {
  3540. name: "mountains",
  3541. src: "background/mountains.png",
  3542. frames: 1,
  3543. layers: 1,
  3544. width: 320,
  3545. height: 218
  3546. }, {
  3547. name: "sky",
  3548. src: "background/sky.png",
  3549. frames: 1,
  3550. layers: 1,
  3551. width: 320,
  3552. height: 480
  3553. }, {
  3554. name: "trees",
  3555. src: "background/trees.png",
  3556. frames: 1,
  3557. layers: 1,
  3558. width: 320,
  3559. height: 210
  3560. }, {
  3561. name: "btn_back",
  3562. src: "btns/btn_back.png",
  3563. frames: 1,
  3564. layers: 1,
  3565. width: 80,
  3566. height: 80
  3567. }, {
  3568. name: "btn_facebook",
  3569. src: "btns/btn_facebook.png",
  3570. frames: 1,
  3571. layers: 1,
  3572. width: 62,
  3573. height: 62
  3574. }, {
  3575. name: "btn_logo",
  3576. src: "btns/btn_logo.png",
  3577. frames: 1,
  3578. layers: 1,
  3579. width: 52,
  3580. height: 52
  3581. }, {
  3582. name: "btn_more_games",
  3583. src: "btns/btn_more_games.png",
  3584. frames: 1,
  3585. layers: 1,
  3586. width: 52,
  3587. height: 52
  3588. }, {
  3589. name: "btn_more_games_1",
  3590. src: "btns/btn_more_games_1.png",
  3591. frames: 1,
  3592. layers: 1,
  3593. width: 62,
  3594. height: 62
  3595. }, {
  3596. name: "btn_restart",
  3597. src: "btns/btn_restart.png",
  3598. frames: 1,
  3599. layers: 1,
  3600. width: 138,
  3601. height: 138
  3602. }, {
  3603. name: "btn_sound",
  3604. src: "btns/btn_sound.png",
  3605. frames: 2,
  3606. layers: 1,
  3607. width: 44,
  3608. height: 44
  3609. }, {
  3610. name: "btn_twitter",
  3611. src: "btns/btn_twitter.png",
  3612. frames: 1,
  3613. layers: 1,
  3614. width: 62,
  3615. height: 62
  3616. }, {
  3617. name: "credits_1",
  3618. src: "credits/credits_1.png",
  3619. frames: 1,
  3620. layers: 1,
  3621. width: 250,
  3622. height: 422
  3623. }, {
  3624. name: "credits_2",
  3625. src: "credits/credits_2.png",
  3626. frames: 1,
  3627. layers: 1,
  3628. width: 250,
  3629. height: 422
  3630. }, {
  3631. name: "font_blue_en",
  3632. src: "fonts/font_blue_en.png",
  3633. frames: 1,
  3634. layers: 1,
  3635. width: 934,
  3636. height: 256
  3637. }, {
  3638. name: "font_blue_ru",
  3639. src: "fonts/font_blue_ru.png",
  3640. frames: 1,
  3641. layers: 1,
  3642. width: 319,
  3643. height: 256
  3644. }, {
  3645. name: "font_green_en",
  3646. src: "fonts/font_green_en.png",
  3647. frames: 1,
  3648. layers: 1,
  3649. width: 934,
  3650. height: 256
  3651. }, {
  3652. name: "font_green_ru",
  3653. src: "fonts/font_green_ru.png",
  3654. frames: 1,
  3655. layers: 1,
  3656. width: 319,
  3657. height: 256
  3658. }, {
  3659. name: "font_red_en",
  3660. src: "fonts/font_red_en.png",
  3661. frames: 1,
  3662. layers: 1,
  3663. width: 857,
  3664. height: 256
  3665. }, {
  3666. name: "font_red_ru",
  3667. src: "fonts/font_red_ru.png",
  3668. frames: 1,
  3669. layers: 1,
  3670. width: 304,
  3671. height: 256
  3672. }, {
  3673. name: "complete_preview",
  3674. src: "level_complete/complete_preview.png",
  3675. frames: 1,
  3676. layers: 1,
  3677. width: 320,
  3678. height: 558
  3679. }, {
  3680. name: "score_panel",
  3681. src: "level_complete/score_panel.png",
  3682. frames: 1,
  3683. layers: 1,
  3684. width: 286,
  3685. height: 222
  3686. }, {
  3687. name: "left_tile",
  3688. src: "tiles/left_tile.png",
  3689. frames: 1,
  3690. layers: 1,
  3691. width: 50,
  3692. height: 50
  3693. }, {
  3694. name: "right_tile",
  3695. src: "tiles/right_tile.png",
  3696. frames: 1,
  3697. layers: 1,
  3698. width: 50,
  3699. height: 50
  3700. }, {
  3701. name: "tile_1",
  3702. src: "tiles/tile_1.png",
  3703. frames: 1,
  3704. layers: 1,
  3705. width: 50,
  3706. height: 50
  3707. }, {
  3708. name: "logo",
  3709. src: "logo.png",
  3710. frames: 1,
  3711. layers: 1,
  3712. width: 304,
  3713. height: 242
  3714. }, {
  3715. name: "bg_left",
  3716. src: "tiles/bg_left.png",
  3717. frames: 1,
  3718. layers: 1,
  3719. width: 27,
  3720. height: 123
  3721. }, {
  3722. name: "bg_right",
  3723. src: "tiles/bg_right.png",
  3724. frames: 1,
  3725. layers: 1,
  3726. width: 27,
  3727. height: 123
  3728. },{
  3729. name: "cn_txt",
  3730. src: "cn/txt.png",
  3731. frames: 1,
  3732. layers: 1,
  3733. width: 240,
  3734. height: 50
  3735. }],
  3736. FaceBook = {
  3737. getUserInfo: function(a, c) {
  3738. FB.getLoginStatus(function(d) {
  3739. "connected" === d.status ? (flag_fb = 1, "function" === typeof a && a(c)) : FB.login(function(d) {
  3740. if (d.authResponse) flag_fb = 1, "function" === typeof a && a(c);
  3741. else return flag_fb = 0, !1
  3742. }, {
  3743. scope: "publish_actions"
  3744. })
  3745. })
  3746. },
  3747. postOnWall: function(a) {
  3748. FB.ui({
  3749. method: "feed",
  3750. name: "I've scored " + a + " in Jumping Snail game. You'll never beat me!",
  3751. link: "http://playtomax.com/details/Jumping-Snail",
  3752. picture: "http://public.playtomax.com/static/games/thumbs2x/jumping_snail.jpg",
  3753. description: "Jumping snail is an jumping game, where you climb up the tree, avoiding of nasty bugs.",
  3754. caption: "playtomax.com"
  3755. })
  3756. }
  3757. },
  3758. GAME_ID = "jumping_snail",
  3759. stage = null,
  3760. fps = 60,
  3761. pps = 1E3,
  3762. library = null,
  3763. GET = {},
  3764. LANDSCAPE_MODE = !1;
  3765. window.onload = function() {
  3766. GET = Utils.parseGet();
  3767. Utils.addMobileListeners(LANDSCAPE_MODE, !0);
  3768. Utils.mobileCorrectPixelRatio();
  3769. Utils.addFitLayoutListeners();
  3770. ExternalAPI.exec("init");
  3771. Utils.switchToTimeMode(1E3 / fps);
  3772. setTimeout(startLoad, 600)
  3773. };
  3774. function startLoad() {
  3775. var a = Utils.getMobileScreenResolution(LANDSCAPE_MODE);
  3776. GET.debug && (a = Utils.getScaleScreenResolution(1, LANDSCAPE_MODE));
  3777. if (Utils.mobileCheckSlowDevice() || Utils.isFirefox()) a = Utils.getScaleScreenResolution(1, LANDSCAPE_MODE);
  3778. Utils.globalScale = a.scale;
  3779. Utils.createLayout(document.getElementById(Utils.DOMMainContainerId), a);
  3780. Utils.addEventListener("fitlayout", function() {
  3781. stage && (stage.drawScene(stage.canvas), stage.drawScene(stage.backgroundCanvas, !0));
  3782. resizeCSSBack()
  3783. });
  3784. Utils.addEventListener("lockscreen",
  3785. function() {
  3786. stage && stage.started && stage.stop()
  3787. });
  3788. Utils.addEventListener("unlockscreen", function() {
  3789. stage && !stage.started && stage.start()
  3790. });
  3791. Utils.mobileHideAddressBar();
  3792. UserSettings.load();
  3793. I18.initLocale();
  3794. ["font_blue", "font_green", "font_red"].forEach(function(a) {
  3795. GU.addJSFile("js/fonts/" + a + "_" + I18.currentLocale + ".js")
  3796. });
  3797. GET.debug || Utils.checkOrientation(LANDSCAPE_MODE);
  3798. library = new AssetsLibrary("images", Utils.globalScale, assets);
  3799. TTLoader.create(loadSoundsEnd, !0, 1 == GET.debug);
  3800. library.load(loadImagesEnd,
  3801. TTLoader.showLoadProgress, 0, 50)
  3802. }
  3803. function loadImagesEnd() {
  3804. for (var a = [], c = 0; c < SoundUtils.tracks.length; c++) a.push("sounds/" + SoundUtils.tracks[c]);
  3805. c = new SoundsPreloader;
  3806. c.maxProgressVal = 50;
  3807. c.minProgressVal = 50;
  3808. c.load(a, TTLoader.loadComplete, TTLoader.showLoadProgress)
  3809. }
  3810. function loadSoundsEnd() {
  3811. SoundUtils.setMixer();
  3812. SoundUtils.playBack();
  3813. Utils.showMainLayoutContent();
  3814. createScene()
  3815. }
  3816. var backgroundImage = null;
  3817. function setCSSBack(a) {
  3818. if (a) {
  3819. backgroundImage = a;
  3820. var c = document.getElementById("screen_background_container");
  3821. c.style.backgroundImage = "url(" + a.src + ")";
  3822. c.style.backgroundRepeat = "repeat"
  3823. }
  3824. resizeCSSBack()
  3825. }
  3826. function resizeCSSBack() {
  3827. backgroundImage && Utils.getWindowRect()
  3828. }
  3829. function createStage() {
  3830. stage && (stage.destroy(), stage.stop());
  3831. stage = new Stage("screen", 320, 480, !1);
  3832. stage.setBackgroundCanvas("screen_background");
  3833. stage.delay = 1E3 / fps;
  3834. stage.ceilSizes = !0;
  3835. stage.showFPS = !1
  3836. }
  3837. function createScene() {
  3838. createStage();
  3839. setCSSBack(library.getBitmap("tile_1"));
  3840. MainScene.start();
  3841. stage.start();
  3842. stage.refreshBackground()
  3843. }
  3844. function getGameDataId() {
  3845. return "playtomax_" + GAME_ID + "_data"
  3846. }
  3847. function showMoreGames() {
  3848. if(document.referrer){
  3849. // Play68.goHome();
  3850. }else{
  3851. // play68_goHome();
  3852. }
  3853. /*window.open(ExternalAPI.exec("getMoreGamesURL"), "_blank");
  3854. return !1*/
  3855. }
  3856. function getStageWidth() {
  3857. return Math.floor(LANDSCAPE_MODE ? 480 : 320)
  3858. }
  3859. function getStageHeight() {
  3860. return Math.floor(LANDSCAPE_MODE ? 320 : 480)
  3861. }
  3862. function getStageWidthCenter() {
  3863. return getStageWidth() / 2
  3864. }
  3865. function getStageHeightCenter() {
  3866. return getStageHeight() / 2
  3867. }
  3868. var I18 = {
  3869. currentLocale: "en",
  3870. supportedLanguage: ["en", "ru"],
  3871. strings: {},
  3872. init: function(a) {
  3873. Utils.get("localization/" + I18.currentLocale + ".csv", null, null, function(c) {
  3874. var d = {};
  3875. c = c.split("\n");
  3876. for (var e, f = 0; f < c.length; f++) e = c[f].split(";"), d[I18.trim(e[0])] = I18.trim(e[1]);
  3877. I18.setup(d);
  3878. "function" === typeof a && a()
  3879. })
  3880. },
  3881. initLocale: function() {
  3882. if (!I18.currentLocale) {
  3883. var a = window.navigator.language ? window.navigator.language.substr(0, 2) : "";
  3884. 0 > I18.supportedLanguage.indexOf(a) && (a = I18.supportedLanguage[0]);
  3885. I18.currentLocale =
  3886. a
  3887. }
  3888. },
  3889. setup: function(a) {
  3890. I18.strings = a
  3891. },
  3892. trim: function(a) {
  3893. return a ? a.replace(/^\s+|\s+$/gm, "") : ""
  3894. },
  3895. arrayAntidot: function(a) {
  3896. if (a) return 0 < a.length && Utils.isArray(a[0]) ? a[0] : a
  3897. },
  3898. getString: function(a, c) {
  3899. "undefined" == typeof c && (c = null);
  3900. var d = I18.getStringOrNull(a, c);
  3901. return null == d ? "{" + a + "}" : d
  3902. },
  3903. getStringOrNull: function(a, c) {
  3904. "undefined" == typeof c && (c = null);
  3905. var d = I18.strings[a];
  3906. "undefined" == typeof d && (d = null);
  3907. if (null == c || null == d) return d;
  3908. c = [d].concat(I18.arrayAntidot(c));
  3909. return I18.sprintf.apply(I18, c)
  3910. },
  3911. f: function(a) {
  3912. var c =
  3913. I18.arrayAntidot(Array.prototype.slice.call(arguments, 1));
  3914. Utils.isArray(c) || (c = [c]);
  3915. return I18.getString(a, c)
  3916. },
  3917. s: function(a, c, d) {
  3918. Utils.isArray(d) || (d = [d]);
  3919. return I18.getString(a + "_" + c, I18.arrayAntidot(d))
  3920. },
  3921. sf: function(a, c, d) {
  3922. return I18.getString(a + "_" + c, I18.arrayAntidot(d))
  3923. },
  3924. psf: function(a, c, d, e, f) {
  3925. return I18.getString(a + "_" + c + "_" + d, I18.arrayAntidot(e))
  3926. },
  3927. sprintf: function() {
  3928. var a = arguments,
  3929. c = 0,
  3930. d = function(a, c, d, e) {
  3931. d || (d = " ");
  3932. c = a.length >= c ? "" : Array(1 + c - a.length >>> 0).join(d);
  3933. return e ? a + c : c + a
  3934. },
  3935. e = function(a,
  3936. c, e, f, m, n) {
  3937. var p = f - a.length;
  3938. 0 < p && (a = e || !m ? d(a, f, n, e) : a.slice(0, c.length) + d("", p, "0", !0) + a.slice(c.length));
  3939. return a
  3940. },
  3941. f = function(a, c, f, k, m, n, p) {
  3942. a >>>= 0;
  3943. f = f && a && {
  3944. 2: "0b",
  3945. 8: "0",
  3946. 16: "0x"
  3947. }[c] || "";
  3948. a = f + d(a.toString(c), n || 0, "0", !1);
  3949. return e(a, f, k, m, p)
  3950. };
  3951. return a[c++].replace(/%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuideEfFgG])/g, function(g, h, l, k, m, n, p) {
  3952. var q, u;
  3953. if ("%%" === g) return "%";
  3954. var t = !1;
  3955. u = "";
  3956. var v = m = !1;
  3957. q = " ";
  3958. for (var x = l.length, w = 0; l && w < x; w++) switch (l.charAt(w)) {
  3959. case " ":
  3960. u = " ";
  3961. break;
  3962. case "+":
  3963. u = "+";
  3964. break;
  3965. case "-":
  3966. t = !0;
  3967. break;
  3968. case "'":
  3969. q = l.charAt(w + 1);
  3970. break;
  3971. case "0":
  3972. m = !0;
  3973. q = "0";
  3974. break;
  3975. case "#":
  3976. v = !0
  3977. }
  3978. k = k ? "*" === k ? +a[c++] : "*" == k.charAt(0) ? +a[k.slice(1, -1)] : +k : 0;
  3979. 0 > k && (k = -k, t = !0);
  3980. if (!isFinite(k)) throw Error("sprintf: (minimum-)width must be finite");
  3981. n = n ? "*" === n ? +a[c++] : "*" == n.charAt(0) ? +a[n.slice(1, -1)] : +n : -1 < "fFeE".indexOf(p) ? 6 : "d" === p ? 0 : void 0;
  3982. h = h ? a[h.slice(0, -1)] : a[c++];
  3983. switch (p) {
  3984. case "s":
  3985. return p = String(h), null != n && (p = p.slice(0, n)), e(p, "", t, k, m, q);
  3986. case "c":
  3987. return p = String.fromCharCode(+h),
  3988. null != n && (p = p.slice(0, n)), e(p, "", t, k, m, void 0);
  3989. case "b":
  3990. return f(h, 2, v, t, k, n, m);
  3991. case "o":
  3992. return f(h, 8, v, t, k, n, m);
  3993. case "x":
  3994. return f(h, 16, v, t, k, n, m);
  3995. case "X":
  3996. return f(h, 16, v, t, k, n, m).toUpperCase();
  3997. case "u":
  3998. return f(h, 10, v, t, k, n, m);
  3999. case "i":
  4000. case "d":
  4001. return q = +h || 0, q = Math.round(q - q % 1), g = 0 > q ? "-" : u, h = g + d(String(Math.abs(q)), n, "0", !1), e(h, g, t, k, m);
  4002. case "e":
  4003. case "E":
  4004. case "f":
  4005. case "F":
  4006. case "g":
  4007. case "G":
  4008. return q = +h, g = 0 > q ? "-" : u, u = ["toExponential", "toFixed", "toPrecision"]["efg".indexOf(p.toLowerCase())], p = ["toString",
  4009. "toUpperCase"
  4010. ]["eEfFgG".indexOf(p) % 2], h = g + Math.abs(q)[u](n), e(h, g, t, k, m)[p]();
  4011. default:
  4012. return g
  4013. }
  4014. })
  4015. }
  4016. },
  4017. UserSettings = {
  4018. cookieObj: {},
  4019. load: function() {
  4020. var a = Utils.getCookie(getGameDataId());
  4021. a && (UserSettings.cookieObj = JSON.parse(a));
  4022. UserSettings.music = 1;
  4023. UserSettings.points = UserSettings.cookieObj.points || 0;
  4024. UserSettings.skin = UserSettings.cookieObj.skin || 0
  4025. },
  4026. save: function() {
  4027. UserSettings.cookieObj.music = UserSettings.music;
  4028. UserSettings.cookieObj.points = UserSettings.points;
  4029. Utils.setCookie(getGameDataId(), JSON.stringify(UserSettings.cookieObj))
  4030. },
  4031. reset: function() {
  4032. UserSettings.cookieObj.points = 0;
  4033. UserSettings.save()
  4034. }
  4035. },
  4036. GameConfig = {
  4037. level: {}
  4038. };
  4039. GameConfig.level.borderWidth = 20;
  4040. GameConfig.level.topBorderHeight = 65;
  4041. GameConfig.level.bottomBorderHeight = 90;
  4042. GameConfig.level.speedY = 220;
  4043. GameConfig.level.doubleTapDuration = 800;
  4044. GameConfig.snail = {};
  4045. GameConfig.snail.speedX = 130;
  4046. GameConfig.snail.hitAreaRadius = 12;
  4047. GameConfig.snail.jumpDuration = 400;
  4048. GameConfig.snail.jumpHighDuration = 300;
  4049. GameConfig.snail.jumpPostHighDuration = 200;
  4050. GameConfig.snail.jumpEasing = "cubic.easeOut";
  4051. GameConfig.snail.jumpFallEasing = "cubic.easeIn";
  4052. GameConfig.snail.jumpHighEasing = "cubic.easeOut";
  4053. GameConfig.snail.jumpPostHighEasing = "cubic.easeIn";
  4054. GameConfig.snail.jumpSpeedXKoef = 1.6;
  4055. GameConfig.stick = {};
  4056. GameConfig.stick.y0 = 165;
  4057. GameConfig.stick.dY = 110;
  4058. GameConfig.enemy = {};
  4059. GameConfig.enemy.speeds = [60, 70, 80, 90, 100];
  4060. var SoundUtils = {
  4061. tracks: "fail jump landing music tap win".split(" "),
  4062. soundEnable: !1,
  4063. effectEnable: !1,
  4064. mixer: null,
  4065. soundBtn: null,
  4066. effectBtn: null,
  4067. iosMode: !1,
  4068. android: !1,
  4069. currentTrack: "",
  4070. channel_cnt: 10,
  4071. playBack: function() {
  4072. SoundUtils.mixer && SoundUtils.soundEnable && "music" != SoundUtils.currentTrack && (SoundUtils.mixer.play("music", !0, !1, 0), SoundUtils.currentTrack = "music")
  4073. },
  4074. setMixer: function() {
  4075. SoundUtils.iosMode = -1 != navigator.userAgent.toLowerCase().indexOf("mac");
  4076. Utils.isAndroid() && (SoundUtils.android = !0);
  4077. var a =
  4078. AudioMixer.isWebAudioSupport() ? SoundUtils.channel_cnt : 1;
  4079. SoundUtils.mixer = new AudioMixer("sounds", a);
  4080. 1 == UserSettings.music && (SoundUtils.soundEnable = !0, SoundUtils.effectEnable = !0)
  4081. },
  4082. setSoundBtn: function() {
  4083. SoundUtils.soundBtn.gotoAndStop(SoundUtils.soundEnable ? 0 : 1)
  4084. },
  4085. switchSoundBtn: function() {
  4086. if (!SoundUtils.soundBtn) return !1;
  4087. SoundUtils.soundEnable ? SoundUtils.offSoundBtn() : SoundUtils.onSoundBtn();
  4088. return !1
  4089. },
  4090. onSoundBtn: function() {
  4091. if (!SoundUtils.soundBtn) return !1;
  4092. SoundUtils.soundBtn.gotoAndStop(0);
  4093. SoundUtils.soundEnable = !0;
  4094. SoundUtils.playBack();
  4095. UserSettings.music = 1;
  4096. UserSettings.save()
  4097. },
  4098. offSoundBtn: function() {
  4099. if (!SoundUtils.soundBtn || !SoundUtils.mixer) return !1;
  4100. SoundUtils.soundBtn.gotoAndStop(1);
  4101. SoundUtils.soundEnable = !1;
  4102. SoundUtils.mixer.stop(0);
  4103. SoundUtils.currentTrack = "";
  4104. UserSettings.music = 0;
  4105. UserSettings.save()
  4106. },
  4107. playEffect: function(a) {
  4108. if (!AudioMixer.isWebAudioSupport()) return !1;
  4109. SoundUtils.mixer && SoundUtils.soundEnable && SoundUtils.mixer.play(a, !1, !0)
  4110. }
  4111. },
  4112. GU = {
  4113. addJSFile: function(a) {
  4114. var c = document.createElement("script");
  4115. c.src = a;
  4116. document.getElementsByTagName("head")[0].appendChild(c)
  4117. },
  4118. destroyMeAfterTween: function(a) {
  4119. a.target.obj.destroy = !0
  4120. },
  4121. preventMe: function() {
  4122. return !1
  4123. },
  4124. setS: function(a, c, d, e, f) {
  4125. c = c ? library.getSprite(c ? c : null, null, OwnSprite) : new OwnSprite(null, 1, 1);
  4126. c.setPosition(d, e);
  4127. GU.applyProperties(c, f);
  4128. a.addChild(c);
  4129. return c
  4130. },
  4131. setTS: function(a, c, d, e, f) {
  4132. c = library.getAsset(c);
  4133. c = new TilesSprite(c.bitmap, c.width, c.height, f._frames, c.frames, c.layers);
  4134. GU.applyProperties(c, f);
  4135. c.setPosition(d, e);
  4136. a.addChild(c);
  4137. return c
  4138. },
  4139. setG: function(a, c, d, e, f) {
  4140. c = new Graphics[c](d, e);
  4141. GU.applyProperties(c, f);
  4142. a.addChild(c);
  4143. return c
  4144. },
  4145. setGT: function(a, c, d, e, f) {
  4146. c = new Graphics.text(d, e, c);
  4147. GU.applyProperties(c, f);
  4148. a.addChild(c);
  4149. return c
  4150. },
  4151. setST: function(a, c, d, e, f, g) {
  4152. c = library.getAsset(c);
  4153. c = new SimpleText(c.bitmap, c.width, c.height, c.frames);
  4154. c.setPosition(e, f);
  4155. c.parent = a;
  4156. GU.applyProperties(c, g);
  4157. c.write(d);
  4158. return c
  4159. },
  4160. setBT: function(a, c, d, e, f, g) {
  4161. c = c + "_" + I18.currentLocale;
  4162. var h = window[c];
  4163. c = new BitmapText(library.getBitmap(c), h);
  4164. c.setPosition(e,
  4165. f);
  4166. c.parent = a;
  4167. GU.applyProperties(c, g);
  4168. c.write(d);
  4169. return c
  4170. },
  4171. applyProperties: function(a, c) {
  4172. var d, e;
  4173. for (e in c) d = c[e], "zI" == e || "zIndex" == e ? a.setZIndex(d) : "static" == e || "s" == e ? a.setStatic(d) : "w" == e ? a.width = d : "h" == e ? a.height = d : "fC" == e ? a.fillColor = d : "o" == e ? a.opacity = d : "r" == e ? a.rotation = d : "a" == e ? a.align = d : "vA" == e ? a.valign = d : a[e] = d
  4174. }
  4175. };
  4176. GU.center = {
  4177. x: getStageWidthCenter(),
  4178. y: getStageHeightCenter()
  4179. };
  4180. GU.Math = {};
  4181. GU.Math.calcLength = function(a, c, d, e) {
  4182. a -= d;
  4183. c -= e;
  4184. return ~~Math.sqrt(a * a + c * c)
  4185. };
  4186. GU.Math.calcAngle = function(a, c, d, e, f) {
  4187. a = Math.atan2(c - e, a - d);
  4188. if (f) return a;
  4189. a = ~~Utils.radian2grad(a);
  4190. 0 > a && (a = 360 + a);
  4191. return a
  4192. };
  4193. GU.Math.circleIntersectLine = function(a, c, d, e, f, g, h) {
  4194. var l = Math.calcLength(e, f, c, d),
  4195. k = Math.calcLength(g, h, c, d);
  4196. if (l <= a || k <= a) return !0;
  4197. var k = (h - f) / (g - e),
  4198. l = -1 / k,
  4199. l = (k * e - f - l * c + d) / (k - l),
  4200. k = k * (l - e) + f,
  4201. m = !0;
  4202. g > e ? l >= e && l <= g || (m = !1) : l >= g && l <= e || (m = !1);
  4203. h > f ? k >= f && k <= h || (m = !1) : k >= h && k <= f || (m = !1);
  4204. return m ? Math.calcLength(c, d, l, k) < a ? !0 : !1 : !1
  4205. };
  4206. GU.Math.circleIntersectRect = function(a, c, d, e, f, g, h) {
  4207. return g < c ? f < a ? (f - a) * (f - a) + (g - c) * (g - c) <= h * h : f > d ? (f - d) * (f - d) + (g - c) * (g - c) <= h * h : c - g <= h : g > e ? f < a ? (f - a) * (f - a) + (g - e) * (g - e) <= h * h : f > d ? (f - d) * (f - d) + (g - e) * (g - e) <= h * h : g - e <= h : f < a ? a - f <= h : f > d ? f - d <= h : f - a <= h || d - f <= h || g - c <= h || e - g <= h
  4208. };
  4209. GU.Math.getRandomValue = function(a, c) {
  4210. return Math.floor(Math.random() * (c + 1 - a)) + a
  4211. };
  4212. GU.Array = {};
  4213. GU.Array.getRandomValue = function(a) {
  4214. var c = Math.floor(Math.random() * a.length);
  4215. return a[c]
  4216. };
  4217. GU.Array.isPresentValue = function(a, c) {
  4218. return 0 <= a.indexOf(c)
  4219. };
  4220. GU.Array.deleteElement = function(a, c) {
  4221. a.splice(a.indexOf(c), 1)
  4222. };
  4223. function OwnSprite(a, c, d, e, f) {
  4224. Utils.callSuperConstructor(OwnSprite, this, a, c, d, e, f)
  4225. }
  4226. Utils.extend(OwnSprite, Sprite);
  4227. OwnSprite.prototype.preventAllEvents = function() {
  4228. this.addEventListener("mousedown", GU.preventMe);
  4229. this.addEventListener("mouseup", GU.preventMe);
  4230. this.addEventListener("mousemove", GU.preventMe);
  4231. this.addEventListener("mouseout", GU.preventMe);
  4232. this.addEventListener("mouseover", GU.preventMe);
  4233. this.addEventListener("click", GU.preventMe)
  4234. };
  4235. OwnSprite.prototype.dd = function() {
  4236. this.onmousedown = function(a) {
  4237. this.startDrag(a.x, a.y);
  4238. return !1
  4239. };
  4240. this.onmouseup = function(a) {
  4241. this.stopDrag();
  4242. console.log(~~this.x, ~~this.y);
  4243. return !1
  4244. }
  4245. };
  4246. OwnSprite.prototype.destroyMe = function() {
  4247. this.destroy = !0
  4248. };
  4249. OwnSprite.prototype.checkStaticSprites = function(a) {
  4250. function c(d) {
  4251. d.static || (a && console.log(d[a]), e++);
  4252. if (d.objects)
  4253. for (var f = 0; f < d.objects.length; f++) c(d.objects[f])
  4254. }
  4255. function d(c) {
  4256. c.static && (a && console.log(c[a]), h++);
  4257. if (c.objects)
  4258. for (var e = 0; e < c.objects.length; e++) d(c.objects[e])
  4259. }
  4260. console.log("-----------------------\x3e");
  4261. console.log("DYNAMIC SPRITES:");
  4262. for (var e = 0, f = 0; f < this.objects.length; f++) {
  4263. var g = this.objects[f];
  4264. c(g)
  4265. }
  4266. console.log("Total dynamic count: " + e);
  4267. console.log("STATIC SPRITES:");
  4268. for (var h =
  4269. 0, f = 0; f < this.objects.length; f++) g = this.objects[f], d(g);
  4270. console.log("Total static count: " + h);
  4271. console.log("<-----------------------")
  4272. };
  4273. function Button(a, c, d, e, f) {
  4274. Utils.callSuperConstructor(Button, this, null, 1, 1);
  4275. a = library.getAsset("name");
  4276. this.bitmap = a.bitmap;
  4277. this.width = a.width;
  4278. this.height = a.height;
  4279. this.totalFrames = a.frames;
  4280. this.totalLayers = a.layers;
  4281. this.mouseDownHandler = Utils.proxy(this.mouseDownHandler, this);
  4282. this.mouseUpHandler = Utils.proxy(this.mouseUpHandler, this);
  4283. this.mouseOverHandler = Utils.proxy(this.mouseOverHandler, this);
  4284. this.mouseDownHandler = Utils.proxy(this.mouseDownHandler, this);
  4285. this.mouseMoveHandler = Utils.proxy(this.mouseMoveHandler,
  4286. this);
  4287. this.clickHandler = Utils.proxy(this.clickHandler, this)
  4288. }
  4289. Utils.extend(Button, OwnSprite);
  4290. Button.prototype.addListeners = function() {
  4291. this.addEventListener("mousedown", this.mouseDownHandler);
  4292. this.addEventListener("mouseup", this.mouseUpHandler);
  4293. this.addEventListener("mousemove", this.mouseMoveHandler);
  4294. this.addEventListener("mouseover", this.mouseOverHandler);
  4295. this.addEventListener("mouseout", this.mouseOutHandler);
  4296. this.addEventListener("click", this.clickHandler)
  4297. };
  4298. Button.prototype.setStartSkin = function() {};
  4299. Button.prototype.mouseDownHandler = function() {};
  4300. Button.prototype.mouseUpHandler = function() {};
  4301. Button.prototype.mouseOverHandler = function() {};
  4302. Button.prototype.mouseOutHandler = function() {};
  4303. Button.prototype.mouseMoveHandler = function() {};
  4304. Button.prototype.clickHandler = function() {};
  4305. function Enemy() {
  4306. this.type = GU.Math.getRandomValue(1, 4);
  4307. var a = library.getAsset("enemy_" + this.type);
  4308. Utils.callSuperConstructor(Enemy, this, a.bitmap, a.width, a.height, a.frames * a.layers, a.frames, a.layers);
  4309. this.changeFrameDelay = pps / 24;
  4310. this.direction = GU.Math.getRandomValue(Enemy.DIRECTION_RIGHT, Enemy.DIRECTION_LEFT);
  4311. this.scaleX = this.direction == Enemy.DIRECTION_RIGHT ? 1 : -1;
  4312. this.speedX = GU.Array.getRandomValue(GameConfig.enemy.speeds);
  4313. this.collisionArea = {
  4314. r: 4 != this.type ? 22 : 18
  4315. }
  4316. }
  4317. Utils.extend(Enemy, TilesSprite);
  4318. Enemy.prototype.set = function() {
  4319. this.setPosition(100, -25)
  4320. };
  4321. Enemy.prototype.changeDirection = function() {
  4322. this.direction = !this.direction;
  4323. this.scaleX *= -1
  4324. };
  4325. Enemy.prototype.step = function(a) {
  4326. a *= this.speedX / 1E3;
  4327. this.x += this.direction == Snail.DIRECTION_RIGHT ? a : -a;
  4328. this.x >= GU.center.x - GameConfig.level.borderWidth && this.direction == Enemy.DIRECTION_RIGHT ? this.changeDirection() : this.x <= -GU.center.x + GameConfig.level.borderWidth && this.direction == Enemy.DIRECTION_LEFT && this.changeDirection()
  4329. };
  4330. Enemy.DIRECTION_RIGHT = 0;
  4331. Enemy.DIRECTION_LEFT = 1;
  4332. Enemy.add = function(a) {
  4333. var c = new Enemy;
  4334. a.addChild(c);
  4335. c.set();
  4336. return c
  4337. };
  4338. function Stick(a) {
  4339. this.id = a;
  4340. this.enemy = null;
  4341. this.type = GU.Math.getRandomValue(1, 3);
  4342. Utils.callSuperConstructor(Stick, this, null, 1, 1)
  4343. }
  4344. Utils.extend(Stick, OwnSprite);
  4345. Stick.prototype.set = function() {
  4346. var a = GameConfig.stick.y0 - this.id * GameConfig.stick.dY;
  4347. this.stickSpr = 0 == this.id ? GU.setS(this, "crass", 0, 32) : GU.setS(this, "lvl_" + this.type, 0, 0);
  4348. this.setPosition(0, a);
  4349. this.checkIsEmpty() || this.setEnemy()
  4350. };
  4351. Stick.prototype.setEnemy = function() {
  4352. this.enemy = Enemy.add(this.stickSpr)
  4353. };
  4354. Stick.prototype.trim = function() {
  4355. 0 != this.id && Animation.play(this.stickSpr, [{
  4356. tweens: [{
  4357. prop: "y",
  4358. to: 5,
  4359. ease: Easing.quadratic.easeIn
  4360. }],
  4361. duration: 100
  4362. }, {
  4363. tweens: [{
  4364. prop: "y",
  4365. to: 0,
  4366. ease: Easing.bounce.easeOut
  4367. }],
  4368. duration: 600
  4369. }])
  4370. };
  4371. Stick.prototype.checkIsEmpty = function() {
  4372. for (var a = 0, c = 0, d = !1; c <= this.id;) c += a, a++, c == this.id && (d = !0);
  4373. return d
  4374. };
  4375. Stick.add = function(a, c) {
  4376. var d = new Stick(c);
  4377. a.addChild(d);
  4378. d.set();
  4379. return d
  4380. };
  4381. function Snail() {
  4382. var a = library.getAsset("char_walk");
  4383. Utils.callSuperConstructor(Snail, this, a.bitmap, a.width, a.height, a.frames * a.layers, a.frames, a.layers);
  4384. this.endJump = Utils.proxy(this.endJump, this);
  4385. this.checkJump = Utils.proxy(this.checkJump, this);
  4386. this.changeDirection = Utils.proxy(this.changeDirection, this);
  4387. this.checkSkinFrame = Utils.proxy(this.checkSkinFrame, this);
  4388. this.changeFrameDelay = pps / 24;
  4389. this.stickId = 0;
  4390. this.direction = Snail.DIRECTION_RIGHT;
  4391. this.collisionArea = {
  4392. r: 22
  4393. }
  4394. }
  4395. Utils.extend(Snail, TilesSprite);
  4396. Snail.prototype.set = function() {
  4397. this.setPosition(0, GameConfig.stick.y0 - 25)
  4398. };
  4399. Snail.prototype.startInMenu = function() {
  4400. this.state = Snail.STATE_START
  4401. };
  4402. Snail.prototype.setSkin = function(a) {
  4403. var c = library.getAsset(a);
  4404. this.bitmap = c.bitmap;
  4405. this.width = c.width;
  4406. this.height = c.height;
  4407. this.currentFrameX = 0;
  4408. this.totalFrames = c.frames;
  4409. this.totalLayers = c.layers;
  4410. this.framesCount = c.frames * c.layers;
  4411. "char_walk" == a ? (this.changeFrameDelay = pps / 24, this.removeCheckSkinListener()) : (this.changeFrameDelay = Math.min(2 * GameConfig.snail.jumpDuration, GameConfig.snail.jumpHighDuration + GameConfig.snail.jumpPostHighDuration) / this.framesCount, this.addCheckSkinListener())
  4412. };
  4413. Snail.prototype.addCheckSkinListener = function() {
  4414. this.addEventListener("changeframe", this.checkSkinFrame)
  4415. };
  4416. Snail.prototype.removeCheckSkinListener = function() {
  4417. this.removeEventListener("changeframe", this.checkSkinFrame)
  4418. };
  4419. Snail.prototype.checkSkinFrame = function() {
  4420. this.currentFrameX == this.framesCount - 1 && this.setSkin("char_walk")
  4421. };
  4422. Snail.prototype.jump = function(a) {
  4423. this.endJumpCallback = a;
  4424. this.jumping = !0;
  4425. this.startJumpY = this.y;
  4426. this.currentTime = 0;
  4427. this.setSkin("char_jump");
  4428. SoundUtils.playEffect("jump")
  4429. };
  4430. Snail.prototype.playJumping = function(a) {
  4431. this.y = Snail.getEasing(GameConfig.snail.jumpEasing)(this.currentTime, this.startJumpY, .8 * -GameConfig.stick.dY, GameConfig.snail.jumpDuration);
  4432. this.currentTime += a;
  4433. this.currentTime > GameConfig.snail.jumpDuration && (this.y = this.startJumpY - .8 * GameConfig.stick.dY, this.currentTime = 0, this.jumping = !1, this.startJumpY = this.y, this.fallJumping = !0)
  4434. };
  4435. Snail.prototype.playFallingJump = function(a) {
  4436. this.y = Snail.getEasing(GameConfig.snail.jumpFallEasing)(this.currentTime, this.startJumpY, .8 * GameConfig.stick.dY, GameConfig.snail.jumpDuration);
  4437. this.currentTime += a;
  4438. this.currentTime > GameConfig.snail.jumpDuration && (this.y = this.startJumpY + .8 * GameConfig.stick.dY, this.jumping = this.fallJumping = !1, this.endJump())
  4439. };
  4440. Snail.prototype.prepareForHighJump = function() {
  4441. this.stickId++;
  4442. MainScene.area.makeParallaxStep();
  4443. this.currentTime = 0;
  4444. this.startJumpY = this.y;
  4445. this.highJumping = !0;
  4446. this.fallJumping = this.jumping = !1
  4447. };
  4448. Snail.prototype.playHighJump = function(a) {
  4449. var c = GameConfig.stick.y0 - 25 - this.stickId * GameConfig.stick.dY - .1 * GameConfig.stick.dY;
  4450. this.y = Snail.getEasing(GameConfig.snail.jumpHighEasing)(this.currentTime, this.startJumpY, c - this.startJumpY, GameConfig.snail.jumpHighDuration);
  4451. this.currentTime += a;
  4452. this.currentTime > GameConfig.snail.jumpHighDuration && (this.y = c, this.jumping = this.highJumping = !1, this.startJumpY = this.y, this.highPostJumping = !0, this.currentTime = 0)
  4453. };
  4454. Snail.prototype.playPostHighJump = function(a) {
  4455. var c = GameConfig.stick.y0 - 25 - this.stickId * GameConfig.stick.dY;
  4456. this.y = Snail.getEasing(GameConfig.snail.jumpPostHighEasing)(this.currentTime, this.startJumpY, c - this.startJumpY, GameConfig.snail.jumpPostHighDuration);
  4457. this.currentTime += a;
  4458. this.currentTime > GameConfig.snail.jumpPostHighDuration && (this.y = c, this.highPostJumping = !1, this.endJump(), MainScene.level.addPoints())
  4459. };
  4460. Snail.prototype.endJump = function() {
  4461. this.endJumpCallback()
  4462. };
  4463. Snail.prototype.showDeath = function() {
  4464. this.state = Snail.STATE_DEAD
  4465. };
  4466. Snail.prototype.changeDirection = function() {
  4467. this.direction = !this.direction;
  4468. this.scaleX *= -1
  4469. };
  4470. Snail.prototype.step = function(a) {
  4471. a = GameConfig.snail.speedX / 1E3 * a * (this.jumping || this.highJumping || this.highPostJumping ? GameConfig.snail.jumpSpeedXKoef : 1);
  4472. this.x += this.direction == Snail.DIRECTION_RIGHT ? a : -a;
  4473. this.x >= GU.center.x - GameConfig.level.borderWidth && this.direction == Snail.DIRECTION_RIGHT ? this.changeDirection() : this.x <= -GU.center.x + GameConfig.level.borderWidth && this.direction == Snail.DIRECTION_LEFT && this.changeDirection()
  4474. };
  4475. Snail.prototype.showDeathAnimation = function(a) {
  4476. Animation.play(this, [{
  4477. tweens: [],
  4478. duration: 300
  4479. }, {
  4480. tweens: [{
  4481. prop: "y",
  4482. from: this.y,
  4483. to: this.y + 400,
  4484. ease: Easing.quadratic.easeIn
  4485. }, {
  4486. prop: "rotation",
  4487. to: this.direction == Snail.DIRECTION_RIGHT ? -Math.PI : Math.PI,
  4488. ease: Easing.linear.easeOut
  4489. }],
  4490. duration: 750,
  4491. onfinish: a
  4492. }])
  4493. };
  4494. Snail.getEasing = function(a) {
  4495. a = a.split(".");
  4496. return Easing[a[0]][a[1]]
  4497. };
  4498. Snail.DIRECTION_RIGHT = 0;
  4499. Snail.DIRECTION_LEFT = 1;
  4500. Snail.STATE_SLEEP = 0;
  4501. Snail.STATE_FALL = 1;
  4502. Snail.STATE_JUMP = 2;
  4503. Snail.STATE_DEAD = 3;
  4504. Snail.STATE_START = 4;
  4505. Snail.add = function(a) {
  4506. var c = new Snail;
  4507. a.addChild(c);
  4508. c.set();
  4509. return c
  4510. };
  4511. function MainScene() {
  4512. Utils.callSuperConstructor(MainScene, this, null, 1, 1)
  4513. }
  4514. Utils.extend(MainScene, OwnSprite);
  4515. MainScene.prototype.set = function() {
  4516. this.setBack()
  4517. };
  4518. MainScene.prototype.setBack = function() {
  4519. GU.setS(this, "sky", 0, 0, {
  4520. static: !0
  4521. });
  4522. this.mountains = GU.setS(this, "mountains", 0, -15, {
  4523. static: !1,
  4524. startY: -15
  4525. });
  4526. this.bushes = GU.setS(this, "bushes", 0, 50, {
  4527. static: !1,
  4528. startY: 50
  4529. });
  4530. this.trees = GU.setS(this, "trees", 0, 135, {
  4531. static: !1,
  4532. startY: 135
  4533. });
  4534. GU.setS(this, "cloud_1", -92, -208);
  4535. GU.setS(this, "cloud_2", 75, -190);
  4536. this.fastShowMenuSpr = GU.setS(this, null, 0, 0, {
  4537. w: 2 * GU.center.x,
  4538. h: 2 * GU.center.y
  4539. });
  4540. this.setTiles();
  4541. this.soundBtn = GU.setS(this, "btn_sound", 133, -210);
  4542. this.soundBtn.setZIndex(100);
  4543. this.soundBtn.addEventListener("mousedown", SoundUtils.switchSoundBtn);
  4544. this.soundBtn.addEventListener("mouseup", GU.preventMe);
  4545. SoundUtils.soundBtn = this.soundBtn;
  4546. SoundUtils.setSoundBtn()
  4547. };
  4548. MainScene.prototype.setTiles = function() {
  4549. this.tilesSpr = GU.setS(this, null, 0, 0);
  4550. this.tilesSpr.setZIndex(100);
  4551. for (var a = -GU.center.x + 13, c = GU.center.x - 13, d = 0; 5 > d; d++) GU.setS(this.tilesSpr, "bg_left", a, -178 + 120 * d), GU.setS(this.tilesSpr, "bg_right", c, -178 + 120 * d)
  4552. };
  4553. MainScene.prototype.makeParallaxStep = function() {
  4554. this.tween1 && this.tween1.stop();
  4555. this.tween2 && this.tween2.stop();
  4556. this.tween3 && this.tween3.stop();
  4557. this.tween1 = this.mountains.addTween("y", this.mountains.y + 12, 1E3).play();
  4558. this.tween2 = this.bushes.addTween("y", this.bushes.y + 13, 1E3).play();
  4559. this.tween3 = this.trees.addTween("y", this.trees.y + 14, 1E3).play()
  4560. };
  4561. MainScene.prototype.addBackListener = function() {
  4562. this.fastShowMenuSpr.addEventListener("mouseup", Utils.proxy(this.fastStartMenu, this))
  4563. };
  4564. MainScene.prototype.removeBackListener = function() {
  4565. this.fastShowMenuSpr.removeAllEventListeners()
  4566. };
  4567. MainScene.prototype.resetParallax = function() {
  4568. this.mountains.y = this.mountains.startY;
  4569. this.bushes.y = this.bushes.startY;
  4570. this.trees.y = this.trees.startY
  4571. };
  4572. MainScene.prototype.setMenu = function() {
  4573. MainScene.level && MainScene.level.destroyMe();
  4574. this.setLevel();
  4575. MainScene.menu = Menu.add(this);
  4576. MainScene.menu.setZIndex(50)
  4577. };
  4578. MainScene.prototype.fastStartMenu = function() {
  4579. this.removeBackListener();
  4580. MainScene.snail.startCallback = null;
  4581. Menu.show();
  4582. return !1
  4583. };
  4584. MainScene.prototype.setLevel = function() {
  4585. this.resetParallax();
  4586. MainScene.level = Level.add(this);
  4587. MainScene.level.setZIndex(50)
  4588. };
  4589. MainScene.prototype.setPopup = function(a) {
  4590. MainScene.popup = Popup.add(this, a);
  4591. MainScene.popup.setZIndex(50)
  4592. };
  4593. MainScene.MENU_SCENE = 0;
  4594. MainScene.GAME_SCENE = 1;
  4595. MainScene.POPUP_SCENE = 2;
  4596. MainScene.CREDITS_SCENE = 3;
  4597. MainScene.currentScene = MainScene.MENU_SCENE;
  4598. MainScene.area = null;
  4599. MainScene.snail = null;
  4600. MainScene.start = function() {
  4601. MainScene.area = new MainScene;
  4602. MainScene.area.setPosition(GU.center.x, GU.center.y);
  4603. stage.addChild(MainScene.area);
  4604. MainScene.area.set();
  4605. MainScene.area.setMenu()
  4606. };
  4607. function Level() {
  4608. Utils.callSuperConstructor(Level, this, null, 1, 1);
  4609. this.clickOnBack = Utils.proxy(this.clickOnBack, this);
  4610. this.endJump = Utils.proxy(this.endJump, this);
  4611. this.tick = Utils.proxy(this.tick, this);
  4612. this.showPopup = Utils.proxy(this.showPopup, this);
  4613. this.unBlockClick = Utils.proxy(this.unBlockClick, this);
  4614. this.lastStickId = 0;
  4615. this.sticks = [];
  4616. this.points = 0
  4617. }
  4618. Utils.extend(Level, OwnSprite);
  4619. Level.prototype.set = function() {
  4620. this.movingSprite = GU.setS(this, null, 0, 0, {
  4621. w: 2 * GU.center.x,
  4622. h: 2 * GU.center.y
  4623. });
  4624. this.stickSpr = GU.setS(this.movingSprite, null, 0, 0, {
  4625. w: 1,
  4626. h: 1
  4627. });
  4628. this.startSleepMode();
  4629. this.setSnail()
  4630. };
  4631. Level.prototype.setSnail = function() {
  4632. MainScene.snail = Snail.add(this.movingSprite)
  4633. };
  4634. Level.prototype.startSleepMode = function() {
  4635. this.state = Level.STATE_MENU;
  4636. this.setSticks()
  4637. };
  4638. Level.prototype.startActiveMode = function() {
  4639. this.state = Level.STATE_ACTIVE;
  4640. this.pointsText = GU.setBT(this, "font_blue", this.points, 0, -260, {
  4641. a: BitmapText.ALIGN_CENTER
  4642. });
  4643. this.pointsText.moveTo(0, -180, pps / 2, Easing.cubic.easeOut);
  4644. this.listenerSpr = GU.setS(this, null, 0, 0, {
  4645. w: 2 * GU.center.x,
  4646. h: 2 * GU.center.y
  4647. });
  4648. this.addBackListener();
  4649. stage.addEventListener("pretick", this.tick)
  4650. };
  4651. Level.prototype.tick = function(a) {
  4652. MainScene.snail.step(a.delta);
  4653. for (var c = 0, d = 0; d < this.sticks.length; d++) {
  4654. var e = this.sticks[d];
  4655. e.id == MainScene.snail.stickId && (c = e.y, e.getAbsolutePosition().y < GU.center.y + GameConfig.stick.y0 ? this.moveLevelDownByY(a.delta) : this.movingSprite.y = GameConfig.stick.y0 - c);
  4656. if (e.enemy) {
  4657. if (e.id == MainScene.snail.stickId) {
  4658. var c = e.enemy.getAbsolutePosition(),
  4659. f = MainScene.snail.getAbsolutePosition();
  4660. if (GU.Math.calcLength(c.x, c.y, f.x, f.y) <= e.enemy.collisionArea.r + MainScene.snail.collisionArea.r) {
  4661. this.showGameOver();
  4662. return
  4663. }
  4664. }
  4665. e.enemy.step(a.delta)
  4666. }
  4667. }
  4668. MainScene.snail.highJumping ? MainScene.snail.playHighJump(a.delta) : MainScene.snail.highPostJumping ? MainScene.snail.playPostHighJump(a.delta) : MainScene.snail.jumping ? MainScene.snail.playJumping(a.delta) : MainScene.snail.fallJumping && MainScene.snail.playFallingJump(a.delta);
  4669. this.sticks[0].getAbsolutePosition().y > 2 * GU.center.y + 50 && (this.sticks[0].destroyMe(), this.sticks.shift())
  4670. };
  4671. Level.prototype.moveLevelDownByY = function(a) {
  4672. this.movingSprite.y += GameConfig.level.speedY / 1E3 * a
  4673. };
  4674. Level.prototype.stopTick = function() {
  4675. stage.removeEventListener("pretick", this.tick);
  4676. this.removeBackListener()
  4677. };
  4678. Level.highJump = !1;
  4679. Level.doubleClickFlag = !1;
  4680. Level.prototype.clickOnBack = function() {
  4681. Level.doubleClickFlag && !Level.highJump && (Level.highJump = !0, MainScene.snail.prepareForHighJump());
  4682. if (this.blockJump) return !1;
  4683. this.blockClick();
  4684. this.startDoubleClickTimer();
  4685. MainScene.snail.jump(this.endJump)
  4686. };
  4687. Level.prototype.blockClick = function() {
  4688. this.blockJump = !0
  4689. };
  4690. Level.prototype.unBlockClick = function() {
  4691. this.blockJump = Level.highJump = !1
  4692. };
  4693. Level.prototype.endJump = function() {
  4694. Level.highJump && this.setStick();
  4695. stage.setTimeout(this.unBlockClick, 100);
  4696. this.trimStick()
  4697. };
  4698. Level.prototype.trimStick = function() {
  4699. this.getStick(MainScene.snail.stickId).trim()
  4700. };
  4701. Level.prototype.getStick = function(a) {
  4702. for (a = 0; a < this.sticks.length; a++) {
  4703. var c = this.sticks[a];
  4704. if (c.id == MainScene.snail.stickId) return c
  4705. }
  4706. };
  4707. Level.prototype.startDoubleClickTimer = function() {
  4708. Level.doubleClickFlag = !0;
  4709. stage.setTimeout(Level.endDoubleClickFlag, GameConfig.level.doubleTapDuration)
  4710. };
  4711. Level.endDoubleClickFlag = function() {
  4712. Level.doubleClickFlag = !1
  4713. };
  4714. Level.prototype.setSticks = function() {
  4715. this.setStick()
  4716. };
  4717. Level.prototype.setStick = function() {
  4718. var a = Stick.add(this.stickSpr, this.lastStickId);
  4719. this.lastStickId++;
  4720. this.sticks.push(a);
  4721. 0 < a.getAbsolutePosition().y && this.setStick()
  4722. };
  4723. Level.prototype.addBackListener = function() {
  4724. this.listenerSpr.addEventListener("mousedown", this.clickOnBack)
  4725. };
  4726. Level.prototype.removeBackListener = function() {
  4727. this.listenerSpr.removeAllEventListeners()
  4728. };
  4729. Level.prototype.hideLevel = function() {
  4730. this.fadeTo(0, pps / 2, null, GU.destroyMeAfterTween)
  4731. };
  4732. Level.prototype.addPoints = function() {
  4733. this.points++;
  4734. this.pointsText.write(this.points)
  4735. };
  4736. Level.prototype.showGameOver = function() {
  4737. this.stopTick();
  4738. this.removeBackListener();
  4739. this.points > UserSettings.points && (UserSettings.points = this.points, UserSettings.save());
  4740. this.showSnailDeathAnimation()
  4741. };
  4742. Level.prototype.showSnailDeathAnimation = function() {
  4743. MainScene.snail.showDeathAnimation(this.showPopup)
  4744. };
  4745. Level.prototype.showPopup = function() {
  4746. this.points > UserSettings.points && (UserSettings.points = this.points);
  4747. UserSettings.save();
  4748. this.hideLevel();
  4749. MainScene.area.setPopup(this.points)
  4750. };
  4751. Level.STATE_MENU = 1;
  4752. Level.STATE_ACTIVE = 2;
  4753. Level.STATE_GAME_OVER = 3;
  4754. Level.add = function(a) {
  4755. var c = new Level;
  4756. c.setPosition(0, 0);
  4757. a.addChild(c);
  4758. c.set();
  4759. return c
  4760. };
  4761. function Menu() {
  4762. Utils.callSuperConstructor(Menu, this, null, 1, 1);
  4763. this.startLevel = Utils.proxy(this.startLevel, this);
  4764. this.showCredits = Utils.proxy(this.showCredits, this);
  4765. this.addAllListeners = Utils.proxy(this.addAllListeners, this);
  4766. this.removeAllListeners = Utils.proxy(this.removeAllListeners, this)
  4767. }
  4768. Utils.extend(Menu, OwnSprite);
  4769. Menu.prototype.set = function() {
  4770. this.setPosition(0, 0);
  4771. GU.setS(this, "logo", 0, -130);
  4772. GU.setBT(this, "font_green", "Best score: " + UserSettings.points, 0, 0, {
  4773. a: BitmapText.ALIGN_CENTER
  4774. });
  4775. this.clickSpr = GU.setS(this, null, 0, 0, {
  4776. w: 2 * GU.center.x,
  4777. h: 2 * GU.center.y
  4778. });
  4779. this.moreGamesButton = GU.setS(this, "btn_more_games", 120, 60);
  4780. this.creditsButton = GU.setS(this, "btn_logo", 120, 120);
  4781. /*var a = GU.setBT(this, "font_blue", "Tap to jump, double tap to jump on the next level", 0, 210, {
  4782. a: BitmapText.ALIGN_CENTER,
  4783. maxWidth: 400,
  4784. vA: BitmapText.VALIGN_MIDDLE
  4785. });*/
  4786. var a = GU.setS(this,"cn_txt",0,190);
  4787. a.scaleTo(1);
  4788. // a.refresh();
  4789. this.playShowEffect()
  4790. };
  4791. Menu.prototype.addTapListener = function() {
  4792. this.clickSpr.addEventListener("mouseup", this.startLevel)
  4793. };
  4794. Menu.prototype.removeTapListener = function() {
  4795. this.clickSpr.removeAllEventListeners()
  4796. };
  4797. Menu.prototype.addButtonsListeners = function() {
  4798. this.moreGamesButton.addEventListener("mouseup", showMoreGames);
  4799. this.creditsButton.addEventListener("mouseup", this.showCredits)
  4800. };
  4801. Menu.prototype.removeButtonsListeners = function() {
  4802. this.clickSpr.removeAllEventListeners();
  4803. this.moreGamesButton.removeAllEventListeners();
  4804. this.creditsButton.removeAllEventListeners()
  4805. };
  4806. Menu.prototype.setButtons = function() {
  4807. this.moreGamesButton = new Button(this, "btn_more_games", -60, 65);
  4808. this.creditsButton = new Button(this, "ptm", 60, 65)
  4809. };
  4810. Menu.prototype.playShowEffect = function() {
  4811. this.addTapListener();
  4812. this.addButtonsListeners()
  4813. };
  4814. Menu.prototype.playHideEffect = function() {
  4815. this.removeButtonsListeners();
  4816. this.fadeTo(0, pps / 2, null, GU.destroyMeAfterTween)
  4817. };
  4818. Menu.prototype.playHideCreditsEffect = function() {
  4819. this.removeAllListeners();
  4820. this.moveBy(0, 2 * -GU.center.y, pps)
  4821. };
  4822. Menu.prototype.playShowCreditsEffect = function() {
  4823. this.moveBy(0, 2 * GU.center.y, pps, null, this.addAllListeners)
  4824. };
  4825. Menu.prototype.addAllListeners = function() {
  4826. this.addButtonsListeners();
  4827. this.addTapListener()
  4828. };
  4829. Menu.prototype.removeAllListeners = function() {
  4830. this.removeButtonsListeners();
  4831. this.removeTapListener()
  4832. };
  4833. Menu.prototype.startLevel = function() {
  4834. this.playHideEffect();
  4835. MainScene.level.startActiveMode();
  4836. SoundUtils.playEffect("tap");
  4837. return !1
  4838. };
  4839. Menu.prototype.showCredits = function() {
  4840. this.playHideCreditsEffect();
  4841. Credits.add(MainScene.area);
  4842. SoundUtils.playEffect("tap");
  4843. return !1
  4844. };
  4845. Menu.add = function(a) {
  4846. var c = new Menu;
  4847. a.addChild(c);
  4848. c.set();
  4849. return c
  4850. };
  4851. function Credits() {
  4852. Utils.callSuperConstructor(Credits, this, null, 1, 1);
  4853. this.addCloseListener = Utils.proxy(this.addCloseListener, this);
  4854. this.backToMenu = Utils.proxy(this.backToMenu, this)
  4855. }
  4856. Utils.extend(Credits, OwnSprite);
  4857. Credits.prototype.set = function() {
  4858. this.setPosition(0, 2 * GU.center.y);
  4859. this.back = GU.setS(this, "credits_1", 0, 0);
  4860. this.playShowEffect()
  4861. };
  4862. Credits.prototype.playShowEffect = function() {
  4863. this.moveBy(0, 2 * -GU.center.y, pps, null, this.addCloseListener)
  4864. };
  4865. Credits.prototype.playHideEffect = function() {
  4866. this.removeCloseListener();
  4867. this.moveBy(0, 2 * GU.center.y, pps, null, GU.destroyMeAfterTween)
  4868. };
  4869. Credits.prototype.backToMenu = function() {
  4870. this.playHideEffect();
  4871. MainScene.menu.playShowCreditsEffect();
  4872. SoundUtils.playEffect("tap");
  4873. return !1
  4874. };
  4875. Credits.prototype.addCloseListener = function() {
  4876. this.back.addEventListener("mouseup", this.backToMenu)
  4877. };
  4878. Credits.prototype.removeCloseListener = function() {
  4879. this.back.removeAllEventListeners()
  4880. };
  4881. Credits.add = function(a) {
  4882. var c = new Credits;
  4883. a.addChild(c);
  4884. c.set();
  4885. return c
  4886. };
  4887. function Popup(a) {
  4888. Utils.callSuperConstructor(Popup, this, null, 1, 1);
  4889. this.points = a;
  4890. this.opacity = 0;
  4891. this.restartGame = Utils.proxy(this.restartGame, this);
  4892. this.facebook = Utils.proxy(this.facebook, this);
  4893. this.twitter = Utils.proxy(this.twitter, this);
  4894. this.addButtonsListeners = Utils.proxy(this.addButtonsListeners, this)
  4895. }
  4896. Utils.extend(Popup, OwnSprite);
  4897. Popup.prototype.set = function() {
  4898. this.setPosition(0, 0);
  4899. this.setElements();
  4900. this.playShowEffect();
  4901. // ExternalAPI.exec("showAds")
  4902. };
  4903. Popup.prototype.setElements = function() {
  4904. this.panel = GU.setS(this, "score_panel", 0, -250);
  4905. this.scoreTextTitle = GU.setBT(this, "font_blue", "SCORE", -20, -320, {
  4906. a: BitmapText.ALIGN_CENTER
  4907. });
  4908. this.scoreTextTitle.rotateTo(-Math.PI / 15);
  4909. this.scoreTextTitle.refresh();
  4910. this.scoreText = GU.setBT(this, "font_blue", this.points, -10, -280, {
  4911. a: BitmapText.ALIGN_CENTER
  4912. });
  4913. this.scoreText.rotateTo(-Math.PI / 15);
  4914. this.scoreText.refresh();
  4915. this.bestScoreTextTitle = GU.setBT(this, "font_blue", "BEST SCORE", 0, -230, {
  4916. a: BitmapText.ALIGN_CENTER
  4917. });
  4918. this.bestScoreTextTitle.rotateTo(-Math.PI / 12);
  4919. this.bestScoreTextTitle.refresh();
  4920. this.bestScoreText = GU.setBT(this, "font_blue", UserSettings.points, 20, -195, {
  4921. a: BitmapText.ALIGN_CENTER
  4922. });
  4923. this.bestScoreText.rotateTo(-Math.PI / 12);
  4924. this.bestScoreText.refresh();
  4925. this.moreGamesBtn = GU.setS(this, "btn_more_games_1", -60, 210);
  4926. // this.facebookBtn = GU.setS(this, "btn_facebook", -86, 190);
  4927. this.twitterBtn = GU.setS(this, "btn_twitter", 60, 210);
  4928. this.restartBtn = GU.setS(this, "btn_restart", 0, 320)
  4929. // play68_score = UserSettings.points;
  4930. // updateShare(play68_score);
  4931. // Play68.setRankingScoreDesc(play68_score);
  4932. };
  4933. Popup.prototype.addButtonsListeners = function() {
  4934. this.restartBtn.addEventListener("mouseup", this.restartGame);
  4935. this.moreGamesBtn.addEventListener("mouseup", showMoreGames);
  4936. // this.facebookBtn.addEventListener("mouseup", this.facebook);
  4937. this.twitterBtn.addEventListener("mouseup", this.twitter)
  4938. };
  4939. Popup.prototype.removeButtonsListeners = function() {
  4940. this.restartBtn.removeAllEventListeners();
  4941. this.moreGamesBtn.removeAllEventListeners();
  4942. // this.facebookBtn.removeAllEventListeners();
  4943. this.twitterBtn.removeAllEventListeners()
  4944. };
  4945. Popup.prototype.playShowEffect = function() {
  4946. this.fadeTo(1, pps / 2, null, this.addButtonsListeners);
  4947. this.panel.moveBy(0, 160, pps / 2);
  4948. this.scoreTextTitle.moveBy(0, 160, pps / 2);
  4949. this.scoreText.moveBy(0, 160, pps / 2);
  4950. this.bestScoreTextTitle.moveBy(0, 160, pps / 2);
  4951. this.bestScoreText.moveBy(0, 160, pps / 2);
  4952. this.moreGamesBtn.moveBy(0, -160, pps / 2);
  4953. // this.facebookBtn.moveBy(0, -160, pps / 2);
  4954. this.twitterBtn.moveBy(0, -160, pps / 2);
  4955. this.restartBtn.moveBy(0, -160, pps / 2);
  4956. SoundUtils.playEffect("win")
  4957. };
  4958. Popup.prototype.facebook = function() {
  4959. // FaceBook.getUserInfo(FaceBook.postOnWall, this.points)
  4960. };
  4961. Popup.prototype.twitter = function() {
  4962. // play68_submitScore(play68_score);
  4963. // ExternalAPI.exec("shareTwitter", "I've scored " + this.points + " in #JumpingSnail. You'll never beat me!")
  4964. };
  4965. Popup.prototype.playHideEffect = function() {
  4966. this.removeButtonsListeners();
  4967. GU.setS(stage, null, GU.center.x, GU.center.y, {
  4968. w: 2 * GU.center.x,
  4969. h: 2 * GU.center.y,
  4970. fC: "white",
  4971. o: 0
  4972. }).fadeTo(1, pps / 2, null, Utils.proxy(function(a) {
  4973. a.target.obj.destroy = !0;
  4974. this.destroyMe();
  4975. MainScene.area.setMenu()
  4976. }, this))
  4977. };
  4978. Popup.prototype.restartGame = function() {
  4979. this.playHideEffect();
  4980. SoundUtils.playEffect("tap");
  4981. return !1
  4982. };
  4983. Popup.add = function(a, c) {
  4984. var d = new Popup(c);
  4985. a.addChild(d);
  4986. d.set();
  4987. return d
  4988. };