158 lines
5.9 KiB
TypeScript
158 lines
5.9 KiB
TypeScript
// 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";
|
|
import NumberToImage from "../NumberToImage";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
|
|
@ccclass
|
|
export default class Lock extends cc.Component {
|
|
static _instance: any;
|
|
time: number = 0;
|
|
type: string = "block"
|
|
// mapInfo: number[][] = [];
|
|
|
|
onLoad() {
|
|
|
|
}
|
|
|
|
start() {
|
|
}
|
|
|
|
init(time, type, block) {
|
|
if (time) this.time = time;
|
|
if (type) this.type = type;
|
|
this.node.getChildByName("time").active = true;
|
|
NumberToImage.numberToImageNodes(this.time, 20, 8, "lock_", this.node.getChildByName("time"), false);
|
|
let lock = this.node.getChildByName("lock");
|
|
if (block != null) {
|
|
switch (block) {
|
|
case 0:
|
|
lock.getChildByName("lock_1").active = true;
|
|
break;
|
|
case 1:
|
|
lock.getChildByName("lock_2").active = true;
|
|
break;
|
|
case 2:
|
|
lock.getChildByName("lock_3").active = true;
|
|
break;
|
|
case 3:
|
|
lock.getChildByName("lock_4").active = true;
|
|
break;
|
|
case 4:
|
|
lock.getChildByName("lock_10").active = true;
|
|
break;
|
|
case 5:
|
|
lock.getChildByName("lock_5").active = true;
|
|
break;
|
|
case 6:
|
|
lock.getChildByName("lock_6").active = true;
|
|
break;
|
|
case 7:
|
|
lock.getChildByName("lock_7").active = true;
|
|
break;
|
|
case 8:
|
|
lock.getChildByName("lock_8").active = true;
|
|
lock.getChildByName("lock_8").scaleX = -1;
|
|
break;
|
|
case 9:
|
|
lock.getChildByName("lock_9").active = true;
|
|
lock.getChildByName("lock_9").scaleX = -1;
|
|
break;
|
|
case 10:
|
|
lock.getChildByName("lock_8").active = true;
|
|
lock.getChildByName("lock_8").scaleY = -1;
|
|
lock.getChildByName("lock_8").scaleX = -1;
|
|
lock.getChildByName("lock_8").y += 12;
|
|
lock.getChildByName("lock_8").x -= 2;
|
|
break;
|
|
case 11:
|
|
lock.getChildByName("lock_9").active = true;
|
|
lock.getChildByName("lock_9").scaleY = -1;
|
|
lock.getChildByName("lock_9").y += 2;
|
|
lock.getChildByName("lock_9").x -= 2;
|
|
break;
|
|
case 12:
|
|
lock.getChildByName("lock_8").active = true;
|
|
lock.getChildByName("lock_8").x += 1;
|
|
break;
|
|
case 13:
|
|
lock.getChildByName("lock_9").active = true;
|
|
lock.getChildByName("lock_9").x -= 3;
|
|
|
|
break;
|
|
case 14:
|
|
lock.getChildByName("lock_4").active = true;
|
|
lock.getChildByName("lock_4").scaleY = -1;
|
|
lock.getChildByName("lock_4").y += 10;
|
|
break;
|
|
case 15:
|
|
lock.getChildByName("lock_4").active = true;
|
|
lock.getChildByName("lock_4").y -= 1;
|
|
break;
|
|
case 16:
|
|
lock.getChildByName("lock_3").active = true;
|
|
lock.getChildByName("lock_3").scaleX = -1;
|
|
break;
|
|
case 17:
|
|
lock.getChildByName("lock_3").active = true;
|
|
break;
|
|
case 18:
|
|
lock.getChildByName("lock_2").active = true;
|
|
break;
|
|
case 19:
|
|
lock.getChildByName("lock_4").active = true;
|
|
lock.getChildByName("lock_4").y -= 10;
|
|
break;
|
|
case 20:
|
|
lock.getChildByName("lock_4").active = true;
|
|
lock.getChildByName("lock_4").scaleX = -1;
|
|
lock.getChildByName("lock_4").y -= 8;
|
|
break;
|
|
case 21:
|
|
lock.getChildByName("lock_4").active = true;
|
|
lock.getChildByName("lock_4").scaleY = -1;
|
|
lock.getChildByName("lock_4").scaleX = -1;
|
|
lock.getChildByName("lock_4").y += 18;
|
|
break;
|
|
case 22:
|
|
lock.getChildByName("lock_4").active = true;
|
|
lock.getChildByName("lock_4").scaleY = -1;
|
|
lock.getChildByName("lock_4").y += 18;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
reduce() {
|
|
this.time -= 1;
|
|
NumberToImage.numberToImageNodes(this.time, 20, 8, "lock_", this.node.getChildByName("time"), false);
|
|
cc.fx.GameTool.numberScaleAction(this.node.getChildByName("time"));
|
|
if (this.time <= 0) {
|
|
if (this.type == "block") {
|
|
if (this.node.parent) this.node.parent.getComponent("Block").type = 0;
|
|
}
|
|
else if (this.type == "wall") {
|
|
this.node.parent.getChildByName("wall").getComponent("Wall").specialBackup = 0;
|
|
if (this.node.parent.getChildByName("wall").getComponent("Wall").special == 6) {
|
|
if (this.node.parent) {
|
|
this.node.parent.getChildByName("wall").getComponent("Wall").special = 0;
|
|
}
|
|
}
|
|
}
|
|
this.node.destroy();
|
|
this.node.removeFromParent();
|
|
}
|
|
}
|
|
|
|
// update (dt) {}
|
|
}
|