咸鱼的反击
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.

446 lines
17 KiB

3 months ago
import EventMgr from "../../../../FrameWork/Event/EventMgr";
import { ryw_Event } from "../../../../FrameWork/Event/EventEnum";
import Common5 from "../../../../Platform/th/Common5";
import Common from "../../../../FrameWork/Util/Common";
import DaDianScript from "../../../../FrameWork/Base/DaDianScript";
import WordGameBaseComponent from "../../../../FrameWork/Base/WordGameBaseComptent";
import Game from "../../../../Scripts/WenZiRes/ui/Game";
const {ccclass, property} = cc._decorator;
enum TimeStatus{
GuoQu,
WeiLai
}
let CurGameConfig = {
CheckNode:[
'ck_背景','ck_雪爷爷','ck_破衣爷爷1','ck_椅子1','ck_奶奶','ck_木门','ck_猪','ck_烤架','ck_红薯','ck_垃圾','ck_脸盆','ck_木盆','ck_全家福'
],
XianZaiTexture:[
'q_背景','q_雪爷爷spine','h_破衣爷爷spine','h_穿衣爷爷1','q_奶奶spine','q_门spine','q_猪','q_烤架','q_红薯','q_可动垃圾','q_脸盆','q_木盆','q_全家福'
],
WeiLaiTexture:[
'h_背景','h_破衣爷爷spine','','h_按摩椅1','h_老奶奶','h_门','h_猪','h_燃气灶','h_烤乳猪','h_冰箱','h_洗手盆','h_洗衣机','h_小孩'
],
WeiLaiAudio:[
'终于住上新房子了','住不上雪屋了,怪可惜的','新衣服就是好啊','这高科技的椅子就是舒服',
'没想到老婆子一打扮还挺好看','终于不漏风了','来年有猪肉吃了','还是这个烤着方便','家里唯一的猪仔啊,就被你这个老太婆烤了',
'这是给我准备的吗','热水洗脸就是舒服','解放双手了','奶奶,我来看你了'
]
}
@ccclass
export default class KongChaoLaoRen extends WordGameBaseComponent{
@property(cc.Node)
maskNode:cc.Node = null;
@property(cc.Node)
mapNode:cc.Node = null;
gameInfo = null
bundle = null
mapNodeFixedScale:number = 0.6//固定缩放(图片太大了)
touchStartTime:number = 0//触摸开始时间
originalTouchDistance:number = 0 //起始双指触摸间距
lastScale:number = 1//上次缩放值
curScale:number = 1//当前缩放值
touchId1:number = -1
touchId2:number = -2
curFinishNum:number = 0
isStepRight:boolean = true
isKaiMen:boolean = false
isHuanMen:boolean = false
isHuanZhu:boolean = false
isChuangYi:boolean = false
isHuanYiZi:boolean = false
onLoad(){
DaDianScript.userEnterDaDian()
Common.Type = 0;
Common.subLevel = 0;
Common.GameSubTipConfigs=[Common5.gameConfig.zmGameConfig[Common5.selectGameNum].toolTip]
Common.GameSubAnswerConfigs=[Common5.gameConfig.zmGameConfig[Common5.selectGameNum].answer]
this.bundle = Common5.gameConfig.zmGameConfig[Common5.selectGameNum].bundle
EventMgr.onEvent_custom(ryw_Event.timeOut, (tab) => {
Game.ins.showFail();;
}, this);
EventMgr.onEvent_custom(ryw_Event.DirectTouchMoveCheck, (data_) => {
if(data_.targetNode.name == 'touchNodeMen'){
this.isKaiMen = true
if(this.isHuanMen){
this.mapNode.getChildByName('好门开').active = true
this.mapNode.getChildByName('h_门').active = false
this.mapNode.getChildByName('h_门spine').active = false
}
}
}, this);
}
start(){
super.start();
cc.macro.ENABLE_MULTI_TOUCH = true;
this.initMapNodeTouchEvent()
}
//初始化触摸监听
initMapNodeTouchEvent(){
this.initMouseEvent();
this.mapNode.on(cc.Node.EventType.TOUCH_START, this.touchStart_mapNode,this)
this.mapNode.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove_mapNode,this)
this.mapNode.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd_mapNode,this)
this.mapNode.on(cc.Node.EventType.TOUCH_END, this.touchEnd_mapNode,this)
let prefabWidth = this.mapNode.width
let prefabHeight = this.mapNode.height
let maskWidth = this.maskNode.width
let maskHeight = this.maskNode.height
let widthScale = maskWidth/prefabWidth
let heightScale = maskHeight/prefabHeight
if(prefabWidth<prefabHeight){
this.mapNodeFixedScale = widthScale
}else{
this.mapNodeFixedScale = heightScale
}
this.mapNode.scale = this.mapNodeFixedScale
this.curScale = this.mapNodeFixedScale
this.lastScale = this.mapNodeFixedScale
this.specialNodeTouchEvent()
}
touchStart_mapNode(event){
Common5.playEffect("click")
if(this.touchId1 < 0){
this.touchId1 = event.touch.getID()
}else if(this.touchId2 < 0){
this.touchId2 = event.touch.getID()
}
if(this.touchId1 >= 0 && this.touchId2 >= 0){
// console.log("邵阳1—双点触摸开始")
}
this.touchStartTime = Date.now()
}
touchMove_mapNode(event){
let touches = event.getTouches()
if(touches.length == 2){ //缩放
if(this.originalTouchDistance == 0){
this.originalTouchDistance = this.getDistance(touches[0].getLocation(),touches[1].getLocation())
}
//获取双指移动数据
let curDistance = this.getDistance(touches[0].getLocation(),touches[1].getLocation())
let tempScale = curDistance/this.originalTouchDistance
let y = 0.5*tempScale + 0.5
let scale = y * this.lastScale
if(scale < this.mapNodeFixedScale){
scale = this.mapNodeFixedScale
}else if(scale > 3){
scale = 3
}else{
}
this.mapNode.scale = scale
this.curScale = scale
this.goToBoundary();
}else if(touches.length == 1){ //拖动
let delta = event.getDelta()
this.mapNode.x += delta.x
this.mapNode.y += delta.y
// console.log(this.mapNode.scale,this.mapNode.x,this.mapNode.y);
this.goToBoundary()
}
}
touchEnd_mapNode(event){
console.log('touchEnd===')
let dateNow = Date.now()
if(dateNow - this.touchStartTime > 0.2 * 1000){
// console.log('0.2===')
// //补丁,长按两秒
// if(dateNow - this.touchStartTime > 1.5 * 1000){
// console.log('2===')
// let wl_fangzi = this.mapNode.getChildByName('wl_房子')
// let chuanghuguan = wl_fangzi.getChildByName('窗户关')
// let chuanghukai = wl_fangzi.getChildByName('窗户开')
// let rect = chuanghuguan.getBoundingBoxToWorld()
// if(wl_fangzi.active && chuanghuguan.active && rect.contains(event.getLocation())){
// chuanghuguan.active = false
// chuanghukai.active = true
// this.isKaiChuang = true
// }
// }
}else{
// this.isFind = false;
let touchPos = event.getLocation();
this.checkIsInAreaNewVersion(touchPos)
}
if(event.touch.getID() == this.touchId1){
this.touchId1 = -1
}else if(event.touch.getID() == this.touchId2){
this.touchId2 = -2
}
if(this.touchId1 < 0 && this.touchId2 < 0){
this.originalTouchDistance = 0
this.lastScale = this.curScale
// this.goToBoundary()
}
}
//距离
getDistance(startPos,endPos){
var pos = cc.v2(startPos.x - endPos.x,startPos.y - endPos.y)
var dis = Math.sqrt(pos.x * pos.x + pos.y * pos.y)
return dis
}
//检测边界
goToBoundary(){
let widthMask = this.maskNode.width
let heightMask = this.maskNode.height
let widthMap = this.mapNode.width*this.curScale
let heightMap = this.mapNode.height*this.curScale
//右边界
if(this.mapNode.x + widthMap/2 <= widthMask/2){
this.mapNode.x = widthMask/2 - widthMap/2
//左边界
}else if(this.mapNode.x - widthMap/2>= -widthMask/2){
this.mapNode.x = -widthMask/2 + widthMap/2
}
//上边界
if(this.mapNode.y + heightMap/2 <= heightMask/2){
this.mapNode.y = heightMask/2 - heightMap/2
//下边界
}else if(this.mapNode.y - heightMap/2 >= -heightMask/2){
this.mapNode.y = -heightMask/2 + heightMap/2
}
}
initMouseEvent(){
this.mapNode.on(cc.Node.EventType.MOUSE_WHEEL,function(event){//监听名称+事件参数
console.log(event);
let tmpscale = this.mapNode.scale;
if (event._scrollY > 0){
if (this.mapNode.scale < 3){
tmpscale+=0.2;
this.mapNode.scale = tmpscale
this.curScale = tmpscale
this.lastScale = tmpscale
}
}
else {
if (this.mapNode.scale > this.mapNodeFixedScale){
tmpscale-=0.2;
this.mapNode.scale = tmpscale
this.curScale = tmpscale
this.lastScale = tmpscale
}
}
// console.log(this.mapNode.scale,this.mapNode.x,this.mapNode.y);
this.goToBoundary();
},this);
}
//检测node是否进入target区域(新版)
checkIsInAreaNewVersion(pos){
// //茬点触碰逻辑
// let childrens = this.mapNode.getChildByName("chaDianNode").children
// for(var i =0;i<childrens.length;i++){
// let rect = childrens[i].getBoundingBoxToWorld()
// if(rect.contains(pos)){
// if(this.gameInfo.ChaNode[childrens[i].name].isFindOut){
// continue
// }else{
// //暂不可点击
// if(!this.gameInfo.ChaNode[childrens[i].name].isCanTouch){
// continue
// }
// this.gameInfo.ChaNode[childrens[i].name].isFindOut = true
// if (this.gameInfo.PrefabInfo.zhaoChaType == ZhaoChaType.Type6){
// this.findOnChaDian(childrens[i],this.gameId)
// }
// else {
// this.findOnChaDian(childrens[i])
// }
// this.isFind = true
// }
// break
// }else{
// //点错这里需要减5s
// }
// }
// this.handSpecialGameLogic(pos)
}
//特殊节点的点击事件(主要处理节点可以移动的问题)
specialNodeTouchEvent(){
let qianNode = this.mapNode.getChildByName("qianNode")
for(let i=0;i<qianNode.childrenCount;i++){
this.openTouchEvent(qianNode.getChildByName('money_'+i),true,CurGameConfig.CheckNode,CurGameConfig.XianZaiTexture,CurGameConfig.WeiLaiTexture)
}
}
openTouchEvent(node,isCanMove, checkNodeTab,changeNodeTab1,changeNodeTab2){
var attrs = {
checkNodeTab: checkNodeTab,
changeNodeTab1:changeNodeTab1,
changeNodeTab2:changeNodeTab2,
isCanMove:isCanMove,
startPos: node.getPosition(),//初始位置
};
node.attr(attrs)
node.on(cc.Node.EventType.TOUCH_START,this.touchStartSpecicalNode,this)
node.on(cc.Node.EventType.TOUCH_MOVE,this.touchMoveSpecicalNode,this)
node.on(cc.Node.EventType.TOUCH_CANCEL,this.touchEndSpecicalNode,this)
node.on(cc.Node.EventType.TOUCH_END,this.touchEndSpecicalNode,this)
}
closeTouchEvent(node){
node.off(cc.Node.EventType.TOUCH_START,this.touchStartSpecicalNode,this)
node.off(cc.Node.EventType.TOUCH_MOVE,this.touchMoveSpecicalNode,this)
node.off(cc.Node.EventType.TOUCH_CANCEL,this.touchEndSpecicalNode,this)
node.off(cc.Node.EventType.TOUCH_END,this.touchEndSpecicalNode,this)
}
private specialTouchTime = Date.now();
touchStartSpecicalNode(event){
Common5.playEffect("click")
this.specialTouchTime = Date.now();
}
touchMoveSpecicalNode(event){
let target = event.target;
if(!target.isCanMove){
return
}
let posi = event.getLocation()//世界坐标
posi = target.parent.convertToNodeSpaceAR(posi)
target.setPosition(posi)
}
touchEndSpecicalNode(event){
// event.target.zIndex = 0
let target = event.target;
let checkIndex = this.checkArea(target,target.checkNodeTab)
if (checkIndex >= 0) {
this.curFinishNum ++
this.checkIsFinish(true)
this.showDuiHua(CurGameConfig.WeiLaiAudio[checkIndex])
this.closeTouchEvent(event.target)
event.target.active = false
let changeNode1 = this.mapNode.getChildByName(target.changeNodeTab1[checkIndex])
if(changeNode1){
changeNode1.active = false
}
let changeNode2 = this.mapNode.getChildByName(target.changeNodeTab2[checkIndex])
if(changeNode2){
changeNode2.active = true
}
let checkNode = this.mapNode.getChildByName(target.checkNodeTab[checkIndex])
if(checkNode){
checkNode.active = false
}
}else{
event.target.setPosition(event.target.startPos)
}
}
checkArea(node,checkNodeTab){
let checkIndex = -1
for(let i=0;i<checkNodeTab.length;i++){
let target = this.mapNode.getChildByName(checkNodeTab[i])
if(target && target.active && Common5.checkContainsNode(target,node)){
if(target.name == 'ck_雪爷爷' ){
this.mapNode.getChildByName('ck_破衣爷爷1').active = true
this.mapNode.getChildByName('ck_椅子1').active = true
}else if(target.name == 'ck_破衣爷爷1'){
if(!this.isChuangYi){
this.isChuangYi = true
if(this.isHuanYiZi){
this.mapNode.getChildByName('h_按摩椅2').active = true
this.mapNode.getChildByName('h_穿衣爷爷1').active = false
}else{
this.mapNode.getChildByName('h_穿衣爷爷1').active = true
}
}else{
continue
}
}else if(target.name == 'ck_椅子1' ){
if(!this.isHuanYiZi){
this.isHuanYiZi = true
this.mapNode.getChildByName('h_破衣爷爷spine').active = false
if(this.isChuangYi){
this.mapNode.getChildByName('h_按摩椅2').active = true
}else{
this.mapNode.getChildByName('h_按摩椅1').active = true
}
}else{
continue
}
}else if(target.name == 'ck_猪'){
if(!this.isKaiMen || this.isHuanZhu){
continue
}else{
this.isHuanZhu = true
}
}else if(target.name == 'ck_木门'){
if(this.isKaiMen && !this.isHuanZhu){
continue
}
if(!this.isHuanMen){
this.isHuanMen = true
this.mapNode.getChildByName('q_门spine').active = false
this.mapNode.getChildByName('h_门spine').active = false
// this.mapNode.getChildByName('touchNodeMen').active = false
}else{
continue
}
}
checkIndex = i
break
}
}
return checkIndex
}
checkIsFinish(bRight){
// if(!bRight){
// this.isStepRight = bRight
// }
if(this.curFinishNum >= 13){
this.scheduleOnce(()=>{
Game.ins.showSuccess()
},2)
}
}
showDuiHua(str, func?) {
console.log("str==", str)
if (!str || str == '') {
return;
}
Common5.playEffectCustom(this.bundle, 'sound/'+str);
let qiPao = this.node.getChildByName("duihua")
qiPao.stopAllActions()
qiPao.getChildByName("tabLab2").getComponent(cc.Label).string = str
qiPao.active = true
qiPao.scale = 0
cc.tween(qiPao)
.to(0.2, { scale: 1 })
.delay(3)
.call(() => {
qiPao.active = false;
if (func) {
func();
}
})
.start();
}
}