开局破防了
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.
 
 
 
 
 

143 lines
4.7 KiB

import DaDianScript from "../../FrameWork/Base/DaDianScript";
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 NewClass extends cc.Component {
@property(cc.Node)
private middle:cc.Node = null;
@property(cc.Node)
private bottom:cc.Node = null;
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.middle.children.forEach(p=>{
p.children.forEach(pp=>{
if(pp.name == 'nan' || pp.name == 'nv'){
pp.opacity = 0;
}
})
})
this.bottom.children.forEach(p=>{
p.children.forEach(pp=>{
if(pp.name == 'drop'){
// console.log('ssss',pp);
this.gameNodeOn(pp);
}
})
})
}
private gameNodeOn(p:cc.Node){
// console.log(p.name);
p.on(cc.Node.EventType.TOUCH_START, this.touchStart, this);
p.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
p.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
p.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
}
private gameNodeOff(p:cc.Node){
p.off(cc.Node.EventType.TOUCH_START, this.touchStart, this);
p.off(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this);
p.off(cc.Node.EventType.TOUCH_END, this.touchEnd, this);
p.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
}
private errorTimes = 0;
private oldPos:cc.Vec2 = null;
private currDrop:cc.Node = null;
private isTouched:boolean = false;
private gameStop:boolean = false;
private touchTime = Date.now();
private touchStart(event: cc.Event.EventTouch){
let node = event.target as cc.Node;
if(this.isTouched) return;
if(this.gameStop) return;
Common5.playEffect('click')
this.currDrop = node;
this.oldPos = this.currDrop.getPosition();
this.isTouched = true;
this.touchTime = Date.now();
}
private touchMove(event: cc.Event.EventTouch){
if(this.currDrop == null) return;
if(this.gameStop) return;
// let pos = this.currDrop.getPosition();
// let pos2 = event.getDelta();
// pos = pos.addSelf(pos2);
// this.currDrop.setPosition(pos);
let nodeLoc = event.getLocation()
let nodePos = event.target.parent.convertToNodeSpaceAR(nodeLoc)
// event.target.setPosition(nodePos)
this.currDrop.setPosition(nodePos);
}
private touchEnd(event: cc.Event.EventTouch){
if(this.currDrop == null) return;
if(this.gameStop) return;
// Common5.playEffect('click')
let d = 1000;
let n:cc.Node = null;
this.middle.children.forEach(p=>{
p.children.forEach(pp=>{
if(pp.name == 'nan' || pp.name == 'nv'){
let distance = Common5.makeNodeDistance_custom(pp, this.currDrop);
if(distance < d){
d = distance;
n = pp;
}
}
})
})
if(d < 100 && n != null && this.currDrop.getComponent(cc.Label).string == n.getComponent(cc.Label).string){
n.opacity = 255;
Common5.playEffect('succ2')
cc.tween(n)
.to(0.3,{scale:1.1})
.to(0.3,{scale:1.0})
.to(0.3,{scale:0.9})
.to(0.3,{scale:1.0})
.start();
}else if(d<40){
Common5.playEffect('fail2')
this.errorTimes += 1;
this.bottom.getChildByName('tips').getComponent(cc.Label).string = '剩余错误次数:' + (3 - this.errorTimes).toString();
}
this.currDrop.setPosition(this.oldPos)
this.currDrop = null;
this.isTouched = false;
this.detect();
}
private detect(){
if(this.errorTimes < 3){
let succ = true;
this.middle.children.forEach(p=>{
p.children.forEach(pp=>{
if(pp.name == 'nan' || pp.name == 'nv'){
if(pp.opacity == 0) succ = false;
}
})
})
if(succ){
Game.ins.showSuccess();
}
}else{
Game.ins.showFail();;
}
}
}