cb/assets/Script/Wall.ts
2026-04-01 19:49:10 +08:00

1627 lines
71 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ============================================
// Wall.ts - 墙壁/门组件脚本
// 负责游戏中墙壁和门的创建、显示、状态管理
// 包括:普通门、星星门、开关门、冻结门、旋转门、上锁门、跳跃门、延伸伸缩门、带色旋转门
// ============================================
import MapConroler from "./Map";
import NumberToImage from "./NumberToImage";
const { ccclass, property } = cc._decorator;
// ============================================
// 枚举定义 - 门的特殊类型
// ============================================
export enum WallSpecial {
/*普通门 - 最基础的门,方块可以消除在上面*/
"普通门" = 0,
/*星星门 - 需要集齐星星才能打开的门*/
"星星门" = 1,
/*开关门 - 需要对应开关触发的门*/
"开关门" = 2,
/*冻结门 - 会冻结方块一段时间的门*/
"冻结门" = 3,
/*旋转门顺时针 - 会顺时针旋转的门*/
"旋转门顺时针" = 4,
/*旋转门逆时针 - 会逆时针旋转的门*/
"旋转门逆时针" = 5,
/*上锁门 - 需要钥匙或特定条件才能打开的门*/
"上锁门" = 6,
/*跳格门 - 方块消除后会跳到指定位置的门*/
"跳格门" = 7,
/*延伸伸缩门 - 可以伸缩长度的门*/
"延伸伸缩门" = 9,
/*顺时针带色门 - 顺时针旋转且有渐变颜色的门*/
"顺时针带色门" = 10,
/*逆时针带色门 - 逆时针旋转且有渐变颜色的门*/
"逆时针带色门" = 11,
}
// ============================================
// 枚举定义 - 墙或门的方向类型
// ============================================
export enum WallType {
/*横向向下的门*/
"门横向下" = 0,
/*横向向上的门*/
"门横向上" = 1,
/*竖向向右的门*/
"门竖向右" = 2,
/*竖向向左的门*/
"门竖向左" = 3,
/*横向向下的墙*/
"墙横向下" = 4,
/*横向向上的墙*/
"墙横向上" = 5,
/*竖向向右的墙*/
"墙竖向右" = 6,
/*竖向向左的墙*/
"墙竖向左" = 7,
}
// ============================================
// 枚举定义 - 门的颜色
// ============================================
export enum WallColor {
/*紫色门 - 需要紫色方块消除*/
"紫色" = 0,
/*黄色门 - 需要黄色方块消除*/
"黄色" = 1,
/*绿色门 - 需要绿色方块消除*/
"绿色" = 2,
/*蓝色门 - 需要蓝色方块消除*/
"蓝色" = 3,
/*粉色门 - 需要粉色方块消除*/
"粉色" = 4,
/*橘黄色门 - 需要橘黄色方块消除*/
"橘黄色" = 5,
/*青色门 - 需要青色方块消除*/
"青色" = 6,
/*白色门 - 需要白色方块消除*/
"白色" = 7,
/*红色门 - 需要红色方块消除*/
"红色" = 8,
/*灰色门 - 需要灰色方块消除*/
"灰色" = 9,
/*暗色门 - 特殊暗色门*/
"暗" = 10,
/*默认色门 - 默认颜色*/
"默认色" = 11,
/*延伸伸缩门专用颜色*/
"延伸伸缩门" = 30,
}
// ============================================
// Wall类 - 墙壁/门的主要逻辑组件
// ============================================
@ccclass
export default class Wall extends cc.Component {
// ============================================
// Cocos Creator 属性定义
// ============================================
/*显示门/墙上数字的Label组件*/
@property(cc.Label)
number: cc.Label = null;
/*墙或门的方向枚举属性,编辑器中可选择*/
@property({
tooltip: '墙或者门的方向',
type: cc.Enum(WallType),
})
type: WallType = WallType.;
/*门的特殊类型枚举属性,如普通门、星星门、开关门等*/
@property({
tooltip: '墙或者门的方向',
type: cc.Enum(WallSpecial),
})
special: WallSpecial = WallSpecial.;
/*门的颜色枚举属性,决定什么颜色的方块可以消除*/
@property({
tooltip: '门的颜色',
type: cc.Enum(WallColor),
})
color: WallColor = WallColor.;
/*遮罩节点 - 用于显示变色门的颜色渐变效果*/
@property(cc.Node)
maskNode: cc.Node = null;
/*遮罩宽度 - 变色门遮罩的宽度*/
@property(cc.Float)
maskWidth: number = 138;
/*遮罩高度 - 变色门遮罩的高度*/
@property(cc.Float)
maskHeight: number = 69;
/*墙壁的精灵图集 - 包含门的各种颜色和长度样式*/
@property(cc.SpriteAtlas)
wall_SpriteFrames: cc.SpriteAtlas = null;
/*门下方的精灵图集 - 门的下半部分样式*/
@property(cc.SpriteAtlas)
down_SpriteFrames: cc.SpriteAtlas = null;
/*伸缩障碍杆的精灵帧 - 延伸伸缩门使用的图标*/
@property(cc.SpriteFrame)
stickSpriteFrame: cc.SpriteFrame = null;
/*冻结特效的预制体 - 冻结门上的冰晶特效*/
@property(cc.Prefab)
freezeSpine: cc.Prefab = null;
// ============================================
// 成员变量定义
// ============================================
/*门在地图网格中的X坐标 - 用于定位和碰撞检测*/
posX: number;
/*门在地图网格中的Y坐标 - 用于定位和碰撞检测*/
posY: number;
/*门的朝向方向 - 取值up/down/left/right及各种组合方向*/
direction: any;
/*门的配置信息 - 从JSON读取的完整门配置数据*/
wall_Info: any;
/*同组门的数组 - 一组相关的门(如同一条线路上的多个门)*/
teamDoors: any;
/*开关门的开关节点 - 用于显示开关门是开启还是关闭状态*/
openNode: cc.Node;
/*旋转门的旋转节点 - 旋转门特效的父节点*/
revolvingNode: cc.Node;
/*带色旋转门的颜色渐变节点 - 显示颜色从一端到另一端的渐变效果*/
revolvingColorNode: cc.Node;
/*跳跃门的跳跃目标节点 - 标记方块消除后会跳到哪里*/
jumpNode: cc.Node;
/*冻结门的冻结数字显示节点 - 显示还需要冻结多少步*/
freezeNode: cc.Node;
/*开关门是否开启的状态标志 - true表示门开着false表示门关着*/
open: boolean;
/*冻结门的剩余冻结步数 - 方块踩上去会被冻结的步数*/
freezeNumber: number;
/*门的编号 - 用于标识和查找特定的门*/
num: number;
/*向左移动的动画tween对象 - 用于播放向左伸展的动画*/
leftTween: any;
/*向右移动的动画tween对象 - 用于播放向右伸展的动画*/
rightTween: any;
/*变色门的颜色数组 - 存储颜色变化顺序,如[1,2,3]表示从黄色变到绿色再变到蓝色*/
colorArray: any;
/*变色门颜色的初始数组 - 记录原始颜色顺序,用于重置*/
colorStartArray: any;
/*变色门颜色数组的长度 - 记录有几种颜色在变化*/
colorLength: number = 0;
/*门的实时长度 - 会随着长短门变化而改变的值*/
realLength: number = 0;
/*长短变化门的配置数组 - 如[1,3]表示在1和3之间切换长度*/
longAndShort: number[] = [];
/*长短门的变化顺序标志 - true为正序false为逆序*/
order: boolean = true;
/*门的基础长度 - 门的原始设计长度*/
length: number = 0;
/*特殊门类型的备份 - 备份原始的特殊类型(不包含旋转门)*/
specialBackup: any;
/*长短变化门的颜色 - 长短门变化时显示的特效颜色*/
longAndShortColor: any = null;
/*可以伸缩障碍的块数组 - 延伸伸缩门前方会被顶起来的方块列表*/
stickBlock: any = [];
/*跳跃门的配置信息 - 记录跳跃门跳格的数量和方向*/
jump: any;
/*旋转门自带的颜色值 - 用于带色旋转门记录原本的颜色*/
revolvingColor: 0;
/*门的基础颜色 - 记录门的原始颜色,用于恢复*/
baseColor: WallColor;
/*标志位:是否已为旋转门设定过长度 - 防止重复设置*/
addPos: boolean = false;
// ============================================
// Cocos生命周期 - start方法
// 在组件第一次激活时调用,通常用于初始化
// ============================================
start() {
}
// ============================================
// JSON深拷贝方法
// 功能将对象转为JSON字符串再转回实现深拷贝完全独立的副本
// 用途:避免修改配置时影响原始数据
// ============================================
jsonDeepClone<T>(obj: T): T {
return JSON.parse(JSON.stringify(obj));
}
// ============================================
// 门的初始化方法
// 功能:初始化门的各种属性和状态,包括方向、特殊类型、颜色等
// 参数说明:
// - wall_Info: 门的配置信息对象,包含类型、颜色、长度等
// - posX: 门在地图网格中的X坐标
// - posY: 门在地图网格中的Y坐标
// - direction: 门的朝向方向如up/down/left/right
// ============================================
init(wall_Info, posX: number, posY: number, direction: any) {
// 初始化变色门相关的数组
this.colorArray = [];
this.colorStartArray = [];
this.colorLength = 0;
// 深拷贝门的配置信息,保存门的原始数据
this.wall_Info = this.jsonDeepClone(wall_Info);
// 初始化跳跃门为null
this.jump = null;
// 初始化长短变化门的颜色为null
this.longAndShortColor = null;
// 清空可伸缩障碍的块数组
this.stickBlock = [];
// 根据wall_Info是否为null来判断是创建普通门还是特殊门
if (wall_Info == null) {
// 普通门的初始化
// 设置门在地图网格中的坐标
this.posX = posX;
this.posY = posY;
// 设置门的朝向方向
if (direction) this.direction = direction;
// 根据门的方向设置门的层级zIndex确保正确的遮挡关系
// 不同方向的门显示在不同的层级,避免相互遮挡
if (direction == "up") {
// 向上方向的门,层级 = 100 + posX - posY * 3
this.node.parent.zIndex = 100 + this.posX - this.posY * 3;
}
else if (direction == "down" || direction == "right") {
// 向下或向右的门,层级 = 20 + posX - posY * 3
this.node.parent.zIndex = 20 + this.posX - this.posY * 3;
}
else if (direction == "downleft" || direction == "downright" || direction == "rightup"
|| direction == "rightdown") {
// 斜向方向的门,层级 = 20 + posX - posY * 3
this.node.parent.zIndex = 20 + this.posX - this.posY * 3;
}
else if (direction == "left" || direction == "leftup" || direction == "upleft") {
// 向左或左上方向的门,层级 = 70 + posX - posY * 3
this.node.parent.zIndex = 70 + this.posX - this.posY * 3;
}
else if (direction == "leftdown" || direction == "upright") {
// 左下或右上方向的门,层级 = 100 + posX - posY * 3
this.node.parent.zIndex = 100 + this.posX - this.posY * 3;
}
else {
// 其他方向的门,层级 = 70 + posX - posY * 3
this.node.parent.zIndex = 70 + this.posX - this.posY * 3;
}
// 将地图网格上的方块标记为"墙",表示这个位置是墙不是普通地块
MapConroler._instance.mapBlocksWall[this.posX][this.posY].getComponent("MapBlock").block_Id = "Wall";
}
// 如果wall_Info不为null则是特殊门的初始化
if (wall_Info != null) {
// 重置长度添加标志位
this.addPos = false;
// 备份特殊门类型
this.specialBackup = 0;
// 设置门的颜色
this.color = this.wall_Info.color;
// 记录门的基础颜色
this.baseColor = this.color;
// 如果有旋转门颜色,则保存
if (this.wall_Info.revolvingColor != undefined) {
this.revolvingColor = this.wall_Info.revolvingColor;
}
// 如果是伸缩障碍杆特殊的门设置特殊颜色值30
if (this.wall_Info.stickLength) {
this.color = 30;
}
// 设置门的特殊类型
this.special = this.wall_Info.special;
// 备份特殊类型(但旋转门不备份)
if (this.special != WallSpecial. && this.special != WallSpecial.
&& this.special != WallSpecial. && this.special != WallSpecial.) {
this.specialBackup = this.special;
}
else {
this.special = this.wall_Info.special;
}
// 设置门的编号
this.num = this.wall_Info.num;
// 设置门的长度
this.length = this.wall_Info.length;
// 设置门的实时长度
this.realLength = this.wall_Info.length;
// 获取旋转门的节点
let name2 = "rotate" + this.wall_Info.length;
this.revolvingNode = this.node.parent.getChildByName("revolving").getChildByName(name2);
// 获取带色旋转门的颜色渐变节点
this.revolvingColorNode = this.node.parent.getChildByName("revolvingColor");
// 跳跃门初始化
if (this.wall_Info.jump != undefined) {
this.jumpInit();
}
else {
this.jump = null;
}
// 变色门初始化
if (this.wall_Info.colorArray) {
// 将颜色数组字符串转换为数字数组(+1是因为颜色值从1开始
this.colorArray = this.wall_Info.colorArray.split('').map(char => parseInt(char) + 1);
this.colorStartArray = this.wall_Info.colorArray.split('').map(char => parseInt(char) + 1);
this.colorLength = this.colorStartArray.length;
// 标记当前关卡有变色门
MapConroler._instance.changeColor = true;
// 将此门加入变色门数组
MapConroler._instance.colorDoors.push(this);
}
//旋转门层级初始化
if (this.revolvingNode) {
this.revolvingNode.parent.zIndex = 199;
this.revolvingNode.active = false;
}
//带底色旋转门层级初始化
if (this.revolvingColorNode) {
this.revolvingColorNode.zIndex = 200;
this.revolvingColorNode.active = false;
}
if (this.wall_Info.length > 0) {
if (!this.wall_Info.longAndShort) this.initColor(this.wall_Info.length, this.color);
}
else {
this.node.getComponent(cc.Sprite).spriteFrame = null;
}
if (this.posX != null) {
MapConroler._instance.mapBlocksWall[this.posX][this.posY].getComponent("MapBlock").block_Id = "Wall";
//console.log(this.posX,this.posY,MapConroler._instance.mapBlocksWall[this.posX][this.posY].getComponent("MapBlock").block_Id);
}
this.initType();
MapConroler._instance.wall_Pass.push(this);
// 长短变化的门
if (this.wall_Info.longAndShort) {
// console.log(this.node.uuid, this.wall_Info.length);
this.longAndShort = this.wall_Info.longAndShort.toString().split('').map(Number);
this.order = this.wall_Info.order;
if (this.wall_Info.colorChange != undefined && this.wall_Info.colorChange != null) {
MapConroler._instance.changeWallColor = true;
this.longAndShortColor = this.wall_Info.colorChange + 1;
if (this.wall_Info.length > 0) {
if (this.direction == "down") {
this.node.parent.zIndex = 20 + this.posX - this.posY * 3 + 3;
}
else if (this.direction == "right") {
this.node.parent.zIndex = 20 + this.posX - (this.posY - 0) * 3;
}
else if (this.direction == "up") {
this.node.parent.zIndex = 100 + this.posX - this.posY * 3 + 3;
}
else if (this.direction == "left") {
this.node.parent.zIndex = 70 + this.posX - (this.posY - 0) * 3;
}
this.maskNode.active = true;
if (this.longAndShortColor) this.setLongAndShortColor(this.longAndShortColor, null);
//console.log("长的变身颜色", this.node.uuid, this.node.parent.zIndex);
}
}
}
}
// setTimeout(() => {
// this.node.getChildByName("num").getComponent(cc.Label).string = ":" + this.node.parent.zIndex;
// }, 1000);
}
// ============================================
// 设置门的组合(组队)
// 功能:将相关的门分到同一组,用于管理如长短门、连续门等需要协同工作的门
// 参数说明:
// - over: boolean类型表示是否是这组门的最后一个
// 逻辑说明:
// - 如果门有长度>0先调用setLongAndShort()处理长短门
// - 然后将门加入全局teamDoors数组
// - 同时维护自身的teamDoors引用
// - 如果是最后一个门over==true再次调用setLongAndShort()完成设置
// ============================================
setTeamDoors(over) {
// 如果门有长度>0先处理长短门的初始化并清空全局teamDoors数组
if (this.wall_Info.length > 0) {
this.setLongAndShort();
MapConroler._instance.teamDoors = [];
}
// 将此门加入全局teamDoors数组
MapConroler._instance.teamDoors.push(this);
// 同步维护自身的teamDoors引用
this.teamDoors = MapConroler._instance.teamDoors;
// 如果是这组门的最后一个,完成长短门的最终设置
if (over == true) {
this.setLongAndShort();
}
}
// ============================================
// 创建门的颜色显示
// 功能根据门的颜色和长度设置门的外观包括icon和down两部分
// 参数说明:
// - length: 门的长度,决定使用哪种长度的精灵图
// - color: 门的颜色值如果不传则使用门自身的color属性
// 特殊说明:
// - 当color为30时表示是延伸伸缩门使用特殊的stickSpriteFrame
// - 左右方向的门left/right需要额外的double偏移量3
// ============================================
initColor(length: number, color: number) {
// 获取门的方向up/down/left/right
let direction = this.node.parent.name;
// 左右方向的门需要额外偏移3
let double = 0;
if (direction == "left" || direction == "right") {
double = 3;
}
// 如果没有传颜色参数,使用门自身的颜色
let colorTip = color || this.color;
// 伸缩门颜色特殊处理color==30表示伸缩门
if (colorTip == 30) {
// 设置伸缩门的icon和down的精灵图
if (this.node.getChildByName("icon")) this.node.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.stickSpriteFrame;
this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = this.stickSpriteFrame;
}
else {
// 普通门的颜色处理
if (this.wall_SpriteFrames) {
// 拼接精灵图名称,格式:颜色+ "color" + 长度
let name = colorTip + "color" + (length + double);
var spriteFrame = this.wall_SpriteFrames._spriteFrames[name];
// 设置门本身的精灵图
if (this.node.getComponent(cc.Sprite)) this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
// 设置icon的精灵图
if (this.node.getChildByName("icon")) this.node.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
}
// 设置门下方down的精灵图
if (this.down_SpriteFrames) {
// 拼接精灵图名称,格式:颜色+ "down" + 长度
let name2 = colorTip + "down" + (length + double);
var downFrame = this.down_SpriteFrames._spriteFrames[name2];
this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = downFrame;
}
}
}
// ============================================
// 创建特殊类型门的视觉表现
// 功能根据门的special类型创建对应的视觉效果和节点
// 特殊门类型说明:
// - 星星门:显示星星图标,需要根据门长度激活对应数量的星星
// - 开关门显示开关把手根据open状态显示开启/关闭
// - 冻结门:显示冰冻数字,显示剩余冻结步数
// - 旋转门:显示旋转动画节点
// - 带色旋转门:显示颜色渐变效果
// - 上锁门:显示锁图标
// - 延伸伸缩门:显示伸缩杆和进度条
// ============================================
initType() {
switch (this.special) {
case WallSpecial.星星门:
let star = cc.instantiate(MapConroler._instance.Block_Prop[this.special]);
star.parent = this.node.parent;
// console.log("门的方向",this.direction,"长度",this.wall_Info.length);
// star.scaleX = star.scaleY = 0.5;
if (this.wall_Info.length > 0) {
if (this.direction == "right" || this.direction == "left") {
star.children[this.wall_Info.length + 2].active = true;
}
else if (this.direction == "up" || this.direction == "down") {
star.children[this.wall_Info.length - 1].active = true;
}
}
star.setPosition(this.node.width / 2 + this.node.x, this.node.height / 2 + this.node.y);
break;
case WallSpecial.开关门:
let name = "open" + this.wall_Info.length;
this.openNode = this.node.parent.getChildByName("open").getChildByName(name);
this.openNode.active = true;
if (this.wall_Info.lock == false) {
this.open = true;
this.openNode.children[0].scaleX *= 0.01;
this.openNode.children[1].scaleX *= 0.01;
}
else {
this.open = false;
}
break;
case WallSpecial.冻结门:
let freeze = "freeze" + this.wall_Info.length;
this.freezeNode = this.node.parent.getChildByName("freeze").getChildByName(freeze);
this.freezeNode.active = true;
if (this.wall_Info.freeze) {
this.freezeNumber = this.wall_Info.freeze;
NumberToImage.numberToImageNodes(this.freezeNumber, 20, 8, "lock_", this.freezeNode.getChildByName("num"), false);
}
break;
case WallSpecial.旋转门顺时针: case WallSpecial.旋转门逆时针:
if (this.wall_Info.length > 0) {
this.revolvingNode.active = true;
}
break;
case WallSpecial.顺时针带色门: case WallSpecial.逆时针带色门:
this.color = this.revolvingColor;
if (this.wall_Info.length > 0) {
this.revolvingColorNode.active = true;
this.revolvingColor = this.wall_Info.revolvingColor;
this.initColor(this.wall_Info.length, this.revolvingColor);
this.revolvingColorNode.getChildByName("start").getComponent(cc.Sprite).spriteFrame = this.wall_SpriteFrames._spriteFrames["color" + this.baseColor];
this.revolvingColorNode.getChildByName("end").getComponent(cc.Sprite).spriteFrame = this.wall_SpriteFrames._spriteFrames["color" + this.baseColor];
console.log(this.node.uuid, this.wall_Info.length);
if (this.direction == "up" || this.direction == "down") {
this.revolvingColorNode.getChildByName("end").x += (this.wall_Info.length - 1) * 120;
}
else if (this.direction == "right" || this.direction == "left") {
this.revolvingColorNode.getChildByName("end").y += (this.wall_Info.length - 1) * 120;
}
this.addPos = true;
}
break;
case WallSpecial.上锁门:
let lock = cc.instantiate(MapConroler._instance.Block_Prop[3]);
lock.parent = this.node.parent;
lock.color = cc.color(251, 158, 7, 255);
if (this.wall_Info.length == 0) {
lock.opacity = 0;
}
lock.scaleX = lock.scaleY = 0.65;
if (this.direction == "up") {
lock.setPosition((this.wall_Info.length - 1) * 60 - 10, 38);
if (this.wall_Info.length == 1) lock.x += 5;
}
else if (this.direction == "down") {
lock.setPosition((this.wall_Info.length - 1) * 60 - 10, -38);
if (this.wall_Info.length == 1) lock.x += 5;
}
if (this.direction == "right") {
lock.setPosition(30, (this.wall_Info.length - 1) * 60);
if (this.wall_Info.length == 1) lock.y += 10;
}
else if (this.direction == "left") {
lock.setPosition(-46, (this.wall_Info.length - 1) * 60);
if (this.wall_Info.length == 1) lock.y += 10;
}
lock.getComponent("Lock").init(this.wall_Info.lockTime, "wall", null);
break;
case WallSpecial.延伸伸缩门:
if (this.wall_Info.stickLength) {
let pos = cc.v2(0, 0);
let blockPos = [];
if (this.direction == "up") {
pos = cc.v2(0, 1);
}
else if (this.direction == "down") {
pos = cc.v2(0, -1);
}
if (this.direction == "right") {
pos = cc.v2(1, 0);
}
else if (this.direction == "left") {
pos = cc.v2(-1, 0);
}
for (let i = 0; i < this.wall_Info.stickLength; i++) {
let blockPosition = cc.v2(this.posX + (i + 1) * pos.x, this.posY + (i + 1) * pos.y);
blockPos.push(blockPosition);
}
this.node.parent.getChildByName("stick").active = true;
this.node.parent.getChildByName("progress").active = true;
this.node.parent.getChildByName("progressBg").active = true;
MapConroler._instance.pushStick_block(blockPos, this);
}
break;
}
if (this.wall_Info.colorArray) {
if (this.wall_Info.length > 0) {
this.maskNode.active = true;
this.setMask();
}
}
}
// ============================================
// 延伸伸缩门的变化方法
// 功能:控制延伸伸缩门的伸缩状态变化
// 参数说明:
// - type: 可选参数如果传true则切换门的显示/隐藏状态
// 逻辑说明:
// - 首先检查是否有可伸缩的方块stickBlock
// - 如果有type参数切换stickShow状态
// - 更新所有相关方块的stick和rise节点的显示状态
// - 更新进度条progress的宽度和动画
// ============================================
stickWallChange(type) {
// 如果没有可伸缩的方块,直接返回
if (this.stickBlock.length == 0) return;
// 如果传了type参数切换stickShow状态
if (type) {
if (this.wall_Info.stickShow != undefined) {
this.wall_Info.stickShow = !this.wall_Info.stickShow;
}
}
// 更新所有可伸缩方块的显示状态
if (this.stickBlock.length > 0) {
for (let i = 0; i < this.stickBlock.length; i++) {
// 显示stick节点
this.stickBlock[i].getChildByName("stick").active = true;
// 根据stickShow状态显示/隐藏rise节点
this.stickBlock[i].getChildByName("rise").active = this.wall_Info.stickShow;
}
}
// 更新进度条的宽度
this.node.parent.getChildByName("progress").width = 120 * this.wall_Info.stickLength;
this.node.parent.getChildByName("progressBg").width = this.node.parent.getChildByName("progress").width - 5;
// 根据stickShow状态执行不同的动画
if (!this.wall_Info.stickShow) {
// 如果要隐藏执行收缩动画0.2秒内宽度变为0
cc.tween(this.node.parent.getChildByName("progress"))
.to(0.2, { width: 0 })
.start();
}
else {
// 如果要显示先设置宽度为0然后执行伸展动画0.3秒内宽度变为120*stickLength
this.node.parent.getChildByName("progress").width = 0;
cc.tween(this.node.parent.getChildByName("progress"))
.to(0.3, { width: 120 * this.wall_Info.stickLength })
.start();
}
}
// ============================================
// 播放星星门通过特效
// 功能:当方块通过星星门时,播放星星逃跑的动画
// 触发时机:方块在星星门上消除时调用
// ============================================
playStarDoor() {
// 检查是否有star节点
if (this.node.parent.getChildByName("star")) {
let star = this.node.parent.getChildByName("star");
// 遍历所有星星子节点
for (let i = 0; i < star.children.length; i++) {
// 如果星星子节点处于激活状态
if (star.children[i].active == true) {
let starChild = star.children[i];
// 遍历星星的每个部分,激活并播放"taopao1"动画
for (let j = 0; j < starChild.children.length; j++) {
starChild.children[j].active = true
starChild.children[j].getComponent(sp.Skeleton).setAnimation(1, "taopao1", false);
}
}
}
}
}
// ============================================
// 改变开关门的状态
// 功能:切换开关门的开启/关闭状态,并播放对应的动画
// 开关门状态:
// - open == true门开着scaleX == 1方块可以通过
// - open == false门关着scaleX接近0方块不能通过
// 动画说明:
// - 门的两半leftTween和rightTween会分别播放开启/关闭动画
// - 动画时长0.3秒
// ============================================
changeLock() {
// 切换门的开关状态
this.open = !this.open;
// 如果开关节点没有激活,先激活它
if (!this.openNode.active) {
this.openNode.active = true;
}
// 停止之前的动画
if (this.leftTween) {
this.leftTween.stop();
this.leftTween = null;
}
if (this.rightTween) {
this.rightTween.stop();
this.rightTween = null;
}
// 如果门要打开确保scaleX是1如果要关闭确保scaleX接近0
if (this.open == true) {
if (this.openNode.children[0].scaleX < 1 && this.openNode.children[0].scaleX > 0.01) {
this.openNode.children[0].scaleX = 1;
}
}
else {
if (this.openNode.children[0].scaleX < 1 && this.openNode.children[0].scaleX > 0.01) {
this.openNode.children[0].scaleX = 0.01;
}
}
// 计算目标scale值
let fill = this.openNode.children[0].scaleX == 1 ? 0.01 : 1;
if (this.openNode.children[0].scaleX < 0) fill = -fill;
// 播放左边门的动画
this.leftTween = cc.tween(this.openNode.children[0])
.to(0.3, { scaleX: this.openNode.children[0].scaleX < 0 ? -fill : fill })
.call(() => {
this.leftTween = null; // 动画完成后清除引用
})
.start();
// 播放右边门的动画
this.rightTween = cc.tween(this.openNode.children[1])
.to(0.3, { scaleX: this.openNode.children[1].scaleX < 0 ? -fill : fill })
.call(() => {
this.rightTween = null; // 动画完成后清除引用
})
.start();
}
// ============================================
// 改变冻结门的冻结步数
// 功能当方块踩上冻结门时减少冻结步数如果步数为0则解除冻结
// 冻结门机制:
// - 方块踩上冻结门会被冻结(不能移动)
// - 每冻结一步freezeNumber减1
// - 当freezeNumber减到0时冻结解除
// ============================================
changeFreeze() {
// 冻结步数减1
this.freezeNumber -= 1;
// 如果冻结步数为0解冻门
if (this.freezeNumber == 0) {
// console.log(this.node.uuid);
// this.freezeNode.parent.active = false;
this.resetFreeze();
}
else {
NumberToImage.numberToImageNodes(this.freezeNumber, 20, 8, "lock_", this.freezeNode.getChildByName("num"), false);
}
}
// ============================================
// 门向下消除的方法(方块消除时门显示向下)
// 功能:当方块在门上消除时,更新门的显示状态
// 触发时机:方块触摸门并消除时调用
// 注意事项:
// - 如果开关门是打开状态scaleX == 1直接返回不处理
// - 如果冻结门已激活,直接返回不处理
// - 旋转门(4/5)、上锁门(6)、带色旋转门(10/11)不执行此方法
// - 如果门下方Sprite为空说明门已经消除不处理
// ============================================
downDoor() {
// 如果有开关门节点,检查开关门是否开着(开着就返回)
if (this.openNode) {
if (this.openNode.children[0].scaleX == 1)
return;
}
// 如果有冻结门节点,检查冻结门是否已激活(激活就返回)
if (this.freezeNode) {
if (this.freezeNode.active == true)
return;
}
// 旋转门和上锁门不执行向下消除逻辑,直接返回
if (this.special == 4 || this.special == 5 || this.special == 6 || this.special == 10 || this.special == 11) {
return;
}
// 如果门下方Sprite为空说明门已经消除直接返回
if (this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame == null)
return;
// 隐藏门本身
this.node.opacity = 0;
// 如果是星星门向下移动10像素
if (this.special == WallSpecial.) {
this.node.parent.getChildByName("star").y -= 10;
}
// 显示门下方部分
this.node.parent.getChildByName("down").active = true;
// 如果是变色门,更新颜色
if (this.colorArray.length > 0) {
// 根据门的方向计算偏移值左右方向的门需要额外偏移3
let direction = this.node.parent.name;
let double = 0;
if (direction == "left" || direction == "right") {
double = 3;
}
// 获取颜色数组的第二个颜色(下一个要变的颜色)
let color = this.colorArray[1];
// 更新变色门下方的颜色Sprite
if (this.down_SpriteFrames) {
let name = color + "down" + (this.length + double);
var spriteFrame = this.down_SpriteFrames._spriteFrames[name];
this.maskNode.getChildByName("color_icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
}
// 显示变色门的相关节点
this.maskNode.getChildByName("color_down").opacity = 255;
this.maskNode.getChildByName("color_icon").opacity = 0;
}
}
// ============================================
// 门向上恢复的方法(消除完成后门恢复原状)
// 功能:消除动画完成后,恢复门的正常显示状态
// 触发时机:方块消除动画完成后由系统调用
// ============================================
upDoor() {
if (this.special == WallSpecial.) {
this.node.parent.getChildByName("star").y += 10;
}
this.node.parent.getChildByName("down").active = false;
if (this.colorArray.length > 0) {
this.maskNode.getChildByName("color_down").opacity = 0;
this.maskNode.getChildByName("color_icon").opacity = 255;
let direction = this.node.parent.name;
let double = 0;
if (direction == "left" || direction == "right") {
double = 3;
}
if (this.colorArray.length > 1) {
let color = this.colorArray[1];
if (this.wall_SpriteFrames) {
let name = color + "color" + (this.length + double);
var spriteFrame = this.wall_SpriteFrames._spriteFrames[name];
this.maskNode.getChildByName("color_icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
}
}
else {
this.maskNode.getChildByName("color_icon").opacity = 0;
}
}
this.node.opacity = 250;
}
// ============================================
// 重置冻结门的状态
// 功能:当冻结门的冻结步数用完时,解除冻结状态
// 触发时机changeFreeze方法中freezeNumber减到0时调用
// 逻辑说明:
// - 将specialBackup重置为0
// - 如果special是冻结门则恢复为普通门special=0
// - 隐藏冻结门节点
// - 播放"freezeDoor"音效
// ============================================
resetFreeze() {
// 重置特殊类型备份
this.specialBackup = 0;
// 如果是冻结门,恢复为普通门
if (this.special == WallSpecial.) {
this.special = 0;
}
// 如果有冻结门节点
if (this.freezeNode) {
// 播放解冻音效
cc.fx.AudioManager._instance.playEffect("freezeDoor", null);
// 隐藏冻结门节点
this.freezeNode.active = false;
}
}
// ============================================
// 旋转门旋转状态切换
// 功能:根据门的特殊类型,切换旋转门的激活状态
// 旋转门类型:
// - 旋转门顺时针special==4激活旋转节点
// - 旋转门逆时针special==5激活旋转节点
// - 其他带色旋转门:关闭旋转节点
// ============================================
changeRevolvingWall() {
// 如果有旋转门节点
if (this.revolvingNode) {
// 如果是顺时针或逆时针旋转门,激活旋转节点
if (this.special == WallSpecial. || this.special == WallSpecial.) {
this.revolvingNode.active = true;
}
else {
// 其他情况关闭旋转节点
this.revolvingNode.active = false;
}
}
}
// ============================================
// 带底色旋转门的颜色变化
// 功能:更新带色旋转门的颜色值,并控制颜色渐变节点的显示
// 参数说明:
// - color: 可选参数,新的颜色值
// 带色旋转门类型:
// - 顺时针带色门special==10
// - 逆时针带色门special==11
// ============================================
changeRevolvingWallColor(color) {
// 如果有带色旋转门节点
if (this.revolvingColorNode) {
// 如果传了颜色参数,更新旋转门颜色
if (color != null && color != undefined) {
this.revolvingColor = color;
}
// 如果是带色旋转门类型
if (this.special == WallSpecial. || this.special == WallSpecial.) {
this.color = this.revolvingColor;
for (let i = 0; i < this.teamDoors.length; i++) {
this.teamDoors[i].color = this.color;
}
if (this.wall_Info.length > 0) {
this.revolvingColorNode.active = true;
this.revolvingColorNode.zIndex = 200;
this.initColor(this.wall_Info.length, this.color);
this.revolvingColorNode.getChildByName("start").getComponent(cc.Sprite).spriteFrame = this.wall_SpriteFrames._spriteFrames["color" + this.baseColor];
this.revolvingColorNode.getChildByName("end").getComponent(cc.Sprite).spriteFrame = this.wall_SpriteFrames._spriteFrames["color" + this.baseColor];
if (this.addPos == false) {
if (this.direction == "up" || this.direction == "down") {
this.revolvingColorNode.getChildByName("end").x += (this.wall_Info.length - 1) * 120;
}
else if (this.direction == "right" || this.direction == "left") {
this.revolvingColorNode.getChildByName("end").y += (this.wall_Info.length - 1) * 120;
}
}
this.addPos = true;
}
}
else {
this.color = this.baseColor;
for (let i = 0; i < this.teamDoors.length; i++) {
this.teamDoors[i].color = this.color;
}
if (this.wall_Info.length > 0) {
if (!this.wall_Info.longAndShort) this.initColor(this.wall_Info.length, this.color);
}
this.revolvingColorNode.active = false;
}
}
}
//跳跃门跳跃
changeJumpWall(type: boolean) {
if (type == true) {
this.jumpInit();
// setTimeout(() => {
// console.log("跳跃门数组", this.teamDoors[0].node.uuid);
// for (let i = 0; i < this.teamDoors.length; i++) {
// console.log("第" + (i + 1) + "个");
// console.log("初始长度:", this.teamDoors[i].realLength, "长度:", this.teamDoors[i].length, "是否被阻挡:", this.teamDoors[i].jump, this.teamDoors[i].posX, this.teamDoors[i].posY);
// }
// }, 1000);
}
else {
this.jump = null;
setTimeout(() => {
// console.log("被跳走门数组", this.teamDoors[0].node.uuid);
}, 1000);
cc.tween(this.jumpNode)
.to(0.2, { opacity: 0 })
.start();
}
}
//跳跃门初始化
jumpInit() {
this.jump = true;
this.length = 0;
this.jumpNode = this.node.parent.getChildByName("jump");
this.jumpNode.active = true;
cc.tween(this.jumpNode)
.delay(0.1)
.to(0.2, { opacity: 255 })
.start();
if (this.wall_Info.length == 0 && (this.node.parent.name == "right" || this.node.parent.name == "left")) {
this.node.parent.zIndex = 199;
}
}
//根据跳跃门 截断长度s
changeLength() {
// console.log("操作对象", this.node.uuid);
if (this.teamDoors.length == 0)
return;
else if (this.teamDoors.length == 1) {
if (this.jump != true) this.length = 1;
}
else if (this.teamDoors.length == 2) {
if (this.teamDoors[0] == this) {
if (this.teamDoors[0].jump == true) {
this.length = 0;
} else {
if (this.teamDoors[1].jump == true) {
this.length = 1;
}
else {
this.length = this.realLength;
}
}
}
else if (this.teamDoors[1] == this) {
if (this.teamDoors[1].jump == true) {
this.length = 0;
} else {
if (this.teamDoors[0].jump == true) {
this.length = 1;
}
else {
this.length = this.realLength;
}
}
}
}
else if (this.teamDoors.length == 3) {
if (this.teamDoors[0] == this) {
if (this.teamDoors[0].jump == true) {
this.length = 0;
}
else {
if (this.teamDoors[1].jump == true) {
this.length = 1;
}
else if (this.teamDoors[2].jump == true) {
this.length = 2;
}
else {
this.length = this.realLength;
}
}
}
else if (this.teamDoors[1] == this) {
if (this.teamDoors[1].jump == true) {
this.length = 0;
}
else {
if (this.teamDoors[2].jump == true) {
this.length = 1;
}
else {
this.length = 2;
}
if (this.teamDoors[0].jump == false) {
this.length = this.realLength;
}
}
}
else if (this.teamDoors[2] == this) {
if (this.teamDoors[2].jump == true || this.teamDoors[1].jump == false) {
this.length = 0;
}
else {
this.length = 1;
}
}
}
}
//变色门变色总方法
changeColorWall() {
// console.log("通过此门,调用次门数组", this.colorArray);
// console.log("改變顏色:", this.wall_Info.length);
for (let i = 0; i < this.teamDoors.length; i++) {
setTimeout(() => {
this.teamDoors[i].changeColor();
}, i * 10);
}
}
//变色门变色具体执行方法
changeColor() {
// console.log("变色门变色数组数量", this.colorArray, this.node.uuid);
if (this.colorArray.length >= 1 && this.color == this.colorArray[0]) {
let firstItem = this.colorArray.shift(); // 移除第一项
// console.log("移除颜色:", this.color);
// this.colorArray.push(firstItem); // 将第一项添加到数组末尾
if (this.colorArray.length <= 2) {
for (let i = 0; i < this.colorStartArray.length; i++) {
this.colorArray.push(this.colorStartArray[i]);
}
}
}
// console.log("变色门变色数组数量", this.colorArray, this.node.uuid);
this.updateColor();
}
//删除变色门颜色数组中的颜色值
changeDeleteColor(color) {
for (let i = 0; i < this.teamDoors.length; i++) {
setTimeout(() => {
this.teamDoors[i].tempDeleteColor(color);
}, i * 10);
}
}
//删除变色门颜色数组中的颜色值
tempDeleteColor(color) {
if (this.colorArray.length > 1) {
let index = this.colorArray.indexOf(color);
if (index !== -1) {
// console.log("删除颜色:", color, this.colorArray);
this.colorArray.splice(index, 1);
if (this.colorArray.length <= 2) {
for (let i = 0; i < this.colorStartArray.length; i++) {
this.colorArray.push(this.colorStartArray[i]);
}
}
this.updateColor();
}
}
}
//更新变色门颜色
updateColor() {
this.color = this.colorArray[0];
// console.log("改變顏色", this.color);
let direction = this.node.parent.name;
let double = 0;
if (direction == "left" || direction == "right") {
double = 3;
}
if (this.wall_Info.length > 0) {
this.upDoor();
this.setMask();
if (this.wall_SpriteFrames) {
let name = this.color + "color" + (this.wall_Info.length + double);
// console.log("变色名称:", name);
var spriteFrame = this.wall_SpriteFrames._spriteFrames[name];
if (this.node.getComponent(cc.Sprite)) this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
if (this.node.getChildByName("icon")) this.node.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
this.node.getComponent(cc.Sprite).fillRange = 0;
cc.tween(this.node.getComponent(cc.Sprite))
.to(0.2, { fillRange: 1 })
.start();
}
if (this.down_SpriteFrames) {
let name2 = this.color + "down" + (this.wall_Info.length + double);
// console.log("按下名称:", name2);
var downFrame = this.down_SpriteFrames._spriteFrames[name2];
this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = downFrame;
this.node.parent.getChildByName("down").getComponent(cc.Sprite).fillRange = 0;
cc.tween(this.node.parent.getChildByName("down").getComponent(cc.Sprite))
.to(0.2, { fillRange: 1 })
.start();
}
}
}
//变色门删除颜色, 第一个参数为颜色,第二个参数为是否立刻刷新颜色, 第三个参数为是否删除起始颜色
removeColor(color, type) {
// console.log("整体删除颜色");
if (this.colorStartArray.length > 1) {
let index = this.colorStartArray.indexOf(color);
if (index !== -1) {
this.colorStartArray.splice(index, 1);
}
}
if (this.colorArray.length > 1) {
for (let j = 0; j < this.colorArray.length; j++) {
if (this.colorArray[j] == color) {
this.colorArray.splice(j, 1);
// console.log("删除方法中,该墙体有该颜色", j)
j--;
}
}
if (this.colorArray.length <= 2) {
for (let i = 0; i < this.colorStartArray.length; i++) {
this.colorArray.push(this.colorStartArray[i]);
}
}
if (type == true) this.updateColor();
}
// console.log(this.wall_Info.length, "删除颜色:", color, "删除后数组:", this.colorArray, "删除起始颜色:", this.colorStartArray);
}
//添加变色门遮罩
setMask() {
let direction = this.node.parent.name;
let double = 0;
if (direction == "left" || direction == "right") {
double = 3;
}
if (this.colorArray.length > 1) {
let color = this.colorArray[1];
if (this.wall_SpriteFrames) {
let name = color + "color" + (this.wall_Info.length + double);
var spriteFrame = this.wall_SpriteFrames._spriteFrames[name];
this.maskNode.getChildByName("color_icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
this.maskNode.getChildByName("color_icon").getComponent(cc.Sprite).fillRange = 0;
cc.tween(this.maskNode.getChildByName("color_icon").getComponent(cc.Sprite))
.to(0.2, { fillRange: 1 })
.start();
}
if (this.down_SpriteFrames) {
let name2 = color + "down" + (this.wall_Info.length + double);
var downFrame = this.down_SpriteFrames._spriteFrames[name2];
this.maskNode.getChildByName("color_down").getComponent(cc.Sprite).spriteFrame = downFrame;
this.maskNode.getChildByName("color_down").getComponent(cc.Sprite).fillRange = 0;
cc.tween(this.maskNode.getChildByName("color_down").getComponent(cc.Sprite))
.to(0.2, { fillRange: 1 })
.start();
}
}
else {
this.maskNode.getChildByName("color_icon").opacity = 0;
}
// 设置遮罩节点大小和位置
this.setMaskPosition();
}
setMaskPosition() {
if (this.node.parent.name == "down") {
if (this.wall_Info.length == 3) {
this.maskNode.width = 290;
this.maskNode.height = 69;
this.maskNode.position = cc.v3(116, -39, 0); // 居中
}
else if (this.wall_Info.length == 2) {
this.maskNode.width = 178;
this.maskNode.height = 69;
this.maskNode.position = cc.v3(54, -39, 0); // 居中
}
else if (this.wall_Info.length == 1) {
this.maskNode.width = 70;
this.maskNode.height = 69;
this.maskNode.position = cc.v3(-7, -39, 0); // 居中
}
}
else if (this.node.parent.name == "up") {
if (this.wall_Info.length == 3) {
this.maskNode.width = 290;
this.maskNode.height = 69;
this.maskNode.position = cc.v3(116, 34, 0); // 居中
}
else if (this.wall_Info.length == 2) {
this.maskNode.width = 178;
this.maskNode.height = 69;
this.maskNode.position = cc.v3(56, 34, 0); // 居中
}
else if (this.wall_Info.length == 1) {
this.maskNode.width = 70;
this.maskNode.height = 69;
this.maskNode.position = cc.v3(-2.44, 34, 0); // 居中
}
}
else if (this.node.parent.name == "right") {
if (this.wall_Info.length == 3) {
this.maskNode.width = 69;
this.maskNode.height = 290;
this.maskNode.position = cc.v3(37, 120, 0); // 居中
}
else if (this.wall_Info.length == 2) {
this.maskNode.width = 69;
this.maskNode.height = 178;
this.maskNode.position = cc.v3(37, 60, 0); // 居中
}
else if (this.wall_Info.length == 1) {
this.maskNode.width = 69;
this.maskNode.height = 70;
this.maskNode.position = cc.v3(37, 0, 0); // 居中
this.maskNode.anchorY = 0.35;
}
}
else if (this.node.parent.name == "left") {
if (this.wall_Info.length == 3) {
this.maskNode.width = 69;
this.maskNode.height = 290;
this.maskNode.position = cc.v3(-39.5, 120, 0); // 居中
}
else if (this.wall_Info.length == 2) {
this.maskNode.width = 69;
this.maskNode.height = 178;
this.maskNode.position = cc.v3(-39.5, 60, 0); // 居中
}
else if (this.wall_Info.length == 1) {
this.maskNode.width = 69;
this.maskNode.height = 70;
this.maskNode.position = cc.v3(-39.5, 0, 0); // 居中
this.maskNode.anchorY = 0.35;
}
}
}
//设置长短变化门并且有颜色改变的
setLongAndShortColor(color, length) {
let direction = this.node.parent.name;
let double = 0;
if (direction == "left" || direction == "right") {
double = 3;
}
let changdu = (this.wall_Info.length + double);
if (length != null)
changdu = length + double;
if (this.wall_SpriteFrames) {
let name = color + "color" + changdu;
var spriteFrame = this.wall_SpriteFrames._spriteFrames[name];
this.maskNode.getChildByName("color_icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
this.maskNode.getChildByName("color_icon").getComponent(cc.Sprite).fillRange = 1;
//console.log(this.node.uuid, "______________________长度" + changdu, name);
}
if (this.down_SpriteFrames) {
let name2 = color + "color" + changdu;
var downFrame = this.down_SpriteFrames._spriteFrames[name2];
this.maskNode.getChildByName("color_down").getComponent(cc.Sprite).spriteFrame = downFrame;
this.maskNode.getChildByName("color_down").getComponent(cc.Sprite).fillRange = 1;
}
this.maskNode.active = true;
// 设置遮罩节点大小和位置
this.setMaskPosition();
}
//初始化的时候,处理一组门的长短变化状态
setLongAndShort() {
//数组为空返回
if (MapConroler._instance.teamDoors.length <= 0) {
return;
}
//上一个墙壁数组并不是长短门返回
if (!MapConroler._instance.teamDoors[0].wall_Info.longAndShort) {
return;
}
let start = MapConroler._instance.teamDoors[0];
let over = MapConroler._instance.teamDoors[0].length != 3 ? MapConroler._instance.teamDoors[1] : MapConroler._instance.teamDoors[2];
let end = null;
if (MapConroler._instance.teamDoors[0].length == 3 && MapConroler._instance.teamDoors[0].longAndShort[0] == 1) {
end = MapConroler._instance.teamDoors[1];
}
if (MapConroler._instance.teamDoors[0].longAndShort[0] == MapConroler._instance.teamDoors[0].wall_Info.length) {
over = null;
end = null;
}
if (MapConroler._instance.teamDoors[0].wall_Info.longAndShort[0] == 1 && MapConroler._instance.teamDoors[0].order == true) {
var temp = this.wall_Info;
}
if (MapConroler._instance.teamDoors[0].order == false) {
//上来是开满的
if (MapConroler._instance.teamDoors[0].longAndShort[0] > MapConroler._instance.teamDoors[0].longAndShort[1]) {
// console.log("是全开的", this.wall_Info.num, MapConroler._instance.teamDoors[0].longAndShort);
start = MapConroler._instance.teamDoors[0];
over = null;
end = null;
} else { //上来是缺口的
// console.log("是缺口的", this.wall_Info.num, MapConroler._instance.teamDoors[0].longAndShort);
start = MapConroler._instance.teamDoors[1];
over = MapConroler._instance.teamDoors[0];
if (MapConroler._instance.teamDoors.length == 3) {
if (MapConroler._instance.teamDoors[0].longAndShort[0] == 2) {
start = MapConroler._instance.teamDoors[1];
over = MapConroler._instance.teamDoors[0];
}
else if (MapConroler._instance.teamDoors[0].longAndShort[0] == 1) {
start = MapConroler._instance.teamDoors[2];
over = MapConroler._instance.teamDoors[1];
end = MapConroler._instance.teamDoors[0];
}
}
}
}
// console.log("数组长度:", MapConroler._instance.teamDoors.length);
start.runLongAndShort(0, start.getComponent("Wall"));
if (end == null) {
if (over) over.runLongAndShort(2, start.getComponent("Wall"));
}
else {
if (over) over.runLongAndShort(1, start.getComponent("Wall"));
if (end) end.runLongAndShort(3, start.getComponent("Wall"));
}
//下一帧执行
}
//长短门改变变化
runLongAndShort(type, startWall) {
for (let i = 0; i < this.teamDoors.length; i++) {
// console.log(this.teamDoors[i].node.uuid, this.teamDoors[i].node.parent.zIndex);
}
// console.log(this.node.parent.name);
//顺向的, 在第一个。
// console.log("执行:", this.longAndShort[0], this.longAndShort[1]);
this.length = this.longAndShort[0];
this.realLength = this.length;
if (type == 0) {
// this.length = this.longAndShort[0];
// console.log(this.wall_Info.num, "实际长度:", this.length, "本身长度:", this.wall_Info.length);
if (this.wall_Info.length == this.length) {
if (this.teamDoors[1].node.getComponent(cc.Sprite)) this.teamDoors[1].node.getComponent(cc.Sprite).spriteFrame = null;
if (this.teamDoors[1].node.getChildByName("icon")) this.teamDoors[1].node.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = null;
this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = null;
this.color = this.wall_Info.color;
this.initColor(this.longAndShort[0], this.color);
if (this.wall_Info.colorChange != undefined && this.wall_Info.colorChange != null) {
for (let i = 0; i < this.teamDoors.length; i++) {
this.teamDoors[i].maskNode.active = false;
this.teamDoors[i].color = this.wall_Info.color;
}
this.maskNode.active = true;
if (this.longAndShortColor) this.setLongAndShortColor(this.longAndShortColor, null);
//console.log("长的变身颜色", this.node.uuid, this.longAndShortColor, this.color);
}
}
else {
if (this.wall_Info.colorChange != undefined && this.wall_Info.colorChange != null) {
this.initColor(this.longAndShort[0], this.longAndShortColor);
if (this.teamDoors[0].order == true) {
this.teamDoors[0].setLongAndShortColor(this.teamDoors[0].wall_Info.color, null);
}
else {
// this.teamDoors[this.teamDoors.length - 1].setLongAndShortColor(this.teamDoors[0].wall_Info.color, null);
this.teamDoors[this.teamDoors.length - 1].setLongAndShortColor(this.teamDoors[this.teamDoors.length - 1].wall_Info.color, (this.teamDoors.length - 1));
}
//console.log("短的变身颜色", this.node.uuid, this.longAndShortColor, this.color);
this.color = this.longAndShortColor;
}
else {
this.initColor(this.longAndShort[0], null);
// this.setLongAndShortColor(this.color);
}
}
}
else if (type == 1) {
// console.log(this.wall_Info.num, "隐身", "实际长度:", this.length, "本身长度:", this.wall_Info.length);
this.node.getComponent(cc.Sprite).spriteFrame = null;
this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = null;
this.node.parent.getChildByName("length").active = true;
}
else if (type == 2 || type == 3) {
// console.log(this.wall_Info.num, "隐身", "实际长度:", this.length, "本身长度:", this.wall_Info.length);
this.node.getComponent(cc.Sprite).spriteFrame = null;
let name = "";
if (this.node.parent.name == "down" || this.node.parent.name == "up") name = "heng";
else name = "shu";
name = name + (2 * (type - 1));
if (this.node.parent.name == "down" && this.teamDoors[0].order == false) {
if (name == "heng2") name = "heng1";
else if (name == "heng4") name = "heng3";
}
else if (this.node.parent.name == "up" && this.teamDoors[0].order == false) {
if (name == "heng2") name = "heng1";
else if (name == "heng4") name = "heng3";
}
else if (this.node.parent.name == "left" && this.teamDoors[0].order == true) {
if (name == "shu2") name = "shu1";
else if (name == "shu4") name = "shu3";
}
else if (this.node.parent.name == "right" && this.teamDoors[0].order == true) {
if (name == "shu2") name = "shu1";
else if (name == "shu4") name = "shu3";
}
// console.log("墻體名字:", name, this.node.name, this.node.parent.name, this.teamDoors[0].order);
var spriteFrame = this.wall_SpriteFrames._spriteFrames[name];
if (this.node.getComponent(cc.Sprite)) this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = null;
this.node.parent.getChildByName("length").active = true;
if (this.wall_Info.colorChange != undefined && this.wall_Info.colorChange != null) {
let longLength = type - 1;
if (this.teamDoors[0].order == true) {
// this.setLongAndShortColor(this.teamDoors[0].wall_Info.color, longLength);
//console.log("短 的变身颜色", this.node.uuid, this.teamDoors[0].wall_Info.color, longLength);
}
else {
for (let i = 0; i < this.teamDoors.length; i++) {
this.teamDoors[i].maskNode.active = false;
}
this.setLongAndShortColor(this.teamDoors[this.teamDoors.length - 1].wall_Info.color, this.wall_Info.length);
//console.log(this.node.uuid, "逆向_____短的变身颜色", this.node.uuid, this.teamDoors[this.teamDoors.length - 1].wall_Info.color, this.wall_Info.length);
}
// this.maskNode.active = true;
}
// this.teamDoors[1].maskNode.active = true;
// this.teamDoors[1].setLongAndShortColor(this.teamDoors[0].wall_Info.color);
}
if (type == 0) {
setTimeout(() => {
for (let k = 0; k < this.teamDoors.length; k++) {
this.teamDoors[k].longAndShort.reverse();
// console.log("第" + k + "个门", this.teamDoors[k].longAndShort[0], this.teamDoors[k].longAndShort[1]);
}
}, 1);
}
}
//改变长短门变化状态
changeLongAndShort() {
for (let i = 0; i < this.teamDoors.length; i++) {
this.teamDoors[i].node.parent.getChildByName("length").active = false;
}
let start = this.teamDoors[0];
let over = this.teamDoors.length != 3 ? this.teamDoors[1] : this.teamDoors[2];
let end = null;
if (this.teamDoors[0].order == true) {
if (this.teamDoors[0].length == 3 && this.teamDoors[0].longAndShort[0] == 1) {
end = this.teamDoors[1];
}
if (this.teamDoors[0].length == 2 && this.teamDoors[0].longAndShort[0] == 1) {
// end = this.teamDoors[1];
end = null;
}
if (this.teamDoors[0].longAndShort[0] == this.teamDoors[0].wall_Info.length) {
over = null;
end = null;
}
}
else {
end = null;
//上来是开满的
if (this.teamDoors[this.teamDoors.length - 1].longAndShort[0] > this.teamDoors[this.teamDoors.length - 1].longAndShort[1]) {
// console.log("是全开的", this.wall_Info.num, MapConroler._instance.teamDoors[0].longAndShort);
start = this.teamDoors[0];
this.teamDoors[1].node.getComponent(cc.Sprite).spriteFrame = null;
this.teamDoors[1].node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = null;
if (this.teamDoors.length > 2) {
this.teamDoors[2].node.getComponent(cc.Sprite).spriteFrame = null;
this.teamDoors[2].node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = null;
}
over = null;
end = null;
} else { //上来是缺口的
var temp1 = this.teamDoors[this.teamDoors.length - 1].longAndShort[0];
var temp2 = this.teamDoors[this.teamDoors.length - 1].longAndShort[1];
// console.log("是缺口的", this.wall_Info.num, temp1, temp2);
start = this.teamDoors[1];
over = this.teamDoors[0];
if (this.teamDoors.length == 3) {
if (this.teamDoors[0].longAndShort[0] == 2) {
start = this.teamDoors[1];
over = this.teamDoors[0];
}
else if (this.teamDoors[0].longAndShort[0] == 1) {
start = this.teamDoors[2];
over = this.teamDoors[1];
end = this.teamDoors[0];
}
}
}
}
// console.log("数组长度:", MapConroler._instance.teamDoors.length);
start.runLongAndShort(0, start.getComponent("Wall"));
if (end == null) {
if (over) over.runLongAndShort(2, start.getComponent("Wall"));
}
else {
if (over) over.runLongAndShort(1, start.getComponent("Wall"));
if (end) end.runLongAndShort(3, start.getComponent("Wall"));
}
}
// update(dt) {
// }
}