GC.js 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843
  1. /**
  2. * Created by juho on 2016-03-28.
  3. */
  4. import * as PIXI from './pixi';
  5. import pixi_spine from './pixi-spine'
  6. import GD from './human.min'
  7. import { TimelineLite, Sine, TweenMax, Power0 } from './TweenMax.min'
  8. import bm from './ButtonManager';
  9. import em from './EffectManager';
  10. import TextStyle from './TextStyle'
  11. import { pixelRatioX, pixelRatioY, windowWidth, windowHeight } from './fitConfig';
  12. var gWidth = windowWidth * pixelRatioX
  13. var gHeight = windowHeight * pixelRatioY
  14. var GraphicManager = (function () {
  15. function GraphicManager() {
  16. }
  17. GraphicManager.drawRect = function (w, h, col) {
  18. var g = new PIXI.Graphics();
  19. (!col) ? g.beginFill(0X00FF00, 1) : g.beginFill(col, 1);
  20. g.drawRect(0, 0, w, h);
  21. g.endFill();
  22. return g;
  23. };
  24. GraphicManager.drawCircle = function (r, col) {
  25. var g = new PIXI.Graphics();
  26. (!col) ? g.beginFill(0X00FF00, 1) : g.beginFill(col, 1);
  27. g.drawCircle(0, 0, r);
  28. g.endFill();
  29. return g;
  30. };
  31. return GraphicManager;
  32. }());
  33. var gc = {
  34. isDebug: true,
  35. loader: null,
  36. stats: null,
  37. width: gWidth,
  38. height: gHeight,
  39. IS_MOBILE: true,
  40. onBgm: true,
  41. onFx: true,
  42. pauseGame: false,
  43. stage: null,
  44. soundPopup: null,
  45. intro: null,
  46. tutorial: null,
  47. game: null,
  48. chapter: 1,//게임 챕터.. 1:카드랜드 2:버섯랜드 3:장미랜드 4:모자랜드 5:나무랜드
  49. bShare: false,
  50. showVd: false,
  51. recoveryTimes: 1
  52. };
  53. /**
  54. * Created by admin on 2018-06-07.
  55. */
  56. gc.PopupSound = function () {
  57. PIXI.Container.call(this);
  58. this.bgBlack = GraphicManager.drawRect(gc.width, gc.height, "0X000000");
  59. this.bgBlack.alpha = 0.7;
  60. this.bg = new PIXI.Sprite.fromFrame("popup_bg_sound1.png");
  61. this.bg.anchor.set(0.5);
  62. this.btnClose = new PIXI.Sprite.fromFrame("popup_btn_close.png");
  63. this.btnClose.anchor.set(0.5);
  64. bm.buttonEvent(this.btnClose, true, null, null, this.closeSoundPopup.bind(this));
  65. this.btnBgm = new PIXI.Sprite.fromFrame("popup_btn_sound1_off.png");
  66. this.btnBgm.anchor.set(0.5);
  67. bm.buttonEvent(this.btnBgm, true, null, null, this.setBgm.bind(this));
  68. this.btnFx = new PIXI.Sprite.fromFrame("popup_btn_sound2_off.png");
  69. this.btnFx.anchor.set(0.5);
  70. bm.buttonEvent(this.btnFx, true, null, null, this.setFx.bind(this));
  71. this.btnRestart = new PIXI.Sprite.fromFrame("popup_btn_restart.png");
  72. this.btnRestart.anchor.set(0.5);
  73. bm.buttonEvent(this.btnRestart, true, null, null, (function () {
  74. // restartGame();
  75. this.setInteractive(false);
  76. GD.stage.removeChild(this);
  77. onGame();
  78. }).bind(this));
  79. };
  80. gc.PopupSound.constructor = gc.PopupSound;
  81. gc.PopupSound.prototype = Object.create(PIXI.Container.prototype);
  82. gc.PopupSound.prototype.onSoundPopup = function () {
  83. this.reset();
  84. this.setBgImg();
  85. this.setButtonImage();
  86. this.setPosition();
  87. this.bg.addChild(this.btnBgm);
  88. this.bg.addChild(this.btnFx);
  89. this.bg.addChild(this.btnClose);
  90. this.addChild(this.bgBlack);
  91. this.addChild(this.bg);
  92. if (gc.game) {
  93. this.bg.addChild(this.btnRestart);
  94. gc.game.pause();
  95. }
  96. var time = 0.1;
  97. TweenMax.fromTo(this.bg.scale, time, { x: 0, y: 0 }, {
  98. x: 1.05, y: 1.05, onComplete: (function () {
  99. TweenMax.to(this.bg.scale, time / 2, {
  100. x: 1, y: 1, onComplete: (function () {
  101. this.bg.scale.x = 1;
  102. this.bg.scale.y = 1;
  103. this.setInteractive(true);
  104. }).bind(this)
  105. });
  106. }).bind(this)
  107. });
  108. GD.stage.addChild(this);
  109. };
  110. gc.PopupSound.prototype.closeSoundPopup = function () {
  111. gc.pauseGame = false;
  112. var time = 0.1;
  113. this.bg.scale.x = 1;
  114. this.bg.scale.y = 1;
  115. TweenMax.to(this.bg.scale, time, {
  116. x: 1.1, y: 1.1, onComplete: (function () {
  117. TweenMax.to(this.bg.scale, time / 2, {
  118. x: 0, y: 0, onComplete: (function () {
  119. GD.stage.removeChild(this);
  120. if (gc.intro) {
  121. gc.intro.setInteractive(true);
  122. }
  123. else if (gc.game) {
  124. gc.game.resume();
  125. }
  126. }).bind(this)
  127. });
  128. }).bind(this)
  129. });
  130. };
  131. //배경 이미지
  132. gc.PopupSound.prototype.setBgImg = function () {
  133. if (gc.intro) this.bg.texture = PIXI.Texture.fromFrame("popup_bg_sound2.png");
  134. else if (gc.game) this.bg.texture = PIXI.Texture.fromFrame("popup_bg_sound1.png");
  135. this.bg.scale.x = 1;
  136. this.bg.scale.y = 1;
  137. };
  138. //버튼 이미지 활성화 설정
  139. gc.PopupSound.prototype.setButtonImage = function () {
  140. if (gc.onBgm) this.btnBgm.texture = PIXI.Texture.fromFrame("popup_btn_sound1_on.png");
  141. else this.btnBgm.texture = PIXI.Texture.fromFrame("popup_btn_sound1_off.png");
  142. if (gc.onFx) this.btnFx.texture = PIXI.Texture.fromFrame("popup_btn_sound2_on.png");
  143. else this.btnFx.texture = PIXI.Texture.fromFrame("popup_btn_sound2_off.png");
  144. };
  145. //좌표 설정
  146. gc.PopupSound.prototype.setPosition = function () {
  147. this.bg.x = gc.width / 2;
  148. this.bg.y = gc.height / 2;
  149. var gap = 60;
  150. this.btnClose.x = this.bg.width / 2 - 50;
  151. this.btnClose.y = -this.bg.height / 2 + gap;
  152. if (gc.intro) {
  153. gap = this.btnBgm.height + 40;
  154. this.btnBgm.y = -this.bg.height / 2 + 190;
  155. this.btnFx.y = this.btnBgm.y + gap;
  156. this.btnRestart.y = this.btnFx.y + gap;
  157. }
  158. else if (gc.game) {
  159. gap = this.btnBgm.height + 10;
  160. this.btnBgm.y = -this.bg.height / 2 + 185;
  161. this.btnFx.y = this.btnBgm.y + gap;
  162. gap += 30;
  163. this.btnRestart.y = this.btnFx.y + gap;
  164. }
  165. this.btnBgm.x = 0;
  166. this.btnFx.x = this.btnBgm.x;
  167. this.btnRestart.x = this.btnBgm.x;
  168. };
  169. //배경음 설정
  170. gc.PopupSound.prototype.setBgm = function () {
  171. gc.onBgm = !gc.onBgm;
  172. console.log("gc.onBgm", gc.onBgm);
  173. // if(!gc.onBgm) GD.soundMute("sound_bgm_mini");
  174. // else GD.soundUnMute("sound_bgm_mini");
  175. if (gc.game) {
  176. if (!gc.onBgm) GD.soundStop("sound_bgm_mini");
  177. else GD.soundPlay("sound_bgm_mini");
  178. }
  179. this.setButtonImage();
  180. };
  181. //효과음 설정
  182. gc.PopupSound.prototype.setFx = function () {
  183. gc.onFx = !gc.onFx;
  184. console.log("gc.onFx", gc.onFx);
  185. this.setButtonImage();
  186. };
  187. gc.PopupSound.prototype.setInteractive = function (bool) {
  188. this.btnClose.interactive = bool;
  189. this.btnBgm.interactive = bool;
  190. this.btnFx.interactive = bool;
  191. this.btnRestart.interactive = bool;
  192. };
  193. gc.PopupSound.prototype.reset = function () {
  194. this.removeChildren();
  195. this.bg.removeChildren();
  196. };
  197. gc.PopupSound.prototype.updateTransform = function () {
  198. try {
  199. PIXI.Container.prototype.updateTransform.call(this);
  200. } catch (e) {
  201. }
  202. };
  203. /**Intro */
  204. /**
  205. * Created by admin on 2018-04-05.
  206. */
  207. gc.Intro = function () {
  208. PIXI.Container.call(this);
  209. this.bg = new PIXI.Sprite.fromFrame("intro_bg.png");
  210. this.btnStart = new PIXI.Sprite.fromFrame("intro_btn_start.png");
  211. this.btnTuto = new PIXI.Sprite.fromFrame("intro_btn_tutorial.png");
  212. this.btnSound = new PIXI.Sprite.fromFrame("intro_btn_sound.png");
  213. };
  214. gc.Intro.constructor = gc.Intro;
  215. gc.Intro.prototype = Object.create(PIXI.Container.prototype);
  216. //인트로 init
  217. gc.Intro.prototype.init = function () {
  218. this.updateTransform();
  219. this.btnStart.anchor.set(0.5);
  220. this.btnStart.x = this.bg.width / 2;
  221. this.btnStart.y = this.bg.height - 140;
  222. bm.buttonEvent(this.btnStart, true, null, null, onGame);
  223. var gap = 260;
  224. this.btnTuto.anchor.set(0.5);
  225. this.btnTuto.x = this.btnStart.x - gap;
  226. this.btnTuto.y = this.btnStart.y;
  227. bm.buttonEvent(this.btnTuto, true, null, null, null);//튜토리얼 열기
  228. this.btnSound.anchor.set(0.5);
  229. this.btnSound.x = this.btnStart.x + gap;
  230. this.btnSound.y = this.btnStart.y;
  231. bm.buttonEvent(this.btnSound, true, null, null, (function () {
  232. this.setInteractive(false);
  233. console.log(gc.soundPopup)
  234. gc.soundPopup.onSoundPopup();
  235. }).bind(this));
  236. this.bg.addChild(this.btnStart);
  237. // this.bg.addChild(this.btnTuto);
  238. this.bg.addChild(this.btnSound);
  239. this.addChild(this.bg);
  240. this.setInteractive(true);
  241. };
  242. //터치 이벤트 활성화
  243. gc.Intro.prototype.setInteractive = function (bool) {
  244. this.btnStart.interactive = bool;
  245. this.btnTuto.interactive = bool;
  246. this.btnSound.interactive = bool;
  247. };
  248. //인트로 초기화
  249. gc.Intro.prototype.reset = function () {
  250. this.setInteractive(false);
  251. this.bg.removeChildren();
  252. this.removeChildren();
  253. };
  254. gc.Intro.prototype.updateTransform = function () {
  255. try {
  256. PIXI.Container.prototype.updateTransform.call(this);
  257. } catch (e) {
  258. }
  259. };
  260. /**
  261. * Created by admin on 2018-06-07.
  262. */
  263. gc.Menu = function (options) {
  264. PIXI.Container.call(this);
  265. this.options = options;
  266. this.bgBlack = GraphicManager.drawRect(gc.width, gc.height, "0X000000");
  267. this.bgBlack.alpha = 0.7;
  268. this.bg = new PIXI.Sprite.fromFrame("popup_help_me.png");
  269. this.bg.anchor.set(0.5);
  270. this.shareText = new PIXI.Text('分享游戏即可复活哦')
  271. this.shareText.anchor.set(.5);
  272. this.adText = new PIXI.Text('观看广告后即可复活哦')
  273. this.adText.anchor.set(.5);
  274. this.btnClose = new PIXI.Sprite.fromFrame("popup_btn_close.png");
  275. this.btnClose.anchor.set(0.5);
  276. bm.buttonEvent(this.btnClose, true, null, null, (function () {
  277. this.closeMenuPopup(function () {
  278. gameEnd()
  279. })
  280. }).bind(this));
  281. this.btnShare = new PIXI.Sprite.fromFrame("popup_share_btn.png");
  282. this.btnShare.anchor.set(0.5);
  283. bm.buttonEvent(this.btnShare, true, null, null, this.setShare.bind(this));
  284. this.btnAd = new PIXI.Sprite.fromFrame("popup_ad_btn.png");
  285. this.btnAd.anchor.set(0.5);
  286. bm.buttonEvent(this.btnAd, true, null, null, this.setAd.bind(this));
  287. this.btnRestart = new PIXI.Sprite.fromFrame("popup_menu_refuse.png");
  288. this.btnRestart.anchor.set(0.5);
  289. bm.buttonEvent(this.btnRestart, true, null, null, (function () {
  290. this.setInteractive(false);
  291. this.closeMenuPopup(function () {
  292. gameEnd();
  293. GD.objSdk.showAdIcon(0, 0);
  294. });
  295. }).bind(this));
  296. this.init();
  297. };
  298. gc.Menu.constructor = gc.Menu;
  299. gc.Menu.prototype = Object.create(PIXI.Container.prototype);
  300. gc.Menu.prototype.init = function () {
  301. this.setPosition()
  302. this.bg.addChild(this.shareText);
  303. this.bg.addChild(this.adText);
  304. this.bg.addChild(this.btnShare);
  305. this.bg.addChild(this.btnAd);
  306. this.bg.addChild(this.btnClose);
  307. this.bg.addChild(this.btnRestart);
  308. this.addChild(this.bgBlack);
  309. this.addChild(this.bg);
  310. this.visible = false;
  311. GD.stage.addChild(this);
  312. }
  313. //좌표 설정
  314. gc.Menu.prototype.setPosition = function () {
  315. this.bg.x = gc.width / 2;
  316. this.bg.y = gc.height / 2;
  317. var gap = 60;
  318. this.btnClose.x = this.bg.width / 2 - 50;
  319. this.btnClose.y = -this.bg.height / 2 + gap;
  320. this.shareText.position.y = -this.bg.height / 2 + 200
  321. this.shareText.style = { fontSize: 36, wordWrap: true, align: 'center' };
  322. this.adText.position.y = -this.bg.height / 2 + 200
  323. this.adText.style = { fontSize: 36, wordWrap: true, align: 'center' };
  324. gap = this.btnShare.height + 10;
  325. this.btnShare.y = this.btnAd.y = this.shareText.position.y + 100;
  326. gap += 30;
  327. this.btnRestart.y = this.btnShare.y + gap;
  328. this.btnShare.x = this.btnAd.x = 0;
  329. this.btnRestart.x = this.btnShare.x;
  330. };
  331. gc.Menu.prototype.onMenuPopup = function (type) {
  332. if (type == 'ad') {
  333. this.shareText.visible = false;
  334. this.adText.visible = true;
  335. this.btnShare.visible = false;
  336. this.btnAd.visible = true;
  337. } else {
  338. this.shareText.visible = true;
  339. this.adText.visible = false;
  340. this.btnShare.visible = true;
  341. this.btnAd.visible = false;
  342. }
  343. this.visible = true;
  344. var time = 0.1;
  345. TweenMax.fromTo(this.bg.scale, time, { x: 0, y: 0 }, {
  346. x: 1.05, y: 1.05, onComplete: (function () {
  347. TweenMax.to(this.bg.scale, time / 2, {
  348. x: 1, y: 1, onComplete: (function () {
  349. this.bg.scale.x = 1;
  350. this.bg.scale.y = 1;
  351. this.setInteractive(true);
  352. }).bind(this)
  353. });
  354. }).bind(this)
  355. });
  356. };
  357. gc.Menu.prototype.closeMenuPopup = function (callback) {
  358. var time = 0.1;
  359. this.bg.scale.x = 1;
  360. this.bg.scale.y = 1;
  361. TweenMax.to(this.bg.scale, time, {
  362. x: 1.1,
  363. y: 1.1,
  364. onComplete: (function () {
  365. TweenMax.to(this.bg.scale, time / 2, {
  366. x: 0, y: 0, onComplete: (function () {
  367. this.visible = false;
  368. callback && callback();
  369. }).bind(this)
  370. });
  371. }).bind(this)
  372. });
  373. };
  374. //효과음 설정
  375. gc.Menu.prototype.setShare = function () {
  376. wx.shareAppMessage({
  377. title: "聪明人都在玩的游戏,快来挑战一下!",
  378. imageUrl: "https://pub.dwstatic.com/wxgame/jumpgame/jumpgame_stair/image/json/intro/shareImage.jpg",
  379. query: ""
  380. })
  381. let showCb = res => {
  382. console.log('share 完成')
  383. if (gc.onBgm) GD.bgmPlay(0.8);
  384. this.closeMenuPopup(function () {
  385. gc.game.recovery();
  386. })
  387. wx.offShow(showCb)
  388. }
  389. wx.onShow(showCb);
  390. };
  391. //효과음 설정
  392. gc.Menu.prototype.setAd = function () {
  393. console.log('点击了观看广告');
  394. let videoAd = wx.createRewardedVideoAd({
  395. adUnitId: 'adunit-0e83e19c26a8d8fc'
  396. })
  397. this.closeMenuPopup();
  398. videoAd.load()
  399. .then(() => {
  400. GD.bgmStop();
  401. videoAd.show()
  402. })
  403. .catch(err => {
  404. console.log(err)
  405. gameEnd();
  406. })
  407. videoAd.onClose(res => {
  408. if (res && res.isEnded || res === undefined) {
  409. if (gc.onBgm) GD.bgmPlay(0.8);
  410. gc.game.recovery();
  411. } else {
  412. gameEnd()
  413. }
  414. })
  415. };
  416. gc.Menu.prototype.setInteractive = function (bool) {
  417. this.btnClose.interactive = bool;
  418. this.btnShare.interactive = bool;
  419. this.btnAd.interactive = bool;
  420. this.btnRestart.interactive = bool;
  421. };
  422. gc.Menu.prototype.reset = function () {
  423. this.removeChildren();
  424. this.bg.removeChildren();
  425. };
  426. gc.Menu.prototype.updateTransform = function () {
  427. try {
  428. PIXI.Container.prototype.updateTransform.call(this);
  429. } catch (e) {
  430. }
  431. };
  432. /**GameScene */
  433. /**
  434. * Created by admin on 2018-04-05.
  435. */
  436. gc.GameScene = function () {
  437. PIXI.Container.call(this);
  438. this.touchBg = new PIXI.Sprite.fromFrame("bg1.png");//터치 감지 배경
  439. this.bg = [new PIXI.Sprite.fromFrame("bg1.png"), new PIXI.Sprite.fromFrame("bg1.png")];
  440. this.bgWall = [new PIXI.Sprite.fromFrame("bg1_1.png"), new PIXI.Sprite.fromFrame("bg1_1.png"),
  441. new PIXI.Sprite.fromFrame("bg1_2.png"), new PIXI.Sprite.fromFrame("bg1_2.png")];
  442. this.soundBtn = new PIXI.Sprite.fromFrame("bt_sound_off.png");
  443. this.scoreText = new gc.NumberText("c_score", 'center', -4);
  444. this.addScoreText = new PIXI.Text("", TextStyle.makeStyle({ size: 50, fontWeight: 'bold' }));//추가점수 텍스트
  445. gc.somi = new gc.Somi();
  446. gc.menu = new gc.Menu();
  447. this.obstacle = new gc.Obstacle();
  448. gc.resultView = new gc.ResultView();
  449. gc.resultView.on("GOTO_MAINPAGE", onIntro);
  450. this.bgContainer = new PIXI.Container();
  451. this.blackoutContainer = this.obstacle.initBlackoutContainer();//장애물 컨테이너
  452. this.birdContainer = this.obstacle.initBirdContainer();//장애물 컨테이너
  453. this.midContainer = new PIXI.Container();//발판, 블랙아웃, 새, 플레이어 ㅓㄴ테이너 설정
  454. this.playerContainer = new PIXI.Container();
  455. this.uiContainer = new PIXI.Container();
  456. this.combo = 0;
  457. //충전 사운드 점점 크게
  458. GD.sound['sound_gauge'].on('end', (function () {
  459. if (this.myCha.status == "readyJump") {
  460. if (this.chargeVolume < 1) this.chargeVolume += 0.1;
  461. if (gc.onFx) GD.soundPlay("sound_gauge", this.chargeVolume);
  462. }
  463. }).bind(this));
  464. this.loadConfig();
  465. gc.recoveryTimes = 1;
  466. console.log('set onshow')
  467. wx.onShow(res => {
  468. if (gc.onBgm) GD.bgmPlay(0.8);
  469. })
  470. };
  471. gc.GameScene.constructor = gc.GameScene;
  472. gc.GameScene.prototype = Object.create(PIXI.Container.prototype);
  473. gc.GameScene.prototype.loadConfig = function () {
  474. let loader = new PIXI.loaders.Loader();
  475. loader.add('shareConfig', 'https://pub.dwstatic.com/wxgame/jumpgame/share.json?_=' + (new Date).getTime())
  476. loader.load((loader, resources) => {
  477. console.log(resources)
  478. if (resources.shareConfig) {
  479. gc.showVd = resources.shareConfig.data.showVd;
  480. gc.bShare = resources.shareConfig.data.bShare;
  481. }
  482. })
  483. }
  484. //스파인 리스너
  485. gc.GameScene.prototype.setSpineListener = function (obj) {
  486. obj.state.addListener({
  487. complete: (function (t) {
  488. if (t.animation.name == "scoreEf") {
  489. this.removeSpineListener(obj);
  490. removeObject(obj);
  491. var time = 0.3;
  492. TweenMax.to(this.scoreNumContainer, time, { ease: Power0.easeNone, y: this.scoreText.y });
  493. TweenMax.to(this.scoreNumContainer.scale, time, {
  494. ease: Power0.easeNone, x: 1, y: 1, onComplete: (function () {
  495. removeObject(this.scoreNumContainer);
  496. this.scoreText.alpha = 1;
  497. }).bind(this)
  498. });
  499. }
  500. }).bind(this)
  501. });
  502. };
  503. gc.GameScene.prototype.removeSpineListener = function (obj) {
  504. obj.state.removeListener();
  505. };
  506. gc.GameScene.prototype.setGameBgImage = function () {
  507. var bgNames = ['bg1', "bg2", "bg2", "bg2", "bg2"];
  508. var i;
  509. for (i = 0; i < this.bg.length; i++) {
  510. this.bg[i].texture = PIXI.Texture.fromFrame(bgNames[gc.chapter - 1] + '.png');
  511. }
  512. for (i = 0; i < this.bgWall.length; i++) {
  513. if (gc.chapter == 1) this.bgWall[i].visible = true;
  514. else this.bgWall[i].visible = false;
  515. }
  516. this.bg[0].y = 0;
  517. this.bg[1].y = this.bg[0].y - this.bg[1].height;
  518. this.bgWall[0].x = -this.bgWall[0].width / 3;
  519. this.bgWall[1].x = this.bgWall[0].x;
  520. this.bgWall[1].y = this.bgWall[0].y - (this.bgWall[1].height + 1000);
  521. this.bgWall[2].x = gc.width - this.bgWall[2].width / 3;
  522. this.bgWall[2].y = gc.height / 2;
  523. this.bgWall[3].x = this.bgWall[2].x;
  524. this.bgWall[3].y = this.bgWall[2].y - (this.bgWall[3].height + 1000);
  525. };
  526. gc.GameScene.prototype.init = function () {
  527. this.reset();
  528. this.setGameBgImage();//배경 이미지 설정
  529. //사운드 버튼.. 임시로 좌표만
  530. this.soundBtn.anchor.set(0.5);
  531. this.soundBtn.x = gc.width - 60;
  532. this.soundBtn.y = 120;
  533. bm.buttonEvent(this.soundBtn, true, this.clickSoundBtn.bind(this));
  534. this.soundBtn.interactive = true;
  535. //소미 생성
  536. this.somi = gc.somi.init();
  537. //점수 획득 이펙트
  538. this.addScoreText.anchor.set(0.5);
  539. //점수 부착
  540. this.addScore();
  541. this.touchBg.alpha = 0;
  542. bm.buttonEvent(this.touchBg, false, this.touchStart.bind(this), null, this.touchEnd.bind(this));
  543. //진행률
  544. if (!gc.progress) gc.progress = new gc.Progress();
  545. gc.progress.setEndStep(gc.chapter);
  546. gc.progress.resetNowStep();
  547. this.progressContainer = gc.progress.init();
  548. this.offUI();
  549. //다음 맵 정보
  550. if (!gc.maps) gc.maps = new gc.Map();
  551. gc.maps.init();
  552. // gc.maps.reset();
  553. gc.maps.initFootHolds(this.startStep, 1, 'basic');//최초 유저가 서있을 발판 만들기
  554. //중력(점프) 설정
  555. if (!gc.gravity) gc.gravity = new gc.Gravity();
  556. gc.gravity.reset();
  557. //유저 캐릭터 설정
  558. this.initMyCha();
  559. //점프 파워 충전 이펙트
  560. this.effectFoot = new PIXI.spine.Spine(GD.loader.resources["ef1"].spineData);
  561. this.effectHead = new PIXI.spine.Spine(GD.loader.resources["ef2"].spineData);
  562. this.bgContainer.addChild(this.bg[0]);
  563. this.bgContainer.addChild(this.bg[1]);
  564. this.bgContainer.addChild(this.bgWall[0]);
  565. this.bgContainer.addChild(this.bgWall[1]);
  566. this.bgContainer.addChild(this.bgWall[2]);
  567. this.bgContainer.addChild(this.bgWall[3]);
  568. this.playerContainer.addChild(this.myCha.img);
  569. this.uiContainer.addChild(this.scoreText);
  570. this.uiContainer.addChild(this.soundBtn);
  571. this.uiContainer.addChild(this.progressContainer);
  572. this.uiContainer.addChild(this.somi);
  573. this.addChild(this.touchBg);
  574. this.addChild(this.bgContainer);
  575. this.addChild(this.uiContainer);
  576. this.addChild(this.midContainer);
  577. this.addChild(gc.menu)
  578. em.floatByY(this.somi, 0.5, 20, 2, gc.somi.disappearSomi.bind(gc.somi));
  579. };
  580. gc.GameScene.prototype.recovery = function () {
  581. this.playerContainer.removeChild(this.myCha.img);
  582. gc.maps.firstFh = false;
  583. gc.gravity.resetPow();
  584. gc.maps.setNowFootHoldPos();
  585. this.oldMyCha = this.myCha;
  586. this.myCha = null;
  587. this.initMyCha();
  588. this.setInteractive(true);
  589. this.setMidContainer(0)
  590. setTimeout(() => {
  591. this.playerContainer.addChild(this.myCha.img)
  592. });
  593. gc.recoveryTimes--;
  594. }
  595. //UI화면 보이기
  596. gc.GameScene.prototype.onUI = function () {
  597. this.scoreText.x = gc.width / 2;
  598. this.scoreText.y = 110;
  599. this.progressContainer.x = gc.width * 0.5 - gc.progress.progressbar.width * 0.5;
  600. this.progressContainer.y = 250;
  601. TweenMax.from(this.scoreText, 0.5, { y: this.scoreText.y - 500 });
  602. TweenMax.from(this.progressContainer, 0.5, { y: this.progressContainer.y - 500 });
  603. };
  604. //UI화면 안보이게하기
  605. gc.GameScene.prototype.offUI = function () {
  606. this.scoreText.x = gc.width / 2;
  607. this.scoreText.y = -110;
  608. this.progressContainer.x = gc.width * 0.5 - gc.progress.progressbar.width * 0.5;
  609. this.progressContainer.y = -250;
  610. };
  611. //배경 스크롤, 좌표 설정
  612. gc.GameScene.prototype.scrollBackground = function (moveTime, dist) {
  613. var i;
  614. var runtime = 0;
  615. var ticker = new PIXI.ticker.Ticker();
  616. ticker.stop();
  617. ticker.add((function (deltaTime) {
  618. runtime += deltaTime;
  619. for (i = 0; i < this.bg.length; i++) {
  620. if (this.bg[i].y >= gc.height) {
  621. if (i == 0) this.bg[i].y = this.bg[1].y - this.bg[i].height;
  622. else this.bg[i].y = this.bg[0].y - this.bg[i].height;
  623. }
  624. this.bg[i].y += dist / (35 * 3);
  625. }
  626. if (runtime >= moveTime * 50) {
  627. ticker.stop();
  628. ticker.remove();
  629. }
  630. }).bind(this));
  631. ticker.start();
  632. for (i = 0; i < this.bgWall.length; i++) {
  633. TweenMax.to(this.bgWall[i], moveTime, {
  634. y: this.bgWall[i].y + parseInt(dist), onComplete: (function (i) {
  635. if (this.bgWall[i].y >= gc.height) {
  636. if (i % 2 == 0) this.bgWall[i].y = this.bgWall[i + 1].y - (this.bgWall[i].height + 1000);
  637. else this.bgWall[i].y = this.bgWall[i - 1].y - (this.bgWall[i].height + 1000);
  638. }
  639. }).bind(this, i)
  640. });
  641. }
  642. };
  643. //발판, 장애물, 유저 레이어 순서 설정
  644. gc.GameScene.prototype.setMidContainer = function (type) {//type0: 기본, 암전 1:유저가 가장 아래 2:발판사이에 유저
  645. // return;
  646. var i;
  647. var mapConList = [];
  648. //발판 컨테이너 스텝 별 내림차순 정렬(점점 작아지게)
  649. mapConList = gc.maps.mapContainers.sort(function (a, b) {
  650. return b.step - a.step;
  651. });
  652. if (type == 0) {//기본, 암전
  653. for (i = 0; i < mapConList.length; i++) {
  654. this.midContainer.addChild(mapConList[i].center);
  655. }
  656. this.midContainer.addChild(this.blackoutContainer);
  657. this.blackoutContainer.addChild(this.birdContainer);
  658. this.midContainer.addChild(this.playerContainer);
  659. }
  660. else if (type == 1) {//유저가 가장 아래
  661. this.midContainer.addChild(this.playerContainer);
  662. for (i = 0; i < mapConList.length; i++) {
  663. this.midContainer.addChild(mapConList[i].center);
  664. }
  665. this.midContainer.addChild(this.blackoutContainer);
  666. this.blackoutContainer.addChild(this.birdContainer);
  667. }
  668. else {
  669. for (i = 0; i < mapConList.length; i++) {
  670. //발판을 내림차순으로 정렬했기 때문에 유저를 먼저 붙인 후 발판을 붙임
  671. if (mapConList[i].step == this.myCha.step) this.midContainer.addChild(this.playerContainer);
  672. this.midContainer.addChild(mapConList[i].center);
  673. }
  674. this.midContainer.addChild(this.blackoutContainer);
  675. this.blackoutContainer.addChild(this.birdContainer);
  676. }
  677. };
  678. //추가될 점수 계산
  679. gc.GameScene.prototype.setAddScore = function (result) {
  680. var score = 1;
  681. if (result == "perfect") {
  682. if (this.combo < 9) this.combo++;
  683. }
  684. else this.combo = 0;
  685. score += this.combo;
  686. return score;
  687. };
  688. //점수 추가
  689. gc.GameScene.prototype.addScore = function (addScore) {
  690. var prescore = this.score;//점수 강조 이펙트 체크를 위함
  691. if (addScore) {
  692. this.score += addScore;
  693. gc.progress.addStep();//진행바 스텝 증가
  694. this.checkScoreEffect(prescore);//점수 강조 체크
  695. //점수 획득 이펙트
  696. if (this.scoreEf) this.scoreEf.kill();
  697. this.scoreEf = null;
  698. this.addScoreText.text = "+" + addScore;
  699. this.addScoreText.alpha = 1;
  700. this.addScoreText.x = this.myCha.img.x;
  701. this.addScoreText.y = this.myCha.img.y;
  702. this.scoreEf = TweenMax.to(this.addScoreText, 2, {
  703. y: this.myCha.img.y - 70, alpha: 0, onComplete: (function () {
  704. removeObject(this.addScoreText);
  705. }).bind(this)
  706. });
  707. this.uiContainer.addChild(this.addScoreText);
  708. }
  709. this.scoreText.setValue(this.score);
  710. if (this.mainScoreEfNum) this.mainScoreEfNum.setValue(this.score);
  711. };
  712. //스테이지 완료 점수 추가
  713. gc.GameScene.prototype.addChapterClearScore = function () {
  714. var addscore = 0;
  715. if (gc.chapter == 1) addscore = 400;
  716. else if (gc.chapter == 2) addscore = 500;
  717. else if (gc.chapter == 3 || gc.chapter == 4 || gc.chapter == 5) addscore = 600;
  718. this.score += addscore;
  719. this.scoreText.text = this.score;
  720. };
  721. //유저 캐릭터 생성
  722. gc.GameScene.prototype.initMyCha = function () {
  723. if (!gc.characters) gc.characters = new gc.Characters();
  724. gc.characters.reset();
  725. this.myCha = { img: null, status: "stand", x: 0, y: 0, step: 0, combo: -1, jumpDir: 1 };
  726. this.myCha.img = gc.characters.init(0);
  727. this.myCha.status = "stand";
  728. this.myCha.x = gc.maps.nowFootholdPos.x;
  729. this.myCha.y = gc.maps.nowFootholdPos.y;
  730. this.myCha.img.x = this.myCha.x;
  731. this.myCha.img.y = this.myCha.y;
  732. this.myCha.jumpDir = this.oldMyCha ? this.oldMyCha.jumpDir : 1;
  733. this.myCha.step = this.oldMyCha ? this.oldMyCha.step : 0;
  734. gc.characters.standAnimate(this.myCha.img);
  735. this.setPlayerStandScale();
  736. };
  737. //유저가 바라볼 방향
  738. gc.GameScene.prototype.setPlayerStandScale = function () {
  739. if (this.myCha.jumpDir == 1) this.myCha.img.scale.x = -1;//오른쪽 바라보기
  740. else this.myCha.img.scale.x = 1;//왼쪽 바라보기
  741. };
  742. //화면 갱신.. 발판 내리기, 발판 폭파
  743. gc.GameScene.prototype.setBackground = function () {
  744. var delayTime = 0.3;
  745. var wait = false;//소미가 나오는 동안 멈추기 위함
  746. gc.maps.setNowFootHoldPos();//유저가 발판에 올라선 후 발판 좌표 저장
  747. gc.maps.pullDownFootHolds();//발판, 유저 내리기
  748. //발판 생성
  749. if (gc.onFx) GD.soundPlay("sound_newblock");
  750. if (gc.progress.endStep - gc.progress.nowStep == 2) {//마지막 발판 직전은 무조건 점프발판
  751. if (gc.chapter == 5) gc.maps.initFootHolds(this.startStep + 1, 1, "jump");
  752. else gc.maps.initFootHolds(this.startStep + 1, 1, "basic");
  753. } else if (gc.progress.endStep - gc.progress.nowStep == 1) {//발판 생성..챕터의 마지막 발판은 무조건 기본 발판
  754. wait = true;
  755. gc.maps.initFootHolds(this.startStep + 1, 1, 'basic');
  756. }
  757. else {
  758. gc.maps.initFootHolds(this.startStep + 1, 1);
  759. }
  760. //만들어진 발판이 화면 사이드 밖으로 나갔는지 체크
  761. gc.maps.checkFootHoldsOutofScene();
  762. this.obstacle.removeFarBirds();//멀리 있는 새 제거
  763. if (wait) TweenMax.delayedCall(1.6, resumeSetBackground.bind(this));
  764. else resumeSetBackground.bind(this)();
  765. this.onSlideFootHold = false;
  766. function resumeSetBackground() {
  767. if (gc.maps.nowFootholdPos.info.skillType == "jump") {
  768. this.myCha.status = "inJump";//점프 중 상태로 변경
  769. TweenMax.delayedCall(0.15, (function () {
  770. this.jumpPlayer();
  771. gc.characters.jumpAnimate(this.myCha.img);
  772. gc.maps.jumpAnimate();
  773. }).bind(this));
  774. }
  775. else {
  776. this.myCha.status = "stand";
  777. this.setInteractive(true);
  778. }//터치 제어
  779. //슬라이드 발판 여부 설정
  780. TweenMax.delayedCall(delayTime, (function () {
  781. this.slideBlockAct();//현재 발판이 슬라이드 발판이면 다음 발판으로 미끄러짐
  782. }).bind(this));
  783. }
  784. //포탈 이미지 화면에 붙이기
  785. if (gc.progress.nowStep == gc.progress.endStep - 1) {//챕터의 마지막 발판이 생겼을 경우
  786. if (this.portal) {
  787. removeObject(this.portal);
  788. this.removeSpineListener(this.portal);
  789. }
  790. this.portal = null;
  791. // var name = "portal" + gc.chapter;
  792. var name = "portal1";
  793. this.portal = new PIXI.spine.Spine(GD.loader.resources[name].spineData);
  794. this.portal.x = gc.maps.nextFootholdPos.x;
  795. this.portal.y = gc.maps.nextFootholdPos.y - 50;
  796. this.setSpineListener(this.portal);
  797. this.setAppearAnimate(this.portal);
  798. if (gc.chapter != 5) {
  799. var con = gc.maps.findContainer(gc.maps.nextFootholdPos.info.step);
  800. con.center.addChild(this.portal);
  801. TweenMax.delayedCall(0.8, (function () {
  802. gc.somi.portalSomi();
  803. }).bind(this));
  804. }
  805. else {
  806. gc.somi.sitOnLastFootHold(gc.maps.nextFootholdPos.x, gc.maps.nextFootholdPos.y - 50);
  807. }
  808. }
  809. //소미 설정
  810. if (gc.progress.endStep - gc.progress.nowStep == 3) {//목표지점까지 2번 더 뛰어야 할 경우
  811. gc.somi.appearSomi();
  812. }
  813. };
  814. //서있는 발판이 슬라이딩 발판이면 미끄러지기
  815. gc.GameScene.prototype.slideBlockAct = function () {
  816. var i;
  817. this.onSlideFootHold = false;
  818. for (i = 0; i < gc.maps.allFootHolds.length; i++) {
  819. if (gc.maps.allFootHolds[i].step == this.myCha.step && gc.maps.allFootHolds[i].stair == "top") {
  820. if (gc.maps.allFootHolds[i].skillType == "slide") {
  821. this.onSlideFootHold = true;
  822. break;
  823. }
  824. }
  825. }
  826. };
  827. //-----------------------------장애물 발생 여부
  828. //새 장애물
  829. gc.GameScene.prototype.setObstacleBird = function (moveDist, moveTime) {//새가 움직일 거리
  830. var rand = Math.floor(Math.random() * 100);
  831. var onBird = false;
  832. if (gc.chapter == 3) {
  833. if (rand < 10) onBird = true;
  834. }
  835. else if (gc.chapter == "5") {
  836. if (rand < 10) onBird = true;
  837. }
  838. if (gc.progress.nowStep <= 1 || gc.maps.nowFootholdPos.info.skillType == 'jump' || gc.maps.nextFootholdPos.info.skillType == 'jump')
  839. onBird = false;
  840. if (this.birdCnt >= 3) onBird = false;//새가 연속으로 3번 이상 나오지 않게끔 하기
  841. if (onBird) {
  842. this.birdCnt++;
  843. this.onObstacleBird(moveDist, moveTime);
  844. }
  845. else this.birdCnt = 0;
  846. };
  847. gc.GameScene.prototype.onObstacleBird = function (moveDist, moveTime) {
  848. var bird = this.obstacle.findBird();
  849. bird.step = this.myCha.step + 1;
  850. bird.center.x = gc.maps.nextFootholdPos.x;
  851. bird.center.y = gc.maps.nextFootholdPos.y;
  852. bird.img.x = 0;
  853. bird.img.y = 0;
  854. TweenMax.from(bird.center, moveTime, {
  855. y: bird.center.y + moveDist, onComplete: (function () {
  856. TweenMax.delayedCall(0.1, (function () {
  857. var birdDist = bird.img.y + 140;
  858. TweenMax.to(bird.img, 0.3, { y: birdDist });
  859. bird.isFly = true;
  860. this.obstacle.flyAnimate(bird.img);
  861. }).bind(this));
  862. }).bind(this)
  863. });
  864. this.birdContainer.addChildAt(bird.center, 0);
  865. };
  866. //암전 장애물
  867. gc.GameScene.prototype.setObstacleBlackout = function () {//정전 여부
  868. if (gc.progress.nowStep > 1 && gc.maps.nowFootholdPos.info.skillType != 'jump') {
  869. var rand = Math.floor(Math.random() * 100);
  870. this.obstacle.offLight = false;
  871. if (gc.chapter == 4) {
  872. if (rand < 5) this.obstacle.offLight = true;
  873. }
  874. else if (gc.chapter == "5") {
  875. if (rand < 5) this.obstacle.offLight = true;
  876. //엔딩컷 전에는 슬로우 모션이 되야하므로.
  877. if (gc.progress.endStep - gc.progress.nowStep == 1) this.obstacle.offLight = false;
  878. }
  879. if (this.obstacle.offLight) {
  880. this.onSpecialMessage(2);
  881. this.obstacle.offGameLight();
  882. }
  883. }
  884. };
  885. //--------------터치 이벤트
  886. gc.GameScene.prototype.touchStart = function () {
  887. //점프 준비중 애니메이션으로
  888. //서있는 상태일 때
  889. if (this.myCha.status == "stand") {
  890. this.chargeVolume = 0.3;
  891. if (gc.onFx) GD.soundPlay("sound_gauge", this.chargeVolume);
  892. this.myCha.status = "readyJump";//점프 준비 상태로 변경
  893. gc.characters.waitJumpAnimate(this.myCha.img);
  894. gc.maps.waitJumpAnimate();
  895. }
  896. };
  897. gc.GameScene.prototype.touchEnd = function () {
  898. //점프하는 이미지
  899. if (this.myCha.status == "readyJump") {
  900. GD.soundStop("sound_gauge");
  901. this.setInteractive(false);//터치 제어
  902. removeObject(this.effectFoot);
  903. removeObject(this.effectHead);
  904. this.myCha.status = "inJump";//점프 중 상태로 변경
  905. this.jumpPlayer();
  906. gc.characters.jumpAnimate(this.myCha.img);
  907. gc.maps.jumpAnimate();
  908. }
  909. gc.gravity.resetGuideLight();
  910. };
  911. //플레이어 충전 이펙트 보이기
  912. gc.GameScene.prototype.onChargeEffect = function () {
  913. this.setEffectAnimate(this.effectFoot);
  914. this.setEffectAnimate(this.effectHead);
  915. this.effectFoot.skeleton.setToSetupPose();
  916. this.effectHead.skeleton.setToSetupPose();
  917. this.effectFoot.x = this.myCha.x;
  918. this.effectFoot.y = this.myCha.y;
  919. this.effectHead.x = this.myCha.x;
  920. this.effectHead.y = this.myCha.y - 50;
  921. var time = 0.3;//발판 움직이는 시간보다 좀 더 짧게
  922. TweenMax.from(this.effectFoot, time, { x: this.myCha.img.x, y: this.myCha.img.y });
  923. TweenMax.from(this.effectHead, time, { x: this.myCha.img.x, y: this.myCha.img.y });
  924. this.playerContainer.addChildAt(this.effectFoot, 0);
  925. this.playerContainer.addChild(this.effectHead);
  926. };
  927. //사운드 버튼 클릭
  928. gc.GameScene.prototype.clickSoundBtn = function () {
  929. if (this.myCha.status != "readyJump") {
  930. gc.soundPopup.onSoundPopup();
  931. }
  932. };
  933. //점프 대기중 상태 체크
  934. gc.GameScene.prototype.checkInJumpWait = function () {
  935. if (this.myCha.status == "readyJump") {
  936. gc.gravity.addPow();
  937. }
  938. };
  939. //얼음 블록 터질때 유저가 얼음 발판에 있는지 확인
  940. gc.GameScene.prototype.checkPlayerInIceFootHold = function (fhStep) {
  941. if (this.myCha.step == fhStep) {
  942. if (this.myCha.status != "inJump" && this.myCha.status != "over") {
  943. this.myCha.status = 'over';
  944. removeObject(this.effectFoot);
  945. removeObject(this.effectHead);
  946. gc.characters.standFailAnimate(this.myCha.img);
  947. }
  948. }
  949. };
  950. //슬라이드 발판에 서있는지 확인
  951. gc.GameScene.prototype.checkOnSlide = function () {
  952. if (!gc.pauseGame) {
  953. var frame = 60 * 5;//60프레임이라 보고 5초당 해당 거리만큼 움직여라
  954. var vx = gc.maps.nowFootholdPos.info.fhWidth;
  955. var vy = gc.maps.nowFootholdPos.info.fhHeight;
  956. if (this.myCha.jumpDir == -1) vx = -vx;
  957. if (this.onSlideFootHold) {
  958. if (this.myCha.status == "stand") {
  959. gc.maps.setNowFootHoldPos();//발판 좌표 재설정
  960. this.myCha.x += vx / frame;
  961. this.myCha.y -= vy / frame;
  962. this.myCha.img.x = this.myCha.x;
  963. this.myCha.img.y = this.myCha.y;
  964. gc.maps.setFootHoldDist();//다음 발판까지 거리 설정
  965. var result = gc.gravity.checkInSameFootHold();
  966. if (result.result == "danger" || result.result == "weak" || result.result == "too much") {
  967. this.myCha.status = 'over';
  968. if (result.result == "danger") gc.characters.standFailAnimate(this.myCha.img);
  969. else if (result.result == "weak") gc.characters.hitWallAnimate(this.myCha.img);
  970. else if (result.result == "too much") gc.characters.fallDownAnimate(this.myCha.img);
  971. }
  972. }
  973. }
  974. }
  975. };
  976. //점프하기
  977. gc.GameScene.prototype.jumpPlayer = function () {
  978. if (gc.onFx) GD.soundPlay("sound_jump");
  979. var result = {};
  980. if (gc.maps.nowFootholdPos.info.skillType == "jump") {
  981. gc.gravity.chargePow = gc.maps.footHoldGap;
  982. result = gc.gravity.calcJumpResult();
  983. }
  984. else {
  985. result = gc.gravity.calcJumpResult();
  986. }
  987. console.log("점프결과", result);
  988. var movetime = 0.4;
  989. var vx = result.vx;
  990. var vy = result.vy;
  991. if (result.result == "weak") {//벽에 부딪치는 경우 목표 x좌표의 조정
  992. vx += gc.gravity.calcSideGapWithPlayer(this.myCha.x + vx);//유저와 다음발판 줄기 사이의 거리
  993. }
  994. //점프할 최대 높이
  995. var topY = vy - (this.myCha.y - vy) * 0.05;
  996. var upGoalX = 0;
  997. var upGoalY = topY;
  998. if (result.result == "too much") upGoalX = vx * 0.68;
  999. else upGoalX = vx * 0.6;
  1000. var startUpX = this.myCha.x;
  1001. var startUpY = this.myCha.y;
  1002. //올라선 발판이 점프발판인 경우 유저 오브젝트 이미지의 좌표로 계산
  1003. if (gc.maps.nowFootholdPos.info.skillType == "jump") startUpY = this.myCha.img.y;
  1004. var startDownX = startUpX + upGoalX;
  1005. var startDownY = startUpY + upGoalY;
  1006. this.myCha.x += vx;
  1007. this.myCha.y += vy;
  1008. var landingAniY = (this.myCha.img.y + vy) * 0.95;
  1009. var landingAniX = (this.myCha.img.x + vx) * 0.8;
  1010. //마지막 챕터의 마지막 점프
  1011. var allGameClear = false;
  1012. if (gc.chapter == 5 && gc.progress.endStep - gc.progress.nowStep == 1) {
  1013. if (result.result == "perfect" || result.result == "nice" || result.result == "good") {
  1014. movetime *= 5;
  1015. var g = GraphicManager.drawRect(gc.width, gc.height, "0XFFFFFF");
  1016. TweenMax.from(g, movetime * 0.5, {
  1017. alpha: 0, onComplete: (function () {
  1018. console.log("엔딩컷신");
  1019. }).bind(this)
  1020. });
  1021. this.addChild(g);
  1022. allGameClear = true;
  1023. }
  1024. }
  1025. var upTweener = TweenMax.to(this.myCha.img, movetime * 0.6, {
  1026. ease: Power0.easeNone,
  1027. bezier: {
  1028. type: "quadratic",
  1029. values: [{ x: startUpX, y: startUpY },
  1030. { x: (startUpX + upGoalX * 0.2), y: startUpY + upGoalY * 0.9 },
  1031. { x: (startUpX + upGoalX), y: startUpY + upGoalY }]
  1032. },
  1033. onUpdate: (function () {
  1034. this.checkHitWithBird(upTweener);
  1035. }).bind(this),
  1036. // onComplete:downTween.bind(this)
  1037. onComplete: (function () {
  1038. if (!allGameClear) downTween.bind(this)();
  1039. }).bind(this)
  1040. });
  1041. function downTween() {
  1042. var isLandingAni = (result.result == "perfect" || result.result == "nice" || result.result == "good");
  1043. var downGoalX = vx - upGoalX;
  1044. var downGoalY = (topY - vy);
  1045. var downTime = movetime * 0.3;
  1046. var inSameFoothold = gc.gravity.checkInSameFootHold();
  1047. console.log("같은 발판에 올라섬", inSameFoothold);
  1048. if (inSameFoothold != "stand") {
  1049. if (!isLandingAni) {//다음 발판에 올라가지 못함
  1050. if (result.result != "danger") {
  1051. if (result.result != "too much") {
  1052. this.checkDepth(this.myCha.x);
  1053. }
  1054. else {// 벽에 부딪침
  1055. this.checkDepth(this.myCha.x + downGoalX);
  1056. downGoalY = -(gc.height - this.myCha.img.y);
  1057. downGoalX = vx * 0.5;
  1058. downTime = movetime * 0.7;
  1059. }
  1060. }
  1061. }
  1062. }
  1063. var downTweener = TweenMax.to(this.myCha.img, downTime, {
  1064. ease: Power0.easeNone,
  1065. bezier: {
  1066. type: "quadratic",
  1067. values: [{ x: startDownX, y: startDownY },
  1068. { x: (startDownX + downGoalX * 0.85), y: (startDownY - downGoalY * 0.1) },
  1069. { x: startDownX + downGoalX, y: startDownY - downGoalY }]
  1070. },
  1071. onUpdate: (function () {
  1072. this.checkHitWithBird(downTweener);
  1073. // - 착지에 가까운 위치에 도달했을 때 애니메이션 변경
  1074. if (isLandingAni === true && this.myCha.img.y >= landingAniY) {
  1075. if (this.myCha.img.x >= landingAniX) {
  1076. isLandingAni = false;
  1077. gc.characters.standClearAnimate(this.myCha.img);
  1078. }
  1079. }
  1080. }).bind(this),
  1081. onComplete: (function () {
  1082. if (result.result == "perfect" || result.result == "nice" || result.result == "good") {
  1083. //유저가 바라볼 방향 설정
  1084. this.myCha.jumpDir = gc.maps.initFootholdInfo.dir;
  1085. this.setPlayerStandScale();
  1086. this.startStep += this.jumpStep;
  1087. this.myCha.step = this.startStep;
  1088. gc.gravity.resetPow();
  1089. gc.maps.jumpIn();//올라선 발판 안착 애니메이션
  1090. //암전 취소
  1091. this.obstacle.onGameLight();
  1092. //점수 추가, 점수 이펙트 여부, 발판 생성(챕터 클리어)
  1093. var score = this.setAddScore(result.result);
  1094. this.addScore(score);
  1095. if (gc.maps.nowFootholdPos.info.skillType == "jump") this.onSpecialMessage(0);
  1096. else if (gc.maps.nowFootholdPos.info.skillType == "ice" || gc.maps.nowFootholdPos.info.skillType == "slide")
  1097. this.onSpecialMessage(1);
  1098. }
  1099. else {//跳得不好或者更跑的时候
  1100. gc.maps.setNowFootHoldPos();//登上跳板后,把坐标储存起来
  1101. //미리 체크해둠
  1102. if (inSameFoothold == "stand") {//제자리에 올라갔을 때
  1103. this.combo = 0;
  1104. this.myCha.status = "stand";
  1105. this.setPlayerStandScale();
  1106. gc.maps.setFootHoldDist();
  1107. gc.gravity.resetPow();
  1108. gc.maps.jumpIn();//올라선 발판 안착 애니메이션
  1109. TweenMax.delayedCall(0.1, (function () {
  1110. this.setInteractive(true);//터치 제어
  1111. }).bind(this));
  1112. gc.characters.standAnimate(this.myCha.img);
  1113. }
  1114. else {//허공에 떨어질 때
  1115. this.myCha.status = 'over';
  1116. if (result.result == "danger") {
  1117. if (gc.onFx) GD.soundPlay("sound_dangling");
  1118. gc.characters.standFailAnimate(this.myCha.img);
  1119. }//발판에서 떨어짐
  1120. else if (result.result == "weak") {
  1121. if (gc.onFx) GD.soundPlay("sound_wallhit");
  1122. gc.characters.hitWallAnimate(this.myCha.img);
  1123. var ef = this.onHitEffect();
  1124. ef.x = this.myCha.img.x;
  1125. ef.y = this.myCha.img.y;
  1126. this.midContainer.addChild(ef);
  1127. }//벽에 부딪침
  1128. else if (result.result == "too much") {//허공에 떨어짐
  1129. if (gc.onFx) GD.soundPlay("sound_falling");
  1130. removeObject(gc.game.myCha.img);
  1131. gameOver();
  1132. }
  1133. }
  1134. }
  1135. }).bind(this)
  1136. })
  1137. }
  1138. };
  1139. //새와 부딪침 처리
  1140. gc.GameScene.prototype.checkHitWithBird = function (tween) {
  1141. var isHitBird = this.obstacle.checkHitWithBird();//새와 부딪쳤는지 체크
  1142. if (isHitBird) {
  1143. if (gc.onFx) GD.soundPlay("sound_birdhit");
  1144. tween.kill();
  1145. gc.characters.hitWallAnimate(this.myCha.img);
  1146. }
  1147. };
  1148. //레이어 처리
  1149. gc.GameScene.prototype.checkDepth = function (checkX) {
  1150. if (this.obstacle) {
  1151. if (this.obstacle.offLight) this.setMidContainer(0);//암전상태일때는 유저가 가장 위에 보임
  1152. else {
  1153. var px = checkX;//this.myCha.img.x;
  1154. var fh = gc.maps.nextFootholdPos;
  1155. if (this.myCha.jumpDir == 1) {//오른쪽으로 뛸 때
  1156. if (px <= fh.x) this.setMidContainer(2);//발판 사이에 떨어짐
  1157. else this.setMidContainer(1);//너무 멀리 뜀
  1158. }
  1159. else {//왼쪽으로 뛸 때
  1160. if (px <= fh.x) this.setMidContainer(1);//너무 멀리 뜀
  1161. else this.setMidContainer(2);//발판 사이에 떨어짐
  1162. }
  1163. }
  1164. }
  1165. };
  1166. //점수 강조 체크
  1167. gc.GameScene.prototype.checkScoreEffect = function (preScore) {
  1168. var prescore = preScore;
  1169. var nowscore = this.score;
  1170. //1000단위 변화 체크
  1171. var preUnit = Math.floor(prescore / 1000);
  1172. var nowUnit = Math.floor(nowscore / 1000);
  1173. if (preUnit != nowUnit) {
  1174. this.onScoreEffect("1000");
  1175. return;
  1176. }
  1177. else {
  1178. prescore -= preUnit * 1000;
  1179. nowscore -= nowUnit * 1000;
  1180. //100단위 체크
  1181. preUnit = Math.floor(prescore / 100);
  1182. nowUnit = Math.floor(nowscore / 100);
  1183. if (preUnit != nowUnit) {
  1184. this.onScoreEffect("100");
  1185. return;
  1186. }
  1187. else {
  1188. prescore -= preUnit * 100;
  1189. nowscore -= nowUnit * 100;
  1190. //50단위 체크
  1191. preUnit = Math.floor(prescore / 50);
  1192. nowUnit = Math.floor(nowscore / 50);
  1193. if (preUnit != nowUnit) {
  1194. this.onScoreEffect("50");
  1195. return;
  1196. }
  1197. }
  1198. }
  1199. this.checkChapterOver();//해당 챕터가 완료되었는지 체크
  1200. };
  1201. //벽에 부딪치는 이펙트
  1202. gc.GameScene.prototype.onHitEffect = function () {
  1203. var ef = new PIXI.spine.Spine(GD.loader.resources["cha_hit"].spineData);
  1204. ef.skeleton.setToSetupPose();
  1205. ef.state.timeScale = 1.2;
  1206. ef.state.setAnimation(0, "cha_hit", false, 0);
  1207. return ef;
  1208. };
  1209. //점수 강조 이펙트
  1210. gc.GameScene.prototype.onScoreEffect = function (type) {
  1211. this.scoreText.alpha = 0;
  1212. var soundName = "sound_" + type;
  1213. if (gc.onFx) GD.soundPlay(soundName);
  1214. //점수 강조 이펙트 생성
  1215. this.scoreEfBg = null;
  1216. this.scoreEfBg = new PIXI.spine.Spine(GD.loader.resources["scoreEf" + type].spineData);
  1217. this.setSpineListener(this.scoreEfBg);
  1218. this.scoreEfBg.x = this.scoreText.x;
  1219. this.scoreEfBg.y = this.scoreText.y + 30;
  1220. //강조할 점수 텍스트
  1221. if (!this.mainScoreEfNum) {
  1222. this.scoreNumContainer = new PIXI.Container();
  1223. this.scoreNumContainer.x = this.scoreText.x;
  1224. this.scoreNumContainer.y = this.scoreText.y + 15;
  1225. this.mainScoreEfNum = new gc.NumberText("c_score", 'center', -4);
  1226. this.mainScoreEfNum.setValue(0);
  1227. this.scoreNumContainer.addChild(this.mainScoreEfNum);
  1228. }
  1229. this.setScoreEfAnimate(this.scoreEfBg);
  1230. this.uiContainer.addChild(this.scoreEfBg);
  1231. //점수 텍스트 이펙트
  1232. this.mainScoreEfNum.setValue(this.score);
  1233. this.scoreNumContainer.x = this.scoreText.x;
  1234. this.scoreNumContainer.y = this.scoreText.y - 30;
  1235. var time1 = 0.4, time2 = 0.1, time3 = 0.3;
  1236. TweenMax.from(this.scoreNumContainer, time1, {
  1237. y: this.scoreNumContainer.y - 220, onComplete: (function () {
  1238. TweenMax.to(this.scoreNumContainer, time2, { y: this.scoreNumContainer.y - 20 });
  1239. }).bind(this)
  1240. });
  1241. TweenMax.fromTo(this.scoreNumContainer.scale, time1, { ease: Power0.easeNone, x: 4.8, y: 4.8, alpha: 0 }, {
  1242. x: 1.4, y: 1.4, alpha: 1, onComplete: (function () {
  1243. TweenMax.to(this.scoreNumContainer.scale, time2, { ease: Power0.easeNone, x: 1.7, y: 1.7 });
  1244. }).bind(this)
  1245. });
  1246. this.uiContainer.addChild(this.scoreNumContainer);
  1247. this.checkChapterOver();//해당 챕터가 완료되었는지 체크
  1248. };
  1249. //게임 상태 메세지 이펙트
  1250. gc.GameScene.prototype.onStateMessage = function (type) {
  1251. var name = "";
  1252. if (type == 0) name = "t_begin";//처음 시작
  1253. else if (type == 1) name = "t_again";//챕터 시작
  1254. else if (type == 2) name = "t_gameover";//게임오버
  1255. if (!this.messageText) this.messageText = new PIXI.Sprite.fromFrame(name + ".png");
  1256. else this.messageText.texture = PIXI.Texture.fromFrame(name + ".png");
  1257. this.messageText.x = gc.width / 2;
  1258. this.messageText.y = gc.height / 2;
  1259. this.messageText.alpha = 1;
  1260. if (type < 2) {//게임 시작, 새로운 챕터 시작
  1261. this.messageText.anchor.x = 0.5;
  1262. this.messageText.anchor.y = 1;
  1263. var time = 0.4;
  1264. TweenMax.from(this.messageText, time, { ease: Power0.easeNone, y: this.messageText.y + 40, alpha: 0 });
  1265. time = 0.3;
  1266. em.bumpToY(this.messageText, time, 0.1, returnMessage.bind(this));
  1267. }
  1268. else if (type == 2) {//게임오버
  1269. this.messageText.anchor.set(0.5);
  1270. em.bumpFromToX(this.messageText, 0.3, 0, 1.1, 1, returnMessage.bind(this));
  1271. }
  1272. //이펙트가 끝난 후 리턴 함수
  1273. function returnMessage() {
  1274. if (type < 2) {
  1275. TweenMax.delayedCall(0.5, (function () {
  1276. TweenMax.to(this.messageText, time, {
  1277. y: this.messageText.y + 40, alpha: 0, onComplete: (function () {
  1278. removeObject(this.messageText);
  1279. }).bind(this)
  1280. });
  1281. }).bind(this));
  1282. }
  1283. else if (type == 2) {
  1284. //this.addResult();//네이버 결과 저장
  1285. onIntro();//로컬 실행
  1286. }
  1287. }
  1288. this.uiContainer.addChild(this.messageText);
  1289. };
  1290. gc.GameScene.prototype.onSpecialMessage = function (type) {
  1291. var name = "";
  1292. if (type == 0) name = "t_lucky";//점프발판
  1293. else if (type == 1) name = "t_watchout";//얼음, 슬라이드발판
  1294. else if (type == 2) name = "t_sodark";//암전
  1295. if (type == 0 || type == 1) {
  1296. if (!this.specialMessage) this.specialMessage = new PIXI.Sprite.fromFrame(name + ".png");
  1297. else this.specialMessage.texture = PIXI.Texture.fromFrame(name + ".png");
  1298. if (this.specialEf) this.specialEf.kill();
  1299. this.specialEf = null;
  1300. var time = 0.5;
  1301. if (type == 1 || type == 2) time = 1;
  1302. this.specialMessage.alpha = 1;
  1303. this.specialMessage.anchor.set(0.5);
  1304. this.specialMessage.x = this.myCha.img.x;
  1305. this.specialMessage.y = this.myCha.img.y - 80;
  1306. this.specialEf = TweenMax.to(this.specialMessage, time, { ease: Power0.easeNone, y: this.specialMessage.y - 70, alpha: 0, onComplete: returnMessage.bind(this) });
  1307. this.uiContainer.addChild(this.specialMessage);
  1308. }
  1309. else if (type == 2) {
  1310. if (!this.blackoutMessage) this.blackoutMessage = new PIXI.Sprite.fromFrame(name + ".png");
  1311. this.blackoutMessage.anchor.set(0.5);
  1312. this.blackoutMessage.alpha = 1;
  1313. this.blackoutMessage.x = gc.width / 2;
  1314. this.blackoutMessage.y = gc.height / 3;
  1315. em.bumpFromToX(this.blackoutMessage, 0.3, 0, 1.2, 1, (function () {
  1316. TweenMax.to(this.blackoutMessage, 0.5, {
  1317. alpha: 0, onComplete: (function () {
  1318. removeObject(this.blackoutMessage);
  1319. }).bind(this)
  1320. });
  1321. }).bind(this));
  1322. this.uiContainer.addChild(this.blackoutMessage);
  1323. }
  1324. //이펙트가 끝난 후 리턴 함수
  1325. function returnMessage() {
  1326. removeObject(this.specialMessage);
  1327. }
  1328. };
  1329. //챕터 완료 확인
  1330. gc.GameScene.prototype.checkChapterOver = function () {
  1331. if (gc.progress.nowStep == gc.progress.endStep) this.chapterClear = true;
  1332. else {
  1333. this.chapterClear = false;
  1334. }
  1335. if (this.chapterClear) {
  1336. if (gc.onFx) GD.soundPlay("sound_clear");
  1337. this.obstacle.resetBirds();
  1338. //스테이지별 추가 점수
  1339. this.addChapterClearScore();
  1340. var light = new PIXI.Sprite.fromFrame("light1.png");
  1341. light.anchor.set(0.5);
  1342. light.x = this.portal.x;
  1343. light.y = this.portal.y;
  1344. this.addChild(light);
  1345. var time = 2;
  1346. TweenMax.fromTo(light.scale, time, { x: 0, y: 0 }, {
  1347. x: 30, y: 30, onComplete: (function () {
  1348. gc.chapter++;
  1349. this.setNextChapterScene();
  1350. var con = gc.maps.findContainer(gc.maps.nowFootholdPos.info.step);
  1351. con.center.addChild(this.portal);
  1352. this.portal.x = gc.maps.nowFootholdPos.x;
  1353. this.portal.y = gc.maps.nowFootholdPos.y - 50;
  1354. light.x = this.portal.x;
  1355. light.y = this.portal.y;
  1356. TweenMax.to(light.scale, time / 2, {
  1357. x: 0, y: 0, onComplete: (function () {
  1358. if (gc.onFx) GD.soundPlay("sound_newtheme");
  1359. removeObject(light);
  1360. em.floatByY(this.somi, 0.5, 20, 2, gc.somi.disappearSomi.bind(gc.somi));
  1361. }).bind(this)
  1362. })
  1363. }).bind(this)
  1364. });
  1365. }
  1366. else {
  1367. this.setBackground();//발판 내리기, 다음 발판 생성
  1368. }
  1369. };
  1370. //다음 챕터 화면으로 갱신
  1371. gc.GameScene.prototype.setNextChapterScene = function () {
  1372. this.offUI();
  1373. this.setGameBgImage();//배경 이미지 설정
  1374. gc.somi.resetSomi();
  1375. this.uiContainer.addChild(this.somi);
  1376. this.onSlideFootHold = false;
  1377. gc.maps.resetAllFootHold();
  1378. gc.maps.reset();//발판 초기화
  1379. gc.progress.setEndStep();//스테이지별 스텝 설정
  1380. gc.progress.resetNowStep();//진행바 초기화
  1381. gc.maps.initFootHolds(this.startStep, 1, 'basic');
  1382. this.myCha.status = "stand";
  1383. this.myCha.x = gc.maps.nowFootholdPos.x;
  1384. this.myCha.y = gc.maps.nowFootholdPos.y;
  1385. this.myCha.img.x = this.myCha.x;
  1386. this.myCha.img.y = this.myCha.y;
  1387. this.myCha.jumpDir = 1;
  1388. this.setPlayerStandScale();
  1389. };
  1390. //눌렸을때 이펙트
  1391. gc.GameScene.prototype.setEffectAnimate = function (obj) {
  1392. obj.skeleton.setToSetupPose();
  1393. obj.state.setAnimation(0, "ef", true, 0);
  1394. };
  1395. //--------------------이벤트 활성화
  1396. gc.GameScene.prototype.setInteractive = function (bool) {
  1397. this.touchBg.interactive = bool;
  1398. //this.soundBtn.interactive = bool;/*네이버 연동 후 활성화 시키기*/
  1399. };
  1400. //스파인 애니메이션
  1401. //포탈 생성 애니
  1402. gc.GameScene.prototype.setAppearAnimate = function (obj) {
  1403. this.resetAnimate(obj);
  1404. var aniname = "portal_appear";
  1405. var aniObj = obj.state.setAnimation(0, aniname, false, 0);
  1406. obj.state.addAnimation(0, "portal_normal", true, aniObj.animationEnd);
  1407. };
  1408. //점수 강조 이펙트
  1409. gc.GameScene.prototype.setScoreEfAnimate = function (obj) {
  1410. this.resetAnimate(obj);
  1411. var aniname = "scoreEf";
  1412. obj.state.setAnimation(0, aniname, false, 0);
  1413. };
  1414. gc.GameScene.prototype.resetAnimate = function (obj) {
  1415. obj.state.clearTracks();
  1416. obj.skeleton.setToSetupPose();
  1417. obj.state.timeScale = 1;
  1418. // obj.update(1);
  1419. // obj.state.setEmptyAnimation(0,1);
  1420. };
  1421. gc.GameScene.prototype.reset = function () {
  1422. gc.gravity = null;
  1423. gc.maps = null;
  1424. this.progressContainer = null;//진행률 컨테이너
  1425. this.scoreEfBg = null;
  1426. this.chapterClear = true;//처음 발판 생성시 기본 좌표에 생성하기 위함
  1427. this.removeChildren();
  1428. this.playerContainer.removeChildren();
  1429. if (this.portal) removeObject(this.portal);
  1430. this.portal = null;
  1431. this.myCha = null;
  1432. this.combo = 0;
  1433. this.score = 0;
  1434. this.birdCnt = 0;//새가 연속으로 나온 횟수
  1435. this.chargeVolume = 0.3;
  1436. this.startStep = 0;//현재 유저가 서있는 스텝
  1437. this.jumpStep = 1;//현재 스텝과 다음 스텝의 차이
  1438. this.onSlideFootHold = false;//슬라이드 발판 위에 있는지 여부
  1439. };
  1440. gc.GameScene.prototype.pause = function () {
  1441. gc.pauseGame = true;
  1442. this.setFlag();
  1443. TweenMax.pauseAll();
  1444. console.log("일시정지");
  1445. };
  1446. gc.GameScene.prototype.resume = function () {
  1447. gc.pauseGame = false;
  1448. this.setFlag();
  1449. TweenMax.resumeAll();
  1450. console.log("계속하기");
  1451. };
  1452. gc.GameScene.prototype.setFlag = function () {
  1453. this.myCha.img.autoUpdate = !gc.pauseGame;
  1454. this.somi.autoUpdate = !gc.pauseGame;
  1455. if (this.portal) this.portal.autoUpdate = !gc.pauseGame;
  1456. if (this.scoreEfBg) this.scoreEfBg.autoUpdate = !gc.pauseGame;
  1457. for (var i = 0; i < gc.maps.allFootHolds.length; i++) gc.maps.allFootHolds[i].img.autoUpdate = !gc.pauseGame;
  1458. this.setInteractive(!gc.pauseGame);
  1459. };
  1460. gc.GameScene.prototype.addResult = function () {
  1461. GamePocket.Sdk.Ranking.addMyScore(this.score, (function (response) {
  1462. //this.loadingHide();
  1463. if (response.code === GamePocket.Sdk.ResponseCode.SUCCESS) {
  1464. var ranking = response.result;
  1465. //console.log("랭킹을 남긴 사용자 수 : " + ranking.countOfAllUsers);
  1466. //console.log("" + ranking.percentile);
  1467. //console.log("" + ranking.group);
  1468. //console.log("" + ranking.groupIcon);
  1469. //console.log("" + ranking.score);
  1470. this.onResultView(this.score, ranking.score, "", ranking.groupIcon, 1);
  1471. } else {
  1472. if (response.code == GamePocket.Sdk.ResponseCode.NOT_FOUND_GAME || response.code == GamePocket.Sdk.ResponseCode.NO_AUTHENTICATION) {
  1473. this.onResultView(this.score, 0, 0, "DIAMOND", 2, 2);
  1474. } else {
  1475. this.onResultView(this.score, 0, 0, "DIAMOND", 2, 1);
  1476. }
  1477. //console.log(response.code);
  1478. }//fail process
  1479. }).bind(this));
  1480. };
  1481. gc.GameScene.prototype.onResultView = function (score, bestScore, rank, group, type, message) {
  1482. console.log("onResultView score:" + score + " best Score:" + bestScore + " rank:" + rank + " group:" + group + " tpye:" + type + " message:" + message);
  1483. gc.resultView.init(score, bestScore, rank, group, type, message);
  1484. GD.stage.addChild(gc.resultView);
  1485. };
  1486. gc.GameScene.prototype.updateTransform = function () {
  1487. try {
  1488. this.checkInJumpWait();
  1489. this.checkOnSlide();
  1490. if (this.obstacle) this.obstacle.flyBird();
  1491. PIXI.Container.prototype.updateTransform.call(this);
  1492. } catch (e) {
  1493. }
  1494. };
  1495. /**
  1496. * Created by juho on 2016-03-30.
  1497. */
  1498. gc.NumberText = function (fileName, align, space, iconName, iconAlign, commaName) {
  1499. this.CENTER = 'center';
  1500. this.RIGHT = 'right';
  1501. this.LEFT = 'left';
  1502. this.value = 0;
  1503. this.isChange = false;
  1504. this.list = [];
  1505. this.tmpList = [];
  1506. this.fileName = fileName;
  1507. this.align = align;
  1508. this.space = space;
  1509. this.iconName = iconName;
  1510. this.iconAlign = iconAlign;
  1511. this.commaName = commaName;
  1512. this.icon = null;
  1513. PIXI.Container.call(this);
  1514. this.container = new PIXI.Container();
  1515. this.addChild(this.container);
  1516. this.setValue(0);
  1517. };
  1518. gc.NumberText.constructor = gc.NumberText;
  1519. gc.NumberText.prototype = Object.create(PIXI.Container.prototype);
  1520. gc.NumberText.prototype.setValue = function (value) {
  1521. this.value = value;
  1522. this.isChange = true;
  1523. };
  1524. gc.NumberText.prototype.getNumberSprite = function (num) {
  1525. var sprite, name;
  1526. name = this.fileName + num + '.png';
  1527. if (this.tmpList.length > 0) {
  1528. sprite = this.tmpList.shift();
  1529. sprite.texture = PIXI.Texture.fromFrame(name);
  1530. } else {
  1531. sprite = PIXI.Sprite.fromFrame(name);
  1532. }
  1533. return sprite;
  1534. };
  1535. gc.NumberText.prototype.getCommaSprite = function () {
  1536. var sprite, name = this.commaName + '.png';
  1537. if (this.tmpList.length > 0) {
  1538. sprite = this.tmpList.shift();
  1539. sprite.texture = PIXI.Texture.fromFrame(name);
  1540. } else {
  1541. sprite = PIXI.Sprite.fromFrame(name);
  1542. }
  1543. return sprite;
  1544. };
  1545. gc.NumberText.prototype.removeAll = function () {
  1546. var txt, i = this.list.length;
  1547. while (i--) {
  1548. txt = this.list.shift();
  1549. this.tmpList.push(txt);
  1550. }
  1551. if (this.container) this.container.removeChildren();
  1552. };
  1553. gc.NumberText.prototype.updateTransform = function () {
  1554. if (this.isChange) {
  1555. this.removeAll();
  1556. var numStr = (this.commaName) ? Util.comma(this.value) : this.value.toString();
  1557. var index = 0, txt, str,
  1558. space = 0,
  1559. i = numStr.length;
  1560. if (this.iconName) {
  1561. if (!this.icon) this.icon = PIXI.Sprite.fromFrame(this.iconName);
  1562. this.container.addChild(this.icon);
  1563. if (this.iconAlign == 'left') {
  1564. space += this.icon.width + this.space;
  1565. }
  1566. }
  1567. while (i--) {
  1568. str = numStr.substr(index, 1);
  1569. if (str == '.') {
  1570. txt = this.getCommaSprite();
  1571. } else {
  1572. txt = this.getNumberSprite(parseInt(str) + 1);
  1573. }
  1574. txt.x = space;
  1575. space += txt.width;
  1576. if (i > 0) space += this.space;
  1577. index++;
  1578. this.container.addChild(txt);
  1579. this.list[i] = txt;
  1580. }
  1581. if (this.iconAlign == 'right') {
  1582. this.icon.x = space;
  1583. space += this.icon.width + this.space;
  1584. }
  1585. if (this.align == this.CENTER) {
  1586. this.container.x = -space / 2;
  1587. } else if (this.align == this.RIGHT) {
  1588. this.container.x = -space;
  1589. }
  1590. this.isChange = false;
  1591. }
  1592. PIXI.Container.prototype.updateTransform.call(this);
  1593. };
  1594. /**
  1595. * Created by admin on 2018-06-14.
  1596. */
  1597. gc.Somi = function () {
  1598. PIXI.Container.call(this);
  1599. this.somi = new PIXI.spine.Spine(GD.loader.resources["somi"].spineData);
  1600. };
  1601. gc.Somi.constructor = gc.Somi;
  1602. gc.Somi.prototype = Object.create(PIXI.Container.prototype);
  1603. gc.Somi.prototype.setSpineListener = function (obj) {
  1604. obj.state.addListener({
  1605. complete: (function (t) {
  1606. if (t.animation.name == "somi") {
  1607. this.removeSpineListener(obj);
  1608. removeObject(obj);
  1609. }
  1610. }).bind(this)
  1611. });
  1612. };
  1613. gc.Somi.prototype.removeSpineListener = function (obj) {
  1614. obj.state.removeListener();
  1615. };
  1616. gc.Somi.prototype.init = function () {
  1617. this.resetSomi();
  1618. this.somiHelpAnimate(this.somi);
  1619. return this.somi;
  1620. };
  1621. //화면 밖으로 날아가기
  1622. gc.Somi.prototype.disappearSomi = function () {
  1623. this.resetSomi();
  1624. TweenMax.to(this.somi, 1, {
  1625. y: -250, onComplete: (function () {
  1626. //유저가 생성된 후 건너가야 할 발판 생성
  1627. gc.maps.initFootHolds(gc.game.startStep + 1, 1);
  1628. gc.maps.setFootHoldDist();//유저와 다음 발판 사이 거리 계산
  1629. gc.game.setInteractive(true);
  1630. var message = (gc.chapter == 1) ? 0 : 1;
  1631. gc.game.onStateMessage(message);//게임 시작 문구
  1632. gc.game.onUI();
  1633. }).bind(this)
  1634. });
  1635. };
  1636. //화면으로 나타나기
  1637. gc.Somi.prototype.appearSomi = function () {
  1638. this.resetSomi();
  1639. TweenMax.from(this.somi, 1, { y: -250 });
  1640. };
  1641. //포탈로 넘어가기
  1642. gc.Somi.prototype.portalSomi = function () {
  1643. if (gc.chapter != 5) {
  1644. TweenMax.to(this.somi, 0.3, {
  1645. x: gc.game.portal.x, y: gc.game.portal.y + 40, onComplete: (function () {
  1646. TweenMax.to(this.somi.scale, 0.1, {
  1647. x: 0, y: 0, onComplete: (function () {
  1648. var ef = gc.game.onHitEffect();
  1649. this.setSpineListener(ef);
  1650. ef.x = gc.game.portal.x;
  1651. ef.y = gc.game.portal.y;
  1652. gc.game.uiContainer.addChild(ef);
  1653. removeObject(this.somi);
  1654. }).bind(this)
  1655. });
  1656. }).bind(this)
  1657. });
  1658. }
  1659. };
  1660. //마지막 발판 위에 앉아있기
  1661. gc.Somi.prototype.sitOnLastFootHold = function (x, y) {
  1662. TweenMax.to(this.somi, 1, { x: x, y: y });
  1663. };
  1664. //소미 상태 초기화
  1665. gc.Somi.prototype.resetSomi = function () {
  1666. this.somi.scale.x = 1;
  1667. this.somi.scale.y = 1;
  1668. this.somi.rotation = 0;
  1669. this.somi.x = gc.width * 0.5;
  1670. this.somi.y = 450;
  1671. };
  1672. //소미 애니메이션
  1673. gc.Somi.prototype.somiHelpAnimate = function (obj) {
  1674. this.resetAnimate(obj);
  1675. var aniname = "somi";
  1676. obj.state.setAnimation(0, aniname, true, 0);
  1677. };
  1678. gc.Somi.prototype.resetAnimate = function (obj) {
  1679. obj.state.clearTracks();
  1680. obj.skeleton.setToSetupPose();
  1681. obj.state.timeScale = 1;
  1682. // obj.update(1);
  1683. // obj.state.setEmptyAnimation(0,1);
  1684. };
  1685. gc.Somi.prototype.updateTransform = function () {
  1686. try {
  1687. PIXI.Container.prototype.updateTransform.call(this);
  1688. } catch (e) {
  1689. }
  1690. };
  1691. /**
  1692. * Created by admin on 2018-05-18.
  1693. */
  1694. gc.Obstacle = function () {
  1695. PIXI.Container.call(this);
  1696. this.birds = [];
  1697. this.blackout = null;
  1698. this.offLight = false;
  1699. this.blackoutCon = new PIXI.Container();
  1700. this.birdCon = new PIXI.Container();
  1701. };
  1702. gc.Obstacle.constructor = gc.Obstacle;
  1703. gc.Obstacle.prototype = Object.create(PIXI.Container.prototype);
  1704. //------------초기화
  1705. gc.Obstacle.prototype.initBirdContainer = function () {
  1706. this.birdCon.removeChildren();
  1707. this.resetBirds();
  1708. return this.birdCon;
  1709. };
  1710. gc.Obstacle.prototype.initBlackoutContainer = function () {
  1711. this.blackoutCon.removeChildren();
  1712. this.offLight = false;
  1713. return this.blackoutCon;
  1714. };
  1715. //사용할 새 생성
  1716. gc.Obstacle.prototype.findBird = function () {
  1717. var i;
  1718. var bird = null;
  1719. for (i = 0; i < this.birds.length; i++) {
  1720. if (!this.birds[i].isWork) {
  1721. bird = this.birds[i];
  1722. this.birds[i].isWork = true;
  1723. break;
  1724. }
  1725. }
  1726. if (!bird) {
  1727. bird = {
  1728. center: new PIXI.Container(),
  1729. img: new PIXI.spine.Spine(GD.loader.resources['bird3'].spineData),
  1730. step: null,
  1731. isWork: true,
  1732. isFly: false
  1733. }
  1734. //히트영역 저장
  1735. var element = bird;
  1736. var img = element.img;
  1737. var bounds = new pixi_spine.core.SkeletonBounds();
  1738. bounds.update(img.skeleton, true);
  1739. var hitboxVertex = Array.prototype.slice.call(bounds.polygons[0]);
  1740. bird.hitArea = new PIXI.Polygon(hitboxVertex);
  1741. bird.center.addChild(bird.img);
  1742. this.birds.push(bird);
  1743. }
  1744. this.resetAnimate(bird.img);
  1745. return bird;
  1746. };
  1747. //모든 새 초기화
  1748. gc.Obstacle.prototype.resetBirds = function () {
  1749. var i = 0;
  1750. for (i = 0; i < this.birds.length; i++) {
  1751. this.resetBird(this.birds[i]);
  1752. }
  1753. };
  1754. //멀리있는 새 초기화
  1755. gc.Obstacle.prototype.removeFarBirds = function () {
  1756. for (var i = 0; i < this.birds.length; i++) {
  1757. if (this.birds[i].isWork && (gc.game.myCha.step - this.birds[i].step) >= 2) {
  1758. this.resetBird(this.birds[i]);
  1759. }
  1760. }
  1761. };
  1762. //새 한마리씩 없애기
  1763. gc.Obstacle.prototype.resetBird = function (bird) {
  1764. bird.img.rotation = 0;
  1765. bird.img.scale.x = 1;
  1766. bird.img.x = 0;
  1767. bird.img.y = 0;
  1768. bird.step = null;
  1769. bird.isWork = false;
  1770. bird.isFly = false;
  1771. bird.center.rotation = 0;
  1772. removeObject(bird.center);
  1773. };
  1774. //새 날아다니기
  1775. gc.Obstacle.prototype.flyBird = function () {
  1776. var i;
  1777. for (i = 0; i < this.birds.length; i++) {
  1778. if (this.birds[i].isWork && this.birds[i].isFly) {
  1779. var preAngle = this.birds[i].center.rotation;
  1780. this.birds[i].center.rotation += Math.PI / 60;//2초에 한바퀴.. 60프레임 기준
  1781. if (this.birds[i].center.rotation >= Math.PI * 2) {
  1782. this.birds[i].center.rotation -= Math.PI * 2;
  1783. }
  1784. this.birds[i].img.rotation = -this.birds[i].center.rotation;//1초에 한바퀴
  1785. }
  1786. }
  1787. };
  1788. //새와 유저 부딪침 체크
  1789. gc.Obstacle.prototype.checkHitWithBird = function () {
  1790. var isCollide = false;
  1791. var bx, by;//새 좌표
  1792. var dx, dy, dist;
  1793. for (var i = 0; i < this.birds.length; i++) {
  1794. if (this.birds[i].isWork) {
  1795. bx = this.birds[i].img.worldTransform.tx;
  1796. by = this.birds[i].img.worldTransform.ty;
  1797. dx = Math.abs(gc.game.myCha.img.worldTransform.tx - bx);
  1798. dy = Math.abs(gc.game.myCha.img.worldTransform.ty - by);
  1799. dist = Math.sqrt(dx * dx + dy * dy);
  1800. if (dist < 70) {
  1801. isCollide = true;
  1802. this.birds[i].isFly = false;
  1803. break;
  1804. }
  1805. }
  1806. }
  1807. return isCollide;
  1808. };
  1809. //새 애니메이션
  1810. gc.Obstacle.prototype.flyAnimate = function (obj) {
  1811. var aniname = "animation";
  1812. this.resetAnimate(obj);
  1813. obj.state.setAnimation(0, aniname, true);
  1814. };
  1815. gc.Obstacle.prototype.frontAnimate = function (obj) {
  1816. var aniname = "front_normal";
  1817. this.resetAnimate(obj);
  1818. obj.state.setAnimation(0, aniname, true);
  1819. };
  1820. gc.Obstacle.prototype.backAnimate = function (obj) {
  1821. var aniname = "back_normal";
  1822. this.resetAnimate(obj);
  1823. obj.state.setAnimation(0, aniname, true);
  1824. };
  1825. gc.Obstacle.prototype.explodeAnimate = function (obj) {
  1826. var aniname = "back_burst";
  1827. this.resetAnimate(obj);
  1828. obj.state.setAnimation(0, aniname, false);
  1829. };
  1830. gc.Obstacle.prototype.resetAnimate = function (obj) {
  1831. obj.state.clearTracks();
  1832. obj.skeleton.setToSetupPose();
  1833. obj.state.timeScale = 1;
  1834. obj.update(1);
  1835. obj.state.setEmptyAnimation(0, 1);
  1836. };
  1837. //암전
  1838. gc.Obstacle.prototype.offGameLight = function () {
  1839. if (!this.blackout) this.blackout = GraphicManager.drawRect(gc.width, gc.height, "0X000000");
  1840. var time = 0.2;
  1841. TweenMax.from(this.blackout, time, { alpha: 0 });
  1842. this.blackoutCon.addChildAt(this.blackout, 0);
  1843. this.offLight = true;
  1844. };
  1845. gc.Obstacle.prototype.onGameLight = function () {
  1846. if (this.blackout) removeObject(this.blackout);
  1847. this.offLight = false;
  1848. };
  1849. gc.Obstacle.prototype.updateTransform = function () {
  1850. try {
  1851. PIXI.Container.prototype.updateTransform.call(this);
  1852. } catch (e) {
  1853. }
  1854. };
  1855. /**
  1856. * created by
  1857. */
  1858. gc.ResultView = function () {
  1859. PIXI.Container.call(this);
  1860. this.darkBg = new PIXI.Graphics();
  1861. this.darkBg.lineStyle(1, 0x000, 1);
  1862. this.darkBg.beginFill(0x000, 0.8);
  1863. this.darkBg.drawRect(0, 0, gc.width, gc.height);
  1864. this.darkBg.endFill();
  1865. this.darkBg.interactive = true;
  1866. this.setTouchEnd(this.darkBg);
  1867. this.bg = PIXI.Sprite.fromFrame("popup_bg1.png");
  1868. this.bg.anchor.set(0.5);
  1869. this.bg.x = gc.width / 2;
  1870. this.bg.y = gc.height / 2;
  1871. this.scoreTxt = new gc.NumberText("c_score_", "center", 0, null, null, "c_score_11");
  1872. this.scoreTxt.x = 0;
  1873. this.scoreTxt.y = -130;
  1874. this.scoreTxt.setValue(1000000);
  1875. this.bg.addChild(this.scoreTxt);
  1876. this.bestScoreTxt = new gc.NumberText("c_score2_", "center", 0, null, null, "c_score2_11");
  1877. this.bestScoreTxt.x = 0;
  1878. this.bestScoreTxt.y = 20;
  1879. this.bg.addChild(this.bestScoreTxt);
  1880. this.gropImg = PIXI.Sprite.fromFrame("popup_icon_1.png");
  1881. this.gropImg.anchor.set(0.5);
  1882. this.gropImg.scale.set(0.4);
  1883. this.gropImg.x = 30;
  1884. this.gropImg.y = 97;
  1885. this.bg.addChild(this.gropImg);
  1886. this.reStartBtn = PIXI.Sprite.fromFrame("popup_bt_retry.png");
  1887. this.reStartBtn.anchor.set(0.5);
  1888. this.reStartBtn.y = 220;
  1889. this.bg.addChild(this.reStartBtn);
  1890. this.setTouchStartAction(this.reStartBtn, function () {
  1891. this.requestCloseWindow();
  1892. }, this);
  1893. this.errorMessageTxt = new PIXI.Text("게임 점수 저장에 실패 했습니다.\n다시 한번 게임에 참여 해 주세요.", { fontSize: '24px', fontWeight: 'bold' });
  1894. this.errorMessageTxt.anchor.set(0.5);
  1895. this.errorMessageTxt.x = 0;
  1896. this.errorMessageTxt.y = 50;
  1897. this.bg.addChild(this.errorMessageTxt);
  1898. };
  1899. gc.ResultView.constructor = gc.ResultView;
  1900. gc.ResultView.prototype = Object.create(PIXI.Container.prototype);
  1901. // 초기화
  1902. gc.ResultView.prototype.init = function (score, bestScore, rank, group, type, message) {
  1903. this.removeAll();
  1904. if (score <= 0) {
  1905. this.scoreTxt.setValue(0);
  1906. } else {
  1907. this.scoreTxt.setValue(score);
  1908. }
  1909. if (bestScore <= 0) {
  1910. this.bestScoreTxt.setValue(0);
  1911. } else {
  1912. this.bestScoreTxt.setValue(bestScore);
  1913. }
  1914. var flag = false;
  1915. if (false) {
  1916. if (group == "DIAMOND") {
  1917. flag = true;
  1918. this.gropImg.texture = PIXI.Texture.fromFrame("popup_icon_1.png");
  1919. } else if (group == "GOLD") {
  1920. flag = true;
  1921. this.gropImg.texture = PIXI.Texture.fromFrame("popup_icon_2.png");
  1922. } else if (group == "SILVER") {
  1923. flag = true;
  1924. this.gropImg.texture = PIXI.Texture.fromFrame("popup_icon_3.png");
  1925. } else if (group == "BRONZE") {
  1926. flag = true;
  1927. this.gropImg.texture = PIXI.Texture.fromFrame("popup_icon_4.png");
  1928. }
  1929. } else {
  1930. try {
  1931. flag = true;
  1932. this.gropImg.texture = PIXI.Texture.fromImage(group);
  1933. } catch (e) {
  1934. flag = false;
  1935. }
  1936. }
  1937. if (flag) {
  1938. this.gropImg.visible = true;
  1939. } else {
  1940. this.gropImg.visible = false;
  1941. }
  1942. this.initPage(type, message);
  1943. this.addChild(this.darkBg);
  1944. this.addChild(this.bg);
  1945. this.setInteractive(true);
  1946. };
  1947. gc.ResultView.prototype.initPage = function (type, message) {
  1948. if (type == 1) {
  1949. this.bg.texture = PIXI.Texture.fromFrame("popup_bg1.png");
  1950. this.scoreTxt.x = 0;
  1951. this.scoreTxt.y = -130;
  1952. this.reStartBtn.y = 220;
  1953. this.bestScoreTxt.visible = true;
  1954. //this.gropImg.visible = true;
  1955. this.errorMessageTxt.visible = false;
  1956. } else {
  1957. if (message == 1) {
  1958. this.errorMessageTxt.text = "게임 점수 저장에 실패 했습니다.\n다시 한번 게임에 참여 해 주세요.";
  1959. } else {
  1960. this.errorMessageTxt.text = '비로그인 시에는 점수가\n 저장되지 않습니다.';
  1961. }
  1962. this.bg.texture = PIXI.Texture.fromFrame("popup_bg4.png");
  1963. this.scoreTxt.x = 0;
  1964. this.scoreTxt.y = -60;
  1965. this.reStartBtn.y = 155;
  1966. this.bestScoreTxt.visible = false;
  1967. this.gropImg.visible = false;
  1968. this.errorMessageTxt.visible = true;
  1969. }
  1970. };
  1971. gc.ResultView.prototype.requestCloseWindow = function () {
  1972. this.setInteractive(false);
  1973. this.removeChildren();
  1974. this.emit("GOTO_MAINPAGE");
  1975. };
  1976. gc.ResultView.prototype.removeAll = function () {
  1977. this.removeChildren();
  1978. };
  1979. gc.ResultView.prototype.setInteractive = function (bool) {
  1980. this.reStartBtn.interactive = bool;
  1981. };
  1982. gc.ResultView.prototype.updateTransform = function () {
  1983. PIXI.Container.prototype.updateTransform.call(this);
  1984. };
  1985. /**
  1986. * Created by admin on 2018-05-15.
  1987. */
  1988. gc.Progress = function () {
  1989. PIXI.Container.call(this);
  1990. this.mainContainer = new PIXI.Container();
  1991. this.progressDia = new PIXI.spine.Spine(GD.loader.resources["target"].spineData);
  1992. this.progressbar = new PIXI.Sprite.fromFrame("navigation_bg.png");
  1993. this.progresspin = new PIXI.Sprite.fromFrame("navigation_bar.png");
  1994. this.endStepList = [40, 50, 60, 60, 60];
  1995. // this.endStepList = [5, 5, 5, 5, 5];
  1996. this.endStep = this.endStepList[0];
  1997. this.nowStep = 0;
  1998. };
  1999. gc.Progress.constructor = gc.Progress;
  2000. gc.Progress.prototype = Object.create(PIXI.Container.prototype);
  2001. //진행 바 이미지 전달
  2002. gc.Progress.prototype.init = function () {
  2003. this.progressDia.x = this.progressbar.width + 30;
  2004. this.progressDia.state.setAnimation(0, "target", true);
  2005. this.progressbar.anchor.y = 0.5;
  2006. this.progresspin.anchor.x = 0.5;
  2007. this.progresspin.anchor.y = 0;
  2008. this.progresspin.y = 5;
  2009. this.setNowPosition();
  2010. this.mainContainer.addChild(this.progressDia);
  2011. this.mainContainer.addChild(this.progressbar);
  2012. this.mainContainer.addChild(this.progresspin);
  2013. return this.mainContainer;
  2014. };
  2015. //진행바 목표점 설정
  2016. gc.Progress.prototype.setEndStep = function () {//현재 챕터 1부터 시작
  2017. this.endStep = this.endStepList[gc.chapter - 1];
  2018. };
  2019. //현재 스텝
  2020. gc.Progress.prototype.addStep = function () {
  2021. this.nowStep++;
  2022. this.setNowPosition();
  2023. };
  2024. //현재 스텝 초기화
  2025. gc.Progress.prototype.resetNowStep = function () {
  2026. this.nowStep = 0;
  2027. this.setNowPosition();
  2028. };
  2029. //현재 진행률에 맞춘 좌표
  2030. gc.Progress.prototype.setNowPosition = function () {
  2031. this.progresspin.x = this.progressbar.width / this.endStep * this.nowStep;
  2032. if (this.nowStep != 0) {
  2033. var moveTime = 0.2;
  2034. TweenMax.from(this.progresspin, moveTime, { x: this.progressbar.width / this.endStep * (this.nowStep - 1) });
  2035. TweenMax.to(this.progresspin.scale, moveTime / 2, {
  2036. x: 1.2, y: 1.2, onComplete: (function () {
  2037. TweenMax.to(this.progresspin.scale, moveTime / 2, { x: 1, y: 1 });
  2038. }).bind(this)
  2039. });
  2040. }
  2041. };
  2042. gc.Progress.prototype.updateTransform = function () {
  2043. try {
  2044. PIXI.Container.prototype.updateTransform.call(this);
  2045. } catch (e) {
  2046. }
  2047. };
  2048. /*Created by admin on 2018-04-05.*/
  2049. gc.Map = function () {
  2050. PIXI.Container.call(this);
  2051. this.allFootHolds = [];//모든 발판
  2052. this.quakeTweeners = [];//흔들리고 있는 발판 리스트
  2053. this.nextfhFloor = 2;//건너가야 할 발판 높이
  2054. //발판 종류 리스트
  2055. this.fhNames = [];
  2056. this.fhNames[0] = "foothold1";//챕터1
  2057. this.fhNames[1] = "foothold2";//챕터2
  2058. this.fhNames[100] = "foothold_ice";
  2059. this.fhNames[200] = "foothold_rail";
  2060. this.fhNames[300] = "foothold_jump";
  2061. this.mapContainers = [];
  2062. };
  2063. gc.Map.constructor = gc.Map;
  2064. gc.Map.prototype = Object.create(PIXI.Container.prototype);
  2065. //-----------애니메이션 완료 리스너
  2066. gc.Map.prototype.setSpineListener = function (obj) {
  2067. obj.state.addListener({
  2068. complete: (function (t) {
  2069. if (t.animation.name == "foothold_basic2") {//발판 튕기기
  2070. this.setBasicAnimate(obj);
  2071. }
  2072. else if (t.animation.name == "bg_basic2") {//줄기 발판 튕기기
  2073. this.setBarAnimate(obj);
  2074. }
  2075. else if (t.animation.name == "bg_basic3") {//줄기 발판 튕기기
  2076. this.setBasicAnimate(obj);
  2077. }
  2078. else if (t.animation.name == "foothold_burst") {//발판 폭파 애니
  2079. removeObject(obj);
  2080. this.resetIceFootHoldData(obj);
  2081. }
  2082. }).bind(this)
  2083. });
  2084. };
  2085. //최초 본인이 서있을 발판 생성
  2086. gc.Map.prototype.init = function () {
  2087. this.allFootHolds = [];//모든 발판
  2088. this.reset();
  2089. };
  2090. //발판 생성 脚踏板
  2091. gc.Map.prototype.initFootHolds = function (step, dist, skilltype) {
  2092. var i;
  2093. //챕터별 사용할 발판 선정
  2094. var fhImgType = gc.chapter - 1;//발판 이미지 타입
  2095. if (fhImgType >= 2) fhImgType = Math.floor(Math.random() * 2);
  2096. //발판의 스킨 타입 설정
  2097. var skinName = ["foothold1_skin", "foothold2_skin", "foothold3_skin"];//스킨 이름
  2098. var pngName = ["foothold1", "foothold2", "foothold3"];//스킨에 따라 이미지 이름 바꿔주기.. 발판 크기 찾기 위함
  2099. var skinIndex = Math.floor(Math.random() * skinName.length);
  2100. var fhSkillType = (skilltype) ? skilltype : this.setFootHoldSkillType();//발판 기능 종류(기본, 점프, 얼음, 슬라이드)
  2101. if (fhSkillType == "ice") fhImgType = 100;
  2102. else if (fhSkillType == "slide") fhImgType = 200;
  2103. else if (fhSkillType == "jump") fhImgType = 300;
  2104. var footholds = [];//아래쪽 발판부터 생성
  2105. //발판 높이 설정
  2106. var basegapFloor = [2, 2, 2, 2, 2];
  2107. var maxgapFloor = [3, 5, 8, 9, 10];
  2108. //발판 높이
  2109. if (this.firstFh) this.nextfhFloor = this.initFootholdInfo.floor;//각 챕터 첫 발판.. 최소 3층
  2110. else this.nextfhFloor = 3 + basegapFloor[gc.chapter - 1] + parseInt(Math.random() * maxgapFloor[gc.chapter - 1]);//최소 3개 + 기본 차 + 추가 차이
  2111. // else this.nextfhFloor = 3 + 2 + 10;//최소 3개 + 기본 차 + 추가 차이
  2112. this.initFootholdInfo.floor = this.nextfhFloor;
  2113. //다음 발판 생성 방향 설정.. 같은 방향으로 2번 이상 갔을 때만 방향 전환 가능.
  2114. if (this.sameDirCnt >= 2) this.nextDir = (Math.floor(Math.random() * 2) == 0) ? 1 : -1;
  2115. if (this.preDir == this.nextDir) {
  2116. this.sameDirCnt++;
  2117. }
  2118. else {
  2119. this.sameDirCnt = 0;
  2120. this.preDir = this.nextDir;
  2121. }
  2122. //발판 생성
  2123. for (i = 0; i < this.nextfhFloor; i++) {
  2124. footholds.push(this.findFootHold(fhImgType, skinName[skinIndex], pngName[skinIndex], fhSkillType, this.nextDir));
  2125. footholds[footholds.length - 1].stair = (i == this.nextfhFloor - 1) ? "top" : i;
  2126. footholds[footholds.length - 1].step = step;
  2127. }
  2128. //유저가 생성되기 전일 경우
  2129. if (this.firstFh) {
  2130. this.setNowFootHoldPos();
  2131. }
  2132. this.attachFootHold(footholds, dist);
  2133. this.firstFh = false;
  2134. };
  2135. //발판 기능 설정
  2136. gc.Map.prototype.setFootHoldSkillType = function () {
  2137. var type = 'basic';
  2138. var rand = Math.floor(Math.random() * 100);
  2139. if (gc.chapter == 1) {//카드랜드
  2140. if (rand < 20) type = 'jump';
  2141. }
  2142. else if (gc.chapter == 2) {//버섯랜드
  2143. if (rand < 10) type = 'ice';
  2144. else if (rand < 30) type = 'jump';
  2145. }
  2146. else if (gc.chapter == 3) {//장미랜드
  2147. if (rand < 10) type = 'slide';
  2148. else if (rand < 30) type = 'ice';
  2149. // type = 'slide';
  2150. }
  2151. else if (gc.chapter == 4) {//모자랜드
  2152. if (rand < 15) type = 'slide';
  2153. else if (rand < 30) type = 'ice';
  2154. else if (rand < 40) type = 'jump';
  2155. }
  2156. else if (gc.chapter == 5) {//나무랜드
  2157. if (rand < 15) type = 'slide';
  2158. else if (rand < 30) type = 'ice';
  2159. else if (rand < 40) type = 'jump';
  2160. }
  2161. // type = 'jump';
  2162. // type = 'basic';
  2163. // type = 'slide';
  2164. // type = 'ice';
  2165. return type;
  2166. };
  2167. //현재 유저 위치와 다음 발판 사이 거리 계산
  2168. gc.Map.prototype.setFootHoldDist = function () {
  2169. if (gc.game.myCha) {
  2170. this.footHoldGapX = Math.abs(gc.game.myCha.x - this.nextFootholdPos.x);
  2171. this.footHoldGapY = Math.abs(gc.game.myCha.y - this.nextFootholdPos.y);
  2172. this.footHoldGap = Math.sqrt(this.footHoldGapX * this.footHoldGapX + this.footHoldGapY * this.footHoldGapY) + this.nextfhFloor * 20;
  2173. }
  2174. // console.log("유저와 발판 사이 거리 측정 x", this.footHoldGapX, "y", this.footHoldGapY, "dist", this.footHoldGap);
  2175. };
  2176. //사용가능한 발판 찾기
  2177. gc.Map.prototype.findFootHold = function (imgType, skinName, mainImgName, skillType, dir) {
  2178. var fh = null;
  2179. var size = null;
  2180. for (var i = 0; i < this.allFootHolds.length; i++) {
  2181. size = null;
  2182. if (!this.allFootHolds[i].isWork) {
  2183. if (this.allFootHolds[i].imgType == imgType && this.allFootHolds[i].skillType == skillType) {
  2184. // console.log("imgType", this.fhNames[imgType], "skillType", skillType, "기존 발판", i);
  2185. fh = this.allFootHolds[i];
  2186. size = this.setFootHoldSize(fh.imgType, mainImgName);
  2187. if (size) {
  2188. fh.fhWidth = size.width;
  2189. fh.fhHeight = size.height;
  2190. }
  2191. this.setFootHoldSkin(fh, skinName);
  2192. this.setFootHoldPolygons(fh);
  2193. fh.isWork = true;
  2194. fh.dir = dir;
  2195. break;
  2196. }
  2197. }
  2198. }
  2199. if (!fh) fh = this.makeFootHold(imgType, skinName, mainImgName, skillType, dir);
  2200. return fh;
  2201. };
  2202. //발판 오브젝트 만들기
  2203. gc.Map.prototype.makeFootHold = function (imgType, skinName, mainImgName, skillType, dir) {
  2204. var size = null;
  2205. var fhWidth, fhHeight;
  2206. if (imgType == 100) {//얼음 발판
  2207. fhWidth = 90;
  2208. fhHeight = 45;
  2209. }
  2210. else if (imgType == 200) {//슬라이드 발판
  2211. fhWidth = 90;
  2212. fhHeight = 45;
  2213. }
  2214. else if (imgType == 300) {//점프 발판
  2215. fhWidth = 90;
  2216. fhHeight = 45;
  2217. }
  2218. var fhName = this.fhNames[imgType];
  2219. //발판 크기 설정
  2220. size = this.setFootHoldSize(imgType, mainImgName);
  2221. if (size) {
  2222. fhWidth = size.width;
  2223. fhHeight = size.height;
  2224. }
  2225. this.allFootHolds.push({
  2226. img: new PIXI.spine.Spine(GD.loader.resources[fhName].spineData),
  2227. imgType: imgType,
  2228. skillType: skillType,
  2229. fhWidth: fhWidth,
  2230. fhHeight: fhHeight,
  2231. dir: dir,
  2232. step: null,
  2233. stair: null,
  2234. isWork: true
  2235. });
  2236. this.setSpineListener(this.allFootHolds[this.allFootHolds.length - 1].img);//애니메이션 완료 리스너 설정
  2237. this.setFootHoldSkin(this.allFootHolds[this.allFootHolds.length - 1], skinName);
  2238. this.setFootHoldPolygons(this.allFootHolds[this.allFootHolds.length - 1]);
  2239. return this.allFootHolds[this.allFootHolds.length - 1];
  2240. };
  2241. //발판 너비 설정
  2242. gc.Map.prototype.setFootHoldSize = function (imgType, mainImgName) {
  2243. var w = null, h = null;
  2244. if (imgType != 100 && imgType != 200 && imgType != 300) {
  2245. var fhName = this.fhNames[imgType];
  2246. var atlasData = GD.loader.resources[fhName].spineAtlas;
  2247. var region = atlasData.findRegion(mainImgName);
  2248. w = region.originalWidth * 0.5;
  2249. h = region.originalHeight * 0.5;
  2250. return { width: w, height: h };
  2251. }
  2252. return false;
  2253. };
  2254. //발판 스킨 설정
  2255. gc.Map.prototype.setFootHoldSkin = function (fh, skinName) {
  2256. if (fh.imgType != 100 && fh.imgType != 200 && fh.imgType != 300) {
  2257. var skeleton = fh.img.skeleton;
  2258. skeleton.setSkin(null);
  2259. skeleton.setSkinByName(skinName);
  2260. skeleton.setSlotsToSetupPose();
  2261. }
  2262. };
  2263. //발판 히트영역 도형 설정
  2264. gc.Map.prototype.setFootHoldPolygons = function (fh) {
  2265. if (fh.imgType != 100 && fh.imgType != 200 && fh.imgType != 300) {
  2266. if (fh.hitArea) fh.hitArea = null;
  2267. if (fh.dangerArea) fh.dangerArea = null;
  2268. }
  2269. if (!fh.hitArea && !fh.dangerArea) {
  2270. var img = fh.img;
  2271. var bounds = new pixi_spine.core.SkeletonBounds();
  2272. bounds.update(img.skeleton, true);
  2273. var hitbox1Vertex = Array.prototype.slice.call(bounds.polygons[0]);
  2274. var hitbox2Vertex = Array.prototype.slice.call(bounds.polygons[1]);
  2275. fh.hitArea = new PIXI.Polygon(hitbox1Vertex);
  2276. fh.dangerArea = new PIXI.Polygon(hitbox2Vertex);
  2277. // var g = new PIXI.Graphics();
  2278. // fh.img.addChild(g);
  2279. // g.alpha = 0.5;
  2280. // g.beginFill(0X00FF00);
  2281. // g.drawPolygon(hitbox1Vertex);
  2282. // g.endFill();
  2283. //
  2284. // g.beginFill(0X0000FF);
  2285. // g.drawPolygon(hitbox2Vertex);
  2286. // g.endFill();
  2287. }
  2288. };
  2289. //현재 발판 위치 저장
  2290. gc.Map.prototype.setNowFootHoldPos = function () {
  2291. for (var i = 0; i < this.allFootHolds.length; i++) {
  2292. if (this.firstFh && this.allFootHolds[i].stair == "top") {
  2293. this.nowFootholdPos = {
  2294. info: this.allFootHolds[i],
  2295. x: this.baseX,
  2296. y: this.allFootHolds[i].img.y
  2297. };
  2298. break;
  2299. }
  2300. else {
  2301. if (gc.game.myCha) {
  2302. if (this.allFootHolds[i].step == gc.game.myCha.step && this.allFootHolds[i].stair == "top") {
  2303. this.nowFootholdPos = {//실제 이미지 좌표가 아닌 값만 바꿔야 하는 경우기 있기 때문에 x, y 좌표 따로 저장
  2304. info: this.allFootHolds[i],
  2305. x: this.allFootHolds[i].img.x,
  2306. y: this.allFootHolds[i].img.y
  2307. };
  2308. break;
  2309. }
  2310. }
  2311. }
  2312. }
  2313. };
  2314. //발판 내리기
  2315. gc.Map.prototype.pullDownFootHolds = function () {
  2316. // console.log("발판 내리기");
  2317. var i;
  2318. var moveTime = 0.35;
  2319. var moveDist = (this.baseY - this.nowFootholdPos.info.fhHeight * 2) - this.nowFootholdPos.y;
  2320. gc.game.scrollBackground(moveTime, moveDist);
  2321. this.nowFootholdPos.y -= moveDist;
  2322. var moveList = [];
  2323. //발판 내리기
  2324. for (i = 0; i < this.allFootHolds.length; i++) {
  2325. if (this.allFootHolds[i].isWork) {
  2326. this.allFootHolds[i].img.y += moveDist;
  2327. moveList.push(this.allFootHolds[i].img);
  2328. }
  2329. }
  2330. if (gc.game.portal) {
  2331. gc.game.portal.y += moveDist;
  2332. moveList.push(gc.game.portal);
  2333. }
  2334. //유저 내리기
  2335. gc.game.myCha.y += moveDist;
  2336. var pushPlayer = false;//유저를 완전히 내릴지 여부
  2337. if (gc.chapter == 5 && gc.progress.endStep - gc.progress.nowStep == 1) pushPlayer = true;
  2338. if (this.nowFootholdPos.info.skillType != "jump") pushPlayer = true;
  2339. if (pushPlayer) {
  2340. gc.game.myCha.img.y = gc.game.myCha.y;
  2341. moveList.push(gc.game.myCha.img);//점프타입 발판에 올라선 경우 내려가는 애니 없이 바로 이미지 내리기
  2342. }
  2343. else {
  2344. var time = 0.15;//점프발판 자동 점프 딜레이 시간
  2345. TweenMax.to(gc.game.myCha.img, time, { y: gc.game.myCha.y - moveDist * (0.3) });
  2346. }
  2347. //새 장애물 내리기
  2348. for (i = 0; i < gc.game.obstacle.birds.length; i++) {
  2349. if (gc.game.obstacle.birds[i].isWork) {
  2350. gc.game.obstacle.birds[i].center.y += moveDist;
  2351. moveList.push(gc.game.obstacle.birds[i].center);
  2352. }
  2353. }
  2354. this.setNowFootHoldPos();//유저가 서있는 발판 좌표저장
  2355. if (moveList.length > 0) this.inPulldownFh = true;
  2356. for (i = 0; i < moveList.length; i++) {
  2357. TweenMax.from(moveList[i], moveTime, {
  2358. y: moveList[i].y - moveDist, onComplete: (function (i) {
  2359. if (i == moveList.length - 1) {
  2360. this.resetFootHoldsData();//보이지 않는 발판 정보 초기화
  2361. this.removeUnusedFootHolds();//발판을 내리고 나서 쓰이지 않는 발판 제거
  2362. this.inPulldownFh = false;
  2363. }
  2364. }).bind(this, i)
  2365. });
  2366. }
  2367. };
  2368. //발판 부착
  2369. gc.Map.prototype.attachFootHold = function (fhs, dist) {
  2370. var i;
  2371. var initEf = false;
  2372. var vx = null;
  2373. var con = null;
  2374. for (i = fhs.length - 1; i >= 0; i--) {
  2375. fhs[i].img.scale.x = 1;
  2376. if (fhs[i].skillType == "slide") {
  2377. if (fhs[i].dir == 1) fhs[i].img.scale.x = -1;
  2378. }
  2379. vx = (this.nowFootholdPos.info.fhWidth + fhs[i].fhWidth) * (0.8) * dist;
  2380. if (this.initFootholdInfo.dir == -1) vx *= -1;
  2381. if (this.firstFh) vx = 0;
  2382. fhs[i].img.x = this.nowFootholdPos.x + vx;
  2383. fhs[i].img.y = this.baseY - 65 * (i);
  2384. //맨 아래 발판 생성시 좌표, 정보 저장
  2385. if (i == 0) {
  2386. this.initFootholdInfo.x = fhs[i].img.x;
  2387. this.initFootholdInfo.dir = fhs[i].dir;
  2388. this.initFootholdInfo.step = fhs[i].step;
  2389. }
  2390. //맨 위 발판 생성시 다음 발판 위치로 저장
  2391. if (fhs[i].stair == "top") {
  2392. this.nextFootholdPos.info = fhs[i];
  2393. this.nextFootholdPos.x = fhs[i].img.x;
  2394. this.nextFootholdPos.y = fhs[i].img.y;
  2395. this.resetAnimateFull(fhs[i].img);//최상위 발판 이미지는 세팅 이미지도 초기화
  2396. this.setBasicAnimate(fhs[i].img);
  2397. }
  2398. else {
  2399. this.setBarAnimate(fhs[i].img);
  2400. }
  2401. }
  2402. if (!this.inPulldownFh) this.setNowFootHoldPos();//유저가 서있는 발판 저장
  2403. this.setFootHoldDist();//현재 유저 위치와 도달해야 할 발판 사이 거리
  2404. //생성 이펙트 발생 여부
  2405. for (i = fhs.length - 1; i >= 0; i--) {
  2406. initEf = this.checkInitEffect(fhs[i]);
  2407. if (initEf) {
  2408. var moveTime = 0.3;
  2409. if (i == 0) {//장애물 발생 설정
  2410. gc.game.setObstacleBird(fhs.length * fhs[i].fhHeight, moveTime);
  2411. }
  2412. TweenMax.delayedCall(0.03 * ((fhs.length - 1) - i), (function (i) {
  2413. TweenMax.from(fhs[i].img, moveTime, {
  2414. y: fhs[i].img.y + fhs.length * fhs[i].fhHeight, onComplete: (function (i) {
  2415. this.updateTransform();
  2416. if (fhs[i].stair == "top") this.setBasicAnimate2(fhs[i].img);
  2417. else this.setBarAnimate2(fhs[i].img);
  2418. // if(fhs[i].stair == "top") this.setInitAnimate(fhs[i].img);
  2419. // else this.setBarInitAnimate(fhs[i].img);
  2420. if (i == fhs.length - 1) {//발판이 모두 올라온 후 장애물 발생 설정
  2421. gc.game.setObstacleBlackout();
  2422. }
  2423. }).bind(this, i)
  2424. });
  2425. //필요한 컨테이너 찾기
  2426. con = this.findContainer(fhs[i].step);
  2427. con.center.addChildAt(fhs[i].img, 0);//위쪽 발판부터 붙이기
  2428. gc.game.setMidContainer(0);//레이어 설정
  2429. }).bind(this, i));
  2430. }
  2431. else {
  2432. //필요한 컨테이너 찾기
  2433. con = this.findContainer(fhs[i].step);
  2434. con.center.addChildAt(fhs[i].img, 0);//위쪽 발판부터 붙이기
  2435. gc.game.setMidContainer(0);//레이어 설정
  2436. }
  2437. }
  2438. };
  2439. //필요한 컨테이너 찾기
  2440. gc.Map.prototype.findContainer = function (step) {
  2441. var i;
  2442. var con = null;
  2443. for (i = 0; i < this.mapContainers.length; i++) {
  2444. if (this.mapContainers[i].step == parseInt(step) || this.mapContainers[i].center.children.length == 0) {//스텝이 같거나 컨테이너에 차일드가 없을 때
  2445. this.mapContainers[i].step = parseInt(step);
  2446. con = this.mapContainers[i];
  2447. break;
  2448. }
  2449. }
  2450. if (!con) {
  2451. this.mapContainers.push({ step: step, center: new PIXI.Container() });
  2452. con = this.mapContainers[this.mapContainers.length - 1];
  2453. }
  2454. return con;
  2455. };
  2456. //화면에 붙일 때 떨어지는 애니 여부
  2457. gc.Map.prototype.checkInitEffect = function (target) {
  2458. var onEf = true;
  2459. if (this.firstFh) {
  2460. onEf = false;
  2461. }
  2462. return onEf;
  2463. };
  2464. //얼음 발판 폭파 타이머
  2465. gc.Map.prototype.setQuakeFootHolds = function (step) {
  2466. var i;
  2467. var list = [];
  2468. for (i = 0; i < this.allFootHolds.length; i++) {
  2469. if (this.allFootHolds[i].isWork && this.allFootHolds[i].step == step) {
  2470. if (this.allFootHolds[i].skillType == "ice") {
  2471. list.push(this.allFootHolds[i]);
  2472. }
  2473. }
  2474. }
  2475. for (i = 0; i < list.length; i++) {
  2476. this.earthquakeFootholds(list[i], list[i].img.x, true);//3초간 발판 흔들기
  2477. }
  2478. };
  2479. //얼음 흔들림 취소
  2480. gc.Map.prototype.stopQuakeFootHold = function (fh) {
  2481. for (var i = 0; i < this.quakeTweeners.length; i++) {
  2482. if (this.quakeTweeners[i].fh == fh) {
  2483. this.quakeTweeners[i].tween.kill();
  2484. this.quakeTweeners[i].explodeDelay.kill();
  2485. this.quakeTweeners.splice(i, 1);
  2486. break;
  2487. }
  2488. }
  2489. };
  2490. //모든 얼음 흔들림 취소
  2491. gc.Map.prototype.resetQuakeFootHolds = function () {
  2492. for (var i = 0; i < this.quakeTweeners.length; i++) {
  2493. this.quakeTweeners[i].tween.kill();
  2494. this.quakeTweeners[i].explodeDelay.kill();
  2495. }
  2496. this.quakeTweeners = [];
  2497. };
  2498. //3초간 발판 흔들기.. 0.1초동안 한 방향으로 움직임->30번 움직이면 3초
  2499. gc.Map.prototype.earthquakeFootholds = function (fh, xPos, firstQuake) {
  2500. var aimX;
  2501. var tweener = this.findQuakeTween(fh, xPos, firstQuake);
  2502. if (firstQuake) {
  2503. var explodeTime = 3;
  2504. tweener.explodeDelay = TweenMax.delayedCall(explodeTime, (function () {
  2505. this.setExplodeAnimate(tweener.fh.img);
  2506. gc.game.checkPlayerInIceFootHold(tweener.fh.step);
  2507. }).bind(this));
  2508. }
  2509. firstQuake = false;
  2510. if (tweener) {
  2511. if (tweener.cnt % 2 == 0) aimX = tweener.centerX + 0.2 * tweener.cnt;
  2512. else aimX = tweener.centerX - 0.2 * tweener.cnt;
  2513. tweener.tween = TweenMax.to(tweener.fh.img, 0.1, {
  2514. x: aimX, onComplete: (function () {
  2515. tweener.cnt++;
  2516. if (tweener.cnt < 28) this.earthquakeFootholds(tweener.fh, xPos, firstQuake);
  2517. else fh.img.x = xPos;
  2518. }).bind(this)
  2519. });
  2520. }
  2521. };
  2522. //흔들리고 있는 트위너 찾기
  2523. gc.Map.prototype.findQuakeTween = function (fh, xPos, firstQuake) {
  2524. var tween = null;
  2525. for (var i = 0; i < this.quakeTweeners.length; i++) {
  2526. if (fh == this.quakeTweeners[i].fh) {
  2527. tween = this.quakeTweeners[i];
  2528. break;
  2529. }
  2530. }
  2531. if (!tween && firstQuake) {
  2532. this.quakeTweeners.push({ tween: null, fh: fh, centerX: xPos, cnt: 0, explodeDelay: null });
  2533. tween = this.quakeTweeners[this.quakeTweeners.length - 1];
  2534. }
  2535. return tween;
  2536. };
  2537. //유저가 점프해서 자리에 안착
  2538. gc.Map.prototype.jumpIn = function () {
  2539. for (var i = 0; i < this.allFootHolds.length; i++) {
  2540. if (this.allFootHolds[i].step == gc.game.myCha.step) {
  2541. if (this.allFootHolds[i].stair == "top") {
  2542. // console.log("유저가 안착한 발판");
  2543. this.setBasicAnimate2(this.allFootHolds[i].img);
  2544. break;
  2545. }
  2546. }
  2547. }
  2548. };
  2549. //보이지 않는 발판 정보 초기화
  2550. gc.Map.prototype.resetFootHoldsData = function () {
  2551. var i = 0;
  2552. var resetList = [];
  2553. for (i = 0; i < this.allFootHolds.length; i++) {
  2554. if (this.allFootHolds[i].isWork) {
  2555. //내 스텝보다 발판 스텝이 낮고, 화면 밖에 있는 경우
  2556. if (this.allFootHolds[i].step < gc.game.myCha.step && this.allFootHolds[i].img.y >= gc.height + 300) {
  2557. if (this.allFootHolds[i].skillType == "ice") this.stopQuakeFootHold(this.allFootHolds[i]);//흔들리고 있는 발판 취소
  2558. resetList.push(this.allFootHolds[i]);
  2559. }
  2560. }
  2561. }
  2562. for (i = 0; i < resetList.length; i++) {
  2563. resetList[i].isWork = false;
  2564. resetList[i].step = null;
  2565. resetList[i].stair = null;
  2566. resetList[i].dir = null;
  2567. }
  2568. };
  2569. //폭파된 발판 정보 초기화
  2570. gc.Map.prototype.resetIceFootHoldData = function (obj) {
  2571. var i;
  2572. var fh = null;
  2573. for (i = 0; i < this.allFootHolds.length; i++) {
  2574. if (this.allFootHolds[i].img == obj) {
  2575. fh = this.allFootHolds[i];
  2576. break;
  2577. }
  2578. }
  2579. if (fh) {
  2580. fh.isWork = false;
  2581. fh.step = null;
  2582. fh.stair = null;
  2583. fh.dir = null;
  2584. }
  2585. };
  2586. //모든 발판 초기화
  2587. gc.Map.prototype.resetAllFootHold = function () {
  2588. for (var i = 0; i < this.allFootHolds.length; i++) {
  2589. this.allFootHolds[i].isWork = false;
  2590. this.allFootHolds[i].step = null;
  2591. this.allFootHolds[i].stair = null;
  2592. this.allFootHolds[i].dir = null;
  2593. }
  2594. };
  2595. //발판 다시 그리기
  2596. gc.Map.prototype.removeUnusedFootHolds = function () {
  2597. for (var i = 0; i < this.allFootHolds.length; i++) {
  2598. if (!this.allFootHolds[i].isWork) removeObject(this.allFootHolds[i].img);
  2599. }
  2600. };
  2601. //현재 서있는 발판 찾아서 점프 대기 상태 애니 실행
  2602. gc.Map.prototype.waitJumpAnimate = function () {
  2603. for (var i = 0; i < this.allFootHolds.length; i++) {
  2604. if (this.allFootHolds[i].isWork) {
  2605. if (this.allFootHolds[i].step == gc.game.myCha.step && this.allFootHolds[i].stair == "top") {
  2606. this.setPressAnimate(this.allFootHolds[i].img);
  2607. break;
  2608. }
  2609. }
  2610. }
  2611. };
  2612. //유저가 점프했던 발판 복구
  2613. gc.Map.prototype.jumpAnimate = function () {
  2614. for (var i = 0; i < this.allFootHolds.length; i++) {
  2615. if (this.allFootHolds[i].isWork) {
  2616. if (this.allFootHolds[i].step == gc.game.myCha.step && this.allFootHolds[i].stair == "top") {
  2617. // console.log("유저가 뛴 발판");
  2618. if (this.allFootHolds[i].skillType == "jump") this.setBasicAnimate3(this.allFootHolds[i].img);
  2619. else this.setBasicAnimate2(this.allFootHolds[i].img);
  2620. break;
  2621. }
  2622. }
  2623. }
  2624. };
  2625. //발판이 화면 사이드 밖으로 나갔는지 체크
  2626. gc.Map.prototype.checkFootHoldsOutofScene = function () {
  2627. // console.log("발판 사이드 아웃 확인");
  2628. this.resetQuakeFootHolds();//흔들림 멈추기
  2629. var i;
  2630. var moveTime = 0.3;
  2631. var maxPos = this.baseX + 440;
  2632. var moveList = [];
  2633. var isOut = false;
  2634. if (this.nextFootholdPos.x < this.baseX || this.nextFootholdPos.x > maxPos) {
  2635. // console.log("발판 사이드로 나갔음");
  2636. isOut = true;
  2637. var outDist = 0;
  2638. if (this.nextFootholdPos.x < this.baseX) {//화면 왼쪽 바깥에 발판이 생겼을 때
  2639. outDist = this.nextFootholdPos.x - this.baseX;
  2640. }
  2641. else if (this.nextFootholdPos.x > maxPos) {//화면 오른쪽 바깥에 발판이 생겼을 때
  2642. outDist = this.nextFootholdPos.x - (maxPos);
  2643. }
  2644. //바뀔 현재 좌표와 다음 발판 좌표 변경
  2645. this.nowFootholdPos.x -= outDist;
  2646. this.nextFootholdPos.x -= outDist;
  2647. //추가점수 텍스트 옮기기
  2648. TweenMax.to(gc.game.addScoreText, moveTime, { x: this.nowFootholdPos.x });
  2649. //특수 이펙트 텍스트 옮기기
  2650. if (gc.game.specialMessage) TweenMax.to(gc.game.specialMessage, moveTime, { x: this.nowFootholdPos.x });
  2651. //발판 옮기기
  2652. for (i = 0; i < this.allFootHolds.length; i++) {
  2653. this.allFootHolds[i].img.x -= outDist;
  2654. moveList.push(this.allFootHolds[i].img);
  2655. // TweenMax.to(this.allFootHolds[i].img, moveTime, {x: this.allFootHolds[i].img.x - outDist});
  2656. }
  2657. gc.game.myCha.x -= outDist;
  2658. gc.game.myCha.img.x = gc.game.myCha.x;
  2659. moveList.push(gc.game.myCha.img);
  2660. //새 장애물이 있는 경우 함께 이동
  2661. for (i = 0; i < gc.game.obstacle.birds.length; i++) {
  2662. if (gc.game.obstacle.birds[i].isWork) {
  2663. gc.game.obstacle.birds[i].center.x -= outDist;
  2664. moveList.push(gc.game.obstacle.birds[i].center);
  2665. // TweenMax.from(gc.game.obstacle.birds[i].center, moveTime, {x:gc.game.obstacle.birds[i].center.x + outDist});
  2666. }
  2667. }
  2668. }
  2669. if (isOut) {
  2670. for (i = 0; i < moveList.length; i++) {
  2671. TweenMax.from(moveList[i], moveTime, { x: moveList[i].x + outDist });
  2672. }
  2673. TweenMax.delayedCall(moveTime + 0.1, (function () {
  2674. this.setQuakeFootHolds(gc.game.myCha.step);
  2675. }).bind(this));
  2676. }
  2677. else {
  2678. this.setQuakeFootHolds(gc.game.myCha.step);
  2679. }
  2680. };
  2681. //-----------발판 애니메이션
  2682. //최상단 발판 기본 애니
  2683. gc.Map.prototype.setBasicAnimate = function (obj) {
  2684. var aniname = "foothold_basic";
  2685. this.resetAnimate(obj);
  2686. obj.state.setAnimation(0, aniname, true, 0);
  2687. };
  2688. //하단 발판 기본 애니
  2689. gc.Map.prototype.setBarAnimate = function (obj) {
  2690. var aniname = "bg_basic";
  2691. this.resetAnimate(obj);
  2692. obj.state.setAnimation(0, aniname, true, 0);
  2693. };
  2694. //튕기는 애니
  2695. gc.Map.prototype.setBasicAnimate2 = function (obj) {
  2696. var aniname = "foothold_basic2";
  2697. this.resetAnimate(obj);
  2698. obj.state.setAnimation(2, aniname, false, 0);
  2699. };
  2700. //점프발판 튕기기
  2701. gc.Map.prototype.setBasicAnimate3 = function (obj) {
  2702. var aniname = "foothold_basic3";
  2703. this.resetAnimate(obj);
  2704. obj.state.setAnimation(2, aniname, false, 0);
  2705. };
  2706. gc.Map.prototype.setBarAnimate2 = function (obj) {
  2707. var aniname = "bg_basic2";
  2708. this.resetAnimate(obj);
  2709. obj.state.setAnimation(10, aniname, false, 0);
  2710. };
  2711. //발판 폭파
  2712. gc.Map.prototype.setExplodeAnimate = function (obj) {
  2713. var aniname = "foothold_burst";
  2714. this.resetAnimate(obj);
  2715. obj.state.setAnimation(3, aniname, false, 0);
  2716. };
  2717. //누르고 있을 때 애니
  2718. gc.Map.prototype.setPressAnimate = function (obj) {
  2719. var aniname = "foothold_on";
  2720. this.resetAnimate(obj);
  2721. obj.state.setAnimation(4, aniname, false, 0);
  2722. };
  2723. //포탈 애니메이션
  2724. gc.Map.prototype.setPortalAppear = function (obj) {
  2725. var aniname = "portal_appear";
  2726. this.resetAnimate(obj);
  2727. obj.state.setAnimation(100, aniname, false, 0);
  2728. };
  2729. gc.Map.prototype.resetAnimate = function (obj) {
  2730. obj.state.clearTracks();
  2731. obj.state.timeScale = 1;
  2732. // obj.update(1);
  2733. // obj.state.setEmptyAnimation(0,1);
  2734. };
  2735. //발판의 경우 최초 세팅 이미지가 다를 수 있으므로(장애물 발판의 경우) 맨 위의 발판 이미지만 최초 이미지로 설정시킴
  2736. gc.Map.prototype.resetAnimateFull = function (obj) {
  2737. obj.skeleton.setToSetupPose();
  2738. this.resetAnimate(obj);
  2739. };
  2740. //리셋
  2741. gc.Map.prototype.reset = function () {
  2742. for (var i = 0; i < this.mapContainers.length; i++) {
  2743. this.mapContainers[i].center.removeChildren();
  2744. }
  2745. this.preDir = 0;
  2746. this.nextDir = 1;
  2747. this.sameDirCnt = 0;
  2748. this.baseX = 140;
  2749. this.baseY = 1160;
  2750. this.nowFootholdPos = { info: null, x: this.baseX, y: this.baseY };//유저가 서있는 발판 좌표
  2751. this.nextFootholdPos = { info: null, x: 0, y: 0 };//건너가야할 발판 좌표
  2752. this.initFootholdInfo = { x: this.baseX, y: this.baseY, dir: 1, step: 0, floor: 3 };//생성되는 발판 정보
  2753. this.footHoldGapX = 0;
  2754. this.footHoldGapY = 0;
  2755. this.footHoldGap = 0;//다음 발판까지의 거리..기본 거리*층수
  2756. this.firstFh = true;//각 챕터의 첫번째 발판인지 여부
  2757. this.inPulldownFh = false;//발판 내리는 중
  2758. };
  2759. gc.Map.prototype.updateTransform = function () {
  2760. try {
  2761. PIXI.Container.prototype.updateTransform.call(this);
  2762. } catch (e) {
  2763. }
  2764. };
  2765. /**
  2766. * Created by admin on 2018-04-05.
  2767. */
  2768. gc.Gravity = function () {
  2769. PIXI.Container.call(this);
  2770. this.gravity = 9.8;
  2771. this.chargePow = 0;
  2772. if (this.jumpAngle >= 0) this.jumpAngle -= Math.PI / 180;
  2773. this.guideLight = [];
  2774. this.onGuide = false;
  2775. };
  2776. gc.Gravity.constructor = gc.Gravity;
  2777. gc.Gravity.prototype = Object.create(PIXI.Container.prototype);
  2778. gc.Gravity.prototype.addPow = function () {
  2779. var prePow = this.chargePow;
  2780. var limit = 70;
  2781. this.chargePow += this.setChargeVelocity();
  2782. //일정 파워 이상 충전했을 때 충전 이펙트 보이기
  2783. if (prePow < limit && this.chargePow >= limit) {
  2784. gc.game.onChargeEffect();
  2785. }
  2786. // if(gc.chapter == 1 && gc.progress.nowStep <10) this.onGuide = true;
  2787. if (gc.progress.nowStep < 10) this.onGuide = true;
  2788. else this.onGuide = false;
  2789. if (this.onGuide)
  2790. this.setGuideLine(this.chargePow, 1 - (gc.progress.nowStep / 10));//가이드라인 그리기
  2791. if (this.chargePow >= 1500) this.chargePow = 1500;
  2792. };
  2793. //충전되는 속도 조절
  2794. gc.Gravity.prototype.setChargeVelocity = function () {
  2795. var velocity = 8;
  2796. //기존 수치
  2797. // if(this.chargePow > 1000) velocity = 15;
  2798. // else if(this.chargePow > 500) velocity = 13;
  2799. // else if(this.chargePow > 300) velocity = 10;
  2800. // else if(this.chargePow > 100) velocity = 8;
  2801. // else velocity = 5;
  2802. //변경수치1
  2803. if (this.chargePow > 1000) velocity = 8 * 1.5 * 1.5 * 1.5 * 1.5;
  2804. else if (this.chargePow > 500) velocity = 8 * 1.5 * 1.5 * 1.5;
  2805. else if (this.chargePow > 300) velocity = 8 * 1.5 * 1.5;
  2806. else if (this.chargePow > 100) velocity = 8 * 1.5;
  2807. else velocity = 8;
  2808. return velocity;
  2809. };
  2810. gc.Gravity.prototype.resetPow = function () {
  2811. this.chargePow = 0;
  2812. };
  2813. //점프 결과 값 계산
  2814. gc.Gravity.prototype.calcJumpResult = function (pow) {
  2815. // this.chargePow = gc.maps.footHoldGap;
  2816. var result = null;
  2817. var vx, vy;
  2818. var chargePow = pow || this.chargePow;
  2819. vx = (gc.maps.footHoldGapX) * (chargePow / gc.maps.footHoldGap);
  2820. vx = (gc.game.myCha.jumpDir == 1) ? vx : -vx;
  2821. vy = -(gc.maps.footHoldGapY) * (chargePow / gc.maps.footHoldGap);
  2822. console.log(vx, vy, chargePow)
  2823. //유저가 도달할 위치
  2824. var px = gc.game.myCha.x + vx;
  2825. var py = gc.game.myCha.y + vy;
  2826. //발판 히트 영역 확인
  2827. var hitClone = gc.maps.nextFootholdPos.info.hitArea.clone();
  2828. var inside = this.checkInside("nextFh", px, py, hitClone);
  2829. //거리 체크할 발판 좌표
  2830. var fhX = gc.maps.nextFootholdPos.x, fhY = gc.maps.nextFootholdPos.y;
  2831. var dist = Math.sqrt((px - fhX) * (px - fhX) + (py - fhY) * (py - fhY));
  2832. if (inside) {//범위내에 올라갔을 때
  2833. //y좌표 수정.. 블럭 가운데 라인에 있게끔하기
  2834. hitClone = gc.maps.nextFootholdPos.info.hitArea.clone();
  2835. if (gc.game.myCha.jumpDir == 1) py = fhY - (px - fhX);
  2836. else py = fhY - (fhX - px);
  2837. dist = Math.sqrt((px - fhX) * (px - fhX) + (py - fhY) * (py - fhY));
  2838. //좌표를 옮긴 후 다시 체크
  2839. inside = this.checkInside("nextFh", px, py, hitClone);
  2840. if (inside) {
  2841. vx = px - gc.game.myCha.x;
  2842. vy = py - gc.game.myCha.y;
  2843. if (dist <= 10) result = "perfect";
  2844. else if (dist <= 40) result = "nice";
  2845. else result = "good";
  2846. }
  2847. else {//좌표를 옮긴 후 발판에서 떨어지는 경우
  2848. result = this.checkFalldown("nextFh", px, py).result;
  2849. }
  2850. }
  2851. else {//범위내에 올라가지 못했을 때
  2852. result = this.checkFalldown("nextFh", px, py).result;
  2853. }
  2854. return { result: result, vx: vx, vy: vy };
  2855. };
  2856. //발판 줄기와 유저의 목적지 사이 거리.. 유저가 더 가야할 거리
  2857. gc.Gravity.prototype.calcSideGapWithPlayer = function (px) {
  2858. var moveDist = 0;
  2859. var fh = gc.maps.nextFootholdPos.info;
  2860. var fhName = gc.maps.fhNames[fh.imgType];
  2861. var imgName = null;
  2862. if (fh.imgType == 0) {
  2863. if (gc.game.myCha.jumpDir == 0) imgName = "foothold" + (fh.skin + 1) + "_side1";
  2864. else imgName = "foothold" + (fh.imgType + 1) + "_side2";
  2865. }
  2866. else if (fh.imgType == 1) {//버섯
  2867. imgName = "foothold_side0";
  2868. }
  2869. else if (fh.imgType == 100) {//얼음
  2870. if (gc.game.myCha.jumpDir == 1) imgName = "ice_side1";
  2871. else imgName = "ice_side2";
  2872. }
  2873. else if (fh.imgType == 200) {//슬라이드
  2874. if (gc.game.myCha.jumpDir == 1) imgName = "foothold_rail_side1";
  2875. else imgName = "foothold_rail_side2";
  2876. }
  2877. else if (fh.imgType == 300) {//점프
  2878. imgName = "foothold_jump_back2";
  2879. }
  2880. var atlasData = GD.loader.resources[fhName].spineAtlas;
  2881. var region = atlasData.findRegion(imgName);
  2882. var fhWidth = region.originalWidth * 0.7;
  2883. var gap = Math.abs(fh.img.x - px);//유저와 발판 사이 거리
  2884. if (gap > fhWidth) moveDist = gap - fhWidth;
  2885. if (gc.game.myCha.jumpDir == -1) moveDist *= -1;
  2886. return moveDist;
  2887. };
  2888. //발판 위에 올라섰는지 확인
  2889. gc.Gravity.prototype.checkInside = function (checkFh, px, py, hitClone) {
  2890. var i;
  2891. if (checkFh == "nextFh") {//다음 발판에 올라섰는지 확인
  2892. for (i = 0; i < hitClone.points.length; i++) {
  2893. if (i % 2 == 0) hitClone.points[i] += gc.maps.nextFootholdPos.x;
  2894. else hitClone.points[i] += gc.maps.nextFootholdPos.y;
  2895. }
  2896. }
  2897. else if (checkFh == "nowFh") {//현재 발판에 올라섰는지 확인
  2898. for (i = 0; i < hitClone.points.length; i++) {
  2899. if (i % 2 == 0) hitClone.points[i] += gc.maps.nowFootholdPos.x;
  2900. else hitClone.points[i] += gc.maps.nowFootholdPos.y;
  2901. }
  2902. }
  2903. return hitClone.contains(px, py);
  2904. };
  2905. //떨어지는 경우 분리
  2906. gc.Gravity.prototype.checkFalldown = function (checkFh, px, py) {
  2907. var hitClone = null;
  2908. var danger = false;
  2909. var dist = null;//발판과 유저 사이 거리
  2910. var fh = null;//해당 발판
  2911. var result = null;
  2912. if (checkFh == "nextFh") { fh = gc.maps.nextFootholdPos; }
  2913. else if (checkFh == "nowFh") { fh = gc.maps.nowFootholdPos; }
  2914. hitClone = fh.info.dangerArea.clone();
  2915. danger = this.checkInside(checkFh, px, py, hitClone);
  2916. dist = Math.abs(px - fh.x);//발판과 유저 사이 거리
  2917. if (danger) result = "danger";
  2918. else if (dist > fh.info.fhWidth) result = "too much";
  2919. else {
  2920. if (gc.game.myCha.jumpDir == 1) {
  2921. if (px <= fh.x) result = "weak";
  2922. else result = "too much";
  2923. }
  2924. else {
  2925. if (px <= fh.x) result = "too much";
  2926. else result = "weak";
  2927. }
  2928. }
  2929. return { result: result };
  2930. };
  2931. //제자리 점프 체크
  2932. gc.Gravity.prototype.checkInSameFootHold = function () {
  2933. var result = null;
  2934. var px = gc.game.myCha.x;
  2935. var py = gc.game.myCha.y;
  2936. var hitClone = gc.maps.nowFootholdPos.info.hitArea.clone();
  2937. var inside = this.checkInside("nowFh", px, py, hitClone);
  2938. if (inside) result = "stand";
  2939. else result = this.checkFalldown("nowFh", px, py);
  2940. return result;
  2941. };
  2942. //점프경로 저장.. 뛸때마다 계산 or 미리 만들어두고 좌표만 조금씩 바꾸기
  2943. gc.Gravity.prototype.setGuideLine = function (pow, alpha) {
  2944. console.log(pow)
  2945. this.resetGuideLight();
  2946. var px, py;
  2947. var vx, vy;
  2948. //목적지 좌표 구하기
  2949. px = gc.game.myCha.x;
  2950. py = gc.game.myCha.y;
  2951. var result = this.calcJumpResult(pow);
  2952. vx = Math.abs(result.vx);
  2953. if (gc.game.myCha.jumpDir == -1) vx *= -1;
  2954. vy = result.vy;
  2955. // 벽에 부딪치는 경우 목표 x좌표의 조정
  2956. if (result.result == "weak") vx += this.calcSideGapWithPlayer(px + vx);//유저와 다음발판 줄기 사이의 거리
  2957. var topY = vy - (py - vy) * 0.05;
  2958. var upGoalX = 0;
  2959. var upGoalY = topY;
  2960. if (result.result == "too much") upGoalX = vx * 0.68;
  2961. else upGoalX = vx * 0.6;
  2962. //시작 좌표
  2963. var startUpX = px;
  2964. var startUpY = py;
  2965. if (gc.maps.nowFootholdPos.info.skillType == "jump") startUpY = this.myCha.img.y;
  2966. var startDownX = startUpX + upGoalX;
  2967. var startDownY = startUpY + upGoalY;
  2968. //꼭대기 좌표
  2969. var peakX = startUpX + upGoalX;
  2970. var peakY = startUpY + upGoalY;
  2971. var downGoalX = vx - upGoalX;
  2972. var downGoalY = (topY - vy);
  2973. var isLandingAni = (result.result == "perfect" || result.result == "nice" || result.result == "good");
  2974. if (!isLandingAni) {//다음 발판에 올라가지 못함
  2975. if (result.result != "danger") {
  2976. if (result.result == "too much") {
  2977. downGoalY = -(gc.height - peakY);
  2978. downGoalX = vx * 0.5;
  2979. }
  2980. }
  2981. }
  2982. //목표 좌표
  2983. var endX = startDownX + downGoalX;
  2984. var endY = startDownY - downGoalY;
  2985. var onGuide = true;
  2986. if (result.result == "too much") {
  2987. if (gc.game.myCha.jumpDir == 1 && endX <= gc.maps.nextFootholdPos.x) onGuide = false;
  2988. else if (gc.game.myCha.jumpDir == -1 && endX >= gc.maps.nextFootholdPos.x) onGuide = false;
  2989. }
  2990. if (onGuide) {
  2991. var i, i_len;
  2992. //위로 올라갈 때 경로
  2993. var upLine = new PIXI.Graphics();
  2994. upLine.lineStyle(10, 0x0000ff);
  2995. upLine.moveTo(px, py);
  2996. upLine.quadraticCurveTo((startUpX + upGoalX * 0.2), (startUpY + upGoalY * 0.9), peakX, peakY);
  2997. var points = upLine.currentPath.shape.points;
  2998. points = this.setUseGuidePoint(points); //점이 너무 많으니 걸러내기
  2999. var light = null;
  3000. for (i = points.length - 1; i > 0; i -= 2) {
  3001. //점 이미지 그리기
  3002. light = null;
  3003. light = this.findGuideLight();
  3004. light.img.x = points[i - 1];
  3005. light.img.y = points[i];
  3006. light.img.alpha = alpha;
  3007. var childCnt = gc.game.midContainer.children.length;
  3008. gc.game.midContainer.addChildAt(light.img, childCnt - 1);
  3009. }
  3010. //내려올 때 경로
  3011. var downLine = new PIXI.Graphics();
  3012. downLine.lineStyle(5, 0x0000ff);
  3013. downLine.moveTo(peakX, peakY);
  3014. downLine.quadraticCurveTo((startDownX + downGoalX * 0.85), (startDownY - downGoalY * 0.1), endX, endY);
  3015. points = downLine.currentPath.shape.points;
  3016. points.splice(0, 2);
  3017. points = this.setUseGuidePoint(points);
  3018. points.push(endX);
  3019. points.push(endY);
  3020. if (result.result == "too much") i = 2;
  3021. else i = 2;
  3022. for (i, i_len = points.length; i < i_len; i += 2) {
  3023. //점 이미지 그리기
  3024. light = null;
  3025. light = this.findGuideLight();
  3026. light.img.x = points[i];
  3027. light.img.y = points[i + 1];
  3028. light.img.alpha = alpha;
  3029. if (gc.game.myCha.jumpDir == 1) {
  3030. if (light.img.x >= gc.maps.nextFootholdPos.x + gc.maps.nextFootholdPos.info.fhWidth * 0.2)
  3031. gc.game.midContainer.addChildAt(light.img, 0);
  3032. else gc.game.midContainer.addChild(light.img);
  3033. }
  3034. else {
  3035. if (light.img.x >= gc.maps.nextFootholdPos.x - gc.maps.nextFootholdPos.info.fhWidth * 0.2)
  3036. gc.game.midContainer.addChild(light.img);
  3037. else gc.game.midContainer.addChildAt(light.img, 0);
  3038. }
  3039. }
  3040. }
  3041. };
  3042. //사용할 점 리스트 추리기
  3043. gc.Gravity.prototype.setUseGuidePoint = function (list) {
  3044. var points = list;
  3045. var dist = 0;
  3046. // for(var i=0; i<points.length-2; i+=2) {
  3047. // for(var j=points.length-2; j>=i+2; j-=2) {
  3048. // dist = Math.pow((points[i] - points[j]), 2) + Math.pow((points[i+1] - points[j+1]), 2);
  3049. // if(dist <= Math.pow(50,2)) {
  3050. // points.splice(j, 2);
  3051. // }
  3052. // }
  3053. // }
  3054. for (var i = points.length - 2; i >= 3; i -= 2) {
  3055. for (var j = 0; j < i; j += 2) {
  3056. dist = Math.pow((points[i] - points[j]), 2) + Math.pow((points[i + 1] - points[j + 1]), 2);
  3057. if (dist <= Math.pow(50, 2)) {
  3058. points.splice(j, 2);
  3059. }
  3060. }
  3061. }
  3062. return points;
  3063. };
  3064. //레이어 처리
  3065. gc.Gravity.prototype.checkDepth = function (checkX) {
  3066. if (this.obstacle) {
  3067. if (this.obstacle.offLight) this.setMidContainer(0);//암전상태일때는 유저가 가장 위에 보임
  3068. else {
  3069. var px = checkX;//this.myCha.img.x;
  3070. var fh = gc.maps.nextFootholdPos;
  3071. if (this.myCha.jumpDir == 1) {//오른쪽으로 뛸 때
  3072. if (px <= fh.x) this.setMidContainer(2);//발판 사이에 떨어짐
  3073. else this.setMidContainer(1);//너무 멀리 뜀
  3074. }
  3075. else {//왼쪽으로 뛸 때
  3076. if (px <= fh.x) this.setMidContainer(1);//너무 멀리 뜀
  3077. else this.setMidContainer(2);//발판 사이에 떨어짐
  3078. }
  3079. }
  3080. }
  3081. };
  3082. //가이드라인 이미지 생성
  3083. gc.Gravity.prototype.findGuideLight = function () {
  3084. var light = null;
  3085. for (var i = 0; i < this.guideLight.length; i++) {
  3086. if (!this.guideLight[i].isWork) {
  3087. light = this.guideLight[i];
  3088. light.isWork = true;
  3089. break;
  3090. }
  3091. }
  3092. if (light === null) {
  3093. this.guideLight.push({ img: new PIXI.Sprite.fromFrame("guide.png"), isWork: true });
  3094. this.guideLight[this.guideLight.length - 1].img.anchor.x = 0.5;
  3095. this.guideLight[this.guideLight.length - 1].img.anchor.y = 1;
  3096. light = this.guideLight[this.guideLight.length - 1];
  3097. }
  3098. return light;
  3099. };
  3100. //가이드라인 이미지 초기화
  3101. gc.Gravity.prototype.resetGuideLight = function () {
  3102. for (var i = 0; i < this.guideLight.length; i++) {
  3103. removeObject(this.guideLight[i].img);
  3104. this.guideLight[i].isWork = false;
  3105. }
  3106. };
  3107. gc.Gravity.prototype.reset = function () {
  3108. this.resetPow();
  3109. };
  3110. gc.Gravity.prototype.updateTransform = function () {
  3111. try {
  3112. PIXI.Container.prototype.updateTransform.call(this);
  3113. } catch (e) {
  3114. }
  3115. };
  3116. /**
  3117. * Created by admin on 2018-04-05.
  3118. */
  3119. gc.Characters = function () {
  3120. PIXI.Container.call(this);
  3121. this.charNames = [
  3122. 'cha1'
  3123. ];
  3124. this.chaList = [];
  3125. };
  3126. gc.Characters.constructor = gc.Characters;
  3127. gc.Characters.prototype = Object.create(PIXI.Container.prototype);
  3128. gc.Characters.prototype.init = function (myCha) {
  3129. this.makeCharacters();
  3130. return this.chaList[myCha];
  3131. };
  3132. //캐릭터 만들어두기
  3133. gc.Characters.prototype.makeCharacters = function () {
  3134. var i = 0;
  3135. for (i = 0; i < this.charNames.length; i++) {
  3136. this.chaList[i] = new PIXI.spine.Spine(GD.loader.resources[this.charNames[i]].spineData);
  3137. this.setSpineListener(this.chaList[i]);
  3138. }
  3139. };
  3140. //-----------애니메이션 완료 리스너
  3141. gc.Characters.prototype.setSpineListener = function (obj) {
  3142. obj.state.addListener({
  3143. complete: (function (t) {
  3144. if (t.animation.name == "cha_fail_over" || t.animation.name == "cha_fail_over2" || t.animation.name == "cha_fail_hit") {//착지 실패
  3145. gameOver();
  3146. }
  3147. }).bind(this),
  3148. event: (function (t, event) {
  3149. if (t.animation.name == "cha_fail_over" && event.data.name == "cha_event1") {
  3150. gc.game.checkDepth(gc.game.myCha.img.x);//이벤트를 받을 때 유저 오브젝트 이미지 위치로 레이어 설정
  3151. }
  3152. })
  3153. });
  3154. };
  3155. //------------애니메이션
  3156. //가만히 서있는 애니메이션
  3157. gc.Characters.prototype.standAnimate = function (obj) {
  3158. var aniname = "cha_basic";
  3159. this.resetAnimate(obj);
  3160. obj.state.setAnimation(0, aniname, true);
  3161. };
  3162. //점프 대기
  3163. gc.Characters.prototype.waitJumpAnimate = function (obj) {
  3164. var aniname = "cha_touchon";
  3165. this.resetAnimate(obj);
  3166. obj.state.setAnimation(0, aniname, false, 0);
  3167. };
  3168. //점프 중
  3169. gc.Characters.prototype.jumpAnimate = function (obj) {
  3170. var aniname = "cha_touchoff";
  3171. this.resetAnimate(obj);
  3172. obj.state.setAnimation(0, aniname, true, 0); // # 캐릭터 회전애니 반복재생
  3173. };
  3174. //착지 성공
  3175. gc.Characters.prototype.standClearAnimate = function (obj) {
  3176. this.resetAnimate(obj);
  3177. var aniname = "cha_landing";
  3178. var aniObj = obj.state.setAnimation(0, aniname, false, 0);
  3179. obj.state.addAnimation(0, "cha_basic", true, aniObj.animationEnd);//착지 성공 후 서있는 애니 실행
  3180. };
  3181. //착지 지점 실패.. 발판 끝에 떨어지기
  3182. gc.Characters.prototype.standFailAnimate = function (obj) {
  3183. var aniname = "cha_fail_over";
  3184. this.resetAnimate(obj);
  3185. obj.state.setAnimation(0, aniname, false, 0);
  3186. };
  3187. //허공에 착지
  3188. gc.Characters.prototype.fallDownAnimate = function (obj) {
  3189. var aniname = "cha_fail_over2";
  3190. this.resetAnimate(obj);
  3191. obj.state.setAnimation(0, aniname, false, 0);
  3192. };
  3193. //벽에 부딪쳐 떨어지기
  3194. gc.Characters.prototype.hitWallAnimate = function (obj) {
  3195. var aniname = "cha_fail_hit";
  3196. this.resetAnimate(obj);
  3197. obj.state.setAnimation(0, aniname, false, 0);
  3198. };
  3199. gc.Characters.prototype.resetAnimate = function (obj) {
  3200. obj.state.clearTracks();
  3201. obj.skeleton.setToSetupPose();
  3202. obj.state.timeScale = 1;
  3203. //obj.update(1);
  3204. //obj.state.setEmptyAnimation(0,1);
  3205. };
  3206. //------------리셋
  3207. gc.Characters.prototype.reset = function () {
  3208. if (gc.game.myCha) {
  3209. this.standAnimate(gc.game.myCha);
  3210. }
  3211. };
  3212. gc.Characters.prototype.updateTransform = function () {
  3213. try {
  3214. PIXI.Container.prototype.updateTransform.call(this);
  3215. } catch (e) {
  3216. }
  3217. };
  3218. // 게임
  3219. function onGame() {
  3220. var chapterValue = window.localStorage.getItem('chapter');
  3221. if (chapterValue === undefined || chapterValue === null || chapterValue === '') {
  3222. chapterValue = 1;
  3223. }
  3224. gc.chapter = JSON.parse(chapterValue);
  3225. if (gc.intro) {
  3226. gc.intro.reset();
  3227. GD.objSdk.hideAdIcon();
  3228. removeObject(gc.intro);
  3229. }
  3230. gc.intro = null;
  3231. removeObject(gc.game);
  3232. gc.game = null;
  3233. if (!gc.game) gc.game = new gc.GameScene();
  3234. gc.game.init();
  3235. GD.stage.addChild(gc.game);
  3236. GD.bgmStop();
  3237. if (gc.onBgm) GD.bgmPlay(0.8);
  3238. if (gc.onFx) GD.soundPlay("sound_start");
  3239. }
  3240. //游戏真正结束
  3241. function gameEnd() {
  3242. window.localStorage.setItem('chapter', gc.chapter.toString());
  3243. if (gc.onFx) GD.soundPlay("sound_gameover");
  3244. gc.game.onStateMessage(2);
  3245. removeObject(gc.game.myCha.img);
  3246. GD.bgmStop();
  3247. }
  3248. //게임오버
  3249. function gameOver() {
  3250. // gameEnd();
  3251. if (gc.recoveryTimes <= 0) {
  3252. gameEnd();
  3253. return;
  3254. }
  3255. if (gc.showVd && window.wx.createRewardedVideoAd) {
  3256. afterGameEndWithShowVd();
  3257. } else if (gc.bShare) {
  3258. afterGameEndWithShare();
  3259. } else {
  3260. gameEnd();
  3261. }
  3262. }
  3263. function afterGameEndWithShare() {
  3264. gc.menu.onMenuPopup('share')
  3265. }
  3266. function afterGameEndWithShowVd() {
  3267. gc.menu.onMenuPopup('ad');
  3268. }
  3269. //오브젝트 지우기
  3270. function removeObject(obj) {
  3271. //어디에 붙어있던 부모를 찾아서 지우므로 어디에 붙어있는지 몰라도 됨.
  3272. if (obj && obj.parent) obj.parent.removeChild(obj);
  3273. };
  3274. // 인트로
  3275. function onIntro() {
  3276. //사운드 팝업
  3277. if (!gc.soundPopup) gc.soundPopup = new gc.PopupSound();
  3278. //개별 인트로
  3279. if (gc.game) {
  3280. TweenMax.killAll();
  3281. removeObject(gc.game);
  3282. }
  3283. gc.game = null;
  3284. removeObject(gc.intro);
  3285. gc.intro = null;
  3286. if (!gc.intro) gc.intro = new gc.Intro();
  3287. gc.intro.init();
  3288. GD.stage.addChild(gc.intro);
  3289. }
  3290. module.exports = gc