ShenNong/assets/Script/GuideManager.ts
YZ\249929363 c2a30b650a 完整版
2024-06-28 16:46:13 +08:00

287 lines
10 KiB
TypeScript

import AudioManager from "./module/Music/AudioManager";
// 主游戏控制类
const {ccclass, property} = cc._decorator;
@ccclass
export default class GuideManager extends cc.Component {
@property(cc.Node)
Tip: cc.Node = null;
@property(cc.SpriteAtlas)
FoodPlist: cc.SpriteAtlas = null;
@property(cc.Node)
Btn_New: cc.Node = null;
@property(cc.Node)
Btn_Hear: cc.Node = null;
@property(cc.Node)
Btn_See: cc.Node = null;
@property(cc.Node)
Plant: cc.Node = null;
voiceSpriteFrame: cc.SpriteFrame; //是否可点击
needleTween: cc.Tween<cc.Sprite>;
func: () => void;
custom:number;
now_Food: string; //当前关卡名字信息
customData: { item: string; type: number; right: number; }[];
choice: number;
onLoad () {
this.custom = 0;
}
start () {
}
//初始化数据
init(){
this.voiceSpriteFrame = this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame;``
this.node.getChildByName("jumpBtn").active = true;
this.node.getChildByName("nextBtn").active = false;
cc.tween(this.node.getChildByName("jumpBtn"))
.to(0.35,{opacity:255})
.start();
let tip = cc.fx.tipType.tipOne;
let label = this.node.getChildByName("tip1").getComponent(cc.Label);
cc.fx.GameTool.typingAni(label,tip,this.startGame.bind(this),this);
this.initData();
}
initData(){
this.customData = [
{
"item": "putao",
"type": 1,
"right":1,
},
{
"item": "taozi",
"type": 2,
"right":1,
},
{
"item": "putao",
"type": 2,
"right":3,
},
{
"item": "taozi",
"type": 1,
"right":2,
},
{
"item": "putao",
"type": 1,
"right":2,
},
]
}
passVoice(){
let voice = this.node.getChildByName("voiceTip");
voice.getChildByName("startBtn").getComponent(cc.Button).interactable = false;
voice.getChildByName("playBtn").getComponent(cc.Button).interactable = false;
cc.tween(voice)
.to(0.5,{opacity:0})
.call(()=>{
voice.active = false;
})
.start();
setTimeout(() => {
this.init();
}, 1000);
}
playVoice(){
cc.fx.AudioManager._instance.playEffect("taozi_audio",null);
}
jumpClick(){
cc.director.loadScene("GameScene");
}
nextClick(){
//第一步
this.node.getChildByName("nextBtn").active = false;
let label = this.node.getChildByName("tip1").getComponent(cc.Label);
if(this.custom == 0){
cc.tween(this.node.getChildByName("tip1"))
.to(0.2,{opacity:0})
.call(() =>{
label.string = "";
})
.to(0.1,{opacity:255})
.call(() =>{
let tip = cc.fx.tipType.tipTwo;
cc.fx.GameTool.typingAni(label,tip,this.startGame.bind(this),this);
})
.start();
}
else if(this.custom == 1){
this.node.getChildByName("nextBtn").active = false;
this.node.getChildByName("jumpBtn").active = false;
cc.tween(this.node.getChildByName("tip1"))
.to(0.2,{opacity:0})
.call(() =>{
label.string = "";
this.createCustom();
})
.start();
}
this.custom += 1;
}
createCustom(){
this.choice = 0;
this.Btn_Hear.active = true;
this.Btn_New.active = true;
this.Btn_See.active = true;
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
let name = this.customData[this.custom-2].item;
if(this.customData[this.custom-2].type == 1){
this.Plant.getChildByName("name").getComponent(cc.Label).string = cc.fx.GameTool.getFoodName(name);
name = "prop_"+name;
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.FoodPlist["_spriteFrames"][name];
this.now_Food = name;
cc.tween(this.Plant)
.to(0.2,{opacity:255})
.call(()=>{
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = true;
})
.start();
}
else{
this.Plant.getChildByName("name").getComponent(cc.Label).string = ""
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.voiceSpriteFrame;
let audioName = name + "_audio";
name = "audio"+ name;
this.now_Food = name;
cc.fx.AudioManager._instance.playEffect(audioName,null);
cc.tween(this.Plant)
.to(0.2,{opacity:255})
.call(()=>{
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = true;
})
.start();
}
//关卡+1
}
//新植物按钮
click_Choice(customData,data){
//关掉计时器 处理逻辑之前,先行关掉按钮开关
if(data == "Btn_New"){
this.choice = 1;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
}
else if(data == "Btn_Hear"){
this.choice = 2;
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
}
else if(data == "Btn_See"){
this.choice = 3;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
}
let target = this[data];
var label = this.Tip.getChildByName("content").getComponent(cc.Label);
//正确
if(this.choice == this.customData[this.custom-2].right){
this.Tip.stopAllActions();
this.Tip.active = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
target.getChildByName("err").active = false;
target.getChildByName("correct").active = true;
setTimeout(() => {
this.Btn_New.getChildByName("nomal").active = true;
this.Btn_New.getChildByName("err").active = false;
this.Btn_New.getChildByName("correct").active = false;
this.Btn_Hear.getChildByName("nomal").active = true;
this.Btn_Hear.getChildByName("err").active = false;
this.Btn_Hear.getChildByName("correct").active = false;
this.Btn_See.getChildByName("nomal").active = true;
this.Btn_See.getChildByName("err").active = false;
this.Btn_See.getChildByName("correct").active = false;
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.custom += 1;
if(this.custom >= 7){
this.node.getChildByName("againBtn").active = true;
this.node.getChildByName("startBtn").active = true;
this.Btn_Hear.active = false;
this.Btn_New.active = false;
this.Btn_See.active = false;
}
else this.createCustom();
}, 1000);
}
else{
var tipTemp = cc.fx.tipType.tipErrOld;
this.Tip.active = true;
target.getChildByName("err").active = true;
target.getChildByName("correct").active = false;
switch((this.custom-2)){
case 0: case 1:
tipTemp = cc.fx.tipType.tipErrNew;
break;
case 2:
if(this.choice == 2) tipTemp = cc.fx.tipType.tipErrHear;
break;
case 3:
if(this.choice == 3) tipTemp = cc.fx.tipType.tipErrSee;
break;
case 4:
if(this.choice == 3) tipTemp = cc.fx.tipType.tipErrLast;
break;
}
label.string = tipTemp;
this.Tip.opacity = 255;
this.Tip.stopAllActions();
var self = this;
var action = cc.callFunc(function(){
self.Tip.active = false;
})
this.Tip.runAction(cc.sequence(cc.delayTime(2),cc.fadeIn(0.5),action))
}
}
//开始游戏
startGame(){
this.node.getChildByName("nextBtn").active = true;
cc.tween(this.node.getChildByName("nextBtn"))
.to(0.35,{opacity:255})
.start();
}
againClick(){
cc.director.loadScene("GuideScene");
}
onEnable () {
// cc.fx.Notifications.on("clickSun", this.clickSun, this);
}
onDisable () {
// cc.fx.Notifications.off("clickSun", this.clickSun);
}
update (dt) {
}
}