WaterControl/assets/Script/Block.ts
2024-07-12 17:38:10 +08:00

148 lines
4.0 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
const {ccclass, property} = cc._decorator;
export enum BlockType{
/*普通地块 */
Nomal = 0,
/*起点地块 */
Start = 1,
/*湿地 */
Nunja = 2,
/*山峰 */
Peak = 3,
/*终点地块 */
End = 4,
/*息壤 */
Xi_Soil = 5,
/*加固 */
Reinforce = 6
}
export enum PathType{
err = "err",
up = "up",
down = "down",
left = "left",
right = "right",
up_left = "up_left",
up_right = "up_right",
down_left = "down_left",
down_right = "down_right",
left_up = "left_up",
left_down = "left_down",
right_up = "right_up",
right_down = "right_down",
}
@ccclass
export default class NewClass extends cc.Component {
// LIFE-CYCLE CALLBACKS:
block_Type:number;
path_Type:string;
finishi:boolean
onLoad () {
this.finishi = false;
}
start () {
}
initData(type){
this.block_Type = type;
if(type == cc.Enum(BlockType).Start){
this.node.color = cc.color(245,70,70);
}
else if(type == cc.Enum(BlockType).End){
this.node.color = cc.color(20,255,0);
}
}
setPath(type){
this.path_Type = type;
}
//洪峰执行
runWater(data){
var target = null;
var progress = 1;
var time = data.time;
var order = data.order + 1;
target = this.node.getChildByName("vertical");
console.log(this.path_Type);
if(this.path_Type == cc.Enum(PathType).up){
}
else if(this.path_Type == cc.Enum(PathType).down){
target.angle = 180;
}
else if(this.path_Type == cc.Enum(PathType).left){
target.angle = 90;
}
else if(this.path_Type == cc.Enum(PathType).right){
target.angle = 270;
}
else{
target = this.node.getChildByName("turn");
progress = 0.25;
if(this.path_Type == cc.Enum(PathType).up_left){
target.setPosition(-9,-9);
}
else if(this.path_Type == cc.Enum(PathType).up_right){
target.scaleX = -1;
target.setPosition(9,-9);
}
else if(this.path_Type == cc.Enum(PathType).down_left){
target.angle = 180;
target.scaleX = -1;
target.setPosition(-9,9);
}
else if(this.path_Type == cc.Enum(PathType).down_right){
target.angle = 180;
target.scaleX = 1;
target.setPosition(9,9);
}
else if(this.path_Type == cc.Enum(PathType).left_up){
target.angle = -90;
target.scaleY = -1;
target.setPosition(9,9);
}
else if(this.path_Type == cc.Enum(PathType).left_down){
target.angle = 90;
target.scaleY = -1;
target.setPosition(-9,-9);
}
else if(this.path_Type == cc.Enum(PathType).right_up){
target.angle = -90;
// target.scaleY = -1;
target.setPosition(-9,9);
}
else if(this.path_Type == cc.Enum(PathType).right_down){
target.angle = -90;
target.scaleX = -1;
target.setPosition(-9,-9);
}
}
target.active = true;
target.getComponent(cc.Sprite).fillRange = 0;
cc.tween(target.getComponent(cc.Sprite))
.to(time,{fillRange:progress})
.call(() =>{
if(data.circulate)
cc.fx.Notifications.emit(cc.fx.Message.next,order);
})
.start();
}
// update (dt) {}
}