GameView.ts 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850
  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. adState:boolean = false;
  334. onRewardedVideoAdLoaded(placementId) {
  335. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  336. }
  337. onRewardedVideoAdFailed(placementId, errorInfo) {
  338. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  339. }
  340. onRewardedVideoAdPlayStart(placementId, callbackInfo) {
  341. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  342. let deviceId = AAJS2.getDeviceUserId();
  343. var setting = {};
  344. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  345. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  346. }
  347. onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
  348. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  349. // console.log('zh: ad over 开始发送事件11s')
  350. // //this.node.emit("handleCustomEvent");
  351. // this.handleCustomEvent()
  352. // //cc.sys.localStorage.setItem('zh_ad_type', 'getHammer');//获取锤子
  353. // console.log('zh: ad over 开始发送事件11e')
  354. }
  355. onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
  356. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  357. }
  358. onRewardedVideoAdClosed(placementId, callbackInfo) {
  359. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  360. if(this.adState==true){
  361. this.adState = false;
  362. console.log('zh: ad奖励OK,开始处理奖励')
  363. this.handleCustomEvent()
  364. }else{
  365. console.log('zh: ad奖励标识 NO OK ')
  366. }
  367. }
  368. onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
  369. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  370. }
  371. onReward(placementId, callbackInfo) {
  372. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")"); ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  373. console.log('zh:onReward AD奖励标志OK')
  374. this.adState = true;
  375. }
  376. //#endregion "AD 监听end"
  377. /**
  378. * AD播放完毕\close的事件处理
  379. */
  380. handleCustomEvent() {
  381. let that = this;
  382. console.log('zh:AD 展示完毕')
  383. let adKey = "zh_ad_type"
  384. let idx = cc.sys.localStorage.getItem(adKey);//getHammer ,
  385. console.log('zh:onAdOverEve idx =' + idx)
  386. switch (idx) {
  387. case 'getHammer':
  388. console.log('zh:开发发放道具:一个锤子!')
  389. this.event_adPlayEndForHammer();
  390. break;
  391. case 'getSprite':
  392. ////失败后重新开始
  393. console.log('zh:开发发放道具:一个魔鬼精灵!')
  394. this.event_adPlayEndForHndle_sprite();
  395. //发送事件。。。。todo: 重新开始游戏
  396. //this.node.emit('env_playAdEnd', 'Hello,你好');
  397. // 调用A页面的方法
  398. // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2');
  399. // GlobalManager.instance.callMethod('startGameForFailAD');
  400. break;
  401. case 'pubShop':
  402. console.log('zh:开始通知下属 发放shop道具!')
  403. //that.node.emit('env_playAdEnd', 'Hello,开发发放shop道具吧');
  404. GlobalManager.instance.callMethod('env_playAdEnd');
  405. break;
  406. default:
  407. console.log('zh:未知的道具类型AD' + idx)
  408. }
  409. }
  410. public hide() {
  411. if (Global.config.gameConfig.nativeConfig.type == 2) {
  412. Emit.instance().emit(EmitData.CLOSE_NATIVE);
  413. }
  414. }
  415. //todo logic 方法
  416. private getBlock(size: number, color: number = -1): cc.Node {
  417. let block = this.blockPool.get()
  418. block.width = size * gameConfig.gridSize
  419. block.height = gameConfig.gridSize
  420. block.on(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  421. block.on(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  422. block.on(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  423. block.on(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  424. LoadMgr.loadAtlas("view/gameView/block/p").then((p: cc.SpriteAtlas) => {
  425. let id = ((color * 10) + size)
  426. let spriteFrame = p.getSpriteFrame(id.toString())
  427. block.getComponent(cc.Sprite).spriteFrame = spriteFrame
  428. })
  429. return block
  430. }
  431. //归还方块
  432. private returnBlock(node: cc.Node) {
  433. node.off(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  434. node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  435. node.off(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  436. node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  437. node.parent = null
  438. node.x = 0
  439. node.y = 0
  440. node.width = gameConfig.gridSize
  441. node.height = gameConfig.gridSize
  442. node.getComponent(cc.Sprite).spriteFrame = null
  443. this.blockPool.put(node)
  444. return
  445. }
  446. //预创建最低层的方块
  447. private readyMakeBottomBlock() {
  448. //先随机需要空出来几个
  449. //判断是否需要新手提示
  450. if (!CacheMgr.isNeedHint || gameConfig.hint_data.length == 0) {
  451. let blankNum = Tools.getRandom(gameConfig.bottomBlankMin, gameConfig.bottomBlankMax + 1)
  452. let blankColumns: number[] = []
  453. while (true) {
  454. let column = Tools.getRandom(1, 9)
  455. let flag = Tools.JudgeValueInArr(column, blankColumns)
  456. for (let i = 0; i < blankColumns.length; i++) {
  457. if (column == blankColumns[i]) {
  458. flag = true
  459. }
  460. }
  461. if (flag) {
  462. continue
  463. }
  464. blankColumns.push(column)
  465. if (blankColumns.length >= blankNum) {
  466. break
  467. }
  468. }
  469. //获取数组中连续的一段
  470. let allContinueArr: number[][] = []
  471. let continueArr: number[] = []
  472. for (let i = 1; i < 9; i++) {
  473. if (Tools.JudgeValueInArr(i, blankColumns)) {
  474. if (continueArr.length > 0) {
  475. allContinueArr.push(Tools.deepClone(continueArr))
  476. }
  477. continueArr = []
  478. } else {
  479. continueArr.push(i)
  480. if (i == 8) {
  481. allContinueArr.push(Tools.deepClone(continueArr))
  482. }
  483. }
  484. }
  485. let allBlockInfo: nextBlockInfo[] = []
  486. for (let i = 0; i < allContinueArr.length; i++) {
  487. let blocInfos = this.definitionBlockType(Tools.deepClone(allContinueArr[i]))
  488. blocInfos.forEach((value) => {
  489. allBlockInfo.push(value)
  490. })
  491. }
  492. this.nextBlockInfo = allBlockInfo
  493. } else {
  494. this.nextBlockInfo = gameConfig.hint_data[0]
  495. gameConfig.hint_data.shift()
  496. }
  497. this.updateHint()
  498. }
  499. //根据一个位置数组定义这一组方块类型
  500. private definitionBlockType(arr: number[]): nextBlockInfo[] {
  501. let blockInfos: nextBlockInfo[] = []
  502. while (true) {
  503. let length = arr.length
  504. if (arr.length == 0) {
  505. break
  506. }
  507. if (length >= 4) {
  508. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_4)) {
  509. blockInfos.push({
  510. column: arr[0],
  511. num: 4,
  512. })
  513. arr.splice(0, 4)
  514. continue
  515. }
  516. }
  517. if (length >= 3) {
  518. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_3)) {
  519. blockInfos.push({
  520. column: arr[0],
  521. num: 3
  522. })
  523. arr.splice(0, 3)
  524. continue
  525. }
  526. }
  527. if (length >= 2) {
  528. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_2)) {
  529. blockInfos.push({
  530. column: arr[0],
  531. num: 2,
  532. })
  533. arr.splice(0, 3)
  534. continue
  535. }
  536. }
  537. if (length >= 1) {
  538. if (Tools.checkPer(gameConfig.grade_of_difficulty_config[this.hardLevel].probability_1)) {
  539. blockInfos.push({
  540. column: arr[0],
  541. num: 1,
  542. })
  543. arr.splice(0, 1)
  544. }
  545. }
  546. }
  547. return blockInfos
  548. }
  549. //刷新提示
  550. private updateHint() {
  551. this._hintUI.removeAllChildren()
  552. for (let i = 0; i < this.nextBlockInfo.length; i++) {
  553. let info = this.nextBlockInfo[i]
  554. let hintBlock = new cc.Node("hintBlock")
  555. hintBlock.setAnchorPoint(0, 0)
  556. let sprite = hintBlock.addComponent(cc.Sprite)
  557. sprite.type = cc.Sprite.Type.SLICED
  558. sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM
  559. sprite.spriteFrame = this.hintBlockSpriteFrame
  560. hintBlock.width = info.num * gameConfig.gridSize
  561. hintBlock.height = this._hintUI.height
  562. this._hintUI.addChild(hintBlock)
  563. hintBlock.y = 0
  564. hintBlock.x = this._hintData.linePos[info.column]
  565. }
  566. }
  567. //创建最底层的一套方块
  568. private makeBottomBlock(isStart = false) {
  569. console.log('zh:GameView 创建最底层的一套方块')
  570. if (this.nextBlockInfo.length == 0) {
  571. this.readyMakeBottomBlock()
  572. }
  573. this._mask.active = true
  574. let result = this.upAllLine()
  575. Promise.all(result).then(() => {
  576. //创建方块在下一层
  577. for (let i = 0; i < this.nextBlockInfo.length; i++) {
  578. let lineData = this._lineDatas[10]
  579. let nextBlockInfo = this.nextBlockInfo[i]
  580. let color = Tools.getRandom(1, 6)
  581. let block = this.getBlock(nextBlockInfo.num, color)
  582. block.parent = lineData.line
  583. block.name = "c_" + nextBlockInfo.column
  584. block.x = lineData.linePos[nextBlockInfo.column]
  585. let blockInfo: blockInfo = {
  586. node: block,
  587. column: nextBlockInfo.column,
  588. num: nextBlockInfo.num,
  589. cover: this.getCoverColumn(nextBlockInfo.column, nextBlockInfo.num),
  590. color: color
  591. }
  592. lineData.blockNodes.push(blockInfo)
  593. }
  594. this._mask.active = false
  595. this.readyMakeBottomBlock()
  596. if (isStart) {
  597. this.makeBottomBlock()
  598. } else {
  599. if (CacheMgr.isNeedHint && this.hintFlag) {
  600. this.hintFlag = false
  601. this.hint_play()
  602. }
  603. this.downAllLine(10)
  604. }
  605. })
  606. }
  607. //将一行方块向上移动
  608. private upLine(line: number): any[] {
  609. let result = []
  610. let data = this._lineDatas[line]
  611. let nextData = this._lineDatas[line - 1]
  612. if (data.blockNodes && data.blockNodes.length > 0) {
  613. let nodesData = data.blockNodes
  614. let nextNodesData = nextData.blockNodes
  615. for (let i = 0; i < nodesData.length; i++) {
  616. let n = nodesData[i]
  617. nextNodesData.push(n)
  618. n.node.parent = nextData.line
  619. n.node.y = -gameConfig.gridSize //如果y = 0 的话,就没有动画做了
  620. let p = new Promise((resolve, reject) => {
  621. cc.tween(n.node)
  622. .to(gameConfig.upTime, { y: 0 }, { easing: 'cubicInOut' })
  623. .call(() => {
  624. resolve(true)
  625. })
  626. .start()
  627. })
  628. result.push(p)
  629. }
  630. data.blockNodes = []
  631. }
  632. return result
  633. }
  634. //将所有方块向上移动
  635. private upAllLine(): any[] {
  636. //从倒数第二行开始 依次往上移动
  637. let result = []
  638. for (let i = 2; i <= 10; i++) {
  639. let r = this.upLine(i)
  640. for (let i = 0; i < r.length; i++) {
  641. result.push(r[i])
  642. }
  643. }
  644. return result
  645. }
  646. private getCoverColumn(first: number, num: number): number[] {
  647. let arr: number[] = []
  648. for (let i = first; i < first + num; i++) {
  649. arr.push(i)
  650. }
  651. return arr
  652. }
  653. private handle_block_start(e: cc.Event.EventTouch) {
  654. let node: cc.Node = e.target
  655. this._whiteHint.width = node.width
  656. let world = node.parent.convertToWorldSpaceAR(node.position)
  657. let position = this._whiteHint.parent.convertToNodeSpaceAR(world)
  658. this._whiteHint.x = position.x
  659. this._whiteHint.active = true
  660. this.moveX = node.x
  661. }
  662. private handle_block_move(e) {
  663. let node: cc.Node = e.target
  664. let a = e.getDelta()
  665. let world = node.parent.convertToWorldSpaceAR(node.position)
  666. let position = this._whiteHint.parent.convertToNodeSpaceAR(world)
  667. this._whiteHint.x = position.x
  668. let line = Number(node.parent.name)
  669. let column = Number(node.name.split("_")[1])
  670. let data = this.getCanMoveMax(line, column)
  671. // let position2 = node.parent.convertToNodeSpaceAR(e.getLocation())
  672. let x = node.x += a.x;
  673. if (data.min_x > x) {
  674. x = data.min_x
  675. } else if (data.max_x < x) {
  676. x = data.max_x
  677. }
  678. node.x = x
  679. }
  680. private getCanMoveMax(line: number, column: number) {
  681. let lineData = this._lineDatas[line]
  682. let right_column: number = -1
  683. let num: number = 0
  684. let left_column: number = column
  685. for (let i = 0; i < lineData.blockNodes.length; i++) {
  686. let data = lineData.blockNodes[i]
  687. if (data.column == column) {
  688. num = data.num
  689. right_column = data.cover[data.cover.length - 1]
  690. }
  691. }
  692. let max = 0
  693. let min = 0
  694. //寻找左右两边最大能够移动的距离
  695. while (true) {
  696. right_column++
  697. if (right_column > 8) {
  698. max = right_column - 1
  699. break
  700. }
  701. let flag = true
  702. for (let i = 0; i < lineData.blockNodes.length; i++) {
  703. let data = lineData.blockNodes[i]
  704. for (let j = 0; j < data.cover.length; j++) {
  705. if (data.cover[j] == right_column) {
  706. flag = false
  707. break
  708. }
  709. }
  710. }
  711. if (!flag) {
  712. max = right_column - 1
  713. break
  714. } else {
  715. max = right_column
  716. }
  717. }
  718. while (true) {
  719. left_column--
  720. if (left_column < 1) {
  721. min = left_column + 1
  722. break
  723. }
  724. let flag = true
  725. for (let i = 0; i < lineData.blockNodes.length; i++) {
  726. let data = lineData.blockNodes[i]
  727. for (let j = 0; j < data.cover.length; j++) {
  728. if (data.cover[j] == left_column) {
  729. flag = false
  730. break
  731. }
  732. }
  733. }
  734. if (!flag) {
  735. min = left_column + 1
  736. break
  737. } else {
  738. min = left_column
  739. }
  740. }
  741. let min_x = lineData.linePos[min]
  742. let max_x = lineData.linePos[max - num + 1]
  743. return {
  744. min_x: min_x,
  745. max_x: max_x
  746. }
  747. }
  748. private handle_block_end(e) {
  749. let node: cc.Node = e.target
  750. let line = Number(node.parent.name)
  751. let column = Number(node.name.split("_")[1])
  752. this._whiteHint.active = false
  753. let lineData = this._lineDatas[line]
  754. this.continueXiao = 0
  755. for (let i = 1; i <= 8; i++) {
  756. let grid = lineData.line.getChildByName(i.toString())
  757. let position = cc.v2(grid.x + grid.width / 2, grid.y + grid.height / 2)
  758. if (node.getBoundingBox().contains(position)) {
  759. node.x = lineData.linePos[i]
  760. node.name = "c_" + i
  761. for (let j = 0; j < lineData.blockNodes.length; j++) {
  762. let bInfo = lineData.blockNodes[j]
  763. if (bInfo.column == column) {
  764. bInfo.column = i
  765. bInfo.cover = this.getCoverColumn(i, bInfo.num)
  766. break
  767. }
  768. }
  769. break
  770. }
  771. }
  772. if (node.x == this.moveX) {
  773. this.moveX = -1
  774. return
  775. }
  776. AudioMgr.play("move_end").then()
  777. Tools.vibrateShort()
  778. this.touchEndFlag = true
  779. this.downAllLine(line)
  780. }
  781. //将一行方块向下移动
  782. private downLine(line: number): any[] {
  783. let result = []
  784. let data = this._lineDatas[line]
  785. let needChange: any[] = []
  786. for (let i = 0; i < data.blockNodes.length; i++) {
  787. //循环需要下拉行的 所有方块
  788. let blockInfo = data.blockNodes[i]
  789. //判断每一个方块最多可以下降到哪一行
  790. let toLine = -1
  791. for (let j = line + 1; j <= 10; j++) {
  792. let flag = true
  793. let nextData = this._lineDatas[j]
  794. for (let k = 0; k < nextData.blockNodes.length; k++) {
  795. let cover = nextData.blockNodes[k].cover
  796. if (Tools.judgeArraySame(blockInfo.cover, cover)) {
  797. flag = false
  798. }
  799. }
  800. if (flag) {
  801. toLine = j
  802. } else {
  803. break
  804. }
  805. }
  806. if (toLine != -1) {
  807. needChange.push({
  808. index: i,
  809. to: toLine,
  810. })
  811. let p = new Promise((resolve, reject) => {
  812. let n = blockInfo.node
  813. cc.tween(n)
  814. .to(gameConfig.downTime * 0.6, { y: -gameConfig.gridSize * (toLine - line) }, { easing: 'cubicInOut' })
  815. .by(gameConfig.downTime * 0.2, { y: 10 },)
  816. .by(gameConfig.downTime * 0.2, { y: -10 },)
  817. .union()
  818. .call(() => {
  819. n.parent = this._lineDatas[toLine].line
  820. n.y = 0
  821. resolve(true)
  822. })
  823. .start()
  824. })
  825. result.push(p)
  826. }
  827. }
  828. for (let i = needChange.length - 1; i >= 0; i--) {
  829. let cdata = needChange[i]
  830. this._lineDatas[cdata.to].blockNodes.push(data.blockNodes[cdata.index])
  831. data.blockNodes.splice(cdata.index, 1)
  832. }
  833. return result
  834. }
  835. //将所有方块向下移动
  836. private downAllLine(line: number) {
  837. //从倒数第二行开始 依次往上移动
  838. this._mask.active = true
  839. let result = []
  840. for (let i = line; i >= 1; i--) {
  841. if (i == 10) {
  842. continue
  843. }
  844. let r = this.downLine(i)
  845. for (let i = 0; i < r.length; i++) {
  846. result.push(r[i])
  847. }
  848. }
  849. if (result.length > 0) {
  850. Promise.all(result).then(() => {
  851. AudioMgr.play("down").then()
  852. this.scheduleOnce(() => {
  853. this.judgeAllCanClear()
  854. })
  855. })
  856. } else {
  857. this.judgeAllCanClear()
  858. }
  859. // return result
  860. }
  861. private judgeLineCanClear(line): any {
  862. let result = null
  863. let blockData = this._lineDatas[line].blockNodes
  864. //获取这个一行所有覆盖
  865. let allCover = []
  866. for (let i = 0; i < blockData.length; i++) {
  867. blockData[i].cover.forEach((value) => {
  868. allCover.push(value)
  869. })
  870. }
  871. if (allCover.length >= 8) {
  872. result = new Promise((resolve, reject) => {
  873. cc.tween(this._lineDatas[line].line)
  874. .by(gameConfig.lineShake / 2, { x: -15 },)
  875. .by(gameConfig.lineShake / 2, { x: 15 },)
  876. // .by(gameConfig.lineShake / 30, {y: 2.5}, {easing: 'cubicInOut'})
  877. // .by(gameConfig.lineShake / 30, {x: 5}, {easing: 'cubicInOut'})
  878. // .by(gameConfig.lineShake / 30, {y: -5}, {easing: 'cubicInOut'})
  879. // .by(gameConfig.lineShake / 30, {y: 2.5, x: -2.5}, {easing: 'cubicInOut'})
  880. .union()
  881. // .repeat(6)
  882. .call(() => {
  883. let line_data = this._lineDatas[line]
  884. for (let i = 0; i < blockData.length; i++) {
  885. this.returnBlock(blockData[i].node)
  886. }
  887. resolve(true)
  888. line_data.blockNodes = []
  889. })
  890. .start()
  891. })
  892. }
  893. return result
  894. }
  895. //判断所有行是否存在可以消除的行
  896. private judgeAllCanClear(): any[] {
  897. let result: any[] = []
  898. for (let i = 1; i <= 10; i++) {
  899. let r = this.judgeLineCanClear(i)
  900. if (r) {
  901. result.push(r)
  902. }
  903. }
  904. if (result.length > 0) {
  905. AudioMgr.play("xiaochu")
  906. Tools.vibrateShort("heavy")
  907. this.continueXiao += result.length
  908. this.allContinueXiao += result.length
  909. this.text_defen(result.length)
  910. this.text_addHard()
  911. Promise.all(result).then(() => {
  912. this.scheduleOnce(() => {
  913. this.downAllLine(10)
  914. }, 0)
  915. if (CacheMgr.isNeedHint) {
  916. this.hint_hint()
  917. }
  918. })
  919. } else {
  920. //没有需要消除的,需要判断一下是不是输了 , 即第1层是不是有东西
  921. if (this._lineDatas[1].blockNodes.length > 0) {
  922. //todo 输了
  923. this.fail_win()
  924. return
  925. } else if (this._lineDatas[9].blockNodes.length == 0) {
  926. this.touchEndFlag = false
  927. this.makeBottomBlock()
  928. } else if (this.touchEndFlag) {
  929. this.touchEndFlag = false
  930. this.makeBottomBlock()
  931. } else {
  932. this._mask.active = false
  933. }
  934. }
  935. return result
  936. }
  937. //适配边框
  938. private adaptive() {
  939. let top = this._content_cover.getChildByName("top")
  940. let left = this._content_cover.getChildByName("left_wall")
  941. let right = this._content_cover.getChildByName("right_wall")
  942. let bottom = this._content_cover.getChildByName("bottom")
  943. let temp = this._lineDatas[1].line.getPosition()
  944. temp.y += gameConfig.gridSize
  945. let left_top = this._content_cover.convertToNodeSpaceAR(this._content.convertToWorldSpaceAR(temp))
  946. temp = Tools.getNodeFourPoint(this._lineDatas[10].line).right_down
  947. let right_bottom = this._content_cover.convertToNodeSpaceAR(this._content.convertToWorldSpaceAR(temp))
  948. top.y = left_top.y
  949. top.width = this._content.width + 20
  950. top.getChildByName("scoreData").getComponent(cc.Widget).updateAlignment()
  951. top.getChildByName("hardLevel").getComponent(cc.Widget).updateAlignment()
  952. bottom.y = right_bottom.y
  953. bottom.width = this._content.width + 20
  954. left.height = this._content.height + 20
  955. left.x = left_top.x
  956. left.y = left_top.y - this._content.height / 2
  957. right.height = this._content.height + 20
  958. right.x = right_bottom.x
  959. right.y = left_top.y - this._content.height / 2
  960. }
  961. update() {
  962. this._scoreLabel.string = "score:" + this.score
  963. this._hardLevelLabel.string = "hardLevel:" + this.hardLevel.toString()
  964. if (CacheMgr.setting.hammerNum > 0) {
  965. this._hammer_icon.active = false
  966. this._hammer_sprite.active = true
  967. // console.log("够 的1 ")
  968. this._hammer_sprite.getComponent(cc.Label).string = CacheMgr.setting.hammerNum.toString()
  969. } else {
  970. // console.log("不够1 ")
  971. this._hammer_sprite.active = false
  972. this._hammer_icon.active = true
  973. }
  974. if (CacheMgr.setting.spriteNum > 0) {
  975. // console.log("狗的2 ")
  976. this._sprite_icon.active = false
  977. this._price_sprite.active = true
  978. this._price_sprite.getComponent(cc.Label).string = CacheMgr.setting.spriteNum.toString()
  979. } else {
  980. // console.log("不够2 ")
  981. this._price_sprite.active = false
  982. this._sprite_icon.active = true
  983. }
  984. }
  985. //更新精灵节点
  986. updateSprite() {
  987. this.sprite_color = Tools.getRandom(1, 6)
  988. this._sprite.getChildByName("sprite").getComponent(cc.Sprite).spriteFrame = this.sprite_spriteFrame[this.sprite_color]
  989. }
  990. private fail_win() {
  991. AudioMgr.play("fail")
  992. Tools.vibrateLong()
  993. let result: any[] = []
  994. let time: number = 0
  995. for (let i = 1; i <= 10; i++) {
  996. let lineData = this._lineDatas[i]
  997. lineData.blockNodes.forEach((value) => {
  998. let node = value.node
  999. let world = this._mouth.parent.convertToWorldSpaceAR(this._mouth.position)
  1000. let position = node.parent.convertToNodeSpaceAR(world)
  1001. position.x -= gameConfig.gridSize / 2
  1002. position.y -= gameConfig.gridSize / 2
  1003. // node.setAnchorPoint(0.5,0.5)
  1004. let p = new Promise((resolve, reject) => {
  1005. cc.tween(node)
  1006. .delay(time)
  1007. .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))
  1008. .call(() => {
  1009. node.active = false
  1010. node.destroy()
  1011. resolve(true)
  1012. })
  1013. .start()
  1014. })
  1015. result.push(p);
  1016. time += gameConfig.blockFlyTime;
  1017. })
  1018. }
  1019. let isNewMax = false;
  1020. CacheMgr.gold = CacheMgr.gold + this.score;
  1021. if (this.score > CacheMgr.checkpoint) {
  1022. CacheMgr.checkpoint = this.score;
  1023. isNewMax = true;
  1024. }
  1025. Promise.all(result).then(() => {
  1026. PanelMgr.INS.openPanel({
  1027. panel: EndView,
  1028. layer: Layer.gameLayer,
  1029. param: {
  1030. score: this.score,
  1031. isNewMax: isNewMax
  1032. },
  1033. call: () => {
  1034. PanelMgr.INS.closePanel(GameView);
  1035. }
  1036. })
  1037. });
  1038. }
  1039. private text_defen(n: number) {
  1040. let num = this.hardLevel * n * this.continueXiao
  1041. this.score += num
  1042. let node: cc.Node = null
  1043. node = cc.instantiate(this.get_prefab)
  1044. node.children[0].getComponent(cc.Label).string = num.toString()
  1045. this._textHint.addChild(node)
  1046. if (this.continueXiao > 1) {
  1047. node = cc.instantiate(this.nice_prefab)
  1048. node.children[0].getComponent(cc.Label).string = this.continueXiao.toString()
  1049. this._textHint.addChild(node)
  1050. }
  1051. }
  1052. private text_start() {
  1053. AudioMgr.play("start")
  1054. let text_prefab = cc.instantiate(this.start_prefab)
  1055. // text_prefab.getComponent(cc.Label).string = "游戏开始"
  1056. text_prefab.getComponent(Text).delay = 5
  1057. // this._textHint.addChild(text_prefab)
  1058. // text_prefab = cc.instantiate(this.text_prefab)
  1059. // text_prefab.getComponent(Text).delay = 5
  1060. // text_prefab.getComponent(cc.Label).string = "拖动方块,消除整行."
  1061. this._textHint.addChild(text_prefab)
  1062. }
  1063. private text_addHard() {
  1064. if (this.hardLevel >= gameConfig.grade_of_difficulty_config.length - 1) {
  1065. return
  1066. }
  1067. if (this.allContinueXiao >= 10) {
  1068. this.hardLevel++
  1069. this.allContinueXiao = 2
  1070. let text_prefab = cc.instantiate(this.hardUp_prefab)
  1071. // text_prefab.getComponent(cc.Label).string = "难度提升,得分X" + this.hardLevel
  1072. text_prefab.children[0].getComponent(cc.Label).string = this.hardLevel.toString()
  1073. text_prefab.getComponent(Text).delay = 5
  1074. this._textHint.addChild(text_prefab)
  1075. }
  1076. }
  1077. private handle_hammer() {
  1078. console.log('zh: hammer 使用锤子')
  1079. if (this._hint_hammer.active) {
  1080. return;
  1081. }
  1082. if (CacheMgr.setting.hammerNum <= 0) {
  1083. console.log('zh: hammer 没有锤子,开始播放视频')
  1084. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  1085. cc.sys.localStorage.setItem('zh_ad_type', 'getHammer');//获取锤子
  1086. console.log('zh:AD ready for handle_hammer')
  1087. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  1088. } else {
  1089. console.log('zh:AD not ready for handle_hammer')
  1090. this.event_adPlayEndForHammer();
  1091. this.initAdForPage();
  1092. }
  1093. //下面是原始的逻辑,下面的代码精简掉即可
  1094. if (2 > 1) {
  1095. return;
  1096. }
  1097. Tools.handleVideo().then((res) => {
  1098. console.log('zh: over ...锤子1')
  1099. if (!res) {
  1100. console.log('zh: over ...锤子2')
  1101. return;
  1102. }
  1103. console.log('zh: over ...锤子3')
  1104. //判断是否存在3个的方块
  1105. let dataBeChui: any[] = []
  1106. for (let i = 1; i <= 10; i++) {
  1107. this._lineDatas[i].blockNodes.forEach((value) => {
  1108. if (value.num >= 3) {
  1109. dataBeChui.push({
  1110. line: i,
  1111. column: value.column
  1112. })
  1113. }
  1114. })
  1115. }
  1116. if (dataBeChui.length == 0) {
  1117. this._hint_hammer.active = true
  1118. // Tools.changeGold(gameConfig.price)
  1119. this.scheduleOnce(() => {
  1120. this._hint_hammer.active = false
  1121. }, gameConfig.hide_hint_sprite)
  1122. CacheMgr.setting.hammerNum++
  1123. CacheMgr.setting = CacheMgr.setting
  1124. return
  1125. }
  1126. this._mask.active = true
  1127. let pss = []
  1128. let needDelete: Map<number, number[]> = new Map<number, number[]>()
  1129. dataBeChui.forEach((value) => {
  1130. let pp = new Promise((resolve, reject) => {
  1131. let lineData = this._lineDatas[value.line]
  1132. let idx = 0
  1133. lineData.blockNodes.forEach((value2, index) => {
  1134. if (value2.column == value.column) {
  1135. idx = index
  1136. }
  1137. })
  1138. let oldBlock = lineData.blockNodes[idx]
  1139. let ps = []
  1140. for (let i = 0; i < oldBlock.cover.length; i++) {
  1141. let h = cc.instantiate(this.hammer_prefab)
  1142. h.width = gameConfig.gridSize
  1143. h.height = gameConfig.gridSize
  1144. let world = oldBlock.node.parent.convertToWorldSpaceAR(oldBlock.node.position)
  1145. this._content.addChild(h)
  1146. h.position = h.parent.convertToNodeSpaceAR(world)
  1147. h.x += oldBlock.node.width / 2
  1148. h.y += oldBlock.node.height / 2
  1149. let p = new Promise((resolve, reject) => {
  1150. cc.tween(h)
  1151. .delay(0.5)
  1152. .to(gameConfig.hammerRotation, { angle: 30 }, { easing: 'cubicInOut' })
  1153. .call(() => {
  1154. cc.tween(oldBlock.node)
  1155. .by(gameConfig.lineShake / 2, { x: -15 },)
  1156. .by(gameConfig.lineShake / 2, { x: 15 },)
  1157. .union()
  1158. .call(() => {
  1159. h.active = false
  1160. h.destroy()
  1161. let node = this.getBlock(1, oldBlock.color)
  1162. node.y = 0
  1163. node.x = lineData.linePos[oldBlock.cover[i]]
  1164. node.name = "c_" + oldBlock.cover[i]
  1165. lineData.line.addChild(node)
  1166. lineData.blockNodes.push({
  1167. node: node,
  1168. column: oldBlock.cover[i],
  1169. num: 1,
  1170. cover: [oldBlock.cover[i]],
  1171. color: oldBlock.color,
  1172. })
  1173. resolve(true)
  1174. })
  1175. .start()
  1176. })
  1177. .start()
  1178. })
  1179. ps.push(p)
  1180. }
  1181. Promise.all(ps).then(() => {
  1182. this.returnBlock(oldBlock.node)
  1183. // needDelete.push({
  1184. // line: value.line,
  1185. // idx: idx
  1186. // })
  1187. if (!needDelete.has(value.line)) {
  1188. needDelete.set(value.line, [])
  1189. }
  1190. needDelete.get(value.line).push(idx)
  1191. // lineData.blockNodes.splice(idx, 1)
  1192. resolve(true)
  1193. })
  1194. })
  1195. pss.push(pp)
  1196. })
  1197. this.scheduleOnce(() => {
  1198. AudioMgr.play("knock")
  1199. }, 0.5)
  1200. Promise.all(pss).then(() => {
  1201. this._mask.active = false
  1202. needDelete.forEach((value, key) => {
  1203. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1204. if (Tools.JudgeValueInArr(i, value)) {
  1205. this._lineDatas[key].blockNodes.splice(i, 1)
  1206. }
  1207. }
  1208. })
  1209. this.scheduleOnce(() => {
  1210. this.downAllLine(10)
  1211. }, 0)
  1212. })
  1213. })
  1214. } else {
  1215. console.log('zh:我有个锤子,所以直接使用')
  1216. //判断是否存在3个的方块
  1217. let dataBeChui: any[] = []
  1218. for (let i = 1; i <= 10; i++) {
  1219. this._lineDatas[i].blockNodes.forEach((value) => {
  1220. if (value.num >= 3) {
  1221. dataBeChui.push({
  1222. line: i,
  1223. column: value.column
  1224. })
  1225. }
  1226. })
  1227. }
  1228. if (dataBeChui.length == 0) {
  1229. this._hint_hammer.active = true
  1230. // Tools.changeGold(gameConfig.price)
  1231. this.scheduleOnce(() => {
  1232. this._hint_hammer.active = false
  1233. }, gameConfig.hide_hint_sprite)
  1234. return
  1235. }
  1236. CacheMgr.setting.hammerNum--
  1237. CacheMgr.setting = CacheMgr.setting
  1238. this._mask.active = true
  1239. let pss = []
  1240. let needDelete: Map<number, number[]> = new Map<number, number[]>()
  1241. dataBeChui.forEach((value) => {
  1242. let pp = new Promise((resolve, reject) => {
  1243. let lineData = this._lineDatas[value.line]
  1244. let idx = 0
  1245. lineData.blockNodes.forEach((value2, index) => {
  1246. if (value2.column == value.column) {
  1247. idx = index
  1248. }
  1249. })
  1250. let oldBlock = lineData.blockNodes[idx]
  1251. let ps = []
  1252. for (let i = 0; i < oldBlock.cover.length; i++) {
  1253. let h = cc.instantiate(this.hammer_prefab)
  1254. h.width = gameConfig.gridSize
  1255. h.height = gameConfig.gridSize
  1256. let world = oldBlock.node.parent.convertToWorldSpaceAR(oldBlock.node.position)
  1257. this._content.addChild(h)
  1258. h.position = h.parent.convertToNodeSpaceAR(world)
  1259. h.x += oldBlock.node.width / 2
  1260. h.y += oldBlock.node.height / 2
  1261. let p = new Promise((resolve, reject) => {
  1262. cc.tween(h)
  1263. .delay(0.5)
  1264. .to(gameConfig.hammerRotation, { angle: 30 }, { easing: 'cubicInOut' })
  1265. .call(() => {
  1266. cc.tween(oldBlock.node)
  1267. .by(gameConfig.lineShake / 2, { x: -15 },)
  1268. .by(gameConfig.lineShake / 2, { x: 15 },)
  1269. .union()
  1270. .call(() => {
  1271. h.active = false
  1272. h.destroy()
  1273. let node = this.getBlock(1, oldBlock.color)
  1274. node.y = 0
  1275. node.x = lineData.linePos[oldBlock.cover[i]]
  1276. node.name = "c_" + oldBlock.cover[i]
  1277. lineData.line.addChild(node)
  1278. lineData.blockNodes.push({
  1279. node: node,
  1280. column: oldBlock.cover[i],
  1281. num: 1,
  1282. cover: [oldBlock.cover[i]],
  1283. color: oldBlock.color,
  1284. })
  1285. resolve(true)
  1286. })
  1287. .start()
  1288. })
  1289. .start()
  1290. })
  1291. ps.push(p)
  1292. }
  1293. Promise.all(ps).then(() => {
  1294. this.returnBlock(oldBlock.node)
  1295. // needDelete.push({
  1296. // line: value.line,
  1297. // idx: idx
  1298. // })
  1299. if (!needDelete.has(value.line)) {
  1300. needDelete.set(value.line, [])
  1301. }
  1302. needDelete.get(value.line).push(idx)
  1303. // lineData.blockNodes.splice(idx, 1)
  1304. resolve(true)
  1305. })
  1306. })
  1307. pss.push(pp)
  1308. })
  1309. this.scheduleOnce(() => {
  1310. AudioMgr.play("knock")
  1311. }, 0.5)
  1312. Promise.all(pss).then(() => {
  1313. this._mask.active = false
  1314. needDelete.forEach((value, key) => {
  1315. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1316. if (Tools.JudgeValueInArr(i, value)) {
  1317. this._lineDatas[key].blockNodes.splice(i, 1)
  1318. }
  1319. }
  1320. })
  1321. this.scheduleOnce(() => {
  1322. this.downAllLine(10)
  1323. }, 0)
  1324. })
  1325. }
  1326. }
  1327. /**
  1328. * 播放广告结束 获得一个锤子,通过事件触发
  1329. */
  1330. public event_adPlayEndForHammer() {
  1331. console.log('zh:锤子 +1')
  1332. CacheMgr.setting.hammerNum++
  1333. CacheMgr.setting = CacheMgr.setting
  1334. this._hammer_sprite.getComponent(cc.Label).string = CacheMgr.setting.hammerNum.toString()
  1335. console.log('zh: 锤1 +1 end')
  1336. }
  1337. private handle_sprite() {
  1338. console.log('zh: hammer 魔鬼闪电')
  1339. if (this._hint_sprite.active) {
  1340. return;
  1341. }
  1342. if (CacheMgr.setting.spriteNum <= 0) {
  1343. console.log('zh: hammer 魔鬼闪电 数量不足 开始播放视频')
  1344. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  1345. cc.sys.localStorage.setItem('zh_ad_type', 'getSprite');//获取锤子
  1346. console.log('zh:AD ready for handle_sprite')
  1347. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  1348. } else {
  1349. console.log('zh:AD not ready for handle_sprite')
  1350. this.event_adPlayEndForHndle_sprite();
  1351. this.initAdForPage();
  1352. }
  1353. //下面是原始的逻辑,下面的代码精简掉即可
  1354. if (2 > 1) {
  1355. return;
  1356. }
  1357. //下面是原始的逻辑,下面的代码精简掉即可
  1358. Tools.handleVideo().then((res) => {
  1359. if (!res) {
  1360. return;
  1361. }
  1362. let needDelData: Map<number, number[]> = new Map<number, number[]>()
  1363. let ps = []
  1364. //遍历颜色
  1365. for (let i = 1; i <= 10; i++) {
  1366. let blockInfo = this._lineDatas[i].blockNodes
  1367. blockInfo.forEach((value, index) => {
  1368. if (value.color == this.sprite_color) {
  1369. if (!needDelData.has(i)) {
  1370. needDelData.set(i, [])
  1371. }
  1372. needDelData.get(i).push(index)
  1373. let sprite_node = cc.instantiate(this.sprite_prefab)
  1374. sprite_node.scale = gameConfig.gridSize / sprite_node.width
  1375. this.node.addChild(sprite_node)
  1376. sprite_node.position = sprite_node.parent.convertToNodeSpaceAR(this._sprite.parent.convertToWorldSpaceAR(this._sprite.position))
  1377. sprite_node.getComponent(cc.Sprite).spriteFrame = this.sprite_spriteFrame[this.sprite_color]
  1378. let p = new Promise((resolve, reject) => {
  1379. let world = value.node.parent.convertToWorldSpaceAR(value.node.position)
  1380. let position = sprite_node.parent.convertToNodeSpaceAR(world)
  1381. position.x += value.node.width / 2
  1382. position.y += value.node.height / 2
  1383. cc.tween(sprite_node)
  1384. .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))
  1385. .call(() => {
  1386. cc.tween(sprite_node)
  1387. .by(gameConfig.sprite_jump / 2, { y: 20 }, { easing: 'cubicInOut' })
  1388. .by(gameConfig.sprite_jump / 2, { y: -20 }, { easing: 'cubicInOut' })
  1389. .union()
  1390. .call(() => {
  1391. cc.tween(value.node)
  1392. .by(gameConfig.lineShake / 2, { x: -15 },)
  1393. .by(gameConfig.lineShake / 2, { x: 15 },)
  1394. .union()
  1395. .call(() => {
  1396. sprite_node.active = false
  1397. value.node.active = false
  1398. value.node.destroy()
  1399. resolve(true)
  1400. })
  1401. .start()
  1402. })
  1403. .start()
  1404. })
  1405. .start()
  1406. })
  1407. ps.push(p)
  1408. }
  1409. })
  1410. }
  1411. if (needDelData.size == 0) {
  1412. this._hint_sprite.active = true
  1413. // Tools.changeGold(gameConfig.price)
  1414. this.scheduleOnce(() => {
  1415. this._hint_sprite.active = false
  1416. }, gameConfig.hide_hint_sprite)
  1417. CacheMgr.setting.spriteNum++
  1418. CacheMgr.setting = CacheMgr.setting
  1419. console.log("加上一次提示机会", CacheMgr.setting)
  1420. return
  1421. }
  1422. // AudioMgr.play("sprite_move")
  1423. this._mask.active = true
  1424. Promise.all(ps).then(() => {
  1425. AudioMgr.play("sprite_xiaochu")
  1426. needDelData.forEach((value, key) => {
  1427. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1428. if (Tools.JudgeValueInArr(i, value)) {
  1429. this._lineDatas[key].blockNodes.splice(i, 1)
  1430. }
  1431. }
  1432. })
  1433. this.updateSprite()
  1434. this.scheduleOnce(() => {
  1435. this.downAllLine(10)
  1436. }, 0)
  1437. this._mask.active = false
  1438. })
  1439. })
  1440. } else {
  1441. let needDelData: Map<number, number[]> = new Map<number, number[]>()
  1442. let ps = []
  1443. //遍历颜色
  1444. for (let i = 1; i <= 10; i++) {
  1445. let blockInfo = this._lineDatas[i].blockNodes
  1446. blockInfo.forEach((value, index) => {
  1447. if (value.color == this.sprite_color) {
  1448. if (!needDelData.has(i)) {
  1449. needDelData.set(i, [])
  1450. }
  1451. needDelData.get(i).push(index)
  1452. let sprite_node = cc.instantiate(this.sprite_prefab)
  1453. sprite_node.scale = gameConfig.gridSize / sprite_node.width
  1454. this.node.addChild(sprite_node)
  1455. sprite_node.position = sprite_node.parent.convertToNodeSpaceAR(this._sprite.parent.convertToWorldSpaceAR(this._sprite.position))
  1456. sprite_node.getComponent(cc.Sprite).spriteFrame = this.sprite_spriteFrame[this.sprite_color]
  1457. let p = new Promise((resolve, reject) => {
  1458. let world = value.node.parent.convertToWorldSpaceAR(value.node.position)
  1459. let position = sprite_node.parent.convertToNodeSpaceAR(world)
  1460. position.x += value.node.width / 2
  1461. position.y += value.node.height / 2
  1462. cc.tween(sprite_node)
  1463. .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))
  1464. .call(() => {
  1465. cc.tween(sprite_node)
  1466. .by(gameConfig.sprite_jump / 2, { y: 20 }, { easing: 'cubicInOut' })
  1467. .by(gameConfig.sprite_jump / 2, { y: -20 }, { easing: 'cubicInOut' })
  1468. .union()
  1469. .call(() => {
  1470. cc.tween(value.node)
  1471. .by(gameConfig.lineShake / 2, { x: -15 },)
  1472. .by(gameConfig.lineShake / 2, { x: 15 },)
  1473. .union()
  1474. .call(() => {
  1475. sprite_node.active = false
  1476. value.node.active = false
  1477. value.node.destroy()
  1478. resolve(true)
  1479. })
  1480. .start()
  1481. })
  1482. .start()
  1483. })
  1484. .start()
  1485. })
  1486. ps.push(p)
  1487. }
  1488. })
  1489. }
  1490. if (needDelData.size == 0) {
  1491. this._hint_sprite.active = true
  1492. // Tools.changeGold(gameConfig.price)
  1493. this.scheduleOnce(() => {
  1494. this._hint_sprite.active = false
  1495. }, gameConfig.hide_hint_sprite)
  1496. return
  1497. }
  1498. CacheMgr.setting.spriteNum--
  1499. CacheMgr.setting = CacheMgr.setting
  1500. // AudioMgr.play("sprite_move")
  1501. this._mask.active = true
  1502. Promise.all(ps).then(() => {
  1503. AudioMgr.play("sprite_xiaochu")
  1504. needDelData.forEach((value, key) => {
  1505. for (let i = this._lineDatas[key].blockNodes.length - 1; i >= 0; i--) {
  1506. if (Tools.JudgeValueInArr(i, value)) {
  1507. this._lineDatas[key].blockNodes.splice(i, 1)
  1508. }
  1509. }
  1510. })
  1511. this.updateSprite()
  1512. this.scheduleOnce(() => {
  1513. this.downAllLine(10)
  1514. }, 0)
  1515. this._mask.active = false
  1516. })
  1517. }
  1518. }
  1519. /**
  1520. * 播放广告结束 获得一个魔鬼闪电,通过事件触发
  1521. */
  1522. public event_adPlayEndForHndle_sprite() {
  1523. CacheMgr.setting.spriteNum++
  1524. CacheMgr.setting = CacheMgr.setting
  1525. this._price_sprite.getComponent(cc.Label).string = CacheMgr.setting.spriteNum.toString()
  1526. }
  1527. private handle_menu() {
  1528. console.log('zh: hammer 菜单')
  1529. // this._menuPanel.active = !this._menuPanel.active
  1530. if (this._menuPanel.y > this._menu.y) {
  1531. if (this._menuPanel.y != this._menu.y + this._menu.height) {
  1532. return
  1533. }
  1534. tween(this._menuPanel)
  1535. .to(gameConfig.menu_box_move, { y: this._menu.y }, { easing: 'cubicInOut' })
  1536. .call(() => {
  1537. this.scheduleOnce(() => {
  1538. this._menuPanel.active = false
  1539. })
  1540. })
  1541. .start()
  1542. } else {
  1543. this._menuPanel.active = true
  1544. tween(this._menuPanel)
  1545. .to(gameConfig.menu_box_move, { y: this._menu.y + this._menu.height })
  1546. .start()
  1547. }
  1548. }
  1549. //重新开始
  1550. private handle_restart() {
  1551. console.log('zh: hammer handle_restart')
  1552. for (let i = 1; i <= 10; i++) {
  1553. let lineData = this._lineDatas[i]
  1554. lineData.blockNodes.forEach((value) => {
  1555. this.returnBlock(value.node)
  1556. })
  1557. lineData.blockNodes = []
  1558. }
  1559. this.continueXiao = 0
  1560. this.allContinueXiao = 0
  1561. this.hardLevel = 1
  1562. this.score = 0
  1563. this.makeBottomBlock(true)
  1564. }
  1565. //返回首页
  1566. private handle_return() {
  1567. console.log('zh: hammer 返回首页')
  1568. PanelMgr.INS.openPanel({
  1569. panel: HomeView,
  1570. layer: Layer.gameLayer,
  1571. call: () => {
  1572. PanelMgr.INS.closePanel(GameView);
  1573. }
  1574. })
  1575. }
  1576. update_hintMask() {
  1577. if (this._hint_mask) {
  1578. this._hint_mask.children[0].x = -this._hint_mask.position.x
  1579. this._hint_mask.children[0].y = -this._hint_mask.position.y
  1580. }
  1581. }
  1582. hint_play() {
  1583. console.log('zh: hint_play')
  1584. this._hint_mask.active = true
  1585. this._hint_mask.width = this._lineDatas[10].line.width
  1586. this._hint_mask.height = this._lineDatas[10].line.height * 2
  1587. this._hint_mask.position = this._lineDatas[10].line.position
  1588. for (let i = 9; i <= 10; i++) {
  1589. if (i == 10) {
  1590. this._lineDatas[i].blockNodes.forEach((value) => {
  1591. let node = value.node
  1592. node.off(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  1593. node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  1594. node.off(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  1595. node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  1596. })
  1597. } else {
  1598. this._lineDatas[i].blockNodes.forEach((value) => {
  1599. if (value.column != 6) {
  1600. let node = value.node
  1601. node.off(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  1602. node.off(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  1603. node.off(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  1604. node.off(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  1605. }
  1606. })
  1607. }
  1608. }
  1609. // this._hint_label.getComponent(cc.Label).string = "按住方块,向左拖动1格"
  1610. this._hint_label.getComponent(cc.Sprite).spriteFrame = this.hint_1_spriteFrame
  1611. this._hint_label.y = this._hint_mask.y + this._hint_mask.height
  1612. this._hint_label.active = true
  1613. this._hint_hand.active = true
  1614. this._hint_hand.width = gameConfig.gridSize
  1615. this._hint_hand.height = gameConfig.gridSize
  1616. let p = cc.v3(this._lineDatas[9].linePos[6])
  1617. let startWorld = this._lineDatas[9].line.convertToWorldSpaceAR(p)
  1618. let startPosition = this.node.convertToNodeSpaceAR(startWorld)
  1619. startPosition.x += gameConfig.gridSize / 2
  1620. startPosition.y -= gameConfig.gridSize / 2
  1621. let p2 = cc.v3(this._lineDatas[9].linePos[5])
  1622. let endWorld = this._lineDatas[9].line.convertToWorldSpaceAR(p2)
  1623. let endPosition = this.node.convertToNodeSpaceAR(endWorld)
  1624. endPosition.y -= gameConfig.gridSize / 2
  1625. this._hint_hand.position = startPosition
  1626. tween(this._hint_hand)
  1627. .to(gameConfig.hint_hand_move, { position: endPosition })
  1628. .to(0, { position: startPosition })
  1629. .union()
  1630. .repeatForever()
  1631. .start()
  1632. this.update_hintMask()
  1633. }
  1634. hint_hint() {
  1635. this._hint_mask.width = this._hintUI.width
  1636. this._hint_mask.height = this._hintUI.height
  1637. this._hint_mask.position = this._hintUI.position
  1638. this._hint_hand.active = false
  1639. // this._hint_label.getComponent(cc.Label).string = "这里是下一行即将出现的方块(点击空白继续)"
  1640. this._hint_label.getComponent(cc.Sprite).spriteFrame = this.hint_2_spriteFrame
  1641. this._hint_label.y = this._hint_mask.y + this._hint_mask.height
  1642. this._hint_label.active = true
  1643. this.update_hintMask()
  1644. this.hint_register()
  1645. CacheMgr.isNeedHint = false
  1646. this._hint_mask.active = false
  1647. this.scheduleOnce(() => {
  1648. tween(this._hint_label)
  1649. .to(1, { opacity: 0 })
  1650. .call(() => {
  1651. this._hint_label.active = false
  1652. })
  1653. .start()
  1654. }, 4)
  1655. }
  1656. hint_register() {
  1657. this._lineDatas[9].blockNodes.forEach((value) => {
  1658. let block = value.node
  1659. block.on(cc.Node.EventType.TOUCH_START, this.handle_block_start, this)
  1660. block.on(cc.Node.EventType.TOUCH_MOVE, this.handle_block_move, this)
  1661. block.on(cc.Node.EventType.TOUCH_END, this.handle_block_end, this)
  1662. block.on(cc.Node.EventType.TOUCH_CANCEL, this.handle_block_end, this)
  1663. })
  1664. }
  1665. //重写 gameBoxScroll 滚动方向
  1666. protected gameBoxScrollViewDirection(): string {
  1667. return "v"
  1668. }
  1669. }
  1670. interface lineData {
  1671. line: cc.Node
  1672. linePos: number[]
  1673. blockNodes: blockInfo[]
  1674. }
  1675. export interface nextBlockInfo {
  1676. num: number
  1677. column: number
  1678. }
  1679. interface blockInfo {
  1680. node: cc.Node,
  1681. column: number,
  1682. num: number,
  1683. cover: number[],
  1684. color: number
  1685. }