GameView.ts 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  1. import LayerPanel, { UrlInfo } from "../../Common/manage/Layer/LayerPanel";
  2. import Tools from "../../Common/Tools";
  3. import EndView from "./EndView";
  4. import Text from "./logic/common/text";
  5. import gameConfig from "./logic/common/config";
  6. import HomeView from "./HomeView";
  7. import CacheMgr from "../../Common/manage/CacheMgr";
  8. import AudioMgr from "../../Common/manage/AudioMgr";
  9. import LoadMgr from "../../Common/manage/LoadMgr";
  10. import Constant from "../../Common/Constant";
  11. import PanelMgr, { Layer } from "../../Common/manage/PanelMgr";
  12. import tween = cc.tween;
  13. import ShowConfig from "../../Common/ShowConfig";
  14. import Global from "../../Common/Global";
  15. import QgBanner from "../../Common/manage/Api/QgBanner";
  16. import Emit from "../../Common/manage/Emit/Emit";
  17. import EmitData from "../../Common/manage/Emit/EmitData";
  18. import AESUtil from "../../AESUtil"
  19. import ATSDK from "../../AnyThinkAds/ATJSSDK";
  20. import ATRewardedVideoSDK from "../../AnyThinkAds/ATRewardedVideoJSSDK";
  21. import AAJS2 from "../../ATAndroidJS2";
  22. import GlobalManager from '../../GlobalManager';
  23. const { ccclass, property } = cc._decorator;
  24. @ccclass
  25. export default class GameView extends LayerPanel {
  26. public static getUrl(): UrlInfo {
  27. return {
  28. bundle: "gameView",
  29. name: "gameView"
  30. }
  31. }
  32. private _paramData: any = {};
  33. private _button: cc.Node = null;
  34. //test
  35. private testMakeBottomBlock: cc.Node = null
  36. private testReadyMakeBottomBlock: cc.Node = null
  37. //logic
  38. @property(cc.SpriteFrame)
  39. public graySpriteFrame: cc.SpriteFrame = null
  40. @property(cc.SpriteFrame)
  41. public whiteSpriteFrame: cc.SpriteFrame = null
  42. @property(cc.SpriteFrame)
  43. public hintBlockSpriteFrame: cc.SpriteFrame = null
  44. @property(cc.Prefab)
  45. public text_prefab: cc.Prefab = null
  46. @property(cc.Prefab)
  47. public hammer_prefab: cc.Prefab = null
  48. @property(cc.Prefab)
  49. public sprite_prefab: cc.Prefab = null
  50. @property([cc.SpriteFrame])
  51. public sprite_spriteFrame: cc.SpriteFrame[] = []
  52. @property(cc.SpriteFrame)
  53. public hint_1_spriteFrame: cc.SpriteFrame = null
  54. @property(cc.SpriteFrame)
  55. public hint_2_spriteFrame: cc.SpriteFrame = null
  56. @property(cc.Prefab)
  57. public start_prefab: cc.Prefab = null
  58. @property(cc.Prefab)
  59. public hardUp_prefab: cc.Prefab = null
  60. @property(cc.Prefab)
  61. public nice_prefab: cc.Prefab = null
  62. @property(cc.Prefab)
  63. public get_prefab: cc.Prefab = null
  64. private _startPoint: cc.Node = null
  65. private _content: cc.Node = null
  66. private _hintUI: cc.Node = null
  67. private _whiteHint: cc.Node = null
  68. private _textHint: cc.Node = null
  69. private _hardLevelLabel: cc.Label = null
  70. private _scoreLabel: cc.Label = null
  71. private _mouth: cc.Node = null
  72. private _mask: cc.Node = null
  73. private _hammer: cc.Node = null
  74. private _sprite: cc.Node = null
  75. private _menu: cc.Node = null
  76. private _menuPanel: cc.Node = null
  77. private _hint_hammer: cc.Node = null
  78. private _hint_sprite: cc.Node = null
  79. private _hint_mask: cc.Node = null
  80. private _hint_label: cc.Node = null
  81. private _hint_hand: cc.Node = null
  82. private _price_sprite: cc.Node = null
  83. private _sprite_icon: cc.Node = null
  84. private _hammer_sprite: cc.Node = null
  85. private _hammer_icon: cc.Node = null
  86. private _content_cover: cc.Node = null
  87. private _lineDatas: lineData[] = [null]
  88. private _hintData: lineData = null
  89. private blockPool: cc.NodePool = null
  90. private nextBlockInfo: nextBlockInfo[] = []
  91. private touchEndFlag: boolean = false
  92. private hardLevel: number = 1
  93. private score: number = 0
  94. private continueXiao: number = 0 // 当前连消
  95. private allContinueXiao: number = 0//当前难度总消除
  96. private moveX = -1
  97. private sprite_color: number = 0 //精灵颜色
  98. private hintFlag = true
  99. public initUI() {
  100. //todo 逻辑
  101. this.testMakeBottomBlock = this.getNode("testUI/makeBottomBlock")
  102. this.testReadyMakeBottomBlock = this.getNode("testUI/readymakeBottomBlock")
  103. this.onTouch(this.testMakeBottomBlock, () => {
  104. this.makeBottomBlock()
  105. })
  106. this.onTouch(this.testReadyMakeBottomBlock, () => {
  107. this.readyMakeBottomBlock()
  108. })
  109. this._startPoint = this.getNode("startPoint")
  110. this._content = this.getNode("content")
  111. this._content_cover = this.getNode("content_cover")
  112. this._hintUI = this.getNode("hintUI")
  113. this._whiteHint = this.getNode("white_hint")
  114. this._textHint = this.getNode("textHint")
  115. this._mouth = this.getNode("content_cover/top/mouth")
  116. this._mask = this.getNode("mask")
  117. this._hammer_sprite = this.getNode("bottomUI/hammer/price")
  118. this._hammer_icon = this.getNode("bottomUI/hammer/vedioIcon")
  119. this._hammer_icon.active = false
  120. this._price_sprite = this.getNode("bottomUI/sprite/price")
  121. this._sprite_icon = this.getNode("bottomUI/sprite/vedioIcon")
  122. this._sprite_icon.active = false
  123. this._hint_mask = this.getNode("hint_mask")
  124. this._hint_mask.active = false
  125. this._hint_label = this.getNode("hint_label")
  126. this._hint_label.active = false
  127. this._hint_hand = this.getNode("hint_hand")
  128. this._hint_hand.active = false
  129. this._menu = this.getNode("bottomUI/menu")
  130. this.onTouch(this._menu, this.handle_menu)
  131. this._menuPanel = this.getNode("bottomUI/menuPanel")
  132. this._menuPanel.active = false
  133. this.onTouch(this._menuPanel.children[0], this.handle_restart)
  134. this.onTouch(this._menuPanel.children[1], this.handle_return)
  135. this._hammer = this.getNode("bottomUI/hammer")
  136. // this._hammer.on(cc.Node.EventType.TOUCH_END, this.handle_hammer, this)
  137. this.onTouch(this._hammer, this.handle_hammer)
  138. this._sprite = this.getNode("bottomUI/sprite")
  139. this.onTouch(this._sprite, this.handle_sprite)
  140. this._hint_hammer = this.getNode("hint_hammer")
  141. this._hint_hammer.active = false
  142. this._hint_sprite = this.getNode("hint_sprite")
  143. this._hint_sprite.active = false
  144. this._hardLevelLabel = this.getNode("content_cover/top/hardLevel").getComponent(cc.Label)
  145. this._scoreLabel = this.getNode("content_cover/top/scoreData").getComponent(cc.Label)
  146. this.updateSprite()
  147. //创建对象池
  148. this.blockPool = new cc.NodePool()
  149. let blockExm = new cc.Node()
  150. blockExm.x = 0
  151. blockExm.y = 0
  152. blockExm.setAnchorPoint(0, 0)
  153. let sprite = blockExm.addComponent(cc.Sprite)
  154. sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM
  155. for (let i = 0; i < 80; i++) {
  156. let node = cc.instantiate(blockExm)
  157. this.blockPool.put(node)
  158. }
  159. this.scheduleOnce(() => {
  160. this._menuPanel.position = this._menu.position
  161. let gridExm = new cc.Node()
  162. gameConfig.gridSize = this._startPoint.height / 10
  163. this._content.width = gameConfig.gridSize * 8
  164. this._content.height = gameConfig.gridSize * 10
  165. this._whiteHint.width = this._content.width
  166. this._whiteHint.height = this._content.height
  167. this._whiteHint.parent = this._content
  168. gridExm.setAnchorPoint(0, 0)
  169. gridExm.width = gameConfig.gridSize
  170. gridExm.height = gameConfig.gridSize
  171. gridExm.opacity = 200
  172. this._hint_hand.width = gameConfig.gridSize
  173. this._hint_hand.height = gameConfig.gridSize
  174. this._hint_hand.setAnchorPoint(0, 0)
  175. let lineContentExm = new cc.Node()
  176. lineContentExm.setAnchorPoint(0.5, 0)
  177. lineContentExm.width = gridExm.width * 8
  178. lineContentExm.height = gridExm.height
  179. this._hintUI.width = lineContentExm.width
  180. let startPosition = this._startPoint.getPosition()
  181. let gridColorTemp = 0 // 0 浅色 1 深色
  182. for (let i = 10; i >= 1; i--) {
  183. let lineContent = cc.instantiate(lineContentExm)
  184. lineContent.name = i.toString()
  185. lineContent.x = 0
  186. lineContent.y = startPosition.y
  187. startPosition.y += lineContent.height
  188. this._content.addChild(lineContent)
  189. let posData = Tools.getNodeFourPoint(lineContent)
  190. lineContent.setAnchorPoint(0, 0)
  191. lineContent.position = cc.v3(posData.left_down)
  192. if (this._hintUI.x != lineContent.x) {
  193. this._hintUI.x = lineContent.x
  194. this._hintData = {
  195. blockNodes: [],
  196. line: this._hintUI,
  197. linePos: [-1]
  198. }
  199. let flagX = 0
  200. for (let i = 1; i <= 8; i++) {
  201. this._hintData.linePos[i] = flagX
  202. flagX += gameConfig.gridSize
  203. }
  204. }
  205. let flagX = 0
  206. let linePosArr: number[] = [-1] //记录 x 轴
  207. for (let j = 1; j <= 8; j++) {
  208. let grid = cc.instantiate(gridExm)
  209. grid.name = j.toString()
  210. let sprite = grid.addComponent(cc.Sprite)
  211. sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM
  212. if (gridColorTemp == 0) {
  213. if (j == 1 && i != 10) {
  214. sprite.spriteFrame = this.graySpriteFrame
  215. } else {
  216. gridColorTemp = 1
  217. sprite.spriteFrame = this.whiteSpriteFrame
  218. }
  219. } else {
  220. if (j == 1 && i != 1) {
  221. sprite.spriteFrame = this.whiteSpriteFrame
  222. } else {
  223. gridColorTemp = 0
  224. sprite.spriteFrame = this.graySpriteFrame
  225. }
  226. }
  227. grid.y = 0
  228. grid.x = flagX
  229. linePosArr.push(grid.x)
  230. flagX += grid.width
  231. lineContent.addChild(grid)
  232. }
  233. this._lineDatas[i] = {
  234. blockNodes: [],
  235. line: lineContent,
  236. linePos: linePosArr
  237. }
  238. if (i == 10) {
  239. this._whiteHint.x = lineContent.x
  240. this._whiteHint.y = lineContent.y
  241. this._whiteHint.active = false
  242. }
  243. }
  244. this.adaptive()
  245. lineContentExm.destroy()
  246. gridExm.destroy()
  247. this._startPoint.destroy()
  248. this.text_start()
  249. this.makeBottomBlock(true)
  250. }, 0)
  251. }
  252. public show(param: any) {
  253. //todo 逻辑
  254. console.log('zh:GameView show')
  255. ShowConfig.show('gameConfig').then((res) => {
  256. if (Global.config.gameConfig.bannerShow == 1) {
  257. QgBanner.showBanner();
  258. } else {
  259. QgBanner.hideBanner();
  260. }
  261. });
  262. }
  263. public onLoad(): void {
  264. console.log('zh:gameView.ts onload')
  265. this.initAd();
  266. this.initAdForPage();
  267. // for (let i = 0; i < 5; i++) {
  268. // // let th = this;
  269. // setTimeout(() => {
  270. // console.log('zh:gameView.ts 测试测试=' + i)
  271. // // th.node.emit('env_playAdEnd', 'Hello,开发发放shop道具吧');
  272. // GlobalManager.instance.callMethod('env_playAdEnd');
  273. // }, 5000);
  274. // }
  275. }
  276. initAd() {
  277. let adKey = "zh_ad_type"
  278. cc.sys.localStorage.setItem(adKey, "");
  279. if (cc.sys.os != cc.sys.OS_ANDROID) {
  280. return;
  281. }
  282. let placementId = AAJS2.getPlacementId();
  283. let deviceId = AAJS2.getDeviceUserId();
  284. var setting = {};
  285. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  286. ATRewardedVideoSDK.loadRewardedVideo(placementId, setting);
  287. //console.log('zh:bbb222')
  288. var customPlacementId = "";
  289. if (cc.sys.os === cc.sys.OS_IOS) {
  290. customPlacementId = placementId;
  291. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  292. customPlacementId = placementId;
  293. }
  294. // 初始化SDK
  295. ATSDK.initSDK("h674584cd6f096", "a010d11a5190a026e6b1fe54f86365f18");//正式的,
  296. // ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告
  297. // ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  298. ATSDK.setLogDebug(true);//zh:diy
  299. var GDPRLevel = ATSDK.getGDPRLevel();
  300. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  301. ATSDK.getUserLocation(function (userLocation) {
  302. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  303. if (userLocation === ATSDK.kATUserLocationInEU) {
  304. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  305. ATSDK.showGDPRAuth();
  306. }
  307. }
  308. });
  309. ATRewardedVideoSDK.setAdListener(this);
  310. if (cc.sys.os === cc.sys.OS_ANDROID) {
  311. setTimeout(() => {
  312. var allInfo = AAJS2.allInfo();
  313. ATSDK.printLog("zh:allInfo=" + allInfo);
  314. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  315. let iv = "Jn0.aWsOu$y-Dbqb";
  316. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  317. ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  318. console.log('zh:ad_allInfo', data);
  319. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  320. }, 200);
  321. }
  322. }
  323. initAdForPage() {
  324. if (cc.sys.os === cc.sys.OS_ANDROID) {
  325. let deviceId = AAJS2.getDeviceUserId();
  326. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  327. var setting = {};
  328. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  329. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  330. }
  331. }
  332. //#region "AD 监听start"
  333. onRewardedVideoAdLoaded(placementId) {
  334. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  335. }
  336. onRewardedVideoAdFailed(placementId, errorInfo) {
  337. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  338. }
  339. onRewardedVideoAdPlayStart(placementId, callbackInfo) {
  340. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  341. let deviceId = AAJS2.getDeviceUserId();
  342. var setting = {};
  343. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  344. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  345. }
  346. onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
  347. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  348. console.log('zh: ad over 开始发送事件11s')
  349. //this.node.emit("handleCustomEvent");
  350. this.handleCustomEvent()
  351. //cc.sys.localStorage.setItem('zh_ad_type', 'getHammer');//获取锤子
  352. console.log('zh: ad over 开始发送事件11e')
  353. }
  354. onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
  355. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  356. }
  357. onRewardedVideoAdClosed(placementId, callbackInfo) {
  358. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  359. }
  360. onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
  361. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  362. }
  363. onReward(placementId, callbackInfo) {
  364. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  365. }
  366. //#endregion "AD 监听end"
  367. /**
  368. * AD播放完毕\close的事件处理
  369. */
  370. handleCustomEvent() {
  371. let that = this;
  372. console.log('zh:AD 展示完毕')
  373. let adKey = "zh_ad_type"
  374. let idx = cc.sys.localStorage.getItem(adKey);//getHammer ,
  375. console.log('zh:onAdOverEve idx =' + idx)
  376. switch (idx) {
  377. case 'getHammer':
  378. console.log('zh:开发发放道具:一个锤子!')
  379. this.event_adPlayEndForHammer();
  380. break;
  381. case 'getSprite':
  382. ////失败后重新开始
  383. console.log('zh:开发发放道具:一个魔鬼精灵!')
  384. this.event_adPlayEndForHndle_sprite();
  385. //发送事件。。。。todo: 重新开始游戏
  386. //this.node.emit('env_playAdEnd', 'Hello,你好');
  387. // 调用A页面的方法
  388. // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2');
  389. // GlobalManager.instance.callMethod('startGameForFailAD');
  390. break;
  391. case 'pubShop':
  392. console.log('zh:开始通知下属 发放shop道具!')
  393. //that.node.emit('env_playAdEnd', 'Hello,开发发放shop道具吧');
  394. GlobalManager.instance.callMethod('env_playAdEnd');
  395. break;
  396. default:
  397. console.log('zh:未知的道具类型AD' + idx)
  398. }
  399. }
  400. public hide() {
  401. if (Global.config.gameConfig.nativeConfig.type == 2) {
  402. Emit.instance().emit(EmitData.CLOSE_NATIVE);
  403. }
  404. }
  405. //todo logic 方法
  406. private getBlock(size: number, color: number = -1): cc.Node {
  407. let block = this.blockPool.get()
  408. block.width = size * gameConfig.gridSize
  409. block.height = gameConfig.gridSize
  410. block.on(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  411. block.on(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  412. block.on(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  413. block.on(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  414. LoadMgr.loadAtlas("view/gameView/block/p").then((p: cc.SpriteAtlas) => {
  415. let id = ((color * 10) + size)
  416. let spriteFrame = p.getSpriteFrame(id.toString())
  417. block.getComponent(cc.Sprite).spriteFrame = spriteFrame
  418. })
  419. return block
  420. }
  421. //归还方块
  422. private returnBlock(node: cc.Node) {
  423. node.off(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  424. node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  425. node.off(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  426. node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  427. node.parent = null
  428. node.x = 0
  429. node.y = 0
  430. node.width = gameConfig.gridSize
  431. node.height = gameConfig.gridSize
  432. node.getComponent(cc.Sprite).spriteFrame = null
  433. this.blockPool.put(node)
  434. return
  435. }
  436. //预创建最低层的方块
  437. private readyMakeBottomBlock() {
  438. //先随机需要空出来几个
  439. //判断是否需要新手提示
  440. if (!CacheMgr.isNeedHint || gameConfig.hint_data.length == 0) {
  441. let blankNum = Tools.getRandom(gameConfig.bottomBlankMin, gameConfig.bottomBlankMax + 1)
  442. let blankColumns: number[] = []
  443. while (true) {
  444. let column = Tools.getRandom(1, 9)
  445. let flag = Tools.JudgeValueInArr(column, blankColumns)
  446. for (let i = 0; i < blankColumns.length; i++) {
  447. if (column == blankColumns[i]) {
  448. flag = true
  449. }
  450. }
  451. if (flag) {
  452. continue
  453. }
  454. blankColumns.push(column)
  455. if (blankColumns.length >= blankNum) {
  456. break
  457. }
  458. }
  459. //获取数组中连续的一段
  460. let allContinueArr: number[][] = []
  461. let continueArr: number[] = []
  462. for (let i = 1; i < 9; i++) {
  463. if (Tools.JudgeValueInArr(i, blankColumns)) {
  464. if (continueArr.length > 0) {
  465. allContinueArr.push(Tools.deepClone(continueArr))
  466. }
  467. continueArr = []
  468. } else {
  469. continueArr.push(i)
  470. if (i == 8) {
  471. allContinueArr.push(Tools.deepClone(continueArr))
  472. }
  473. }
  474. }
  475. let allBlockInfo: nextBlockInfo[] = []
  476. for (let i = 0; i < allContinueArr.length; i++) {
  477. let blocInfos = this.definitionBlockType(Tools.deepClone(allContinueArr[i]))
  478. blocInfos.forEach((value) => {
  479. allBlockInfo.push(value)
  480. })
  481. }
  482. this.nextBlockInfo = allBlockInfo
  483. } else {
  484. this.nextBlockInfo = gameConfig.hint_data[0]
  485. gameConfig.hint_data.shift()
  486. }
  487. this.updateHint()
  488. }
  489. //根据一个位置数组定义这一组方块类型
  490. private definitionBlockType(arr: number[]): nextBlockInfo[] {
  491. let blockInfos: nextBlockInfo[] = []
  492. while (true) {
  493. let length = arr.length
  494. if (arr.length == 0) {
  495. break
  496. }
  497. if (length >= 4) {
  498. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_4)) {
  499. blockInfos.push({
  500. column: arr[0],
  501. num: 4,
  502. })
  503. arr.splice(0, 4)
  504. continue
  505. }
  506. }
  507. if (length >= 3) {
  508. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_3)) {
  509. blockInfos.push({
  510. column: arr[0],
  511. num: 3
  512. })
  513. arr.splice(0, 3)
  514. continue
  515. }
  516. }
  517. if (length >= 2) {
  518. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_2)) {
  519. blockInfos.push({
  520. column: arr[0],
  521. num: 2,
  522. })
  523. arr.splice(0, 3)
  524. continue
  525. }
  526. }
  527. if (length >= 1) {
  528. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_1)) {
  529. blockInfos.push({
  530. column: arr[0],
  531. num: 1,
  532. })
  533. arr.splice(0, 1)
  534. }
  535. }
  536. }
  537. return blockInfos
  538. }
  539. //刷新提示
  540. private updateHint() {
  541. this._hintUI.removeAllChildren()
  542. for (let i = 0; i < this.nextBlockInfo.length; i++) {
  543. let info = this.nextBlockInfo[i]
  544. let hintBlock = new cc.Node("hintBlock")
  545. hintBlock.setAnchorPoint(0, 0)
  546. let sprite = hintBlock.addComponent(cc.Sprite)
  547. sprite.type = cc.Sprite.Type.SLICED
  548. sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM
  549. sprite.spriteFrame = this.hintBlockSpriteFrame
  550. hintBlock.width = info.num * gameConfig.gridSize
  551. hintBlock.height = this._hintUI.height
  552. this._hintUI.addChild(hintBlock)
  553. hintBlock.y = 0
  554. hintBlock.x = this._hintData.linePos[info.column]
  555. }
  556. }
  557. //创建最底层的一套方块
  558. private makeBottomBlock(isStart = false) {
  559. console.log('zh:GameView 创建最底层的一套方块')
  560. if (this.nextBlockInfo.length == 0) {
  561. this.readyMakeBottomBlock()
  562. }
  563. this._mask.active = true
  564. let result = this.upAllLine()
  565. Promise.all(result).then(() => {
  566. //创建方块在下一层
  567. for (let i = 0; i < this.nextBlockInfo.length; i++) {
  568. let lineData = this._lineDatas[10]
  569. let nextBlockInfo = this.nextBlockInfo[i]
  570. let color = Tools.getRandom(1, 6)
  571. let block = this.getBlock(nextBlockInfo.num, color)
  572. block.parent = lineData.line
  573. block.name = "c_" + nextBlockInfo.column
  574. block.x = lineData.linePos[nextBlockInfo.column]
  575. let blockInfo: blockInfo = {
  576. node: block,
  577. column: nextBlockInfo.column,
  578. num: nextBlockInfo.num,
  579. cover: this.getCoverColumn(nextBlockInfo.column, nextBlockInfo.num),
  580. color: color
  581. }
  582. lineData.blockNodes.push(blockInfo)
  583. }
  584. this._mask.active = false
  585. this.readyMakeBottomBlock()
  586. if (isStart) {
  587. this.makeBottomBlock()
  588. } else {
  589. if (CacheMgr.isNeedHint && this.hintFlag) {
  590. this.hintFlag = false
  591. this.hint_play()
  592. }
  593. this.downAllLine(10)
  594. }
  595. })
  596. }
  597. //将一行方块向上移动
  598. private upLine(line: number): any[] {
  599. let result = []
  600. let data = this._lineDatas[line]
  601. let nextData = this._lineDatas[line - 1]
  602. if (data.blockNodes && data.blockNodes.length > 0) {
  603. let nodesData = data.blockNodes
  604. let nextNodesData = nextData.blockNodes
  605. for (let i = 0; i < nodesData.length; i++) {
  606. let n = nodesData[i]
  607. nextNodesData.push(n)
  608. n.node.parent = nextData.line
  609. n.node.y = -gameConfig.gridSize //如果y = 0 的话,就没有动画做了
  610. let p = new Promise((resolve, reject) => {
  611. cc.tween(n.node)
  612. .to(gameConfig.upTime, { y: 0 }, { easing: 'cubicInOut' })
  613. .call(() => {
  614. resolve(true)
  615. })
  616. .start()
  617. })
  618. result.push(p)
  619. }
  620. data.blockNodes = []
  621. }
  622. return result
  623. }
  624. //将所有方块向上移动
  625. private upAllLine(): any[] {
  626. //从倒数第二行开始 依次往上移动
  627. let result = []
  628. for (let i = 2; i <= 10; i++) {
  629. let r = this.upLine(i)
  630. for (let i = 0; i < r.length; i++) {
  631. result.push(r[i])
  632. }
  633. }
  634. return result
  635. }
  636. private getCoverColumn(first: number, num: number): number[] {
  637. let arr: number[] = []
  638. for (let i = first; i < first + num; i++) {
  639. arr.push(i)
  640. }
  641. return arr
  642. }
  643. private handle_block_start(e: cc.Event.EventTouch) {
  644. let node: cc.Node = e.target
  645. this._whiteHint.width = node.width
  646. let world = node.parent.convertToWorldSpaceAR(node.position)
  647. let position = this._whiteHint.parent.convertToNodeSpaceAR(world)
  648. this._whiteHint.x = position.x
  649. this._whiteHint.active = true
  650. this.moveX = node.x
  651. }
  652. private handle_block_move(e) {
  653. let node: cc.Node = e.target
  654. let a = e.getDelta()
  655. let world = node.parent.convertToWorldSpaceAR(node.position)
  656. let position = this._whiteHint.parent.convertToNodeSpaceAR(world)
  657. this._whiteHint.x = position.x
  658. let line = Number(node.parent.name)
  659. let column = Number(node.name.split("_")[1])
  660. let data = this.getCanMoveMax(line, column)
  661. // let position2 = node.parent.convertToNodeSpaceAR(e.getLocation())
  662. let x = node.x += a.x;
  663. if (data.min_x > x) {
  664. x = data.min_x
  665. } else if (data.max_x < x) {
  666. x = data.max_x
  667. }
  668. node.x = x
  669. }
  670. private getCanMoveMax(line: number, column: number) {
  671. let lineData = this._lineDatas[line]
  672. let right_column: number = -1
  673. let num: number = 0
  674. let left_column: number = column
  675. for (let i = 0; i < lineData.blockNodes.length; i++) {
  676. let data = lineData.blockNodes[i]
  677. if (data.column == column) {
  678. num = data.num
  679. right_column = data.cover[data.cover.length - 1]
  680. }
  681. }
  682. let max = 0
  683. let min = 0
  684. //寻找左右两边最大能够移动的距离
  685. while (true) {
  686. right_column++
  687. if (right_column > 8) {
  688. max = right_column - 1
  689. break
  690. }
  691. let flag = true
  692. for (let i = 0; i < lineData.blockNodes.length; i++) {
  693. let data = lineData.blockNodes[i]
  694. for (let j = 0; j < data.cover.length; j++) {
  695. if (data.cover[j] == right_column) {
  696. flag = false
  697. break
  698. }
  699. }
  700. }
  701. if (!flag) {
  702. max = right_column - 1
  703. break
  704. } else {
  705. max = right_column
  706. }
  707. }
  708. while (true) {
  709. left_column--
  710. if (left_column < 1) {
  711. min = left_column + 1
  712. break
  713. }
  714. let flag = true
  715. for (let i = 0; i < lineData.blockNodes.length; i++) {
  716. let data = lineData.blockNodes[i]
  717. for (let j = 0; j < data.cover.length; j++) {
  718. if (data.cover[j] == left_column) {
  719. flag = false
  720. break
  721. }
  722. }
  723. }
  724. if (!flag) {
  725. min = left_column + 1
  726. break
  727. } else {
  728. min = left_column
  729. }
  730. }
  731. let min_x = lineData.linePos[min]
  732. let max_x = lineData.linePos[max - num + 1]
  733. return {
  734. min_x: min_x,
  735. max_x: max_x
  736. }
  737. }
  738. private handle_block_end(e) {
  739. let node: cc.Node = e.target
  740. let line = Number(node.parent.name)
  741. let column = Number(node.name.split("_")[1])
  742. this._whiteHint.active = false
  743. let lineData = this._lineDatas[line]
  744. this.continueXiao = 0
  745. for (let i = 1; i <= 8; i++) {
  746. let grid = lineData.line.getChildByName(i.toString())
  747. let position = cc.v2(grid.x + grid.width / 2, grid.y + grid.height / 2)
  748. if (node.getBoundingBox().contains(position)) {
  749. node.x = lineData.linePos[i]
  750. node.name = "c_" + i
  751. for (let j = 0; j < lineData.blockNodes.length; j++) {
  752. let bInfo = lineData.blockNodes[j]
  753. if (bInfo.column == column) {
  754. bInfo.column = i
  755. bInfo.cover = this.getCoverColumn(i, bInfo.num)
  756. break
  757. }
  758. }
  759. break
  760. }
  761. }
  762. if (node.x == this.moveX) {
  763. this.moveX = -1
  764. return
  765. }
  766. AudioMgr.play("move_end").then()
  767. Tools.vibrateShort()
  768. this.touchEndFlag = true
  769. this.downAllLine(line)
  770. }
  771. //将一行方块向下移动
  772. private downLine(line: number): any[] {
  773. let result = []
  774. let data = this._lineDatas[line]
  775. let needChange: any[] = []
  776. for (let i = 0; i < data.blockNodes.length; i++) {
  777. //循环需要下拉行的 所有方块
  778. let blockInfo = data.blockNodes[i]
  779. //判断每一个方块最多可以下降到哪一行
  780. let toLine = -1
  781. for (let j = line + 1; j <= 10; j++) {
  782. let flag = true
  783. let nextData = this._lineDatas[j]
  784. for (let k = 0; k < nextData.blockNodes.length; k++) {
  785. let cover = nextData.blockNodes[k].cover
  786. if (Tools.judgeArraySame(blockInfo.cover, cover)) {
  787. flag = false
  788. }
  789. }
  790. if (flag) {
  791. toLine = j
  792. } else {
  793. break
  794. }
  795. }
  796. if (toLine != -1) {
  797. needChange.push({
  798. index: i,
  799. to: toLine,
  800. })
  801. let p = new Promise((resolve, reject) => {
  802. let n = blockInfo.node
  803. cc.tween(n)
  804. .to(gameConfig.downTime * 0.6, { y: -gameConfig.gridSize * (toLine - line) }, { easing: 'cubicInOut' })
  805. .by(gameConfig.downTime * 0.2, { y: 10 },)
  806. .by(gameConfig.downTime * 0.2, { y: -10 },)
  807. .union()
  808. .call(() => {
  809. n.parent = this._lineDatas[toLine].line
  810. n.y = 0
  811. resolve(true)
  812. })
  813. .start()
  814. })
  815. result.push(p)
  816. }
  817. }
  818. for (let i = needChange.length - 1; i >= 0; i--) {
  819. let cdata = needChange[i]
  820. this._lineDatas[cdata.to].blockNodes.push(data.blockNodes[cdata.index])
  821. data.blockNodes.splice(cdata.index, 1)
  822. }
  823. return result
  824. }
  825. //将所有方块向下移动
  826. private downAllLine(line: number) {
  827. //从倒数第二行开始 依次往上移动
  828. this._mask.active = true
  829. let result = []
  830. for (let i = line; i >= 1; i--) {
  831. if (i == 10) {
  832. continue
  833. }
  834. let r = this.downLine(i)
  835. for (let i = 0; i < r.length; i++) {
  836. result.push(r[i])
  837. }
  838. }
  839. if (result.length > 0) {
  840. Promise.all(result).then(() => {
  841. AudioMgr.play("down").then()
  842. this.scheduleOnce(() => {
  843. this.judgeAllCanClear()
  844. })
  845. })
  846. } else {
  847. this.judgeAllCanClear()
  848. }
  849. // return result
  850. }
  851. private judgeLineCanClear(line): any {
  852. let result = null
  853. let blockData = this._lineDatas[line].blockNodes
  854. //获取这个一行所有覆盖
  855. let allCover = []
  856. for (let i = 0; i < blockData.length; i++) {
  857. blockData[i].cover.forEach((value) => {
  858. allCover.push(value)
  859. })
  860. }
  861. if (allCover.length >= 8) {
  862. result = new Promise((resolve, reject) => {
  863. cc.tween(this._lineDatas[line].line)
  864. .by(gameConfig.lineShake / 2, { x: -15 },)
  865. .by(gameConfig.lineShake / 2, { x: 15 },)
  866. // .by(gameConfig.lineShake / 30, {y: 2.5}, {easing: 'cubicInOut'})
  867. // .by(gameConfig.lineShake / 30, {x: 5}, {easing: 'cubicInOut'})
  868. // .by(gameConfig.lineShake / 30, {y: -5}, {easing: 'cubicInOut'})
  869. // .by(gameConfig.lineShake / 30, {y: 2.5, x: -2.5}, {easing: 'cubicInOut'})
  870. .union()
  871. // .repeat(6)
  872. .call(() => {
  873. let line_data = this._lineDatas[line]
  874. for (let i = 0; i < blockData.length; i++) {
  875. this.returnBlock(blockData[i].node)
  876. }
  877. resolve(true)
  878. line_data.blockNodes = []
  879. })
  880. .start()
  881. })
  882. }
  883. return result
  884. }
  885. //判断所有行是否存在可以消除的行
  886. private judgeAllCanClear(): any[] {
  887. let result: any[] = []
  888. for (let i = 1; i <= 10; i++) {
  889. let r = this.judgeLineCanClear(i)
  890. if (r) {
  891. result.push(r)
  892. }
  893. }
  894. if (result.length > 0) {
  895. AudioMgr.play("xiaochu")
  896. Tools.vibrateShort("heavy")
  897. this.continueXiao += result.length
  898. this.allContinueXiao += result.length
  899. this.text_defen(result.length)
  900. this.text_addHard()
  901. Promise.all(result).then(() => {
  902. this.scheduleOnce(() => {
  903. this.downAllLine(10)
  904. }, 0)
  905. if (CacheMgr.isNeedHint) {
  906. this.hint_hint()
  907. }
  908. })
  909. } else {
  910. //没有需要消除的,需要判断一下是不是输了 , 即第1层是不是有东西
  911. if (this._lineDatas[1].blockNodes.length > 0) {
  912. //todo 输了
  913. this.fail_win()
  914. return
  915. } else if (this._lineDatas[9].blockNodes.length == 0) {
  916. this.touchEndFlag = false
  917. this.makeBottomBlock()
  918. } else if (this.touchEndFlag) {
  919. this.touchEndFlag = false
  920. this.makeBottomBlock()
  921. } else {
  922. this._mask.active = false
  923. }
  924. }
  925. return result
  926. }
  927. //适配边框
  928. private adaptive() {
  929. let top = this._content_cover.getChildByName("top")
  930. let left = this._content_cover.getChildByName("left_wall")
  931. let right = this._content_cover.getChildByName("right_wall")
  932. let bottom = this._content_cover.getChildByName("bottom")
  933. let temp = this._lineDatas[1].line.getPosition()
  934. temp.y += gameConfig.gridSize
  935. let left_top = this._content_cover.convertToNodeSpaceAR(this._content.convertToWorldSpaceAR(temp))
  936. temp = Tools.getNodeFourPoint(this._lineDatas[10].line).right_down
  937. let right_bottom = this._content_cover.convertToNodeSpaceAR(this._content.convertToWorldSpaceAR(temp))
  938. top.y = left_top.y
  939. top.width = this._content.width + 20
  940. top.getChildByName("scoreData").getComponent(cc.Widget).updateAlignment()
  941. top.getChildByName("hardLevel").getComponent(cc.Widget).updateAlignment()
  942. bottom.y = right_bottom.y
  943. bottom.width = this._content.width + 20
  944. left.height = this._content.height + 20
  945. left.x = left_top.x
  946. left.y = left_top.y - this._content.height / 2
  947. right.height = this._content.height + 20
  948. right.x = right_bottom.x
  949. right.y = left_top.y - this._content.height / 2
  950. }
  951. update() {
  952. this._scoreLabel.string = "score:" + this.score
  953. this._hardLevelLabel.string = "hardLevel:" + this.hardLevel.toString()
  954. if (CacheMgr.setting.hammerNum > 0) {
  955. this._hammer_icon.active = false
  956. this._hammer_sprite.active = true
  957. // console.log("够 的1 ")
  958. this._hammer_sprite.getComponent(cc.Label).string = CacheMgr.setting.hammerNum.toString()
  959. } else {
  960. // console.log("不够1 ")
  961. this._hammer_sprite.active = false
  962. this._hammer_icon.active = true
  963. }
  964. if (CacheMgr.setting.spriteNum > 0) {
  965. // console.log("狗的2 ")
  966. this._sprite_icon.active = false
  967. this._price_sprite.active = true
  968. this._price_sprite.getComponent(cc.Label).string = CacheMgr.setting.spriteNum.toString()
  969. } else {
  970. // console.log("不够2 ")
  971. this._price_sprite.active = false
  972. this._sprite_icon.active = true
  973. }
  974. }
  975. //更新精灵节点
  976. updateSprite() {
  977. this.sprite_color = Tools.getRandom(1, 6)
  978. this._sprite.getChildByName("sprite").getComponent(cc.Sprite).spriteFrame = this.sprite_spriteFrame[this.sprite_color]
  979. }
  980. private fail_win() {
  981. AudioMgr.play("fail")
  982. Tools.vibrateLong()
  983. let result: any[] = []
  984. let time: number = 0
  985. for (let i = 1; i <= 10; i++) {
  986. let lineData = this._lineDatas[i]
  987. lineData.blockNodes.forEach((value) => {
  988. let node = value.node
  989. let world = this._mouth.parent.convertToWorldSpaceAR(this._mouth.position)
  990. let position = node.parent.convertToNodeSpaceAR(world)
  991. position.x -= gameConfig.gridSize / 2
  992. position.y -= gameConfig.gridSize / 2
  993. // node.setAnchorPoint(0.5,0.5)
  994. let p = new Promise((resolve, reject) => {
  995. cc.tween(node)
  996. .delay(time)
  997. .bezierTo(gameConfig.blockFlyTime, cc.v2(Tools.getRandom(0, 500), Tools.getRandom(0, 500)), cc.v2(Tools.getRandom(0, 500), Tools.getRandom(0, 500)), cc.v2(position))
  998. .call(() => {
  999. node.active = false
  1000. node.destroy()
  1001. resolve(true)
  1002. })
  1003. .start()
  1004. })
  1005. result.push(p);
  1006. time += gameConfig.blockFlyTime;
  1007. })
  1008. }
  1009. let isNewMax = false;
  1010. CacheMgr.gold = CacheMgr.gold + this.score;
  1011. if (this.score > CacheMgr.checkpoint) {
  1012. CacheMgr.checkpoint = this.score;
  1013. isNewMax = true;
  1014. }
  1015. Promise.all(result).then(() => {
  1016. PanelMgr.INS.openPanel({
  1017. panel: EndView,
  1018. layer: Layer.gameLayer,
  1019. param: {
  1020. score: this.score,
  1021. isNewMax: isNewMax
  1022. },
  1023. call: () => {
  1024. PanelMgr.INS.closePanel(GameView);
  1025. }
  1026. })
  1027. });
  1028. }
  1029. private text_defen(n: number) {
  1030. let num = this.hardLevel * n * this.continueXiao
  1031. this.score += num
  1032. let node: cc.Node = null
  1033. node = cc.instantiate(this.get_prefab)
  1034. node.children[0].getComponent(cc.Label).string = num.toString()
  1035. this._textHint.addChild(node)
  1036. if (this.continueXiao > 1) {
  1037. node = cc.instantiate(this.nice_prefab)
  1038. node.children[0].getComponent(cc.Label).string = this.continueXiao.toString()
  1039. this._textHint.addChild(node)
  1040. }
  1041. }
  1042. private text_start() {
  1043. AudioMgr.play("start")
  1044. let text_prefab = cc.instantiate(this.start_prefab)
  1045. // text_prefab.getComponent(cc.Label).string = "游戏开始"
  1046. text_prefab.getComponent(Text).delay = 5
  1047. // this._textHint.addChild(text_prefab)
  1048. // text_prefab = cc.instantiate(this.text_prefab)
  1049. // text_prefab.getComponent(Text).delay = 5
  1050. // text_prefab.getComponent(cc.Label).string = "拖动方块,消除整行."
  1051. this._textHint.addChild(text_prefab)
  1052. }
  1053. private text_addHard() {
  1054. if (this.hardLevel >= gameConfig.grade_of_difficulty_config.length - 1) {
  1055. return
  1056. }
  1057. if (this.allContinueXiao >= 10) {
  1058. this.hardLevel++
  1059. this.allContinueXiao = 2
  1060. let text_prefab = cc.instantiate(this.hardUp_prefab)
  1061. // text_prefab.getComponent(cc.Label).string = "难度提升,得分X" + this.hardLevel
  1062. text_prefab.children[0].getComponent(cc.Label).string = this.hardLevel.toString()
  1063. text_prefab.getComponent(Text).delay = 5
  1064. this._textHint.addChild(text_prefab)
  1065. }
  1066. }
  1067. private handle_hammer() {
  1068. console.log('zh: hammer 使用锤子')
  1069. if (this._hint_hammer.active) {
  1070. return;
  1071. }
  1072. if (CacheMgr.setting.hammerNum <= 0) {
  1073. console.log('zh: hammer 没有锤子,开始播放视频')
  1074. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  1075. cc.sys.localStorage.setItem('zh_ad_type', 'getHammer');//获取锤子
  1076. console.log('zh:AD ready for handle_hammer')
  1077. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  1078. } else {
  1079. console.log('zh:AD not ready for handle_hammer')
  1080. this.event_adPlayEndForHammer();
  1081. }
  1082. //下面是原始的逻辑,下面的代码精简掉即可
  1083. if (2 > 1) {
  1084. return;
  1085. }
  1086. Tools.handleVideo().then((res) => {
  1087. console.log('zh: over ...锤子1')
  1088. if (!res) {
  1089. console.log('zh: over ...锤子2')
  1090. return;
  1091. }
  1092. console.log('zh: over ...锤子3')
  1093. //判断是否存在3个的方块
  1094. let dataBeChui: any[] = []
  1095. for (let i = 1; i <= 10; i++) {
  1096. this._lineDatas[i].blockNodes.forEach((value) => {
  1097. if (value.num >= 3) {
  1098. dataBeChui.push({
  1099. line: i,
  1100. column: value.column
  1101. })
  1102. }
  1103. })
  1104. }
  1105. if (dataBeChui.length == 0) {
  1106. this._hint_hammer.active = true
  1107. // Tools.changeGold(gameConfig.price)
  1108. this.scheduleOnce(() => {
  1109. this._hint_hammer.active = false
  1110. }, gameConfig.hide_hint_sprite)
  1111. CacheMgr.setting.hammerNum++
  1112. CacheMgr.setting = CacheMgr.setting
  1113. return
  1114. }
  1115. this._mask.active = true
  1116. let pss = []
  1117. let needDelete: Map<number, number[]> = new Map<number, number[]>()
  1118. dataBeChui.forEach((value) => {
  1119. let pp = new Promise((resolve, reject) => {
  1120. let lineData = this._lineDatas[value.line]
  1121. let idx = 0
  1122. lineData.blockNodes.forEach((value2, index) => {
  1123. if (value2.column == value.column) {
  1124. idx = index
  1125. }
  1126. })
  1127. let oldBlock = lineData.blockNodes[idx]
  1128. let ps = []
  1129. for (let i = 0; i < oldBlock.cover.length; i++) {
  1130. let h = cc.instantiate(this.hammer_prefab)
  1131. h.width = gameConfig.gridSize
  1132. h.height = gameConfig.gridSize
  1133. let world = oldBlock.node.parent.convertToWorldSpaceAR(oldBlock.node.position)
  1134. this._content.addChild(h)
  1135. h.position = h.parent.convertToNodeSpaceAR(world)
  1136. h.x += oldBlock.node.width / 2
  1137. h.y += oldBlock.node.height / 2
  1138. let p = new Promise((resolve, reject) => {
  1139. cc.tween(h)
  1140. .delay(0.5)
  1141. .to(gameConfig.hammerRotation, { angle: 30 }, { easing: 'cubicInOut' })
  1142. .call(() => {
  1143. cc.tween(oldBlock.node)
  1144. .by(gameConfig.lineShake / 2, { x: -15 },)
  1145. .by(gameConfig.lineShake / 2, { x: 15 },)
  1146. .union()
  1147. .call(() => {
  1148. h.active = false
  1149. h.destroy()
  1150. let node = this.getBlock(1, oldBlock.color)
  1151. node.y = 0
  1152. node.x = lineData.linePos[oldBlock.cover[i]]
  1153. node.name = "c_" + oldBlock.cover[i]
  1154. lineData.line.addChild(node)
  1155. lineData.blockNodes.push({
  1156. node: node,
  1157. column: oldBlock.cover[i],
  1158. num: 1,
  1159. cover: [oldBlock.cover[i]],
  1160. color: oldBlock.color,
  1161. })
  1162. resolve(true)
  1163. })
  1164. .start()
  1165. })
  1166. .start()
  1167. })
  1168. ps.push(p)
  1169. }
  1170. Promise.all(ps).then(() => {
  1171. this.returnBlock(oldBlock.node)
  1172. // needDelete.push({
  1173. // line: value.line,
  1174. // idx: idx
  1175. // })
  1176. if (!needDelete.has(value.line)) {
  1177. needDelete.set(value.line, [])
  1178. }
  1179. needDelete.get(value.line).push(idx)
  1180. // lineData.blockNodes.splice(idx, 1)
  1181. resolve(true)
  1182. })
  1183. })
  1184. pss.push(pp)
  1185. })
  1186. this.scheduleOnce(() => {
  1187. AudioMgr.play("knock")
  1188. }, 0.5)
  1189. Promise.all(pss).then(() => {
  1190. this._mask.active = false
  1191. needDelete.forEach((value, key) => {
  1192. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1193. if (Tools.JudgeValueInArr(i, value)) {
  1194. this._lineDatas[key].blockNodes.splice(i, 1)
  1195. }
  1196. }
  1197. })
  1198. this.scheduleOnce(() => {
  1199. this.downAllLine(10)
  1200. }, 0)
  1201. })
  1202. })
  1203. } else {
  1204. console.log('zh:我有个锤子,所以直接使用')
  1205. //判断是否存在3个的方块
  1206. let dataBeChui: any[] = []
  1207. for (let i = 1; i <= 10; i++) {
  1208. this._lineDatas[i].blockNodes.forEach((value) => {
  1209. if (value.num >= 3) {
  1210. dataBeChui.push({
  1211. line: i,
  1212. column: value.column
  1213. })
  1214. }
  1215. })
  1216. }
  1217. if (dataBeChui.length == 0) {
  1218. this._hint_hammer.active = true
  1219. // Tools.changeGold(gameConfig.price)
  1220. this.scheduleOnce(() => {
  1221. this._hint_hammer.active = false
  1222. }, gameConfig.hide_hint_sprite)
  1223. return
  1224. }
  1225. CacheMgr.setting.hammerNum--
  1226. CacheMgr.setting = CacheMgr.setting
  1227. this._mask.active = true
  1228. let pss = []
  1229. let needDelete: Map<number, number[]> = new Map<number, number[]>()
  1230. dataBeChui.forEach((value) => {
  1231. let pp = new Promise((resolve, reject) => {
  1232. let lineData = this._lineDatas[value.line]
  1233. let idx = 0
  1234. lineData.blockNodes.forEach((value2, index) => {
  1235. if (value2.column == value.column) {
  1236. idx = index
  1237. }
  1238. })
  1239. let oldBlock = lineData.blockNodes[idx]
  1240. let ps = []
  1241. for (let i = 0; i < oldBlock.cover.length; i++) {
  1242. let h = cc.instantiate(this.hammer_prefab)
  1243. h.width = gameConfig.gridSize
  1244. h.height = gameConfig.gridSize
  1245. let world = oldBlock.node.parent.convertToWorldSpaceAR(oldBlock.node.position)
  1246. this._content.addChild(h)
  1247. h.position = h.parent.convertToNodeSpaceAR(world)
  1248. h.x += oldBlock.node.width / 2
  1249. h.y += oldBlock.node.height / 2
  1250. let p = new Promise((resolve, reject) => {
  1251. cc.tween(h)
  1252. .delay(0.5)
  1253. .to(gameConfig.hammerRotation, { angle: 30 }, { easing: 'cubicInOut' })
  1254. .call(() => {
  1255. cc.tween(oldBlock.node)
  1256. .by(gameConfig.lineShake / 2, { x: -15 },)
  1257. .by(gameConfig.lineShake / 2, { x: 15 },)
  1258. .union()
  1259. .call(() => {
  1260. h.active = false
  1261. h.destroy()
  1262. let node = this.getBlock(1, oldBlock.color)
  1263. node.y = 0
  1264. node.x = lineData.linePos[oldBlock.cover[i]]
  1265. node.name = "c_" + oldBlock.cover[i]
  1266. lineData.line.addChild(node)
  1267. lineData.blockNodes.push({
  1268. node: node,
  1269. column: oldBlock.cover[i],
  1270. num: 1,
  1271. cover: [oldBlock.cover[i]],
  1272. color: oldBlock.color,
  1273. })
  1274. resolve(true)
  1275. })
  1276. .start()
  1277. })
  1278. .start()
  1279. })
  1280. ps.push(p)
  1281. }
  1282. Promise.all(ps).then(() => {
  1283. this.returnBlock(oldBlock.node)
  1284. // needDelete.push({
  1285. // line: value.line,
  1286. // idx: idx
  1287. // })
  1288. if (!needDelete.has(value.line)) {
  1289. needDelete.set(value.line, [])
  1290. }
  1291. needDelete.get(value.line).push(idx)
  1292. // lineData.blockNodes.splice(idx, 1)
  1293. resolve(true)
  1294. })
  1295. })
  1296. pss.push(pp)
  1297. })
  1298. this.scheduleOnce(() => {
  1299. AudioMgr.play("knock")
  1300. }, 0.5)
  1301. Promise.all(pss).then(() => {
  1302. this._mask.active = false
  1303. needDelete.forEach((value, key) => {
  1304. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1305. if (Tools.JudgeValueInArr(i, value)) {
  1306. this._lineDatas[key].blockNodes.splice(i, 1)
  1307. }
  1308. }
  1309. })
  1310. this.scheduleOnce(() => {
  1311. this.downAllLine(10)
  1312. }, 0)
  1313. })
  1314. }
  1315. }
  1316. /**
  1317. * 播放广告结束 获得一个锤子,通过事件触发
  1318. */
  1319. public event_adPlayEndForHammer() {
  1320. console.log('zh:锤子 +1')
  1321. CacheMgr.setting.hammerNum++
  1322. CacheMgr.setting = CacheMgr.setting
  1323. this._hammer_sprite.getComponent(cc.Label).string = CacheMgr.setting.hammerNum.toString()
  1324. console.log('zh: 锤1 +1 end')
  1325. }
  1326. private handle_sprite() {
  1327. console.log('zh: hammer 魔鬼闪电')
  1328. if (this._hint_sprite.active) {
  1329. return;
  1330. }
  1331. if (CacheMgr.setting.spriteNum <= 0) {
  1332. console.log('zh: hammer 魔鬼闪电 数量不足 开始播放视频')
  1333. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  1334. cc.sys.localStorage.setItem('zh_ad_type', 'getSprite');//获取锤子
  1335. console.log('zh:AD ready for handle_sprite')
  1336. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  1337. } else {
  1338. console.log('zh:AD not ready for handle_sprite')
  1339. this.event_adPlayEndForHndle_sprite();
  1340. }
  1341. //下面是原始的逻辑,下面的代码精简掉即可
  1342. if (2 > 1) {
  1343. return;
  1344. }
  1345. //下面是原始的逻辑,下面的代码精简掉即可
  1346. Tools.handleVideo().then((res) => {
  1347. if (!res) {
  1348. return;
  1349. }
  1350. let needDelData: Map<number, number[]> = new Map<number, number[]>()
  1351. let ps = []
  1352. //遍历颜色
  1353. for (let i = 1; i <= 10; i++) {
  1354. let blockInfo = this._lineDatas[i].blockNodes
  1355. blockInfo.forEach((value, index) => {
  1356. if (value.color == this.sprite_color) {
  1357. if (!needDelData.has(i)) {
  1358. needDelData.set(i, [])
  1359. }
  1360. needDelData.get(i).push(index)
  1361. let sprite_node = cc.instantiate(this.sprite_prefab)
  1362. sprite_node.scale = gameConfig.gridSize / sprite_node.width
  1363. this.node.addChild(sprite_node)
  1364. sprite_node.position = sprite_node.parent.convertToNodeSpaceAR(this._sprite.parent.convertToWorldSpaceAR(this._sprite.position))
  1365. sprite_node.getComponent(cc.Sprite).spriteFrame = this.sprite_spriteFrame[this.sprite_color]
  1366. let p = new Promise((resolve, reject) => {
  1367. let world = value.node.parent.convertToWorldSpaceAR(value.node.position)
  1368. let position = sprite_node.parent.convertToNodeSpaceAR(world)
  1369. position.x += value.node.width / 2
  1370. position.y += value.node.height / 2
  1371. cc.tween(sprite_node)
  1372. .bezierTo(gameConfig.sprite_move, cc.v2(Tools.getRandom(-500, 500), Tools.getRandom(-500, 500)), cc.v2(Tools.getRandom(-500, 500), Tools.getRandom(-500, 500)), cc.v2(position))
  1373. .call(() => {
  1374. cc.tween(sprite_node)
  1375. .by(gameConfig.sprite_jump / 2, { y: 20 }, { easing: 'cubicInOut' })
  1376. .by(gameConfig.sprite_jump / 2, { y: -20 }, { easing: 'cubicInOut' })
  1377. .union()
  1378. .call(() => {
  1379. cc.tween(value.node)
  1380. .by(gameConfig.lineShake / 2, { x: -15 },)
  1381. .by(gameConfig.lineShake / 2, { x: 15 },)
  1382. .union()
  1383. .call(() => {
  1384. sprite_node.active = false
  1385. value.node.active = false
  1386. value.node.destroy()
  1387. resolve(true)
  1388. })
  1389. .start()
  1390. })
  1391. .start()
  1392. })
  1393. .start()
  1394. })
  1395. ps.push(p)
  1396. }
  1397. })
  1398. }
  1399. if (needDelData.size == 0) {
  1400. this._hint_sprite.active = true
  1401. // Tools.changeGold(gameConfig.price)
  1402. this.scheduleOnce(() => {
  1403. this._hint_sprite.active = false
  1404. }, gameConfig.hide_hint_sprite)
  1405. CacheMgr.setting.spriteNum++
  1406. CacheMgr.setting = CacheMgr.setting
  1407. console.log("加上一次提示机会", CacheMgr.setting)
  1408. return
  1409. }
  1410. // AudioMgr.play("sprite_move")
  1411. this._mask.active = true
  1412. Promise.all(ps).then(() => {
  1413. AudioMgr.play("sprite_xiaochu")
  1414. needDelData.forEach((value, key) => {
  1415. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1416. if (Tools.JudgeValueInArr(i, value)) {
  1417. this._lineDatas[key].blockNodes.splice(i, 1)
  1418. }
  1419. }
  1420. })
  1421. this.updateSprite()
  1422. this.scheduleOnce(() => {
  1423. this.downAllLine(10)
  1424. }, 0)
  1425. this._mask.active = false
  1426. })
  1427. })
  1428. } else {
  1429. let needDelData: Map<number, number[]> = new Map<number, number[]>()
  1430. let ps = []
  1431. //遍历颜色
  1432. for (let i = 1; i <= 10; i++) {
  1433. let blockInfo = this._lineDatas[i].blockNodes
  1434. blockInfo.forEach((value, index) => {
  1435. if (value.color == this.sprite_color) {
  1436. if (!needDelData.has(i)) {
  1437. needDelData.set(i, [])
  1438. }
  1439. needDelData.get(i).push(index)
  1440. let sprite_node = cc.instantiate(this.sprite_prefab)
  1441. sprite_node.scale = gameConfig.gridSize / sprite_node.width
  1442. this.node.addChild(sprite_node)
  1443. sprite_node.position = sprite_node.parent.convertToNodeSpaceAR(this._sprite.parent.convertToWorldSpaceAR(this._sprite.position))
  1444. sprite_node.getComponent(cc.Sprite).spriteFrame = this.sprite_spriteFrame[this.sprite_color]
  1445. let p = new Promise((resolve, reject) => {
  1446. let world = value.node.parent.convertToWorldSpaceAR(value.node.position)
  1447. let position = sprite_node.parent.convertToNodeSpaceAR(world)
  1448. position.x += value.node.width / 2
  1449. position.y += value.node.height / 2
  1450. cc.tween(sprite_node)
  1451. .bezierTo(gameConfig.sprite_move, cc.v2(Tools.getRandom(-500, 500), Tools.getRandom(-500, 500)), cc.v2(Tools.getRandom(-500, 500), Tools.getRandom(-500, 500)), cc.v2(position))
  1452. .call(() => {
  1453. cc.tween(sprite_node)
  1454. .by(gameConfig.sprite_jump / 2, { y: 20 }, { easing: 'cubicInOut' })
  1455. .by(gameConfig.sprite_jump / 2, { y: -20 }, { easing: 'cubicInOut' })
  1456. .union()
  1457. .call(() => {
  1458. cc.tween(value.node)
  1459. .by(gameConfig.lineShake / 2, { x: -15 },)
  1460. .by(gameConfig.lineShake / 2, { x: 15 },)
  1461. .union()
  1462. .call(() => {
  1463. sprite_node.active = false
  1464. value.node.active = false
  1465. value.node.destroy()
  1466. resolve(true)
  1467. })
  1468. .start()
  1469. })
  1470. .start()
  1471. })
  1472. .start()
  1473. })
  1474. ps.push(p)
  1475. }
  1476. })
  1477. }
  1478. if (needDelData.size == 0) {
  1479. this._hint_sprite.active = true
  1480. // Tools.changeGold(gameConfig.price)
  1481. this.scheduleOnce(() => {
  1482. this._hint_sprite.active = false
  1483. }, gameConfig.hide_hint_sprite)
  1484. return
  1485. }
  1486. CacheMgr.setting.spriteNum--
  1487. CacheMgr.setting = CacheMgr.setting
  1488. // AudioMgr.play("sprite_move")
  1489. this._mask.active = true
  1490. Promise.all(ps).then(() => {
  1491. AudioMgr.play("sprite_xiaochu")
  1492. needDelData.forEach((value, key) => {
  1493. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1494. if (Tools.JudgeValueInArr(i, value)) {
  1495. this._lineDatas[key].blockNodes.splice(i, 1)
  1496. }
  1497. }
  1498. })
  1499. this.updateSprite()
  1500. this.scheduleOnce(() => {
  1501. this.downAllLine(10)
  1502. }, 0)
  1503. this._mask.active = false
  1504. })
  1505. }
  1506. }
  1507. /**
  1508. * 播放广告结束 获得一个魔鬼闪电,通过事件触发
  1509. */
  1510. public event_adPlayEndForHndle_sprite() {
  1511. CacheMgr.setting.spriteNum++
  1512. CacheMgr.setting = CacheMgr.setting
  1513. this._price_sprite.getComponent(cc.Label).string = CacheMgr.setting.spriteNum.toString()
  1514. }
  1515. private handle_menu() {
  1516. console.log('zh: hammer 菜单')
  1517. // this._menuPanel.active = !this._menuPanel.active
  1518. if (this._menuPanel.y > this._menu.y) {
  1519. if (this._menuPanel.y != this._menu.y + this._menu.height) {
  1520. return
  1521. }
  1522. tween(this._menuPanel)
  1523. .to(gameConfig.menu_box_move, { y: this._menu.y }, { easing: 'cubicInOut' })
  1524. .call(() => {
  1525. this.scheduleOnce(() => {
  1526. this._menuPanel.active = false
  1527. })
  1528. })
  1529. .start()
  1530. } else {
  1531. this._menuPanel.active = true
  1532. tween(this._menuPanel)
  1533. .to(gameConfig.menu_box_move, { y: this._menu.y + this._menu.height })
  1534. .start()
  1535. }
  1536. }
  1537. //重新开始
  1538. private handle_restart() {
  1539. console.log('zh: hammer handle_restart')
  1540. for (let i = 1; i <= 10; i++) {
  1541. let lineData = this._lineDatas[i]
  1542. lineData.blockNodes.forEach((value) => {
  1543. this.returnBlock(value.node)
  1544. })
  1545. lineData.blockNodes = []
  1546. }
  1547. this.continueXiao = 0
  1548. this.allContinueXiao = 0
  1549. this.hardLevel = 1
  1550. this.score = 0
  1551. this.makeBottomBlock(true)
  1552. }
  1553. //返回首页
  1554. private handle_return() {
  1555. console.log('zh: hammer 返回首页')
  1556. PanelMgr.INS.openPanel({
  1557. panel: HomeView,
  1558. layer: Layer.gameLayer,
  1559. call: () => {
  1560. PanelMgr.INS.closePanel(GameView);
  1561. }
  1562. })
  1563. }
  1564. update_hintMask() {
  1565. if (this._hint_mask) {
  1566. this._hint_mask.children[0].x = -this._hint_mask.position.x
  1567. this._hint_mask.children[0].y = -this._hint_mask.position.y
  1568. }
  1569. }
  1570. hint_play() {
  1571. console.log('zh: hint_play')
  1572. this._hint_mask.active = true
  1573. this._hint_mask.width = this._lineDatas[10].line.width
  1574. this._hint_mask.height = this._lineDatas[10].line.height * 2
  1575. this._hint_mask.position = this._lineDatas[10].line.position
  1576. for (let i = 9; i <= 10; i++) {
  1577. if (i == 10) {
  1578. this._lineDatas[i].blockNodes.forEach((value) => {
  1579. let node = value.node
  1580. node.off(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  1581. node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  1582. node.off(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  1583. node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  1584. })
  1585. } else {
  1586. this._lineDatas[i].blockNodes.forEach((value) => {
  1587. if (value.column != 6) {
  1588. let node = value.node
  1589. node.off(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  1590. node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  1591. node.off(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  1592. node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  1593. }
  1594. })
  1595. }
  1596. }
  1597. // this._hint_label.getComponent(cc.Label).string = "按住方块,向左拖动1格"
  1598. this._hint_label.getComponent(cc.Sprite).spriteFrame = this.hint_1_spriteFrame
  1599. this._hint_label.y = this._hint_mask.y + this._hint_mask.height
  1600. this._hint_label.active = true
  1601. this._hint_hand.active = true
  1602. this._hint_hand.width = gameConfig.gridSize
  1603. this._hint_hand.height = gameConfig.gridSize
  1604. let p = cc.v3(this._lineDatas[9].linePos[6])
  1605. let startWorld = this._lineDatas[9].line.convertToWorldSpaceAR(p)
  1606. let startPosition = this.node.convertToNodeSpaceAR(startWorld)
  1607. startPosition.x += gameConfig.gridSize / 2
  1608. startPosition.y -= gameConfig.gridSize / 2
  1609. let p2 = cc.v3(this._lineDatas[9].linePos[5])
  1610. let endWorld = this._lineDatas[9].line.convertToWorldSpaceAR(p2)
  1611. let endPosition = this.node.convertToNodeSpaceAR(endWorld)
  1612. endPosition.y -= gameConfig.gridSize / 2
  1613. this._hint_hand.position = startPosition
  1614. tween(this._hint_hand)
  1615. .to(gameConfig.hint_hand_move, { position: endPosition })
  1616. .to(0, { position: startPosition })
  1617. .union()
  1618. .repeatForever()
  1619. .start()
  1620. this.update_hintMask()
  1621. }
  1622. hint_hint() {
  1623. this._hint_mask.width = this._hintUI.width
  1624. this._hint_mask.height = this._hintUI.height
  1625. this._hint_mask.position = this._hintUI.position
  1626. this._hint_hand.active = false
  1627. // this._hint_label.getComponent(cc.Label).string = "这里是下一行即将出现的方块(点击空白继续)"
  1628. this._hint_label.getComponent(cc.Sprite).spriteFrame = this.hint_2_spriteFrame
  1629. this._hint_label.y = this._hint_mask.y + this._hint_mask.height
  1630. this._hint_label.active = true
  1631. this.update_hintMask()
  1632. this.hint_register()
  1633. CacheMgr.isNeedHint = false
  1634. this._hint_mask.active = false
  1635. this.scheduleOnce(() => {
  1636. tween(this._hint_label)
  1637. .to(1, { opacity: 0 })
  1638. .call(() => {
  1639. this._hint_label.active = false
  1640. })
  1641. .start()
  1642. }, 4)
  1643. }
  1644. hint_register() {
  1645. this._lineDatas[9].blockNodes.forEach((value) => {
  1646. let block = value.node
  1647. block.on(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  1648. block.on(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  1649. block.on(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  1650. block.on(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  1651. })
  1652. }
  1653. //重写 gameBoxScroll 滚动方向
  1654. protected gameBoxScrollViewDirection(): string {
  1655. return "v"
  1656. }
  1657. }
  1658. interface lineData {
  1659. line: cc.Node
  1660. linePos: number[]
  1661. blockNodes: blockInfo[]
  1662. }
  1663. export interface nextBlockInfo {
  1664. num: number
  1665. column: number
  1666. }
  1667. interface blockInfo {
  1668. node: cc.Node,
  1669. column: number,
  1670. num: number,
  1671. cover: number[],
  1672. color: number
  1673. }