// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import GameManager from "./GameManager"; import { LQCollide } from "./lq_collide_system/lq_collide"; import NumberToImage from "./NumberToImage"; import SceneManager from "./SceneManager"; import { MiniGameSdk } from "./Sdk/MiniGameSdk"; import Animation = cc.Animation; // import Revive from "./Revive"; import Utils from "./module/Pay/Utils"; const { ccclass, property } = cc._decorator; @ccclass export default class MapConroler extends cc.Component { static _instance: any; @property({ type: [cc.Prefab], tooltip: "方块数组" }) Block_Array: Array = []; @property({ type: [cc.Prefab], tooltip: "方块道具数组" }) Block_Prop: Array = []; @property(cc.Prefab) MapBlockPrefab: cc.Prefab = null; @property({ type: [cc.SpriteAtlas], tooltip: "方块颜色" }) Block_Color: Array = []; @property({ type: [cc.Prefab], tooltip: "墙壁数组" }) Wall_Prefab: Array = []; @property(cc.Prefab) wallTurnPrefab: cc.Prefab = null; @property(cc.Button) timeBtn: cc.Button = null; @property(cc.Button) destroyBtn: cc.Button = null; @property(cc.Button) magicBtn: cc.Button = null; //魔法棒特效 @property(cc.Node) magics: cc.Node = null; @property(cc.Node) mask: cc.Node = null; //引导道具 @property(cc.Node) guideItem: cc.Node = null; //道具锁 @property([cc.Node]) itemLock: cc.Node[] = []; @property(cc.Label) iceLabel: cc.Label = null; @property(cc.Label) hammerLabel: cc.Label = null; @property(cc.Label) magicLabel: cc.Label = null; @property(cc.Node) iceNode: cc.Node = null; @property(cc.Node) hammerNode: cc.Node = null; @property(cc.Node) magicNode: cc.Node = null; @property(cc.Node) icetimeNode: cc.Node[] = []; @property(cc.Node) magicMask: cc.Node = null; @property(cc.Node) hammerMask: cc.Node = null; @property(cc.Node) freezeMask: cc.Node = null; @property(cc.Node) guideNode: cc.Node = null; @property(cc.Node) hammerAni: cc.Node = null; @property(cc.Node) coinPop: cc.Node = null; //结算界面节点 @property(cc.Node) gameOverNode: cc.Node = null; //复活 @property(cc.Node) revive: cc.Node = null; timeLabel: cc.Node = null; levelLabel: cc.Node = null; coin: cc.Node = null; new_mode: number = 0; new_item: number = 0; mapWidth: number = 0; mapHeight: number = 0; wallNum: number = 0; blockNum: number = 0; reviewState: boolean = false; mapBlocksWall: any; //地图的所有底块 mapInfo: any; //地图除了底块的其他信息 blocks: any; //方块数组 wallInfo: any; //墙壁数组 wallArray: any; // openWall: any; //开关墙数组 freezeWall: any; //冻结墙数组 riseFallBlcok: any; //升降地块数组 scheduleCallback: any;//倒计时用 homeCanTouch: boolean = true;//按钮可用状态 againCanTouch: boolean = true;//重玩按钮可以用状态 gameOver: boolean = false;//游戏结束状态 gameWin: boolean = false;//游戏胜利状态 gameStart: boolean = false;//游戏开始状态 timeNumber: number = 0; //游戏时间 用于倒计时 count_Time: number = 0; //用于统计总游戏时长 add_Time: number = 0; //复活时间 mapBlockArray: any; //地图的所有格子状态存储 pause: boolean = false;//暂停状态 hammer: boolean = false;//锤子状态 ishammer: boolean = false;//魔法棒与锤子区分 ismagic: boolean = false;//魔法棒状态 freezeArray: any; //冻结 loackArray: any; //上锁 particleEffects: cc.ParticleAsset[]; // leftDoors: []; //左门 rightDoors: any; //右门 topDoors: any; //上门 bottomDoors: any; //下门 leftDoors: any; //左门 powerState: boolean = false; //无限体力状态 SceneManager: any; //场景管理器 lastMagicTime: number; //上次使用魔法的时间 wall_Pass: any; //可通过门的数组 arr: any; isreview: boolean = false lastHammerTime: number; // mapInfo: number[][] = []; onLoad() { cc.fx.GameConfig.GM_INFO.review = 0; cc.fx.GameConfig.GM_INFO.reviewBoom = 0; cc.fx.GameConfig.GM_INFO.reviewDoor = 0; cc.fx.GameConfig.GM_INFO.gameState = true; this.mask.opacity = 0; this.node.getChildByName("Adhesive").zIndex = 500; cc.game.setFrameRate(63); cc.fx.AudioManager._instance.playEffect("zhuan2", null); this.node.parent.parent.parent.getChildByName("zhuanchang").active = true; this.node.parent.parent.parent.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "down", false); this.node.parent.parent.parent.getChildByName("zhuanchang").getComponent(sp.Skeleton).setCompleteListener((entry) => { if (entry.animation.name === "down") { // 动画播放结束后执行的逻辑 this.node.parent.parent.parent.getChildByName("zhuanchang").active = false; } }); this.wall_Pass = []; this.blocks = []; this.leftDoors = []; //左门 this.rightDoors = []; //右门 this.topDoors = []; //上门 this.bottomDoors = []; //下门 this.gameWin = false; this.gameOver = false; this.gameStart = false; this.reviewState = false; this.homeCanTouch = true; this.againCanTouch = true; this.powerState = false; this.new_mode = 0; this.new_item = 0; this.count_Time = 0; this.add_Time = 0; this.arr = []; // 初始化结算界面动画数组 this.isreview = false; //this.iceLabel.string = cc.fx.GameConfig.GM_INFO.freezeAmount.toString(); // this.hammerLabel.string = cc.fx.GameConfig.GM_INFO.hammerAmount.toString(); // this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString(); this.setPropNum(); // cc.game.addPersistRootNode(this.node); MapConroler._instance = this; const canvasTemp = cc.find("Canvas"); // 假设 Canvas 节点 if (canvasTemp) { const SceneManager = canvasTemp.getComponent("SceneManager"); if (SceneManager) { MapConroler._instance.SceneManager = SceneManager } else { console.log("SceneManager 组件未找到"); } } else { console.log("SceneManager 节点未找到"); } } start() { setTimeout(() => { cc.director.preloadScene("HomeScene", (err, asset) => { if (err) { console.error('动态加载 HomeScene 失败:', err); return; } }); }, 1000); // console.log("进入GameScene"); this.Block_Array = GameManager._instance.Block_Array; this.Wall_Prefab = GameManager._instance.Wall_Prefab; this.Block_Color = GameManager._instance.Block_Color; // this.particleEffects = GameManager._instance.particleEffects; this.initMap(); } //道具数量 setPropNum() { //如果道具数量大于0,显示 cc.fx.GameConfig.GM_INFO.freezeAmount,如果为零显示'mul10' if (cc.fx.GameConfig.GM_INFO.freezeAmount > 0) { this.iceNode.children[0].active = false; this.iceNode.children[1].active = true; this.iceNode.children[2].active = true; NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.freezeAmount, 20, 15, "mul", this.iceNode.children[2], true); } else { this.iceNode.children[0].active = true this.iceNode.children[1].active = false; this.iceNode.children[2].active = false; } if (cc.fx.GameConfig.GM_INFO.hammerAmount > 0) { this.hammerNode.children[1].active = true; this.hammerNode.children[0].active = false; this.hammerNode.children[2].active = true; NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hammerAmount, 20, 15, "mul", this.hammerNode.children[2], true); } else { this.hammerNode.children[0].active = true; this.hammerNode.children[1].active = false; this.hammerNode.children[2].active = false; } if (cc.fx.GameConfig.GM_INFO.magicAmount > 0) { this.magicNode.children[1].active = true; this.magicNode.children[0].active = false; this.magicNode.children[2].active = true; NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.magicAmount, 20, 15, "mul", this.magicNode.children[2], true); } else { this.magicNode.children[0].active = true this.magicNode.children[1].active = false; this.magicNode.children[2].active = false; } //道具锁 第八关之前全为true const currentLevel = cc.fx.GameConfig.GM_INFO.level + 1; let lock0Active = false; let lock1Active = false; let lock2Active = false; if (currentLevel < 8) { lock0Active = true; lock1Active = true; lock2Active = true; this.iceNode.active = false; this.hammerNode.active = false; this.magicNode.active = false; this.iceNode.parent.getComponent(cc.Button).interactable = false; this.hammerNode.parent.getComponent(cc.Button).interactable = false; this.magicNode.parent.getComponent(cc.Button).interactable = false; } else if (currentLevel >= 8 && currentLevel < 11) { lock0Active = false; lock1Active = true; lock2Active = true; this.iceNode.active = false; this.hammerNode.active = true; this.magicNode.active = false; this.iceNode.parent.getComponent(cc.Button).interactable = false; this.hammerNode.parent.getComponent(cc.Button).interactable = true; this.magicNode.parent.getComponent(cc.Button).interactable = false; } else if (currentLevel >= 11 && currentLevel < 16) { lock0Active = false; lock1Active = false; lock2Active = true; this.iceNode.active = true; this.hammerNode.active = true; this.magicNode.active = false; this.iceNode.parent.getComponent(cc.Button).interactable = true; this.hammerNode.parent.getComponent(cc.Button).interactable = true; this.magicNode.parent.getComponent(cc.Button).interactable = false; } else if (currentLevel >= 16) { lock0Active = false; lock1Active = false; lock2Active = false; this.iceNode.active = true; this.hammerNode.active = true; this.magicNode.active = true; this.iceNode.parent.getComponent(cc.Button).interactable = true; this.hammerNode.parent.getComponent(cc.Button).interactable = true; this.magicNode.parent.getComponent(cc.Button).interactable = true; } this.itemLock[0].active = lock0Active; this.itemLock[1].active = lock1Active; this.itemLock[2].active = lock2Active; if (cc.fx.GameConfig.GM_INFO.magicAFirst == true) { this.magicNode.children[0].active = true; this.magicNode.children[1].active = false; this.magicNode.children[2].active = false; } if (cc.fx.GameConfig.GM_INFO.hammerFirst == true) { this.hammerNode.children[0].active = true; this.hammerNode.children[1].active = false; this.hammerNode.children[2].active = false; } if (cc.fx.GameConfig.GM_INFO.freezeFirst == true) { this.iceNode.children[0].active = true; this.iceNode.children[1].active = false; this.iceNode.children[2].active = false; } } startUpdate() { if (this.isreview) { this.startTimeCutDown(); this.isreview = false; } if (this.gameStart == false) { this.gameStart = true; let power = cc.fx.GameTool.getUserPowerTime(); if (!power) { cc.fx.GameTool.setUserHealth(-1, (data) => { }) } this.powerState = power; this.count_Time = Date.now(); //发送数数事件——进入关卡 console.log("准备进入下一关,发送下一关进入"); if ((cc.fx.GameConfig.GM_INFO.level + 1) == 1) { this.guideNode.getComponent(Animation).stop(); this.guideNode.active = false; } cc.fx.GameTool.shushu_Track("enter_stage"); this.stopTimeCutDown(); this.startTimeCutDown(); } } initMap() { // this.node.getChildByName("Wall").zIndex = 10; this.timeLabel = this.node.parent.getChildByName("Top").getChildByName("time"); this.levelLabel = this.node.parent.getChildByName("Top").getChildByName("level"); this.coin = this.node.parent.getChildByName("Top").getChildByName("shop").getChildByName("coin"); this.timeNumber = cc.fx.GameConfig.LEVEL_INFO[0].time; console.log("当前关卡时间", this.timeNumber); this.add_Time = 0; NumberToImage.getTimeMargin(this.timeNumber, 50, "time_", this.timeLabel) this.updateCoin(); // var timeTemp = cc.fx.GameTool.getTimeMargin(this.timeNumber); // this.timeLabel.string = timeTemp.toString(); let levelName = (cc.fx.GameConfig.GM_INFO.level + 1); if (cc.fx.GameConfig.GM_INFO.otherLevel) { levelName = cc.fx.GameConfig.GM_INFO.otherLevel; } NumberToImage.numberToImageNodes(levelName, 45, 0, "level_", this.levelLabel, true) console.log("当前关卡", cc.fx.GameConfig.GM_INFO.level + 1); //this.startTimeCutDown(); this.mapWidth = cc.fx.GameConfig.LEVEL_INFO[0].map[0]; this.mapHeight = cc.fx.GameConfig.LEVEL_INFO[0].map[1]; let gap = cc.fx.GameConfig.LEVEL_INFO[0].gap; let risefall = cc.fx.GameConfig.LEVEL_INFO[0].risefall; this.pause = false; this.hammer = false; this.ishammer = false; this.ismagic = false; this.wallNum = 0; this.setMapInfo(); this.blocks = []; this.mapBlocksWall = []; this.mapInfo = []; this.wallInfo = []; this.openWall = []; this.wallArray = []; this.freezeWall = []; this.riseFallBlcok = []; this.mapBlockArray = []; this.freezeArray = []; this.loackArray = []; this.count_Time = 0; this.add_Time = 0; let startX = this.mapWidth % 2 == 0 ? -(this.mapWidth - 1) * 60 : -(this.mapWidth - 1) * 60; let startY = this.mapHeight % 2 == 0 ? -(this.mapHeight - 1) * 60 : -(this.mapHeight - 1) * 60; // startX =(this.mapWidth-1)*60 + 60; // startY =-(this.mapHeight-1)*60 - 60; for (let i = 0; i < this.mapWidth; i++) { this.mapBlocksWall[i] = []; for (let j = 0; j < this.mapHeight; j++) { let block = cc.instantiate(this.MapBlockPrefab); block.parent = this.node.getChildByName("mapBlock"); block.getComponent("MapBlock").init(i, j); // block.getChildByName("num").getComponent(cc.Label).string = i + ":" + j; block.setPosition(cc.v2(startX + i * 120, startY + j * 120)) if (risefall != null) { if (risefall.length > 0) { if (this.mapRiseFall(cc.v2(i, j), risefall, block)) { this.riseFallBlcok.push(block); } } } if (gap.length > 0) { if (!this.mapGap(cc.v2(i, j), gap) || i == 0 || i == this.mapWidth - 1 || j == 0 || j == this.mapHeight - 1) { block.opacity = 254; block.removeComponent(cc.Sprite); block.removeAllChildren(); this.wallInfo.push(block); } else this.mapInfo.push(block); } else { if (i == 0 || i == this.mapWidth - 1 || j == 0 || j == this.mapHeight - 1) { block.opacity = 254; block.removeComponent(cc.Sprite); block.removeAllChildren(); this.wallInfo.push(block); } else this.mapInfo.push(block); } this.mapBlocksWall[i].push(block); } } this.wallInit(); this.blockInit(); if ((cc.fx.GameConfig.GM_INFO.level + 1) == 1) { // 如果是第一关,显示引导 this.guideNode.active = true; this.guideNode.zIndex = 1000; this.guideNode.getComponent(Animation).play(); } if (cc.fx.GameConfig.GM_INFO.hammerFirst == true) { this.guideItem.active = true; this.setPropNum(); } if (cc.fx.GameConfig.GM_INFO.freezeFirst == true) { this.guideItem.active = true; this.setPropNum(); } if (cc.fx.GameConfig.GM_INFO.magicAFirst == true) { this.guideItem.active = true; this.setPropNum(); } } //创建方块 // ... 已有代码 ... //创建方块 // ... 已有代码 ... blockInit() { let blockArray = cc.fx.GameConfig.BLOCK_INFO[0]; blockArray = this.sortBlock(blockArray); //console.log("创建方块", blockArray); let index = 0; // 当前要创建的方块索引 let BLOCKS_PER_FRAME = 1; // 初始每帧创建的方块数量 const MAX_PER_FRAME = 10; // 每帧最大创建数量 const MIN_PER_FRAME = 1; // 每帧最小创建数量 const createBlocks = () => { const startTime = performance.now(); for (let i = 0; i < BLOCKS_PER_FRAME && index < blockArray.length; i++) { let blockInfo = blockArray[index]; // 缓存 Block_Array 访问 const blockPrefab = this.Block_Array[blockInfo.block]; let block = cc.instantiate(blockPrefab); block.parent = this.node; block.setPosition(cc.v2(blockInfo.position.x, blockInfo.position.y)); if (blockInfo.block != 23) { this.blockNum += 1; this.blocks.push(block); if (blockInfo.type == 1) { let info = { id: blockInfo.id + 1, block: blockInfo.block, color: blockInfo.stacking, type: 10, position: blockInfo.position, stacking: blockInfo.color }; // 缓存 Block_Array 访问 const blockUpPrefab = this.Block_Array[info.block]; let blockUp = cc.instantiate(blockUpPrefab); blockUp.parent = this.node; blockUp.setPosition(cc.v2(info.position.x, info.position.y)); this.blocks.push(blockUp); block.getComponent("Block").init(blockInfo, null, null, blockUp); blockUp.getComponent("Block").init(info, null, null, block); this.blockNum += 1; } else if (blockInfo.type == 9) { if (blockInfo.adhesiveTime < 2) { index++; continue; } index++; let info = blockArray[index]; // 缓存 Block_Array 访问 const blockUpPrefab = this.Block_Array[info.block]; let blockUp = cc.instantiate(blockUpPrefab); blockUp.parent = this.node; blockUp.setPosition(cc.v2(info.position.x, info.position.y)); this.blocks.push(blockUp); block.getComponent("Block").init(blockInfo, null, null, blockUp, false); setTimeout(() => { blockUp.getComponent("Block").init(info, null, null, block, true); }, 100); this.blockNum += 1; } else { block.getComponent("Block").init(blockInfo); } } else { block.getComponent("Barrier").init(blockInfo); } index++; } const endTime = performance.now(); const frameTime = endTime - startTime; // 如果当前帧执行时间过长,减少每帧创建数量 if (frameTime > 16) { BLOCKS_PER_FRAME = Math.max(BLOCKS_PER_FRAME - 1, MIN_PER_FRAME); } else { BLOCKS_PER_FRAME = Math.min(BLOCKS_PER_FRAME + 1, MAX_PER_FRAME); } // 如果还有方块未创建,下一帧继续创建 if (index < blockArray.length) { // 使用 scheduleOnce 在下一帧执行 createBlocks this.scheduleOnce(() => { createBlocks(); }, 0); } else { } }; // 开始分帧创建方块 createBlocks(); } //给创建方块排序,用来降低drawcall 合批 sortBlock(allBlocks: { color: number; block: number; type: number }[]) { return allBlocks.sort((a, b) => { // 先处理 type 为 1 的情况,将其放到最后 if (a.type === 1 && b.type !== 1) { return 1; } if (a.type !== 1 && b.type === 1) { return -1; } // 对 type 不为 0 的元素按 type 排序 if (a.type !== 0 && b.type !== 0) { return a.type - b.type; } if (a.type !== 0 && b.type === 0) { return 1; } if (a.type === 0 && b.type !== 0) { return -1; } // 再处理 block 为 23 的情况,将其放到最前面 if (a.block === 23 && b.block !== 23) { return -1; } if (a.block !== 23 && b.block === 23) { return 1; } // 其余按 color 升序排列 return a.color - b.color; }); } //创建墙壁 wallInit() { let index = 0; // 当前要创建的墙壁索引 let WALLS_PER_FRAME = 1; // 初始每帧创建的墙壁数量 const MAX_PER_FRAME = 10; // 每帧最大创建数量 const MIN_PER_FRAME = 1; // 每帧最小创建数量 const createWalls = () => { const startTime = performance.now(); for (let i = 0; i < WALLS_PER_FRAME && index < this.wallInfo.length; i++) { let block = this.wallInfo[index]; let dir = this.getWllDiraction("wall", cc.v2(block.getComponent("MapBlock").posX, block.getComponent("MapBlock").posY)); if (dir != null) { this.createWall(dir, block); } index++; } const endTime = performance.now(); const frameTime = endTime - startTime; // 如果当前帧执行时间过长,减少每帧创建数量 if (frameTime > 16) { WALLS_PER_FRAME = Math.max(WALLS_PER_FRAME - 1, MIN_PER_FRAME); } else { WALLS_PER_FRAME = Math.min(WALLS_PER_FRAME + 1, MAX_PER_FRAME); } // 如果还有墙壁未创建,下一帧继续创建 if (index < this.wallInfo.length) { this.scheduleOnce(() => { createWalls(); }, 0); } else { // 所有墙壁创建完成后,创建拐角节点 this.createCornerNodes(); } }; // 开始分帧创建墙壁 createWalls(); } // ... 已有代码 ... getWllDiraction(type, pointA) { let dir = []; let pointB = cc.v2(pointA.x + 1, pointA.y); let pointC = cc.v2(pointA.x - 1, pointA.y); let pointD = cc.v2(pointA.x, pointA.y + 1); let pointE = cc.v2(pointA.x, pointA.y - 1); let opacity = 0; let turn = 0; if (type == "wall") opacity = 255; if (type == "turn") opacity = 250; if (this.mapBlocksWall[pointA.x][pointA.y].opacity == 249 && this.mapBlocksWall[pointB.x][pointB.y].opacity == 249) { //console.log("缺角", pointA, pointB); return null; } else if (this.mapBlocksWall[pointA.x][pointA.y].opacity == 249 && this.mapBlocksWall[pointC.x][pointC.y].opacity == 249) { //console.log("缺角", pointA, pointC); return null; } else if (this.mapBlocksWall[pointA.x][pointA.y].opacity == 249 && this.mapBlocksWall[pointD.x][pointD.y].opacity == 249) { //console.log("缺角", pointA, pointD); return null; } else if (this.mapBlocksWall[pointA.x][pointA.y].opacity == 249 && this.mapBlocksWall[pointE.x][pointE.y].opacity == 249) { //console.log("缺角", pointA, pointE); return null; } if (pointB.x < this.mapWidth) { if (this.mapBlocksWall[pointB.x][pointB.y].opacity == opacity) { if (type == "turn" && this.mapBlocksWall[pointB.x][pointB.y].getComponent("MapBlock").direction == "right") { } else { dir.push("right"); } } else if (type == "turn") { if (this.mapBlocksWall[pointB.x][pointB.y].opacity == 249) { dir.push("right"); turn++; // console.log("right从转角处增加", pointB.x, pointB.y); } } } if (pointC.x >= 0) { if (this.mapBlocksWall[pointC.x][pointC.y].opacity == opacity) { if (type == "turn" && this.mapBlocksWall[pointC.x][pointC.y].getComponent("MapBlock").direction == "left") { } else { dir.push("left"); } } else if (type == "turn") { if (this.mapBlocksWall[pointC.x][pointC.y].opacity == 249) { dir.push("left"); turn++; // console.log("left从转角处增加", turn); } } } if (pointD.y < this.mapHeight) { if (this.mapBlocksWall[pointD.x][pointD.y].opacity == opacity) { if (type == "turn" && this.mapBlocksWall[pointD.x][pointD.y].getComponent("MapBlock").direction == "up") { } else { dir.push("up"); } } else if (type == "turn") { if (this.mapBlocksWall[pointD.x][pointD.y].opacity == 249) { dir.push("up"); turn++; // console.log("up从转角处增加", turn); } } } if (pointE.y >= 0) { if (this.mapBlocksWall[pointE.x][pointE.y].opacity == opacity) { if (type == "turn" && this.mapBlocksWall[pointE.x][pointE.y].getComponent("MapBlock").direction == "down") { } else { dir.push("down"); } } else if (type == "turn") { if (this.mapBlocksWall[pointE.x][pointE.y].opacity == 249) { dir.push("down"); turn++; // console.log("down从转角处增加", turn); } } } if (dir.length > 2) { return null; } if (dir.length == 1) { if (type == "wall") return dir[0]; else { return null; } } else if (dir.length == 2) { return dir[0] + dir[1]; } } createCornerNodes() { // 定义拐角位置 for (let i = 0; i < this.wallInfo.length; i++) { let block = this.wallInfo[i]; if (block.opacity != 250) { let dir = this.getWllDiraction("turn", cc.v2(block.getComponent("MapBlock").posX, block.getComponent("MapBlock").posY)); //console.log("转角方向", dir, block.getComponent("MapBlock").posX, block.getComponent("MapBlock").posY); if (dir != null) { this.createTurn(dir, block, block.getComponent("MapBlock").posX, block.getComponent("MapBlock").posY); } } } } createWall(direction, node) { let wall = null; node.getComponent("MapBlock").setDiraction(direction); switch (direction) { case "right": node.opacity = 250; wall = cc.instantiate(this.Wall_Prefab[4]); this.leftDoors.push(wall); // wall.parent = this.node.getChildByName("Wall"); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); node.opacity = 250; wall.getChildByName("wall").getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); //wall.getChildByName("wall").getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.getChildByName("wall")); this.wallNum += 1; if (wall.getChildByName("wall").getComponent("Wall").special == 2) this.openWall.push(wall); else if (wall.getChildByName("wall").getComponent("Wall").special == 3) this.freezeWall.push(wall); break; case "left": node.opacity = 250; wall = cc.instantiate(this.Wall_Prefab[3]); // wall.parent = this.node.getChildByName("Wall"); this.rightDoors.push(wall); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); wall.getChildByName("wall").getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); this.setDoorInfo(wall.getChildByName("wall")); //wall.getChildByName("wall").getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.wallNum += 1; if (wall.getChildByName("wall").getComponent("Wall").special == 2) this.openWall.push(wall); else if (wall.getChildByName("wall").getComponent("Wall").special == 3) this.freezeWall.push(wall); break; case "up": node.opacity = 250; wall = cc.instantiate(this.Wall_Prefab[5]); this.topDoors.push(wall); // wall.parent = this.node.getChildByName("Wall"); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); wall.getChildByName("wall").getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); this.setDoorInfo(wall.getChildByName("wall")); //wall.getChildByName("wall").getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.wallNum += 1; if (wall.getChildByName("wall").getComponent("Wall").special == 2) this.openWall.push(wall); else if (wall.getChildByName("wall").getComponent("Wall").special == 3) this.freezeWall.push(wall); break; case "down": node.opacity = 250; wall = cc.instantiate(this.Wall_Prefab[0]); this.bottomDoors.push(wall); // wall.parent = this.node.getChildByName("Wall"); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); // this.setDoorInfo(wall.getChildByName("wall")); wall.getChildByName("wall").getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); this.setDoorInfo(wall.getChildByName("wall")); //wall.getChildByName("wall").getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.wallNum += 1; if (wall.getChildByName("wall").getComponent("Wall").special == 2) this.openWall.push(wall); else if (wall.getChildByName("wall").getComponent("Wall").special == 3) this.freezeWall.push(wall); break; case "upright": case "rightup": node.opacity = 249; wall = cc.instantiate(this.Wall_Prefab[7]); // wall.parent = this.node.getChildByName("Wall"); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); wall.children[1].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); wall.children[2].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); //wall.children[0].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[0]); this.wallNum += 1; //wall.children[1].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[1]); this.wallNum += 1; break; case "upleft": case "leftup": node.opacity = 249; wall = cc.instantiate(this.Wall_Prefab[6]); // wall.parent = this.node.getChildByName("Wall"); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); wall.children[1].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); wall.children[2].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); //wall.children[0].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[0]); this.wallNum += 1; //wall.children[1].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[1]); this.wallNum += 1; break; case "downright": case "rightdown": node.opacity = 249; wall = cc.instantiate(this.Wall_Prefab[2]); // wall.parent = this.node.getChildByName("Wall"); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); wall.children[1].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); wall.children[2].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); //wall.children[0].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[0]); this.wallNum += 1; //wall.children[1].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[1]); this.wallNum += 1; break; case "downleft": case "leftdown": node.opacity = 249; wall = cc.instantiate(this.Wall_Prefab[1]); // wall.parent = this.node.getChildByName("Wall"); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); wall.children[1].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); wall.children[2].getComponent("Wall").init(null, node.getComponent("MapBlock").posX, node.getComponent("MapBlock").posY, direction); //wall.children[0].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[0]); this.wallNum += 1; //wall.children[1].getChildByName("num").getComponent(cc.Label).string = this.wallNum.toString(); this.setDoorInfo(wall.children[1]); this.wallNum += 1; break; } // if(wallTurn){ // wallTurn.getComponent("wallTunr").init(wall); // } } setDoorInfo(wall) { let doorInfo = cc.fx.GameConfig.WALL_INFO[0]; if (doorInfo) { for (let j = 0; j < doorInfo.length; j++) { if (doorInfo[j].num == this.wallNum) { wall.getComponent("Wall").init(doorInfo[j], null, null, null); this.wallArray.push(wall.parent); } } } } createTurn(direction, node, posX, posY) { let wall = null; wall = cc.instantiate(this.wallTurnPrefab); wall.parent = this.node; wall.setPosition(cc.v2(node.x, node.y)); switch (direction) { case "upright": case "rightup": wall.angle = 0; wall.getChildByName("icon").angle = 0; break; case "upleft": case "leftup": wall.angle = 90; wall.getChildByName("icon").angle = -90; wall.getChildByName("icon").y += 5; wall.getChildByName("icon").x -= 1.3; break; case "downright": case "rightdown": wall.angle = 270; wall.getChildByName("icon").angle = -270; wall.getChildByName("icon").x += 2.5; wall.getChildByName("icon").y += 1; break; case "downleft": case "leftdown": wall.angle = 180; wall.getChildByName("icon").angle = -180; wall.getChildByName("icon").x += 4.5; wall.getChildByName("icon").y += 3.2; break; } // if(direction == "rightdown" || direction == "downright") { // wall.zIndex = 50 + posX - posY*3; // } // else // wall.zIndex = 50 + posX - posY*3; if (direction == "up" || direction == "leftup" || direction == "upleft" ) { wall.zIndex = 100 + posX - posY * 3; } else if (direction == "rightup" || direction == "upright" || direction == "rightdown" || direction == "downright" || direction == "downleft") { wall.zIndex = 50 + posX - posY * 3; } else if (direction == "left" || direction == "leftdown") { wall.zIndex = 70 + posX - posY * 3; } else wall.zIndex = 70 + posX - posY * 3; // wall.getChildByName("num").angle = -wall.angle; //wall.getChildByName("num").getComponent(cc.Label).string = direction; // wall.getChildByName("num").getComponent(cc.Label).string = wall.zIndex + ""; // console.log(posX,posY,wall.zIndex); // this.wallNum += 1; // wall.getChildByName("num").getComponent(cc.Label).string = this.wallNum + ""; } //地图底块缺口判断 mapGap(point, gap) { for (let i = 0; i < gap.length; i++) { if (point.x == gap[i].x && point.y == gap[i].y) { return false; } } return true; } //升降地块判断 mapRiseFall(point, risefall, block) { for (let i = 0; i < risefall.length; i++) { if (point.x == risefall[i].x && point.y == risefall[i].y) { block.getChildByName("riseup").active = true; let spriteName = "riseup" + risefall[i].color; let spriteName2 = "risefall" + risefall[i].color; let icon = block.getComponent("MapBlock").riseFall.getSpriteFrame(spriteName); let icon2 = block.getComponent("MapBlock").riseFall.getSpriteFrame(spriteName2); block.getChildByName("risefall").getComponent(cc.Sprite).spriteFrame = icon2; block.getChildByName("riseup").getComponent(cc.Sprite).spriteFrame = icon; block.getChildByName("risefall").active = false; block.getChildByName('risefall').getChildByName("color").getComponent(cc.Label).string = risefall[i].color + ""; return true; } } return false; } //升降地块 changeRiseFall(color, down) { color = color.toString(); for (let i = 0; i < this.riseFallBlcok.length; i++) { if (color == this.riseFallBlcok[i].getChildByName("risefall").getChildByName("color").getComponent(cc.Label).string) { if (down) { this.riseFallBlcok[i].getChildByName("risefall").active = true; this.riseFallBlcok[i].getChildByName("riseup").active = false; } else { this.riseFallBlcok[i].getChildByName("risefall").active = false; this.riseFallBlcok[i].getChildByName("riseup").active = true; } } } } //查询叠加快id foundDownBlock(id) { for (let i = 0; i < this.blocks.length; i++) { if (this.blocks[i].getComponent("Block").blockId == id) { return this.blocks[i]; } } return null; } //删除块 removeBlock(id) { for (let i = 0; i < this.blocks.length; i++) { if (this.blocks[i].getComponent("Block").blockId == id) { return this.blocks[i]; } } return null; } getMinAndMax(block) { let width = Math.floor(block.width / 120); let height = Math.floor(block.height / 120); let minX = width; let maxX = this.mapWidth - 2; let minY = 1; let maxY = this.mapHeight - 2 - height + 1; if (block.name == "block10") { minX = width - 1; if (this.mapWidth > 3) maxX = maxX - 1; } else if (block.name == "block11") { minX = width - 2; if (this.mapWidth > 3) maxX = maxX - 2; } else if (block.name == "block14") { minX = width - 1; maxX = maxX - 1; } else if (block.name == "block16") { minX = width - 1; maxX = maxX - 1; } else if (block.name == "block18") { minX = width - 1; maxX = maxX - 1; } else if (block.name == "block21") { minX = width - 1; maxX = maxX - 1; } return { minX: minX, maxX: maxX, minY: minY, maxY: maxY }; } //检测落点是否可以消除 checkPass(node, blocks) { let minAndMax = this.getMinAndMax(node); let minX = minAndMax.minX; let maxX = minAndMax.maxX; let minY = minAndMax.minY; let maxY = minAndMax.maxY; let nodePos = cc.v2(node.getComponent("Block").posX, node.getComponent("Block").posY); // 获取地图边界信息 let allBlocks = []; for (let i = 0; i < blocks.length; i++) { allBlocks.push(cc.v2(nodePos.x + blocks[i].x, nodePos.y + blocks[i].y)); } // const date1 = new Date().getTime(); // console.log("将小块放入数组的时间",date1); let jg = -1; let pz = 0; // 获取所有墙壁节点 // let wall = this.node; let direction = this.checkDiraction(allBlocks, maxX, maxY); // 判断方块是否在地图边缘 if (nodePos.x <= minX || direction[0] == true) { // const date2 = new Date().getTime(); // console.log("碰到左边缘",date2); pz += 1; let leftWalls = []; for (let i = 0; i < this.leftDoors.length; i++) { let wallLeft = this.leftDoors[i].getChildByName("wall"); let wallPos = cc.v2(wallLeft.getComponent("Wall").posX, wallLeft.getComponent("Wall").posY); for (let i = 0; i < allBlocks.length; i++) { if (allBlocks[i].y == wallPos.y && allBlocks[i].x > wallPos.x) { // console.log("id:",wall.getChildByName("num").getComponent(cc.Label).string); leftWalls.push(wallLeft); } } } // console.log("得到左边墙壁数组",date6); if (leftWalls.length != 0) { let result = this.detectingBlock("left", node.getComponent("Block").posX, node.getComponent("Block").posY, allBlocks); if (result == true) result = this.passWall(result, leftWalls, node); // console.log("碰到左边缘结果:",jg); if (result) { this.blockNum -= 1; this.special_Treatment(node); jg = 2; this.createParticle(node, jg); return jg; } } } if (nodePos.x >= maxX || direction[1] == true) { // const date3 = new Date().getTime(); // console.log("碰到右边缘",date3); pz += 1; let rightWalls = []; for (let i = 0; i < this.rightDoors.length; i++) { let wallRight = this.rightDoors[i].getChildByName("wall"); let wallPos = cc.v2(wallRight.getComponent("Wall").posX, wallRight.getComponent("Wall").posY); for (let i = 0; i < allBlocks.length; i++) { if (allBlocks[i].y == wallPos.y && allBlocks[i].x < wallPos.x) { // console.log("id:",wall.getChildByName("num").getComponent(cc.Label).string); rightWalls.push(wallRight); } } } if (rightWalls.length != 0) { let result = this.detectingBlock("right", node.getComponent("Block").posX, node.getComponent("Block").posY, allBlocks); if (result == true) result = this.passWall(result, rightWalls, node); // console.log("碰到右边缘结果:",jg); if (result) { this.blockNum -= 1; this.special_Treatment(node); jg = 3; this.createParticle(node, jg); return jg; } } } if (nodePos.y <= minY || direction[2] == true) { pz += 1; // const date4 = new Date().getTime(); // console.log("碰到下边缘",date4); let downWalls = []; for (let i = 0; i < this.topDoors.length; i++) { let wallBottom = this.topDoors[i].getChildByName("wall"); let wallPos = cc.v2(wallBottom.getComponent("Wall").posX, wallBottom.getComponent("Wall").posY); for (let i = 0; i < allBlocks.length; i++) { let luocha = Math.abs(allBlocks[i].y - wallPos.y) if (allBlocks[i].x == wallPos.x && allBlocks[i].y > wallPos.y && luocha <= node.getComponent("Block").shu) { // console.log("id:",wall.getChildByName("num").getComponent(cc.Label).string); downWalls.push(wallBottom); } } } if (downWalls.length != 0) { let result = this.detectingBlock("down", node.getComponent("Block").posX, node.getComponent("Block").posY, allBlocks); if (result == true) result = this.passWall(result, downWalls, node); // console.log("碰到下边缘结果:",jg); if (result) { this.blockNum -= 1; this.special_Treatment(node); jg = 1; this.createParticle(node, jg); return jg; } } } if (nodePos.y >= maxY || direction[3] == true) { pz += 1; // const date5 = new Date().getTime(); // console.log("碰到上边缘",date5); let upWalls = []; for (let i = 0; i < this.bottomDoors.length; i++) { let wallTop = this.bottomDoors[i].getChildByName("wall"); let wallPos = cc.v2(wallTop.getComponent("Wall").posX, wallTop.getComponent("Wall").posY); for (let i = 0; i < allBlocks.length; i++) { let luocha = Math.abs(allBlocks[i].y - wallPos.y) if (allBlocks[i].x == wallPos.x && allBlocks[i].y < wallPos.y && luocha <= node.getComponent("Block").shu) { upWalls.push(wallTop); } } } if (upWalls.length != 0) { let result = this.detectingBlock("up", node.getComponent("Block").posX, node.getComponent("Block").posY, allBlocks); if (result == true) result = this.passWall(result, upWalls, node); // console.log("碰到上边缘结果:",result); if (result) { this.blockNum -= 1; this.special_Treatment(node); jg = 0; this.createParticle(node, jg); return jg; } } } if (pz == 0) jg = -1; // const date10 = new Date().getTime(); // console.log("所有检测结束耗时",date10,jg); return jg; } changeState(type) { if (this.openWall.length != 0) { for (let i = 0; i < this.openWall.length; i++) { this.openWall[i].getChildByName("wall").getComponent("Wall").changeLock(); } } if (type) { if (this.freezeWall.length != 0) { for (let i = 0; i < this.freezeWall.length; i++) { this.freezeWall[i].getChildByName("wall").getComponent("Wall").changeFreeze(); } } } } //检测是否可以通过门 passWall(jg, wallArray, node) { for (let i = 0; i < wallArray.length; i++) { if (wallArray[i].getComponent("Wall").special == 2) { console.log("尝试通过开关门:", wallArray[i].getComponent("Wall").open); } if (wallArray[i].getComponent("Wall").special == 2 && wallArray[i].getComponent("Wall").open == false) { jg = false; return jg; } if (wallArray[i].getComponent("Wall").special == 3) { jg = false; return jg; } //console.log(wallArray[i].getChildByName("wall").getComponent("Wall").color,node.getComponent("Block").color) if (wallArray[i].getComponent("Wall").color != node.getComponent("Block").color) { jg = false; return jg; } if (node.getComponent("Block").type == 5) { if (wallArray[i].getComponent("Wall").special != 1) { jg = false; return jg; } } } if (jg == true && node.getComponent("Block").type == 5) { for (let j = 0; j < wallArray.length; j++) { if (wallArray[j].getComponent("Wall").special == 1 && wallArray[j].getComponent("Wall").wall_Info.length != 0) { wallArray[j].getComponent("Wall").playStarDoor(); } } } // const date8 = new Date().getTime(); // console.log("检测颜色是否能够通过门",date8); return jg; } //检测方块和门中间有没有夹杂其他块 detectingBlock(direction, posX, posY, blocks) { let jg = true; let id = ""; if (blocks.length > 0) { for (let i = 0; i < blocks.length; i++) { let pos = blocks[i]; let x = pos.x; let y = pos.y; id = this.mapBlocksWall[x][y].getComponent("MapBlock").block_Id; jg = this.checkAllDirections(id, direction, x, y); if (!jg) { // console.log("方向检测没过"); i = 1000000; return jg; } } } // const date7 = new Date().getTime(); // console.log("方向检测通过",date7,jg); return jg; } //检测物体各方向是否有别的物块,防止碰到墙壁了但是是凹凸形状,墙与块之间有阻挡物块 checkAllDirections(id, direction, x, y) { let jg = true; if (direction == "left") { if (this.mapBlocksWall[x - 1][y].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x - 1][y].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x - 1][y].getComponent("MapBlock").block_Id != id) { // console.log("左侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x - 1][y].opacity == 249) { jg = false; return jg; } if ((x - 2) >= 0) { if (this.mapBlocksWall[x - 2][y].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x - 2][y].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x - 2][y].getComponent("MapBlock").block_Id != id) { // console.log("左侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x - 2][y].opacity == 249) { jg = false; return jg; } } } else if (direction == "right") { if (this.mapBlocksWall[x + 1][y].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x + 1][y].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x + 1][y].getComponent("MapBlock").block_Id != id) { // console.log("右侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x + 1][y].opacity == 249) { jg = false; return jg; } if ((x + 2) <= this.mapBlocksWall.length - 1) { if (this.mapBlocksWall[x + 2][y].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x + 2][y].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x + 2][y].getComponent("MapBlock").block_Id != id) { // console.log("右侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x + 2][y].opacity == 249) { jg = false; return jg; } } } if (direction == "up") { if (this.mapBlocksWall[x][y + 1].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x][y + 1].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x][y + 1].getComponent("MapBlock").block_Id != id) { // console.log("上侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x][y + 1].opacity == 249) { jg = false; return jg; } if ((y + 2) <= this.mapBlocksWall[x].length - 1) { if (this.mapBlocksWall[x][y + 2].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x][y + 2].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x][y + 2].getComponent("MapBlock").block_Id != id) { // console.log("上侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x][y + 2].opacity == 249) { jg = false; return jg; } } } if (direction == "down") { if (this.mapBlocksWall[x][y - 1].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x][y - 1].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x][y - 1].getComponent("MapBlock").block_Id != id) { // console.log("下侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x][y - 1].opacity == 249) { jg = false; return jg; } if ((y - 2) >= 0) { if (this.mapBlocksWall[x][y - 2].getComponent("MapBlock").block_Id != "" && this.mapBlocksWall[x][y - 2].getComponent("MapBlock").block_Id != "Wall" && this.mapBlocksWall[x][y - 2].getComponent("MapBlock").block_Id != id) { // console.log("下侧有物体") jg = false; return jg; } if (this.mapBlocksWall[x][y - 2].opacity == 249) { jg = false; return jg; } } } // console.log("检测物体各方向是否有别的物块",jg); return jg; } checkDiraction(allBlocks, maxX, maxY) { let jg = [false, false, false, false]; for (let i = 0; i < allBlocks.length; i++) { if (allBlocks[i].x > 0 && jg[0] == false) { if (this.mapBlocksWall[allBlocks[i].x - 1][allBlocks[i].y].opacity == 250) { jg[0] = true; } } if (jg[1] == false) { if (this.mapBlocksWall[allBlocks[i].x + 1][allBlocks[i].y].opacity == 250) { jg[1] = true; } } if (allBlocks[i].y > 0 && jg[2] == false) { if (this.mapBlocksWall[allBlocks[i].x][allBlocks[i].y - 1].opacity == 250) { jg[2] = true; } } if (jg[3] == false) { if (this.mapBlocksWall[allBlocks[i].x][allBlocks[i].y + 1].opacity == 250) { jg[3] = true; } } } return jg; } checkLeft(allBlocks) { let jg = false; return jg; } checkRight(allBlocks, max) { let jg = false; for (let i = 0; i < allBlocks.length; i++) { } return jg; } checkDown(allBlocks) { let jg = false; for (let i = 0; i < allBlocks.length; i++) { } return jg; } checkUp(allBlocks, max) { let jg = false; for (let i = 0; i < allBlocks.length; i++) { } return jg; } //特殊处理,方块带道具或者需要消除冰块 special_Treatment(node) { let freezeBlock = this.node.children.filter(child => { if (child.getComponent("Block")) { if (child.getComponent("Block").type == 4) return child } }); if (freezeBlock.length > 0) { for (let i = 0; i < freezeBlock.length; i++) { freezeBlock[i].getChildByName("freeze").getComponent("Freeze").reduce(1); } } if (node.getComponent("Block").type == 2 || node.getComponent("Block").type == 4) { let lockBlock = this.node.children.filter(child => { if (child.getComponent("Block")) { if (child.getComponent("Block").type == 3) return child } }); if (lockBlock.length > 0) for (let i = 0; i < lockBlock.length; i++) { lockBlock[i].getChildByName("lock").getComponent("Lock").reduce(); } } for (let i = 0; i < this.blocks.length; i++) { if (this.blocks[i] == node) { this.blocks.splice(i, 1); } } this.changeState(true); } judgeWin(number) { this.blockNum = this.blocks.length; if (number == 1) { if ((this.blockNum == 0 || this.blockNum == 1) && !this.gameWin && !this.gameOver) { this.stopTimeCutDown(); this.stopBoom(); } } else if (number == 0) { if (this.blockNum == 0 && !this.gameWin && !this.gameOver) { this.stopTimeCutDown(); this.stopBoom(); } } } //判断游戏成功下一关 nextLevel() { this.pause = false; this.openIce(); this.blockNum = this.blocks.length; if (this.blockNum == 0 && !this.gameWin && !this.gameOver) { // alert("游戏成功"); // MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.level); this.setOtherLevel(); this.gameWin = true; if (cc.fx.GameConfig.GM_INFO.hp < cc.fx.GameConfig.GM_INFO.hp_Max) { console.log("恢复一点体力", cc.fx.GameConfig.GM_INFO.level); if (!this.powerState) { cc.fx.GameTool.setUserHealth(1, (data) => { }, false) } this.powerState = false; } this.stopTimeCutDown(); // console.log("即将上报成功________________________:",this.add_Time); // console.log("成功消除一个",this.add_Time); cc.fx.GameTool.changeCoin(40 * cc.fx.GameConfig.GM_INFO.doubleCoin); const data = { change_reason: "level", id: (1001 + ""), num: 40 * cc.fx.GameConfig.GM_INFO.doubleCoin } cc.fx.GameTool.shushu_Track("resource_get", data); let overTime = Date.now(); this.count_Time = overTime - this.count_Time; if (cc.fx.GameConfig.GM_INFO.otherLevel > 0) { } else cc.fx.GameTool.addLevel(this.count_Time, this.add_Time); const winCOIN = cc.find("Canvas"); // 假设 Canvas 节点 if (winCOIN) { const wincoin = winCOIN.getComponent(SceneManager); if (wincoin) { wincoin.updateWinCoin(); } else { console.log("JiaZai 组件未找到"); } } else { console.log("JiaZai 节点未找到"); } this.check_NewMode(); setTimeout(() => { this.node.parent.parent.getChildByName("Win").active = true; this.Settlement(); }, 660); // console.log("游戏成功"); } else { if (this.gameOver == true) { this.failLevel("time"); } } } check_NewMode() { for (let i = 0; i < cc.fx.GameConfig.NEW_LEVEL.length; i++) { if ((cc.fx.GameConfig.GM_INFO.level + 1) == cc.fx.GameConfig.NEW_LEVEL[i].level) { this.new_mode = 3; } } for (let i = 0; i < cc.fx.GameConfig.NEW_GUIDE.length; i++) { if ((cc.fx.GameConfig.GM_INFO.level + 1) == cc.fx.GameConfig.NEW_GUIDE[i].level) { this.new_item = 3; } } } winLevel() { // MiniGameSdk.API.showToast(cc.fx.GameConfig.GM_INFO.level); if (this.node.parent.parent.getChildByName("Win").getChildByName("tween"). getChildByName("nextBtn").getComponent("btnControl")._touch == false) { return; } this.node.parent.parent.getChildByName("Win").getChildByName("tween"). getChildByName("nextBtn").getComponent("btnControl").setTouch(false); cc.fx.AudioManager._instance.playEffect("anniu_Big", null); console.log("下一关", cc.fx.GameConfig.GM_INFO.level); this.uploadToCloud(cc.fx.GameConfig.GM_INFO.level + 1); if (cc.fx.GameConfig.GM_INFO.level > 323) { cc.fx.GameConfig.GM_INFO.level = 323; MiniGameSdk.API.showToast("每周更新,敬请期待!"); setTimeout(() => { this.node.parent.parent.getChildByName("Win").getChildByName("tween"). getChildByName("nextBtn").getComponent("btnControl").setTouch(true); }, 500); } else { // console.log("下一关"); if (this.new_mode == 3) { this.node.parent.parent.getChildByName("Win").active = false; this.openNewMode(2); cc.fx.GameConfig.LEVEL_INFO_init(false, 0); return; } if (this.new_item == 3) { if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) { console.log("新手引导开启"); cc.fx.GameConfig.GM_INFO.hammerFirst = true; } if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) { cc.fx.GameConfig.GM_INFO.freezeFirst = true; } if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) { cc.fx.GameConfig.GM_INFO.magicAFirst = true; } } cc.fx.AudioManager._instance.playEffect("zhuan1", null); this.node.parent.parent.parent.getChildByName("zhuanchang").active = true; this.node.parent.parent.parent.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false); setTimeout(() => { cc.fx.GameConfig.LEVEL_INFO_init(true, 0); }, 1200); } } againLevel() { cc.fx.AudioManager._instance.playEffect("anniu_Big", null); if (cc.fx.GameConfig.GM_INFO.hp < 1) { MiniGameSdk.API.showToast("体力值不足"); return; } if (!this.againCanTouch) return; this.againCanTouch = false; // MapConroler._instance = null; cc.fx.AudioManager._instance.playEffect("zhuan1", null); this.node.parent.parent.parent.getChildByName("zhuanchang").active = true; this.node.parent.parent.parent.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false); // this.node.parent.parent.parent.getChildByName("zhuanchang").getComponent(sp.Skeleton).setCompleteListener((entry) => { // if (entry.animation.name === "up") { // // 动画播放结束后执行的逻辑 // this.node.parent.parent.parent.getChildByName("zhuanchang").active = false; // } // }); setTimeout(() => { cc.fx.GameConfig.LEVEL_INFO_init(true, 0); }, 1200); // this.node.parent.parent.parent.destroy(); } //时间到了复活 reviewLevel(event, type) { if (this.reviewState == true) { return; } this.reviewState = true; cc.fx.AudioManager._instance.playEffect("anniu_Big", null); let coin = 500; let data = { type: type, coin: -coin } if (type == "time") { if (cc.fx.GameConfig.GM_INFO.review == 1) coin = 1000; else if (cc.fx.GameConfig.GM_INFO.review == 2) coin = 1500; } else if (type == "boom") { if (cc.fx.GameConfig.GM_INFO.reviewBoom == 1) coin = 1000; else if (cc.fx.GameConfig.GM_INFO.reviewBoom == 2) coin = 1500; } else if (type == "lock") { if (cc.fx.GameConfig.GM_INFO.reviewDoor == 1) coin = 1000; else if (cc.fx.GameConfig.GM_INFO.reviewDoor == 2) coin = 1500; } data.coin = -coin; // console.log("自身金币:",cc.fx.GameConfig.GM_INFO.coin,"消耗金币:",coin); if (cc.fx.GameConfig.GM_INFO.coin < Math.abs(coin)) { MiniGameSdk.API.showToast("金币不足,无法加时间"); setTimeout(() => { this.openShop(); this.reviewState = false; }, 500); return; } else { this.runRewive(data); } } //执行复活函数 runRewive(data) { console.log("复活回调函数内", data); this.isreview = true; cc.fx.GameTool.changeCoin(data.coin); const dataTemp = { change_reason: "游戏内复活消耗金币", id: (1001 + ""), num: data.coin } cc.fx.GameTool.shushu_Track("resource_cost", dataTemp); MiniGameSdk.API.showToast("继续游戏"); this.updateCoin(); // NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); if (data.type == "time") { if (cc.fx.GameConfig.GM_INFO.review < 2) cc.fx.GameConfig.GM_INFO.review += 1; } else if (data.type == "boom") { if (cc.fx.GameConfig.GM_INFO.reviewBoom < 2) cc.fx.GameConfig.GM_INFO.reviewBoom += 1; } else if (data.type == "lock") { this.changeState(false); if (cc.fx.GameConfig.GM_INFO.reviewDoor < 2) cc.fx.GameConfig.GM_INFO.reviewDoor += 1; } this.gameOver = false; this.gameWin = false; this.pause = false; if (data.type == "time") { this.timeNumber = 21; this.add_Time += 20; NumberToImage.getTimeMargin(20, 50, "time_", this.timeLabel) } this.blockNum = this.blocks.length; if (this.blockNum == 0) this.nextLevel(); this.node.parent.parent.getChildByName("Lose").active = false; setTimeout(() => { this.reviewState = false; }, 200); this.stopTimeCutDown(); // this.startTimeCutDown(); } //执行复活函数 runRewiveCopy() { this.isreview = true; MiniGameSdk.API.showToast("继续游戏"); this.gameOver = false; this.gameWin = false; this.pause = false; this.timeNumber = 21; this.add_Time += 20; NumberToImage.getTimeMargin(20, 50, "time_", this.timeLabel) this.blockNum = this.blocks.length; if (this.blockNum == 0) this.nextLevel(); this.node.parent.parent.getChildByName("Lose").active = false; setTimeout(() => { this.reviewState = false; }, 200); this.stopTimeCutDown(); // this.startTimeCutDown(); } homeBtn() { // alert("游戏失败"); if (this.powerState) { this.returnHome(); return; } cc.fx.AudioManager._instance.playEffect("anniu_Big", null); if (!this.homeCanTouch) return; this.homeCanTouch = false; this.node.parent.parent.getChildByName("Lose").active = true; let pauseNode = this.node.parent.parent.getChildByName("Lose").getChildByName("lose"); pauseNode.scale = 0.3; cc.tween(pauseNode) .to(0.2, { scale: 1.05 }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 }, { easing: 'sineOut' }) .start(); this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Time").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Boom").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Lock").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Health").active = true; let overTime = Date.now(); this.count_Time = overTime - this.count_Time; let data = { time: this.count_Time, add_Time: this.add_Time, result: "fail" } if (cc.fx.GameConfig.GM_INFO.revive == 0 && this.revive) { this.revive.getComponent("Revive").offShow(); this.node.active = false; } cc.fx.GameTool.shushu_Track("finish_stage", data); } uploadToCloud(level: number) { if (typeof wx !== 'undefined') { //@ts-ignore wx.setUserCloudStorage({ KVDataList: [ { key: 'level', value: String(level) } ], success: () => console.log('✅ 数据上传成功'), fail: (err) => console.error('❌ 上传失败', err) }); } } returnHome() { cc.fx.AudioManager._instance.playEffect("anniu_Big", null); if (MapConroler._instance = null) { return; } // MiniGameSdk.API.showToast("体力值减少"); MapConroler._instance = null; cc.fx.GameConfig.LEVEL_INFO_init(false, 0); if (this.new_mode == 3) { this.node.parent.parent.getChildByName("Win").active = false; this.openNewMode(1); return; } if (this.new_item == 3) { if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) { cc.fx.GameConfig.GM_INFO.hammerFirst = true; } if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) { cc.fx.GameConfig.GM_INFO.freezeFirst = true; } if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) { cc.fx.GameConfig.GM_INFO.magicAFirst = true; } } cc.fx.AudioManager._instance.playEffect("zhuan1", null); this.node.parent.parent.parent.getChildByName("zhuanchang").active = true; this.node.parent.parent.parent.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false); cc.director.preloadScene("HomeScene", (err, asset) => { if (err) { console.error('动态加载 Prefab 失败:', err); return; } }); setTimeout(() => { cc.director.loadScene("HomeScene"); }, 1200); } //判断游戏失败 failLevel(type) { if (this.gameOver == true || this.gameWin == true) { return; } this.stopTimeCutDown(); let time = 0; this.gameOver = true; if (type == "boom" || type == "lock") { time = 2000; } if (cc.fx.GameConfig.GM_INFO.otherLevel > 0) { let eventData = { identity: "helper", //发起者为helped 帮助者为helper level: cc.fx.GameConfig.GM_INFO.otherLevel, //被帮助关卡等级 success: false, //是否成功 } cc.fx.GameTool.shushu_Track("stage_help", eventData); //帮助通关 } setTimeout(() => { this.node.parent.parent.getChildByName("Lose").active = true; let pauseNode = this.node.parent.parent.getChildByName("Lose").getChildByName("lose"); pauseNode.scale = 0.3; cc.tween(pauseNode) .to(0.2, { scale: 1.05 }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 }, { easing: 'sineOut' }) .start(); this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Time").active = true; this.revive.getComponent("Revive").init(); this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Boom").active = false; if (cc.fx.GameConfig.GM_INFO.otherLevel > 0) { this.node.parent.parent.getChildByName("Lose").getChildByName("share").active = false; } else { console.log("有分享按钮"); setTimeout(() => { this.node.parent.parent.getChildByName("Lose").getChildByName("share").active = true; }, 350); } if (type) { if (type == "time") { this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Time").active = true; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Boom").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Lock").active = false; let buyBtn = this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Time").getChildByName("buyBtn"); buyBtn.getChildByName("coin1").active = buyBtn.getChildByName("coin2").active = buyBtn.getChildByName("coin3").active = false; if (cc.fx.GameConfig.GM_INFO.review == 0) buyBtn.getChildByName("coin1").active = true; else if (cc.fx.GameConfig.GM_INFO.review == 1) buyBtn.getChildByName("coin2").active = true; else if (cc.fx.GameConfig.GM_INFO.review == 2) buyBtn.getChildByName("coin3").active = true; } else if (type == "boom") { this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Time").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Boom").active = true; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Lock").active = false; let buyBtn = this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Boom").getChildByName("buyBtn"); buyBtn.getChildByName("coin1").active = buyBtn.getChildByName("coin2").active = buyBtn.getChildByName("coin3").active = false; if (cc.fx.GameConfig.GM_INFO.reviewBoom == 0) buyBtn.getChildByName("coin1").active = true; else if (cc.fx.GameConfig.GM_INFO.reviewBoom == 1) buyBtn.getChildByName("coin2").active = true; else if (cc.fx.GameConfig.GM_INFO.reviewBoom == 2) buyBtn.getChildByName("coin3").active = true; } else if (type == "lock") { this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Time").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Boom").active = false; this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Lock").active = true; let buyBtn = this.node.parent.parent.getChildByName("Lose").getChildByName("lose").getChildByName("Lock").getChildByName("buyBtn"); buyBtn.getChildByName("coin1").active = buyBtn.getChildByName("coin2").active = buyBtn.getChildByName("coin3").active = false; if (cc.fx.GameConfig.GM_INFO.reviewDoor == 0) buyBtn.getChildByName("coin1").active = true; else if (cc.fx.GameConfig.GM_INFO.reviewDoor == 1) buyBtn.getChildByName("coin2").active = true; else if (cc.fx.GameConfig.GM_INFO.reviewDoor == 2) buyBtn.getChildByName("coin3").active = true; } } }, time); // console.log("游戏失败"); } //打开新模式弹窗 openNewMode(type) { let index = 0; const BLOCKS_PER_FRAME = 5; // 每帧销毁的方块数量 const destroyBlocks = () => { const endIndex = Math.min(index + BLOCKS_PER_FRAME, this.blocks.length); for (; index < endIndex; index++) { if (this.blocks[index]) { this.blocks[index].destroy(); } } // 如果还有方块未销毁,下一帧继续 if (index < this.blocks.length) { this.scheduleOnce(destroyBlocks, 0); } else { } }; // 开始分帧销毁方块 destroyBlocks(); this.node.parent.parent.getChildByName("NewMode").active = true; let pauseNode = this.node.parent.parent.getChildByName("NewMode").getChildByName("newmode"); pauseNode.scale = 0.3; cc.tween(pauseNode) .to(0.2, { scale: 1.05 }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 }, { easing: 'sineOut' }) .start(); this.node.parent.parent.getChildByName("NewMode").getComponent("NewMode").setMode(type); } downDoor(color, type) { for (let i = 0; i < this.wallArray.length; i++) { if (this.wallArray[i].getChildByName("wall").getComponent("Wall").color == color) { if (type) { if (type == 5) { if (this.wallArray[i].getChildByName("wall").getComponent("Wall").special == 1) { this.wallArray[i].getChildByName("wall").getComponent("Wall").downDoor(); } } else this.wallArray[i].getChildByName("wall").getComponent("Wall").downDoor(); } else this.wallArray[i].getChildByName("wall").getComponent("Wall").downDoor(); } } } upDoor() { for (let i = 0; i < this.wallArray.length; i++) { if (this.wallArray[i].getChildByName("wall").opacity == 0) { this.wallArray[i].getChildByName("wall").getComponent("Wall").upDoor(); } } } //开始倒计时 startTimeCutDown() { this.startBoom(); this.scheduleCallback = function () { if (this.pause) return; if (this.timeNumber <= 0) { this.stopTimeCutDown(); var timeTemp = cc.fx.GameTool.getTimeMargin(this.timeNumber); NumberToImage.getTimeMargin(this.timeNumber, 50, "time_", this.timeLabel) // this.timeLabel.string = timeTemp.toString(); if (!this.pause) this.failLevel("time"); } else { this.timeNumber -= 1; var timeTemp = cc.fx.GameTool.getTimeMargin(this.timeNumber); NumberToImage.getTimeMargin(this.timeNumber, 50, "time_", this.timeLabel) // this.timeLabel.string = timeTemp.toString(); } }.bind(this); this.schedule(this.scheduleCallback, 1); } // 停止倒计时 stopTimeCutDown() { if (this.scheduleCallback) { this.unschedule(this.scheduleCallback); this.scheduleCallback = null; } } //使用时间道具 useTimeProp() { var pause = this.iceTrue(); console.log("冰冻状态:", pause); if (pause == true) { return; } let freezeBtn = this.node.parent.getChildByName("Bottom").getChildByName("timeBtn"); if (freezeBtn.getComponent("btnControl")._touch) { freezeBtn.getComponent("btnControl").setTouch(false); if (cc.fx.GameConfig.GM_INFO.freezeAmount < 1) { // if (cc.fx.GameConfig.GM_INFO.coin < 1500) { // MiniGameSdk.API.showToast("金币不足,无法购买道具"); // setTimeout(() => { // this.openShop(); // freezeBtn.getComponent("btnControl").setTouch(true); // }, 500); // return; // } this.node.parent.parent.getChildByName("propWindow").active = true; cc.fx.AudioManager._instance.playEffect("tanchuang", null); let pauseNode = this.node.parent.parent.getChildByName("propWindow").getChildByName("prop"); pauseNode.scale = 0.3; cc.tween(pauseNode) .to(0.2, { scale: 1.05 }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 }, { easing: 'sineOut' }) .start(); this.node.parent.parent.parent.getComponent("SceneManager").openPropBuy("freeze"); } else { if (!this.node.parent.getChildByName("Ice").active && !this.pause) { const timestamp = Date.now(); this.freezeMask.active = true; this.stopBoom(); this.pause = true; this.node.parent.getChildByName("Ice").active = true; this.node.parent.getChildByName("Ice").getChildByName("skeleton").active = true; // this.node.parent.getChildByName("Top").getChildByName("Ice").active = true; this.icetimeNode[0].active = false; //播放第三個子節點的動畫 this.icetimeNode[2].active = true; this.icetimeNode[2].getChildByName("dongjie").getComponent(sp.Skeleton).setAnimation(0, "animation", false); //播放结束后消失 this.icetimeNode[2].getChildByName("dongjie").getComponent(sp.Skeleton).setCompleteListener(() => { this.icetimeNode[2].active = false; this.icetimeNode[1].active = true; this.node.parent.getChildByName("Ice").getChildByName("skeleton").getComponent(sp.Skeleton).setAnimation(0, "animation", true); }) cc.fx.GameConfig.GM_INFO.freezeAmount -= 1; if (cc.fx.GameConfig.GM_INFO.freezeAmount < 0) cc.fx.GameConfig.GM_INFO.freezeAmount = 0; this.setPropNum(); // this.iceLabel.string = cc.fx.GameConfig.GM_INFO.freezeAmount.toString(); let propInfo = cc.fx.StorageMessage.getStorage("prop"); propInfo.freezeAmount = cc.fx.GameConfig.GM_INFO.freezeAmount; propInfo.timestamp = timestamp; cc.fx.StorageMessage.setStorage("prop", propInfo); cc.fx.GameTool.setUserProp(2001, cc.fx.GameConfig.GM_INFO.freezeAmount, (data) => { }) let data = { change_reason: "使用道具", id: "2001", num: -1 } cc.fx.GameTool.shushu_Track("resource_cost", data); } else MiniGameSdk.API.showToast("道具使用中,请稍后再试"); } } } //解开时间冻结 openIce() { if (this.node.parent.getChildByName("Ice").active) { this.freezeMask.active = false; let freezeBtn = this.node.parent.getChildByName("Bottom").getChildByName("timeBtn"); freezeBtn.getComponent("btnControl").setTouch(true); this.node.parent.getChildByName("Ice").getChildByName("skeleton").active = false; this.node.parent.getChildByName("Ice").active = false; // this.node.parent.getChildByName("Top").getChildByName("Ice").active = false; this.icetimeNode[0].active = true; this.icetimeNode[1].active = false; this.pause = false; this.startBoom(); // this.startTimeCutDown(); } } handleBuySuccess(data) { this.node.parent.parent.parent.getComponent("SceneManager").resetBtn(); this.updateCoin(); var pause = this.iceTrue(); if (pause == false) { this.pause = false; this.startBoom(); } const timestamp = Date.now(); // console.log("回调函数内:",this.pause); let freezeBtn = this.node.parent.getChildByName("Bottom").getChildByName("timeBtn"); let hammerBtn = this.node.parent.getChildByName("Bottom").getChildByName("destroyBtn"); let magicBtn = this.node.parent.getChildByName("Bottom").getChildByName("magicBtn"); if (data == "freezeAmount") freezeBtn.getComponent("btnControl").setTouch(true); else if (data == "hammerAmount") hammerBtn.getComponent("btnControl").setTouch(true); else if (data == "magicAmount") magicBtn.getComponent("btnControl").setTouch(true); if (data == "freezeAmount") { // cc.fx.GameConfig.GM_INFO.freezeAmount += 3; let propInfo = cc.fx.StorageMessage.getStorage("prop"); propInfo.freezeAmount = cc.fx.GameConfig.GM_INFO.freezeAmount; propInfo.timestamp = timestamp; cc.fx.StorageMessage.setStorage("prop", propInfo); this.node.parent.parent.parent.getComponent("SceneManager").closePropBuy(); setTimeout(() => { this.setPropNum(); // this.iceLabel.string = cc.fx.GameConfig.GM_INFO.freezeAmount.toString(); // MiniGameSdk.API.showToast("购买冻结时间成功"); let data = [ { type: "freeze", count: 3 }, ] MapConroler._instance.SceneManager.openRewardWindow(data); }, 200); } else if (data == "magicAmount") { // cc.fx.GameConfig.GM_INFO.magicAmount += 3; let propInfo = cc.fx.StorageMessage.getStorage("prop"); propInfo.magicAmount = cc.fx.GameConfig.GM_INFO.magicAmount; propInfo.timestamp = timestamp; cc.fx.StorageMessage.setStorage("prop", propInfo); this.node.parent.parent.parent.getComponent("SceneManager").closePropBuy(); setTimeout(() => { // MiniGameSdk.API.showToast("购买魔法棒成功"); this.setPropNum(); // this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString(); let data = [ { type: "magic", count: 3 }, ] MapConroler._instance.SceneManager.openRewardWindow(data); }, 200); } else if (data == "hammerAmount") { // cc.fx.GameConfig.GM_INFO.hammerAmount += 1; let propInfo = cc.fx.StorageMessage.getStorage("prop"); propInfo.hammerAmount = cc.fx.GameConfig.GM_INFO.hammerAmount; propInfo.timestamp = timestamp; cc.fx.StorageMessage.setStorage("prop", propInfo); this.node.parent.parent.parent.getComponent("SceneManager").closePropBuy(); setTimeout(() => { this.setPropNum(); // this.hammerLabel.string = cc.fx.GameConfig.GM_INFO.hammerAmount.toString(); // MiniGameSdk.API.showToast("购买锤子成功"); let data = [ { type: "hammer", count: 1 }, ] MapConroler._instance.SceneManager.openRewardWindow(data); }, 200); } } updateCoin() { NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); } //使用锤子道具 useHammer() { //一秒之内只能点一次 if (this.lastHammerTime && Date.now() - this.lastHammerTime < 1000) { return; } this.lastHammerTime = Date.now(); if (this.magicMask.active == true || this.timeNumber <= 1 || this.gameOver || this.gameWin) { return; } let hammerBtn = this.node.parent.getChildByName("Bottom").getChildByName("destroyBtn"); if (hammerBtn.getComponent("btnControl")._touch) { hammerBtn.getComponent("btnControl").setTouch(false); if (cc.fx.GameConfig.GM_INFO.hammerAmount < 1) { this.node.parent.parent.getChildByName("propWindow").active = true; cc.fx.AudioManager._instance.playEffect("tanchuang", null); let pauseNode = this.node.parent.parent.getChildByName("propWindow").getChildByName("prop"); pauseNode.scale = 0.3; cc.tween(pauseNode) .to(0.2, { scale: 1.05 }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 }, { easing: 'sineOut' }) .start(); this.node.parent.parent.parent.getComponent("SceneManager").openPropBuy("hammer"); } else { if (!this.hammer) { const timestamp = Date.now(); this.hammerMask.active = true; this.hammer = true; this.ishammer = true; cc.fx.GameConfig.GM_INFO.hammerAmount -= 1; if (cc.fx.GameConfig.GM_INFO.hammerAmount < 0) cc.fx.GameConfig.GM_INFO.hammerAmount = 0; this.setPropNum(); // this.hammerLabel.string = cc.fx.GameConfig.GM_INFO.hammerAmount.toString(); let propInfo = cc.fx.StorageMessage.getStorage("prop"); console.log("锤子道具信息:", propInfo); propInfo.hammerAmount = cc.fx.GameConfig.GM_INFO.hammerAmount; propInfo.timestamp = timestamp; cc.fx.StorageMessage.setStorage("prop", propInfo); cc.fx.GameTool.setUserProp(2002, cc.fx.GameConfig.GM_INFO.hammerAmount, (data) => { }) let data = { change_reason: "使用道具", id: "2002", num: -1 } cc.fx.GameTool.shushu_Track("resource_cost", data); } else MiniGameSdk.API.showToast("道具使用中,请稍后再试"); } } } buyMagic() { if (cc.fx.GameConfig.GM_INFO.coin < 900) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); this.node.parent.parent.parent.getComponent("SceneManager").resetBtn(); setTimeout(() => { this.openShop(); }, 500); return; } cc.fx.GameTool.buyProp(2003, this.handleBuySuccess.bind(this, "magicAmount")); } buyHammer() { if (cc.fx.GameConfig.GM_INFO.coin < 600) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); this.node.parent.parent.parent.getComponent("SceneManager").resetBtn(); setTimeout(() => { this.openShop(); }, 500); return; } cc.fx.GameTool.buyProp(2002, this.handleBuySuccess.bind(this, "hammerAmount")); } buyFreeze() { if (cc.fx.GameConfig.GM_INFO.coin < 600) { MiniGameSdk.API.showToast("金币不足,无法购买道具"); this.node.parent.parent.parent.getComponent("SceneManager").resetBtn(); setTimeout(() => { this.openShop(); }, 500); return; } cc.fx.GameTool.buyProp(2001, this.handleBuySuccess.bind(this, "freezeAmount")); } openShop() { const winCOIN = cc.find("Canvas"); // 假设 Canvas 节点 if (winCOIN) { const wincoin = winCOIN.getComponent(SceneManager); if (wincoin) { this.pause = true; wincoin.openShop(); } else { console.log("JiaZai 组件未找到"); } } else { console.log("JiaZai 节点未找到"); } } //使用魔法棒随机消除两个方块 useMagic() { //一秒之内只能点一次 if (this.lastMagicTime && Date.now() - this.lastMagicTime < 1200) { return; } this.lastMagicTime = Date.now(); if (this.magicMask.active == true || this.timeNumber <= 1 || this.gameOver || this.gameWin) { return; } let magicBtn = this.node.parent.getChildByName("Bottom").getChildByName("magicBtn"); if (magicBtn.getComponent("btnControl")._touch) { magicBtn.getComponent("btnControl").setTouch(false); if (cc.fx.GameConfig.GM_INFO.magicAmount < 1) { // if (cc.fx.GameConfig.GM_INFO.coin < 1500) { // MiniGameSdk.API.showToast("金币不足,无法购买道具"); // setTimeout(() => { // this.openShop(); // magicBtn.getComponent("btnControl").setTouch(true); // }, 500); // return; // } this.node.parent.parent.getChildByName("propWindow").active = true; cc.fx.AudioManager._instance.playEffect("tanchuang", null); let pauseNode = this.node.parent.parent.getChildByName("propWindow").getChildByName("prop"); pauseNode.scale = 0.3; cc.tween(pauseNode) .to(0.2, { scale: 1.05 }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 }, { easing: 'sineOut' }) .start(); this.node.parent.parent.parent.getComponent("SceneManager").openPropBuy("magic"); // MiniGameSdk.API.showToast("魔法棒数量不足,自动购买魔法棒"); } else { const timestamp = Date.now(); this.magicMask.active = true; setTimeout(() => { this.magicMask.active = false; magicBtn.getComponent("btnControl").setTouch(true); }, 1000); //魔法棒 this.ismagic = true; this.magics.active = true; this.magics.scale = 1; const path = [ { "x": -522.8444229452174, "y": -758.2125792877125, "z": 0 }, { "x": -499.7565369594692, "y": -775.5284937770236, "z": 0 }, { "x": -488.2125939665951, "y": -784.1864510216792, "z": 0 }, { "x": -447.8087934915357, "y": -789.9584225181162, "z": 0 }, { "x": -407.4049930164763, "y": -798.6163797627719, "z": 0 }, { "x": -355.4572495485428, "y": -810.1603227556459, "z": 0 }, { "x": -271.76366285020555, "y": -821.70426574852, "z": 0 }, { "x": -199.61401914474237, "y": -821.70426574852, "z": 0 }, { "x": -101.49050370531245, "y": -821.70426574852, "z": 0 }, { "x": -23.568888503412154, "y": -821.70426574852, "z": 0 }, { "x": 37.0368122091769, "y": -815.932294252083, "z": 0 }, { "x": 88.9845556771104, "y": -801.5023655109903, "z": 0 }, { "x": 129.38835615216976, "y": -775.5284937770236, "z": 0 }, { "x": 178.4501138718847, "y": -752.4406077912754, "z": 0 }, { "x": 215.9679285987255, "y": -738.0106790501827, "z": 0 }, { "x": 244.82778608091087, "y": -723.5807503090901, "z": 0 }, { "x": 267.915672066659, "y": -703.3788500715605, "z": 0 }, { "x": 316.97742978637405, "y": -683.1769498340307, "z": 0 }, { "x": 348.72327301677785, "y": -662.9750495965011, "z": 0 }, { "x": 360.26721600965186, "y": -648.5451208554084, "z": 0 }, { "x": 374.69714475074454, "y": -625.4572348696602, "z": 0 }, { "x": 386.24108774361866, "y": -605.2553346321305, "z": 0 }, { "x": 389.1270734918372, "y": -587.9394201428194, "z": 0 }, { "x": 394.8990449882742, "y": -561.9655484088526, "z": 0 }, { "x": 400.67101648471134, "y": -521.5617479337932, "z": 0 }, { "x": 406.44298798114835, "y": -478.2719617105153, "z": 0 }, { "x": 406.44298798114835, "y": -434.98217548723744, "z": 0 }, { "x": 406.44298798114835, "y": -397.4643607603965, "z": 0 }, { "x": 403.5570022329298, "y": -359.9465460335557, "z": 0 }, { "x": 394.8990449882742, "y": -328.2007028031519, "z": 0 }, { "x": 386.24108774361866, "y": -299.34084532096665, "z": 0 }, { "x": 377.5831304989631, "y": -264.7090163423443, "z": 0 }, { "x": 360.26721600965186, "y": -227.19120161550347, "z": 0 }, { "x": 340.0653157721222, "y": -198.33134413331823, "z": 0 }, { "x": 308.31947254171837, "y": -163.69951515469586, "z": 0 }, { "x": 270.80165781487756, "y": -137.72564342072906, "z": 0 }, { "x": 236.1698288362552, "y": -126.18170042785505, "z": 0 }, { "x": 187.10807111654026, "y": -117.52374318319937, "z": 0 }, { "x": 138.04631339682533, "y": -117.52374318319937, "z": 0 }, { "x": 112.07244166285852, "y": -117.52374318319937, "z": 0 }, { "x": 94.7565271735474, "y": -117.52374318319937, "z": 0 }, { "x": 83.21258418067328, "y": -126.18170042785505, "z": 0 }, { "x": 54.35272669848803, "y": -146.38360066538473, "z": 0 }, { "x": 39.922797957395346, "y": -155.0415579100403, "z": 0 }, { "x": 28.378854964521338, "y": -169.47148665113286, "z": 0 }, { "x": 19.72089771986566, "y": -189.67338688866255, "z": 0 }, { "x": 13.948926223428657, "y": -215.64725862262935, "z": 0 }, { "x": 13.948926223428657, "y": -232.96317311194048, "z": 0 }, { "x": 13.948926223428657, "y": -253.16507334947016, "z": 0 } ] // 转换为 cc.v3 数组 const pts = path.map(point => cc.v3(point.x, point.y, point.z)); const totalDur = 0.8; // 总时长 const smoothPts = this.getSmoothPath(pts, 10); // // this.magics.setPosition(smoothPts[0]); let totalLen = 0; let lens: number[] = []; // 1. 先把节点/粒子立即隐藏并复位 this.magics.stopAllActions(); // 立即停止旧动画 this.magics.setPosition(smoothPts[0]); // 必须在一开始就先放到起点 this.magics.active = true; // 保证节点可见 this.magics.children[0].children[2].active = false; // 先关粒子 this.magics.children[0].children[3].active = false; for (let i = 1; i < smoothPts.length; i++) { const len = smoothPts[i].sub(smoothPts[i - 1]).mag(); lens.push(len); totalLen += len; } // 1. 立即停止并清零粒子 const p1 = this.magics.children[0].children[2].getComponent(cc.ParticleSystem); const p2 = this.magics.children[0].children[3].getComponent(cc.ParticleSystem); p1 && p1.stopSystem(); // true 表示立即清零 p2 && p2.stopSystem(); // 2. 把节点放到起点 this.magics.stopAllActions(); this.magics.setPosition(smoothPts[0]); // 3. 下一帧再重新播放 this.scheduleOnce(() => { p1 && p1.resetSystem(); // 重置到初始状态再播放 p2 && p2.resetSystem(); this.magics.children[0].children[2].active = true; this.magics.children[0].children[3].active = true; // 4. tween 动画 let t = cc.tween(this.magics); for (let i = 1; i < smoothPts.length; i++) { const segDur = totalDur * (lens[i - 1] / totalLen); t = t.to(segDur, { position: smoothPts[i] }); } t.delay(0.5).call(() => { p1 && p1.stopSystem(); // 结束后再停 p2 && p2.stopSystem(); this.magics.children[0].children[2].active = false; this.magics.children[0].children[3].active = false; }).to(0.15, { scale: 0 }) .call(() => { this.magics.setPosition(-900, -700, 0); this.magics.active = false; }) .start(); }, 0); cc.fx.GameConfig.GM_INFO.magicAmount -= 1; if (cc.fx.GameConfig.GM_INFO.magicAmount < 0) cc.fx.GameConfig.GM_INFO.magicAmount = 0; this.setPropNum(); // this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString(); let propInfo = cc.fx.StorageMessage.getStorage("prop"); if (propInfo) { propInfo.magicAmount = cc.fx.GameConfig.GM_INFO.magicAmount; propInfo.timestamp = timestamp; cc.fx.StorageMessage.setStorage("prop", propInfo); cc.fx.GameTool.setUserProp(2003, cc.fx.GameConfig.GM_INFO.magicAmount, (data) => { }) let data = { change_reason: "使用道具", id: "2003", num: -1 } cc.fx.GameTool.shushu_Track("resource_cost", data); } let nomalArray = []; // this.magicBtn.node.active = false; for (let i = 0; i < this.blocks.length; i++) { // console.log("方块类型",this.blocks[i].getComponent("Block").type); if (this.blocks[i].getComponent("Block").type == 3) { this.loackArray.push(this.blocks[i]); } else if (this.blocks[i].getComponent("Block").type == 4) { this.freezeArray.push(this.blocks[i]); } else if (this.blocks[i].getComponent("Block").type == 10) { if (this.blocks[i].getComponent("Block").block_Info.node) { nomalArray.push(this.blocks[i].getComponent("Block").block_Info.node); } // else nomalArray.push(this.blocks[i]); } else { if (!this.blocks[i].getComponent("Block").isEliminatedByHammer) { // 只有未被锤子标记的方块才加入魔棒消除数组 nomalArray.push(this.blocks[i]); } } } if (nomalArray.length > 1) { nomalArray = cc.fx.GameTool.shuffleArray(nomalArray); nomalArray[0].getComponent("Block").eliminate(); let time = 0; if (nomalArray[0].getComponent("Block").type == 1 || nomalArray[0].getComponent("Block").type == 9) { time = 200; } nomalArray[1].getComponent("Block").eliminate(); // if (time > 0) { // setTimeout(() => { // nomalArray[1].getComponent("Block").eliminate(); // }, time); // return; // } // else { // nomalArray[1].getComponent("Block").eliminate(); // return; // } } else if (nomalArray.length == 1) { nomalArray[0].getComponent("Block").eliminate(); let time = 0; if (nomalArray[0].getComponent("Block").type == 1 || nomalArray[0].getComponent("Block").type == 9) { time = 200; } setTimeout(() => { if (this.freezeArray.length == 0 && this.loackArray.length == 0) { // console.log("只剩下一个块道具使用完毕"); } else { if (this.loackArray.length != 0) { // console.log("消除一个普通块后,消除一个带锁块"); this.loackArray[0].getComponent("Block").eliminate(); return; } else if (this.freezeArray.length != 0) { // console.log("消除一个普通块后,消除一个冻结块"); this.freezeArray[0].getComponent("Block").eliminate(); return; } } }, 200 + time); } else { let count = 2; if (this.loackArray.length != 0) { for (let i = 0; i < this.loackArray.length; i++) { // console.log("没有普通快,魔法消除一个带锁块"); this.loackArray[i].getComponent("Block").eliminate(); count -= 1; if (count == 0) { break; } } } setTimeout(() => { if (count != 0) { for (let i = 0; i < this.freezeArray.length; i++) { // console.log("没有普通快,魔法消除一个冻结块"); // this.freezeArray[i].getComponent("Block").eliminate(); count -= 1; if (count == 0) { break; } } } }, 100); } } } } //按下暂停按钮 usePause() { if (this.pause) { this.pause = false; this.startBoom(); } else { this.pause = true; this.stopBoom(); } } //根据关卡设置地图大小 setMapInfo() { let width = 0; if (this.mapWidth < 10) { width = 0.2; } else if (this.mapWidth < 17) { width = 0.15 - (this.mapWidth - 11) * 0.01; } this.node.scale = 1.6 + (6 - this.mapWidth) * width; if (this.mapWidth == 8 && this.mapHeight > 13) { this.node.scale = 1; } // this.node.scale = 1; cc.fx.GameConfig.GM_INFO.scale = this.node.scale; // this.node.scale = 0.5; // console.log(this.node.scale); // this.node.scale = 1; } //创建门的粒子特效 createParticle(block, jg) { let particle = cc.instantiate(MapConroler._instance.Block_Prop[9]); particle.parent = this.node; particle.zIndex = 1000; let width = Math.floor(block.width / 120); let height = Math.floor(block.height / 120); let name = ""; if (jg == 0 || jg == 1) { let y = block.y + block.height; let x = block.x - block.width / 2; name = "top_" + width + "_" + height; if (jg == 1) { name = "bot_" + width + "_" + height; y = block.y; } if (block.anchorX == 0.5) { x = block.x; } else if (block.anchorX == 0.33) { x = block.x + block.width * (0.5 - 0.33); } else if (block.anchorX == 0.66) { x = block.x + block.width * (0.5 - 0.66); } particle.setPosition(x, y); } else if (jg == 2 || jg == 3) { name = "left_" + height + "_" + width; let x = block.x - block.width; let y = block.y + block.height / 2; if (block.anchorX == 0.5) { x = block.x - block.width / 2; } else if (block.anchorX == 0.33) { x = block.x - block.width * 0.33; } else if (block.anchorX == 0.66) { x = block.x - block.width * 0.66; } if (jg == 3) { name = "right_" + height + "_" + width; x = block.x; if (block.anchorX == 0.5) { x = block.x + block.width / 2; } else if (block.anchorX == 0.33) { x = block.x + block.width * 0.66; } else if (block.anchorX == 0.66) { x = block.x + block.width * 0.33; } } particle.setPosition(x, y); } let particleNode = particle.getChildByName(name); let color = block.getComponent("Block").color - 1; particleNode.getComponent(cc.ParticleSystem).spriteFrame = particle.getComponent("Reduce").Block_Color[color]; particleNode.active = true; setTimeout(() => { cc.tween(particle) .to(2, { opacity: 0 }) .call(() => { particle.destroy(); }) .start(); }, 1200); } removeOneBlock() { // 移除所有方块 for (let i = 0; i < this.blocks.length; i++) { if (this.blocks[i].opacity == 0) { this.blocks[i].destroy(); this.blocks.splice(i, 1); } } } startBoom() { for (let i = 0; i < this.blocks.length; i++) { if (this.blocks[i].getComponent("Block").type == 6) { this.blocks[i].getChildByName("boom").getComponent("Boom").startBoom(); } } } stopBoom() { for (let i = 0; i < this.blocks.length; i++) { if (this.blocks[i].getComponent("Block").type == 6) { this.blocks[i].getChildByName("boom").getComponent("Boom").stopBoom(); } } } getSmoothPath(pts: cc.Vec3[], radius = 10): cc.Vec3[] { if (pts.length < 3) return pts.slice(); const smoothPts: cc.Vec3[] = [pts[0]]; for (let i = 1; i < pts.length - 1; i++) { const prev = pts[i - 1]; const curr = pts[i]; const next = pts[i + 1]; // 方向向量 const dir1 = curr.sub(prev).normalize(); const dir2 = next.sub(curr).normalize(); // 计算前后过渡点 const before = curr.sub(dir1.mul(radius)); const after = curr.add(dir2.mul(radius)); smoothPts.push(before); smoothPts.push(curr); smoothPts.push(after); } smoothPts.push(pts[pts.length - 1]); return smoothPts; } startHammer(pos: cc.Vec3) { this.hammerAni.active = true; this.hammerAni.scale = 1; // this.hammerAni.position = cc.v3(-116, -800); this.hammerAni.setPosition(pos); this.hammerAni.zIndex = 1000; this.hammerAni.getComponent(sp.Skeleton).setAnimation(0, "animation", false); //播放结束后消失 this.hammerAni.getComponent(sp.Skeleton).setCompleteListener(() => { cc.tween(this.hammerAni).to(0.1, { scale: 0 }).call(() => { this.hammerAni.active = false; }).start(); }) } //判断方块是否可以正常通过门 blockCanPass(block, wall) { let jg = false; let heng = block.getComponent("Block").heng; let shu = block.getComponent("Block").shu; let direction = wall.node.parent.name; if (direction == "left" || direction == "right") { if (wall.wall_Info.length >= shu) { jg = true; } } else { if (wall.wall_Info.length >= heng) { jg = true; } } if (!jg) { console.log("普通快:不可通过"); } return jg; } //判断方块是否是可移动类型 blockCanMove(block) { if (block.getComponent("Block").type == 10 || block.getComponent("Block").type == 3 || block.getComponent("Block").type == 4) { return false; } return true; } //提前判断游戏结束 predict_End() { //return true; console.log("提前判断游戏结束"); if (this.gameOver || this.gameWin) { return true; } let result = false; for (let i = 0; i < this.blocks.length; i++) { //确保方块是可移动状态下再做判断 if (this.blockCanMove(this.blocks[i])) { let color = this.blocks[i].getComponent("Block").color; for (let j = 0; j < this.wall_Pass.length; j++) { //如果颜色相同 if (this.wall_Pass[j].color == color) { //星星块特殊判断 if (this.blocks[i].getComponent("Block").type == 5) { console.log("星星块,判断是否可通行"); if (this.wall_Pass[j].special == 1) { console.log("星星门,可通行"); result = this.blockCanPass(this.blocks[i], this.wall_Pass[j]); if (result == true) return result; } else { console.log("普通门,不可通行"); continue; } } else { if (this.wall_Pass[j].special == 2) { if (this.wall_Pass[j].open == true) { console.log("开关门并且开着"); result = this.blockCanPass(this.blocks[i], this.wall_Pass[j]); if (result == true) return result; } else { console.log("开关门并且关着,________不可通行"); continue; } } else if (this.wall_Pass[j].special == 3) { console.log("冻结门,不可通行"); continue; } else { console.log("普通门,判断是否可通行"); result = this.blockCanPass(this.blocks[i], this.wall_Pass[j]); if (result == true) return result; } } } } } } return result; } //结算界面 Settlement() { cc.fx.AudioManager._instance.playEffect("win", null) //获取this.gameOverNode所有子节点的位置 let child = this.gameOverNode; for (let i = 0; i < this.gameOverNode.childrenCount; i++) { //记录每个节点的位置 const p = child.children[i].position; this.arr[i] = [p.x, p.y, p.z]; } let title = this.gameOverNode.getChildByName("gongxi"); let homeBtn = this.gameOverNode.getChildByName("homeBtn"); let nextBtn = this.gameOverNode.getChildByName("nextBtn"); let tiaodik = this.gameOverNode.getChildByName("tiaodik"); let pian = this.gameOverNode.getChildByName("pian"); let guang = this.gameOverNode.getChildByName("guang"); let coins4 = this.gameOverNode.getChildByName("coins4"); let caidai = this.gameOverNode.getChildByName("caidai"); // 初始化所有元素为隐藏状态 title.active = false; homeBtn.active = false; nextBtn.active = false; tiaodik.active = false; pian.active = false; guang.active = false; coins4.active = false; caidai.active = false; console.log(this.arr, "this.arr"); // 第一步:播放 title - 果冻弹跳效果 cc.tween(title) .to(0, { scale: 0, position: cc.v3(0, 0, 0) }) .call(() => { title.active = true; //播放速度减慢一倍 const anim = title.getChildByName("cai").getComponent(cc.Animation); anim.defaultClip.speed = 0.5; // 全局默认速度 anim.play(); // 开始播放 }) .to(0.12, { scale: 1.2 }, { easing: 'quadOut' }) .to(0.08, { scale: 0.85 }, { easing: 'quadIn' }) .to(0.06, { scale: 1.1 }, { easing: 'quadOut' }) .to(0.04, { scale: 1 }, { easing: 'quadIn' }) .delay(0.1) .to(0.4, { x: this.arr[0][0], y: this.arr[0][1], z: this.arr[0][2] }) .call(() => { this.playButtonGroup(); }) .start(); } // 播放按钮组动画 playButtonGroup() { let homeBtn = this.gameOverNode.getChildByName("homeBtn"); let nextBtn = this.gameOverNode.getChildByName("nextBtn"); let tiaodik = this.gameOverNode.getChildByName("tiaodik"); cc.tween(homeBtn) // .to(0, { position: cc.v3(0, -680, 0), scale: 0 }) .call(() => { homeBtn.active = true; }) .to(0.15, { scale: 1.25 }, { easing: 'backOut' }) .to(0.08, { scale: 0.9 }, { easing: 'quadIn' }) .to(0.06, { scale: 1.15 }, { easing: 'quadOut' }) .to(0.04, { scale: 1 }, { easing: 'quadIn' }) // .to(0.3 / 2, { position: cc.v3(this.arr[6][0], this.arr[6][1], this.arr[6][2]) }) .start(); cc.tween(nextBtn) .delay(0.1) //.to(0, { position: cc.v3(0, -880, 0), scale: 0 }) .call(() => { if (cc.fx.GameConfig.GM_INFO.otherLevel == 0) { nextBtn.active = true; } else { cc.fx.GameConfig.GM_INFO.otherLevel = 0; cc.fx.GameConfig.GM_INFO.otherUid = ""; } }) .to(0.15, { scale: 1.25 }, { easing: 'backOut' }) .to(0.08, { scale: 0.9 }, { easing: 'quadIn' }) .to(0.06, { scale: 1.15 }, { easing: 'quadOut' }) .to(0.04, { scale: 1 }, { easing: 'quadIn' }) .call(() => { this.playDecorationGroup(); }) // .to(0.3 / 2, { position: cc.v3(this.arr[5][0], this.arr[5][1], this.arr[5][2]) }) .start(); // tiaodik 动画(再延迟一点 cc.tween(tiaodik) .delay(0.2) // .to(0, { position: cc.v3(0, -1080, 0), scale: 0 }) .call(() => { tiaodik.active = true; }) .to(0.15, { scale: 1.25 }, { easing: 'backOut' }) .to(0.08, { scale: 0.9 }, { easing: 'quadIn' }) .to(0.06, { scale: 1.15 }, { easing: 'quadOut' }) .to(0.04, { scale: 1 }, { easing: 'quadIn' }) // .to(0.3 / 2, { position: cc.v3(this.arr[4][0], this.arr[4][1], this.arr[4][2]) }) .start(); } // 播放装饰元素动画 playDecorationGroup() { let pian = this.gameOverNode.getChildByName("pian"); let guang = this.gameOverNode.getChildByName("guang"); let coins4 = this.gameOverNode.getChildByName("coins4"); let caidai = this.gameOverNode.getChildByName("caidai"); let diguan = this.gameOverNode.getChildByName("diguan"); // caidai 先播放骨骼动画 cc.tween(caidai) .to(0, { scale: 2 }) .call(() => { caidai.active = true; caidai.getComponent(sp.Skeleton).setAnimation(0, "animation", false); caidai.getComponent(sp.Skeleton).setCompleteListener(() => { caidai.active = false; }); }) .start(); // pian 动画(稍微延迟 cc.tween(pian) .delay(0.05) .to(0, { scale: 0 }) .call(() => { pian.active = true; }) .to(0.3, { scale: 3.6 }) .call(() => { pian.active = false; }) .start(); // guang 动画(再延迟一点) cc.tween(guang) .delay(0.1) .to(0, { scale: 0 }) .call(() => { guang.active = true; }) .to(0.3, { scale: 1 }) .start(); // coins4 动画(最后播放) cc.tween(coins4) .delay(0.15) .to(0, { scale: 0 }) .call(() => { coins4.active = true; }) .to(0.2, { scale: 2.2 }, { easing: 'backOut' }) .to(0.12, { scale: 1.8 }, { easing: 'quadIn' }) .to(0.08, { scale: 2.1 }, { easing: 'quadOut' }) .to(0.06, { scale: 2 }, { easing: 'quadIn' }) .start(); // diguan 动画 cc.tween(diguan) .delay(0.3) .to(0.15, { scale: 2.15 }, { easing: 'backOut' }) .to(0.08, { scale: 1.9 }, { easing: 'quadIn' }) .to(0.06, { scale: 2.05 }, { easing: 'quadOut' }) .to(0.04, { scale: 2 }, { easing: 'quadIn' }) .start(); } setOtherLevel() { if (cc.fx.GameConfig.GM_INFO.otherLevel > 0) { console.log("帮助他人通关"); let level = cc.fx.GameConfig.GM_INFO.otherLevel; let uid = cc.fx.GameConfig.GM_INFO.otherUid; let eventData = { identity: "helper", //发起者为helped 帮助者为helper level: level, //被帮助关卡等级 success: true, //是否成功 } cc.fx.GameTool.shushu_Track("stage_help", eventData); //帮助通关 Utils.shareLevel(level, uid, (data) => { console.log("分享结果:", data); }); } } iceTrue() { if (this.node.parent.getChildByName("Ice").active == true || this.timeNumber <= 1 || this.gameOver || this.gameWin) { return true; } else { return false; } } update(dt) { } }