InGameView.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. import { ui } from "../ui/layaMaxUI";
  2. import { GameTools } from "../Tool/GameTools";
  3. import { SC } from "./ViewManager";
  4. import { EventManager, PropEffecf,StageMode } from "../Tool/EventManager";
  5. import { AccountManager } from "../Net/AccountManager";
  6. import Ball from "../Main/Ball";
  7. import { GameManager } from "../Main/GameManager";
  8. import { DropRule } from "../Tool/DropRule";
  9. import { ServerManager, BlastToMerge } from "../Net/ServerManager";
  10. import { GamePool } from "../Tool/GamePool";
  11. import Gift from "../Main/Gift";
  12. export default class InGameView extends ui.InGameSceneUI implements SC{
  13. private static ins:InGameView;
  14. //本关卡
  15. public STAGE:number;
  16. //是否弹出失败界面
  17. public LoseView = false;
  18. //是否弹出成功界面
  19. public WinView = false;
  20. //球是否溢出
  21. public OverRun = false;
  22. //0.25时是否掉落礼盒
  23. public lingdianerwu = false;
  24. //0.50时是否掉落礼盒
  25. public lingdianwu = false;
  26. //0.75时是否掉落礼盒
  27. public lingdianqiwu = false;
  28. constructor(){
  29. super();
  30. InGameView.ins = this;
  31. EventManager.StageOn(StageMode.Clone,this,this.AddPrefab);
  32. EventManager.StageOn(StageMode.Win,this,this.Win);
  33. EventManager.StageOn(StageMode.Lose,this,this.Lose);
  34. EventManager.StageOn(StageMode.ReStart,this,this.ReStart);
  35. EventManager.StageOn(StageMode.Over,this,this.Over);
  36. EventManager.StageOn(StageMode.Revive,this,this.Revive);
  37. EventManager.StageOn(StageMode.Check,this,this.Check);
  38. // EventManager.StageOn(StageMode.GetReward,this,this)
  39. }
  40. public static get Instance():InGameView{
  41. if(InGameView.ins){
  42. return InGameView.ins
  43. }
  44. else{
  45. return new InGameView();
  46. }
  47. }
  48. Show(){
  49. let stage = AccountManager.Instance.curplayerData.GainAccount("stage");
  50. this.STAGE = Number(stage);
  51. Laya.timer.loop(AccountManager.Instance.curplayerData.Save * 1000,this,this.Save);
  52. Laya.timer.once(200,this,this.SkillRefresh);
  53. Laya.timer.frameLoop(2,this,this.CheckHeight);
  54. Laya.timer.frameLoop(1,this,this.Progress);
  55. Laya.timer.once(AccountManager.Instance.curplayerData.CheckLose * 1000,this,this.CheckLose);
  56. Laya.timer.frameLoop(500,this,this.SkillAnimation);
  57. this.ScoreRefresh();
  58. this.SkillNumRefresh();
  59. this.arrowbtn.clickHandler = new Laya.Handler(this,this.ClickArrow);
  60. this.zhunxin1btn.clickHandler = new Laya.Handler(this,this.ClickZhunXin1);
  61. this.zhunxin2btn.clickHandler = new Laya.Handler(this,this.ClickZhunXin2);
  62. this.doublebtn.clickHandler = new Laya.Handler(this,this.ClickDouble);
  63. this.hammerbtn.clickHandler = new Laya.Handler(this,this.ClickHammer);
  64. this.height = Laya.stage.height;
  65. this.BG.height = Laya.stage.height;
  66. Laya.stage.on(Laya.Event.RESIZE,this,()=>
  67. {
  68. this.height = Laya.stage.height;
  69. this.BG.height = Laya.stage.height;
  70. })
  71. }
  72. //失败检测
  73. Check(){
  74. Laya.timer.clear(this,this.CheckLose);
  75. Laya.timer.once(AccountManager.Instance.curplayerData.CheckLose * 1000,this,this.CheckLose);
  76. }
  77. //添加预设
  78. AddPrefab(ball){
  79. this.prefabbox.addChild(ball);
  80. }
  81. //检测高度
  82. CheckHeight(){
  83. if(GameManager.Instance.CheckHeight){
  84. let down = false;
  85. this.OverRun = false;
  86. for (let i = 0; i < this.prefabbox.numChildren; i++) {
  87. let child = this.prefabbox.getChildAt(i) as Laya.Image;
  88. if(child.y < DropRule.Instance.DropHeight){
  89. down = true;
  90. }
  91. if(child.y < AccountManager.Instance.curplayerData.OverRun){
  92. this.OverRun = true;
  93. }
  94. }
  95. if(!down){
  96. DropRule.Instance.FallDown();
  97. }
  98. }
  99. }
  100. //检测是否游戏失败
  101. CheckLose(){
  102. if(!this.LoseView){
  103. let lose = true;
  104. for (let i = 0; i < this.prefabbox.numChildren; i++) {
  105. let ball = this.prefabbox.getChildAt(i) as Laya.Image;
  106. if(ball.name == "Gift" || ball.name == "TimeGift"){
  107. continue;
  108. }
  109. let light = ball.getChildByName("light") as Laya.Image;
  110. if(light.visible){
  111. lose = false;
  112. }
  113. }
  114. if(lose){
  115. this.LoseView = true;
  116. Laya.timer.clear(this,this.Save);
  117. this.Save(true);
  118. EventManager.StageTrigger(StageMode.Lose);
  119. }
  120. }
  121. }
  122. //开局刷新一下过关要求
  123. ScoreRefresh(){
  124. // let level = AccountManager.Instance.curplayerData.GainCollocation("level");
  125. let score = DropRule.Instance.GoalScore;
  126. this.NowLv.value = DropRule.Instance.STAGE.toString();
  127. this.NextLv.value = (DropRule.Instance.STAGE+1).toString();
  128. this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
  129. this.RequireScore.text = score.toString();
  130. // let stage = level[GameManager.Instance.STAGE];
  131. // score = Number(stage.goal);
  132. // let id =Number(stage.id) ;
  133. // this.NowLv.value = id.toString();
  134. // this.NextLv.value = (id+1).toString();
  135. // this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
  136. // this.RequireScore.text = score.toString();
  137. }
  138. //进入游戏时刷新一下道具数量
  139. SkillNumRefresh(){
  140. this.Func1num.text = AccountManager.Instance.curplayerData.GetPropNum(1).toString();
  141. this.Func2num.text = AccountManager.Instance.curplayerData.GetPropNum(2).toString();
  142. this.Func3num.text = AccountManager.Instance.curplayerData.GetPropNum(3).toString();
  143. this.Func4num.text = AccountManager.Instance.curplayerData.GetPropNum(4).toString();
  144. this.Func5num.text = AccountManager.Instance.curplayerData.GetPropNum(5).toString();
  145. }
  146. //进入游戏时刷新一下技能icon
  147. SkillRefresh(){
  148. this.ani1.play(null,false);
  149. this.ani2.play(null,false);
  150. this.ani3.play(null,false);
  151. this.ani4.play(null,false);
  152. this.ani5.play(null,false);
  153. }
  154. //技能图标动画效果
  155. SkillAnimation() {
  156. let random = GameTools.RandomANumber(1, 6);
  157. switch (random) {
  158. case 1:
  159. this.ani1.play(null, false);
  160. break;
  161. case 2:
  162. this.ani2.play(null, false);
  163. break;
  164. case 3:
  165. this.ani3.play(null, false);
  166. break;
  167. case 4:
  168. this.ani4.play(null, false);
  169. break;
  170. case 5:
  171. this.ani5.play(null, false);
  172. break;
  173. }
  174. }
  175. //比例
  176. private get Ratio():number{
  177. let score = DropRule.Instance.GoalScore;
  178. let value = GameManager.Instance.ScoreProgress/score;
  179. return value;
  180. }
  181. //进度条
  182. Progress(){
  183. if(!this.WinView){
  184. this.LevelProgress.value = this.Ratio;
  185. if(GameManager.Instance.ScoreProgress>=Number(this.RequireScore.text)){
  186. GameManager.Instance.ScoreProgress = Number(this.RequireScore.text);
  187. this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
  188. Laya.timer.clear(this,this.Save);
  189. Laya.timer.clear(this,this.CheckLose);
  190. this.Save(true);
  191. EventManager.StageTrigger(StageMode.Win);
  192. this.WinView = true;
  193. }
  194. this.NowScore.text = GameManager.Instance.ScoreProgress.toString();
  195. }
  196. if(DropRule.Instance.STAGE >= 7){
  197. let X = GameTools.RandomANumber(100,500);
  198. let pos = new Laya.Vector2(X, 10);
  199. if(this.Ratio >= 0.25 && this.Ratio < 0.5 && !this.lingdianerwu){
  200. DropRule.Instance.CreateGift(1,pos,DropRule.Instance.JudgePropNum(),1);
  201. this.lingdianerwu = true;
  202. }
  203. if(this.Ratio >= 0.5 && this.Ratio < 0.75 && !this.lingdianwu){
  204. DropRule.Instance.CreateGift(1,pos,DropRule.Instance.JudgePropNum(),1);
  205. this.lingdianwu = true;
  206. }
  207. if(this.Ratio >= 0.75 && this.Ratio < 1 && !this.lingdianqiwu){
  208. DropRule.Instance.CreateGift(1,pos,DropRule.Instance.JudgePropNum(),1);
  209. this.lingdianqiwu =true;
  210. }
  211. }
  212. }
  213. //推球道具
  214. ClickArrow(){
  215. console.log("点到了推球道具--");
  216. // var agrs = [{ "t": AccountManager.Instance.ServerTime.toString() }];
  217. // ServerManager.Instance.SendHttp(BlastToMerge.KaiShi,agrs,Laya.Handler.create(this, this.StartNextLevel), null);
  218. if(Number(this.Func5num.text)>0){
  219. let args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":GameManager.Instance.play_id},{"fid":"5"}]
  220. ServerManager.Instance.SendHttp(BlastToMerge.Use,args,Laya.Handler.create(this,(res)=>{
  221. for (let i = 0; i < this.prefabbox.numChildren; i++) {
  222. let ball = this.prefabbox.getChildAt(i) as Laya.Image;
  223. if(ball.destroyed){
  224. continue
  225. }
  226. else{
  227. let _rig = ball.getComponent(Laya.RigidBody) as Laya.RigidBody;
  228. _rig.applyLinearImpulseToCenter({x:0,y:-AccountManager.Instance.curplayerData.AddForce});
  229. }
  230. }
  231. this.SkillNumRefresh();
  232. }),Laya.Handler.create(this,(res)=>{
  233. console.log(res);
  234. }))
  235. }
  236. }
  237. //双倍道具
  238. ClickDouble(){
  239. if(Number(this.Func1num.text)>0){
  240. if(EventManager.PropState == PropEffecf.NONE){
  241. this.EffectMode(true,PropEffecf.DOUBLE);
  242. }
  243. else{
  244. this.EffectMode(false);
  245. }
  246. }
  247. // if(EventManager.PropState == PropEffecf.DOUBLE){
  248. // EventManager.EventTrigger(PropEffecf.NONE);
  249. // console.log("切换为普通模式");
  250. // return;
  251. // }
  252. // if(EventManager.PropState != PropEffecf.NONE){
  253. // this.EffectMode(false);
  254. // return;
  255. // }
  256. // if(Number(this.Func1num.text)>0){
  257. // EventManager.EventTrigger(PropEffecf.DOUBLE);
  258. // console.log("切换为双倍模式");
  259. // }
  260. }
  261. //消除最小的球道具
  262. ClickZhunXin1(){
  263. console.log("点到了准心1道具--");
  264. if(Number(this.Func2num.text)>0){
  265. if(EventManager.PropState == PropEffecf.NONE){
  266. this.EffectMode(true,PropEffecf.CLEARLAST);
  267. }
  268. else{
  269. this.EffectMode(false);
  270. }
  271. }
  272. }
  273. //消除次小的球道具
  274. ClickZhunXin2(){
  275. console.log("点到了准心2道具--");
  276. if(Number(this.Func3num.text)>0){
  277. if(EventManager.PropState == PropEffecf.NONE){
  278. this.EffectMode(true,PropEffecf.CLEARTWO);
  279. }
  280. else{
  281. this.EffectMode(false);
  282. }
  283. }
  284. }
  285. //锤子道具
  286. ClickHammer(){
  287. console.log("点到了锤子道具--");
  288. if(Number(this.Func4num.text)>0){
  289. if(EventManager.PropState == PropEffecf.NONE){
  290. this.EffectMode(true,PropEffecf.HAMMER);
  291. }
  292. else{
  293. this.EffectMode(false);
  294. }
  295. }
  296. }
  297. //使用道具
  298. EffectMode(_open:boolean,_type:PropEffecf = null){
  299. this.Effect.visible = _open;
  300. if (_open) {
  301. EventManager.PropState = _type;
  302. let describe3 = this.Effect.getChildByName("describe3") as Laya.Text;
  303. let describe2 = this.Effect.getChildByName("describe2") as Laya.Text;
  304. let describe = this.Effect.getChildByName("describe") as Laya.Text;
  305. let icon = this.Effect.getChildByName("ICON") as Laya.Image;
  306. switch (_type) {
  307. case PropEffecf.CLEARLAST:
  308. this.EffectBtn.visible = true;
  309. describe.visible = true;
  310. describe2.visible = false;
  311. describe3.visible = false;
  312. icon.visible = true;
  313. icon.skin = this.GetIcon(DropRule.Instance.MinBall);
  314. this.ClearNum.text = DropRule.Instance.MinBall.toString();
  315. this.EffectBtn.clickHandler = Laya.Handler.create(this, this.ClearLast);
  316. break;
  317. case PropEffecf.CLEARTWO:
  318. this.EffectBtn.visible = true;
  319. describe.visible = true;
  320. describe2.visible = false;
  321. describe3.visible = false;
  322. icon.visible = true;
  323. icon.skin = this.GetIcon(DropRule.Instance.MinNextBall);
  324. this.ClearNum.text = DropRule.Instance.MinNextBall.toString();
  325. this.EffectBtn.clickHandler = Laya.Handler.create(this, this.ClearTwo);
  326. break;
  327. case PropEffecf.HAMMER:
  328. this.EffectBtn.visible = false;
  329. describe.visible = false;
  330. describe2.visible = true;
  331. describe3.visible = false;
  332. icon.visible = false;
  333. EventManager.EventTrigger(PropEffecf.HAMMER);
  334. break;
  335. case PropEffecf.DOUBLE:
  336. this.EffectBtn.visible = false;
  337. describe.visible = false;
  338. describe2.visible = false;
  339. describe3.visible = true;
  340. icon.visible = false;
  341. EventManager.EventTrigger(PropEffecf.DOUBLE);
  342. break;
  343. }
  344. }
  345. else{
  346. EventManager.PropState = PropEffecf.NONE;
  347. this.EffectBtn.clickHandler = null;
  348. }
  349. }
  350. //清除场景中最小的球
  351. ClearLast(){
  352. var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":GameManager.Instance.play_id},{"fid":"2"}]
  353. ServerManager.Instance.SendHttp(BlastToMerge.Use,args,Laya.Handler.create(this,()=>{
  354. for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
  355. let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
  356. if(prefab.name == "Gift" || prefab.name == "TimeGift"){
  357. continue;
  358. }
  359. let ball = prefab.getComponent(Ball) as Ball;
  360. if(ball.score == DropRule.Instance.MinBall){
  361. GameManager.Instance.ScoreProgress += ball.score;
  362. DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
  363. let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
  364. let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
  365. _collider.enabled = false;
  366. _rig.enabled = false;
  367. // _collider.destroy();
  368. // _rig.destroy();
  369. Laya.timer.clearAll(prefab);
  370. prefab.removeSelf();
  371. // prefab.destroy();
  372. let _index = DropRule.Instance.GetBallIndex(ball.score);
  373. GamePool.Instance.RecoverModel(prefab,_index.toString());
  374. // Laya.Pool.recover("img"+_index.toString,ball);
  375. }
  376. }
  377. this.SkillNumRefresh();
  378. this.Effect.visible = false;
  379. this.EffectBtn.clickHandler = null;
  380. EventManager.PropState = PropEffecf.NONE;
  381. }),Laya.Handler.create(this,()=>{
  382. console.log("道具使用失败");
  383. }))
  384. }
  385. //清除场景中第二小的球
  386. ClearTwo(){
  387. var args = [{"t":AccountManager.Instance.ServerTime.toString()},{"play_id":GameManager.Instance.play_id},{"fid":"3"}]
  388. ServerManager.Instance.SendHttp(BlastToMerge.Use,args,Laya.Handler.create(this,()=>{
  389. for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
  390. let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
  391. if(prefab.name == "Gift" || prefab.name == "TimeGift"){
  392. continue;
  393. }
  394. let ball = prefab.getComponent(Ball) as Ball;
  395. if(ball.score == DropRule.Instance.MinNextBall){
  396. GameManager.Instance.ScoreProgress += ball.score;
  397. DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
  398. let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
  399. let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
  400. _collider.enabled = false;
  401. _rig.enabled = false;
  402. // _collider.destroy();
  403. // _rig.destroy();
  404. Laya.timer.clearAll(prefab);
  405. prefab.removeSelf();
  406. // prefab.destroy();
  407. let _index = DropRule.Instance.GetBallIndex(ball.score);
  408. GamePool.Instance.RecoverModel(prefab,_index.toString());
  409. // Laya.Pool.recover("img"+_index.toString,ball);
  410. // ball.destroy();
  411. }
  412. }
  413. this.SkillNumRefresh();
  414. this.Effect.visible = false;
  415. this.EffectBtn.clickHandler = null;
  416. EventManager.PropState = PropEffecf.NONE;
  417. }),null)
  418. }
  419. /**传入分数 获取球的icon */
  420. GetIcon(_score:number):string{
  421. let index;
  422. for (let i = 0; i < DropRule.Instance.PrefabName.length; i++) {
  423. if(_score == Number(DropRule.Instance.PrefabName[i])){
  424. index = i.toString();
  425. }
  426. }
  427. return "Game/res/Ball/blast"+ index + ".png"
  428. }
  429. //清除舞台上的球
  430. ClearStage(){
  431. if(!this.prefabbox.destroyed){
  432. for (let i = this.prefabbox.numChildren-1; i > -1; i--) {
  433. let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
  434. if(prefab.name == "Gift" || prefab.name == "TimeGift"){
  435. let giftscript = prefab.getComponent(Gift) as Gift;
  436. let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
  437. let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
  438. _collider.enabled = false;
  439. _rig.enabled = false;
  440. _collider.destroy();
  441. _rig.destroy();
  442. Laya.timer.clearAll(prefab);
  443. prefab.removeSelf();
  444. let name = giftscript.type == 0?"Gift":"TimeGift";
  445. GamePool.Instance.RecoverModel(prefab,name);
  446. continue;
  447. }
  448. let ball = prefab.getComponent(Ball) as Ball;
  449. let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
  450. let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
  451. _collider.enabled = false;
  452. _rig.enabled = false;
  453. _collider.destroy();
  454. _rig.destroy();
  455. Laya.timer.clearAll(prefab);
  456. prefab.removeSelf();
  457. let _index = DropRule.Instance.GetBallIndex(ball.score);
  458. GamePool.Instance.RecoverModel(prefab,_index.toString());
  459. // Laya.Pool.recover("img"+_index.toString,ball);
  460. }
  461. }
  462. }
  463. //游戏结束
  464. Over(){
  465. this.ClearStage();
  466. EventManager.StageOff(StageMode.Clone,this,this.AddPrefab);
  467. EventManager.StageOff(StageMode.Win,this,this.Win);
  468. EventManager.StageOff(StageMode.Lose,this,this.Lose);
  469. EventManager.StageOff(StageMode.ReStart,this,this.ReStart);
  470. EventManager.StageOff(StageMode.Over,this,this.Over);
  471. EventManager.StageOff(StageMode.Revive,this,this.Revive);
  472. EventManager.StageOff(StageMode.Check,this,this.Check);
  473. //清除碰撞器
  474. this.ClearCollider(this.BottomCollider);
  475. this.ClearCollider(this.RightCollider);
  476. this.ClearCollider(this.LeftCollider);
  477. }
  478. //复活
  479. Revive(){
  480. for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
  481. let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
  482. if(prefab.name == "Gift" || prefab.name == "TimeGift"){
  483. continue;
  484. }
  485. let ball = prefab.getComponent(Ball) as Ball;
  486. for (let j = 0; j < DropRule.Instance.BallNum.length; j++) {
  487. let Score = DropRule.Instance.GetBallIndex(ball.score);
  488. if(Score+1 ==Number(DropRule.Instance.BallNum[j]) ){
  489. DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
  490. let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
  491. let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
  492. _collider.enabled = false;
  493. _rig.enabled = false;
  494. // _collider.destroy();
  495. // _rig.destroy();
  496. Laya.timer.clearAll(prefab);
  497. prefab.removeSelf();
  498. // prefab.destroy();
  499. let _index = DropRule.Instance.GetBallIndex(ball.score);
  500. GamePool.Instance.RecoverModel(prefab,_index.toString());
  501. // Laya.Pool.recover("img"+_index.toString,prefab);
  502. }
  503. }
  504. }
  505. Laya.timer.frameLoop(2,this,this.CheckHeight);
  506. Laya.timer.once(500,this,()=>{
  507. this.LoseView = false;
  508. })
  509. }
  510. //游戏胜利
  511. Win(){
  512. Laya.timer.clear(this,this.CheckHeight);
  513. }
  514. //游戏失败
  515. Lose(){
  516. Laya.timer.clear(this,this.CheckHeight);
  517. }
  518. //再来一局
  519. ReStart(_data?){
  520. if(_data){
  521. for (let i = this.prefabbox.numChildren-1; i >-1 ; i--) {
  522. let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
  523. if(prefab.name == "Gift" || prefab.name == "TimeGift"){
  524. continue;
  525. }
  526. let ball = prefab.getComponent(Ball) as Ball;
  527. for (let j = 0; j < DropRule.Instance.BallNum.length; j++) {
  528. let Score = DropRule.Instance.GetBallIndex(ball.score);
  529. if(Score+1 == Number(DropRule.Instance.BallNum[j]) ){
  530. DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
  531. let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
  532. let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
  533. _collider.enabled = false;
  534. _rig.enabled = false;
  535. // _collider.destroy();
  536. // _rig.destroy();
  537. Laya.timer.clearAll(prefab);
  538. prefab.removeSelf();
  539. // prefab.destroy();
  540. let _index = DropRule.Instance.GetBallIndex(ball.score);
  541. GamePool.Instance.RecoverModel(prefab,_index.toString());
  542. // Laya.Pool.recover("img"+_index.toString,prefab);
  543. }
  544. }
  545. }
  546. //过关时消除本关 前四位之后的球
  547. let ballarray = this.PassDeal;
  548. if(ballarray.length > 4){
  549. let ballarray2 = [];
  550. for (let m = 0; m < 4; m++) {
  551. ballarray2.push(ballarray[m]);
  552. }
  553. for (let k = this.prefabbox.numChildren-1; k > -1; k--) {
  554. let prefab = this.prefabbox.getChildAt(k) as Laya.Image;
  555. if(prefab.name == "Gift" || prefab.name == "TimeGift"){
  556. continue;
  557. }
  558. let ball = prefab.getComponent(Ball) as Ball;
  559. let dispear = true;
  560. for (let l = 0; l < ballarray2.length; l++) {
  561. if(ball.score == ballarray2[l]){
  562. dispear = false;
  563. }
  564. }
  565. if(dispear){
  566. DropRule.Instance.CreateEffect(ball.score,new Laya.Vector2(prefab.x,prefab.y));
  567. let _rig = prefab.getComponent(Laya.RigidBody) as Laya.RigidBody;
  568. let _collider = prefab.getComponent(Laya.CircleCollider) as Laya.CircleCollider;
  569. _collider.enabled = false;
  570. _rig.enabled = false;
  571. // _collider.destroy();
  572. // _rig.destroy();
  573. Laya.timer.clearAll(prefab);
  574. prefab.removeSelf();
  575. // prefab.destroy();
  576. let _index = DropRule.Instance.GetBallIndex(ball.score);
  577. GamePool.Instance.RecoverModel(prefab,_index.toString());
  578. // Laya.Pool.recover("img"+_index.toString,prefab);
  579. }
  580. }
  581. }
  582. Laya.timer.loop(5000,this,this.Save);
  583. this.WinView = false;
  584. this.lingdianerwu = false;
  585. this.lingdianwu = false;
  586. this.lingdianqiwu = false;
  587. this.ScoreRefresh();
  588. this.Progress();
  589. DropRule.Instance.FallDown(DropRule.Instance.StartNum);
  590. Laya.timer.frameLoop(2,this,this.CheckHeight);
  591. }
  592. else{
  593. this.ClearStage();
  594. this.LoseView = false;
  595. this.WinView = false;
  596. this.lingdianerwu = false;
  597. this.lingdianwu = false;
  598. this.lingdianqiwu = false;
  599. this.ScoreRefresh();
  600. this.Progress();
  601. if(DropRule.Instance.STAGE == 1){
  602. this.Guide.visible = false;
  603. GameManager.Instance.Wave = 1;
  604. DropRule.Instance.GuideFallDown();
  605. GameManager.Instance.CheckHeight = false;
  606. }
  607. else{
  608. DropRule.Instance.FallDown(DropRule.Instance.StartNum);
  609. }
  610. Laya.timer.frameLoop(2,this,this.CheckHeight);
  611. }
  612. }
  613. //清除碰撞器
  614. ClearCollider(_node:Laya.Image){
  615. let collier = _node.getComponent(Laya.ChainCollider) as Laya.ChainCollider;
  616. let rig = _node.getComponent(Laya.RigidBody) as Laya.RigidBody;
  617. if(collier){
  618. collier.enabled = false;
  619. }
  620. if(rig){
  621. rig.enabled = false;
  622. }
  623. if(_node){
  624. _node.removeSelf();
  625. _node.destroy();
  626. }
  627. }
  628. Close(){
  629. Laya.timer.clearAll(this);
  630. }
  631. //过关时消除 除了本关排名前四的球
  632. public get PassDeal():number[]{
  633. let array = [];
  634. let array2 = [];
  635. for (let i = 0; i < this.prefabbox.numChildren; i++) {
  636. let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
  637. if(prefab.name == "Gift" || prefab.name == "TimeGift"){
  638. continue;
  639. }
  640. let ball = prefab.getComponent(Ball) as Ball;
  641. if(array.length == 0){
  642. array.push(ball.score);
  643. }
  644. if(i>0){
  645. let add = true;
  646. for (let j = 0; j < array.length; j++) {
  647. if(ball.score == array[j]){
  648. add = false;
  649. }
  650. }
  651. if(add){
  652. array.push(ball.score);
  653. }
  654. }
  655. }
  656. if(array.length>4){
  657. for (let k = 0; k < array.length; k++) {
  658. for (let l = 0; l < array.length - k -1; l++) {
  659. if(array[l] < array[l+1]){
  660. let temp = array[l];
  661. array[l] = array[l+1];
  662. array[l+1] = temp;
  663. }
  664. }
  665. }
  666. }
  667. return array;
  668. }
  669. //保存关卡进度
  670. Save(_data?){
  671. let type;
  672. let proptype;
  673. let propnum;
  674. let str = "";
  675. let ball;
  676. let score;
  677. let size;
  678. let index;
  679. let point;
  680. let obj = {};
  681. let objarray = [];
  682. if(!_data){
  683. for (let i = 0; i < this.prefabbox.numChildren; i++) {
  684. let prefab = this.prefabbox.getChildAt(i) as Laya.Image;
  685. if(prefab.name == "ball"){
  686. ball = prefab.getComponent(Ball) as Ball;
  687. //分数
  688. score = ball.score;
  689. index =(DropRule.Instance.GetBallIndex(score) + 1).toString();
  690. //尺寸
  691. size = prefab.width.toString();
  692. //坐标
  693. point = new Laya.Vector2(prefab.x,prefab.y);
  694. obj = {"index":index,"size":size,"pos":point,"itemtype":0};//itemtype 0为球 1为礼盒
  695. }
  696. else if(prefab.name == "Gift"){
  697. let giftscript = prefab.getComponent(Gift) as Gift;
  698. type = giftscript.type;
  699. proptype = giftscript.GiftIndex;
  700. propnum = giftscript.GiftNum;
  701. point = new Laya.Vector2(prefab.x,prefab.y);
  702. obj = {"type":type,"proptype":proptype,"propnum":propnum,"pos":point,"itemtype":1};//itemtype 0为球 1为礼盒
  703. }
  704. objarray.push(obj);
  705. }
  706. let jindutiao = {"jindu":GameManager.Instance.ScoreProgress.toString()};
  707. let sizeindex = {"sizeindex":DropRule.Instance.SizeIndex};
  708. let edgeindex = {"edgeindex":DropRule.Instance.EdgeIndex};
  709. objarray.push(edgeindex);
  710. objarray.push(jindutiao);
  711. objarray.push(sizeindex);
  712. var progress = JSON.stringify(objarray);
  713. var args =[{"stage":DropRule.Instance.STAGE.toString()},{"progress":progress}]
  714. }
  715. else{
  716. obj = {"0":"0"};
  717. objarray.push(obj);
  718. var progress = JSON.stringify(objarray);
  719. var args =[{"stage":DropRule.Instance.STAGE.toString()},{"progress":progress}]
  720. }
  721. ServerManager.Instance.SendHttp(BlastToMerge.Save,args,Laya.Handler.create(this,(res)=>{
  722. }),Laya.Handler.create(this,()=>{
  723. console.log("保存进度失败++");
  724. }))
  725. }
  726. }