// 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 MapConroler from "./Map"; const {ccclass, property} = cc._decorator; export enum WallSpecial{ /*普通门*/ "普通门" = 0, /*星星门*/ "星星门" = 1, /*开关门*/ "开关门" = 2, /*冻结门 */ "冻结门" = 3, } export enum WallType{ /*普通地块 */ "门横向下" = 0, /*起点地块 */ "门横向上" = 1, /*湿地 */ "门竖向右" = 2, /*山峰 */ "门竖向左" = 3, /*终点地块 */ "墙横向下" = 4, /*息壤 */ "墙横向上" = 5, /*加固 */ "墙竖向右" = 6, /*加固 */ "墙竖向左" = 7, } export enum WallColor{ /*普通地块 */ "紫色" = 0, /*湿地 */ "黄色" = 1, /*山峰 */ "绿色" = 2, /*终点地块 */ "蓝色" = 3, /*息壤 */ "粉色" = 4, /*加固 */ "橘黄色" = 5, /*加固 */ "青色" = 6, /*加固 */ "白色" = 7, /*普通地块 */ "红色" = 8, /*普通地块 */ "灰色" = 9, } @ccclass export default class Wall extends cc.Component { @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.SpriteAtlas) wall_SpriteFrames: cc.SpriteAtlas = null; @property(cc.SpriteAtlas) down_SpriteFrames: cc.SpriteAtlas = null; posX: number; posY: number; direction: any; wall_Info: any; openNode: cc.Node; freezeNode: cc.Node; open:boolean; // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { // console.log(this.type); } jsonDeepClone(obj: T): T { return JSON.parse(JSON.stringify(obj)); } init(wall_Info, posX: number, posY: number, direction: any){ this.wall_Info = this.jsonDeepClone(wall_Info); // this.open = true; if(wall_Info == null){ this.posX = posX; this.posY = posY; if(direction)this.direction = direction; // console.log("门方向赋值",direction); if(direction == "up" ){ this.node.parent.zIndex = 100 + this.posX - this.posY*3; } else if( direction == "down" || direction == "right" || direction == "rightdown" || direction == "downright" || direction == "rightup" || direction == "upright"){ this.node.parent.zIndex = 30 + this.posX - this.posY*3; } else if( direction == "left"|| direction == "leftdown" || direction == "downleft"){ this.node.parent.zIndex = 70 + this.posX - this.posY*3; } else this.node.parent.zIndex = 70 + this.posX - this.posY*3; 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); // console.log(this.posX,this.posY,this.node.zIndex); //this.node.getChildByName("num").getComponent(cc.Label).string = direction; //this.node.getChildByName("num").getComponent(cc.Label).string = ":" + this.node.parent.zIndex; } if(wall_Info != null){ this.color = wall_Info.color; this.special = wall_Info.special; this.initType(); if(wall_Info.length > 0){ this.initColor(wall_Info.length); } else this.node.removeComponent("cc.Sprite"); 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); } } // setTimeout(() => { // this.node.getChildByName("num").getComponent(cc.Label).string = ":" + this.node.parent.zIndex; // }, 1000); } //创建门的颜色 initColor(length: number){ let direction = this.node.parent.name; let double = 0; if(direction == "left" || direction == "right"){ double = 3; } // debugger; if(this.wall_SpriteFrames){ let name = this.color+"color" + (length+double); var spriteFrame = this.wall_SpriteFrames._spriteFrames[name]; this.node.getComponent(cc.Sprite).spriteFrame = spriteFrame; } if(this.down_SpriteFrames){ let name2 = this.color + "down" + (length+double); var downFrame = this.down_SpriteFrames._spriteFrames[name2]; this.node.parent.getChildByName("down").getComponent(cc.Sprite).spriteFrame = downFrame; } } //创建特殊类型门 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.freezeNode.getChildByName("num").getComponent(cc.Label).string = this.wall_Info.freeze+""; } break; } } //播放星星门通过 playStarDoor(){ if(this.node.parent.getChildByName("star")){ let star = this.node.parent.getChildByName("star"); for(let i=0; i{ // console.log("左边完成"); }) .start(); cc.tween(this.openNode.children[1]) .to(0.3, {scaleX: this.openNode.children[1].scaleX < 0?-fill:fill}) .call(()=>{ // console.log("右边完成"); }) .start(); } changeFreeze(){ let numStr = this.freezeNode.getChildByName("num").getComponent(cc.Label); let num = parseInt(numStr.string); num -= 1; this.freezeNode.getChildByName("num").getComponent(cc.Label).string = num+""; if(num == 0){ this.freezeNode.parent.active = false; } } downDoor(){ if(this.openNode){ if(this.openNode.children[0].scaleX == 1) return; } if(this.freezeNode){ if(this.freezeNode.active == true) return; } this.node.opacity = 0; if(this.special == WallSpecial.星星门){ this.node.parent.getChildByName("star").y -= 10; } this.node.parent.getChildByName("down").active = true; } upDoor(){ if(this.special == WallSpecial.星星门){ this.node.parent.getChildByName("star").y += 10; } this.node.parent.getChildByName("down").active = false; this.node.opacity = 250; } // update (dt) {} }