消除我特牛
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

312 lines
9.2 KiB

// Learn TypeScript:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
import DaDianScript from "../../../FrameWork/Base/DaDianScript";
import WordGameBaseComponent from "../../../FrameWork/Base/WordGameBaseComptent";
import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
import EventMgr from "../../../FrameWork/Event/EventMgr";
import Common from "../../../FrameWork/Util/Common";
import Common5 from "../../../Platform/th/Common5";
import Game from "../../../Scripts/Game";
const {ccclass, property} = cc._decorator;
@ccclass
export default class GuoNianHuiJia extends WordGameBaseComponent {
@property(cc.Node)
myQipaoNode:cc.Node = null;
@property(cc.Node)
qipaoNode:cc.Node = null;
@property(cc.Node)
renwuNodeArray:cc.Node[] = [];
@property(cc.Node)
zhujueNode:cc.Node = null;
@property(cc.Node)
xiangqiNode:cc.Node = null;
@property(cc.Node)
damianyao:cc.Node = null;
@property(cc.Node)
jiugehetao:cc.Node = null;
@property(cc.Node)
mudichuandan:cc.Node = null;
@property(cc.Node)
shouyinji:cc.Node = null;
@property(cc.Node)
wanjuche:cc.Node = null;
@property(cc.Node)
chuiziNode:cc.Node = null;
@property(cc.Node)
yanbaNode:cc.Node = null;
@property(cc.Node)
kuBQNode:cc.Node = null;
//文本配置
curIndex = 0
titleArrayConfig: string[] = [];
duihuaArrayConfig: any[] = [];
chadianArrayConfig: any[] = [];
wrongAnswerConfig: string[] = [];
answersDuihuaConfig: any[] = [];
// onLoad () {}
jsonData = null
start () {
super.start();
DaDianScript.userEnterDaDian();
Common5.getJsonFromBundle(Common5.selectGameInfo.bundle,'script/GuoNianHuiJiaConfig',(assest)=>{
this.jsonData = assest.json
this.initParameters();
})
EventMgr.onEvent_custom(ryw_Event.DirectTouchMoveCheck, (data_) => {
this.normalTouchCheckCallback(data_.targetNode);
}, this);
}
//初始化参数
initParameters() {
this.titleArrayConfig = this.jsonData.titleArray;
this.duihuaArrayConfig = this.jsonData.duihuaArray;
this.chadianArrayConfig = this.jsonData.chadianArray;
this.wrongAnswerConfig = this.jsonData.wrongAnswer;
this.answersDuihuaConfig = this.jsonData.answersDuihua;
Common.Type = 3;
Common.subLevel = 0;
Common.GameSubTipConfigs = this.jsonData.answersArray;
this.curIndex = 0
let regiNodes = [this.xiangqiNode, this.damianyao,this.jiugehetao,this.mudichuandan,this.shouyinji,
this.wanjuche,this.chuiziNode,this.yanbaNode,
]
for(let i = 0;i<this.renwuNodeArray.length;i++){
let renwuNode = this.renwuNodeArray[i]
this.initTouchEvent(regiNodes[i], renwuNode, i)
}
let str = this.duihuaArrayConfig[this.curIndex].str
let delay = this.duihuaArrayConfig[this.curIndex].delayTime
let posiNode = this.renwuNodeArray[this.curIndex].getChildByName('qipaoPosi')
this.showQiPao(this.qipaoNode,str, delay,posiNode)
Game.ins.setGameTitle(this.titleArrayConfig[0]);
//this.unlockLevel(this.curIndex)
}
//解锁提示
unlockLevel(sublevel) {
Game.ins.tipUnlock(sublevel)
}
endGameView(touchIndex) {
Game.ins.stopTime();
this.scheduleOnce(()=>{
if(touchIndex == 'success'){
Game.ins.showSuccess()
}else{
Game.ins.showFail()
}
},3)
}
normalTouchCheckCallback(targetNode: any) {
console.log("targetNodeName+++++++++++++++++++++>" + targetNode.name);
switch (targetNode.name) {
case '窗户':
break;
default:
break;
}
}
initTouchEvent(node:cc.Node,touchArea:cc.Node,needIndex:number){
var attrs = {
recoveparent:node.parent,
recoveposi:node.getPosition(),//初始位置
touchArea:touchArea,
needIndex:needIndex,
};
node.attr(attrs);
this.openTouchEvent(node)
}
// update (dt) {}
openTouchEvent(node) {
node.on(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
node.on(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
}
closeTouchEvent(node: cc.Node) {
node.off(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
node.off(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
}
touchStartNode(event) {
let target = event.target;
let nodeMove = this.node.getChildByName('nodeMove')
Common5.setNodeToTargetPos(nodeMove, target)
target.parent = this.node
target.setPosition(cc.v2(nodeMove.getPosition().x, nodeMove.getPosition().y))
}
touchMoveNode(event) {
//let target = event.target
let nodeLoc = event.getLocation()
let nodePos = event.target.parent.convertToNodeSpaceAR(nodeLoc)
event.target.setPosition(nodePos)
}
touchEndNode(event) {
let target = event.target
if(Common5.checkIntersectsBox(target, target['touchArea']) && this.curIndex == target['needIndex']){
if(this.curIndex == 5){
this.kuBQNode.active = true
}
let str = this.answersDuihuaConfig[this.curIndex].str
let delay = this.answersDuihuaConfig[this.curIndex].delayTime
let posiNode = this.zhujueNode.getChildByName('qipaoPosi')
//
target.active = false
this.qipaoNode.active = false
this.showQiPaoMy(this.myQipaoNode, str, delay,posiNode, ()=>{
let peoPle = this.renwuNodeArray[this.curIndex]
let moveX = 2000
let movey = peoPle.getPosition().y
if(peoPle.getPosition().x>0){
moveX = 2000
}else{
moveX = -2000
}
cc.tween(peoPle)
.to(1, {x:moveX,y:movey})
.call(()=>{
this.unlockLevel(this.curIndex)
peoPle.active = false
this.curIndex++
if(this.curIndex==8){
this.endGameView('success')
}else{
let str = this.duihuaArrayConfig[this.curIndex].str
let delay = this.duihuaArrayConfig[this.curIndex].delayTime
let posiNode = this.renwuNodeArray[this.curIndex].getChildByName('qipaoPosi')
this.showQiPao(this.qipaoNode, str, delay,posiNode)
}
})
.start()
})
}
target.parent = target["recoveparent"]
this.nodeMoveToRecovery(target, target["recoveposi"])
}
nodeMoveToRecovery(node, oldPosi:cc.Vec2, func?:Function){
cc.tween(node)
.to(0.1,{x:oldPosi.x, y:oldPosi.y})
.call(()=>{
if(func){
func()
}
})
.start()
}
showQiPao(qipaoNode, str, delayTime=3, posiNode, callFunc=null){
//let qipaoNode = this.qipaoNode
qipaoNode.scale = 0
Common5.setNodeToTargetPos(qipaoNode, posiNode)
qipaoNode.active = true
qipaoNode.stopAllActions()
qipaoNode.getChildByName("str").getComponent(cc.Label).string = str
if (str) {
Common5.playEffectCustom("GuoNianHuiJia", "sound/"+str);
}
cc.tween(qipaoNode)
.to(0.2,{scale:1})
.delay(delayTime)
.call(()=>{
if(callFunc){
callFunc()
}
})
.start()
}
showQiPaoMy(qipaoNode, str, delayTime=3, posiNode, callFunc=null){
//let qipaoNode = this.qipaoNode
qipaoNode.scale = 0
Common5.setNodeToTargetPos(qipaoNode, posiNode)
qipaoNode.active = true
qipaoNode.stopAllActions()
qipaoNode.getChildByName("str").getComponent(cc.Label).string = str
if (str) {
Common5.playEffectCustom("GuoNianHuiJia", "sound/"+str);
}
cc.tween(qipaoNode)
.to(0.2,{scale:1})
.delay(delayTime)
.to(0.2,{scale:0})
.call(()=>{
if(callFunc){
callFunc()
}
})
.start()
}
// update (dt) {}
}