123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- var GameProtocol = require("RomanGameProtocol");
- import ScenceManager from 'HNScenceManager'
- const arr_posX = [-430, -218, -3, 210, 420];
- cc.Class({
- extends: cc.Component,
- properties: {
- itemClone: cc.Prefab,
- itemSpines: [sp.SkeletonData],
- kuangClone: cc.Node,
- maskClone: cc.Node,
- leftAni: sp.Skeleton,
- rightAni: sp.Skeleton,
- leftLabel: cc.Label,
- rightLabel: cc.Label,
- sizec: 150,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.maxItemLen = 7;
- this.unCheck = true; //不update检测
- this.rollBG = [];
- this.elementNode = [];
- this.elementJS = [];
- this.kuangNode = [];
- this.maskNode = [];
- this.needRolls = []; //存储每个元素是否可以滚动.(金币元素不用滚动)
- this.initData();
- },
- start () {
- },
- resetData(){
- this.nowIndex = 0; //服务器data中m_desk_data的Index
- this.surTimes = 3; //界面显示剩余几次
- },
- initData(){
- this.resetData();
- for(let i=0; i < GameProtocol.MAX_ROW_NUM; i++){
- this.rollBG[i] = [];
- this.elementNode[i] = [];
- this.elementJS[i] = [];
- this.kuangNode[i] = [];
- this.maskNode[i] = [];
- this.needRolls[i] = [];
- let rollNode = this.node.getChildByName(`svNode${i}`);
- if(rollNode){
- for(let j=0; j < GameProtocol.MAX_COL_NUM; j++){
- this.rollBG[i][j] = rollNode.getChildByName("content"+(j+1));
- this.elementNode[i][j] = [];
- this.elementJS[i][j] = [];
- this.needRolls[i][j] = true;
- this.rollBG[i][j].y = 0;
- this.rollBG[i][j].removeAllChildren();
- for(let k=0; k < this.maxItemLen; k++){
- let item = cc.instantiate(this.itemClone);
- item.y = (this.maxItemLen - 2 - k) * this.sizec;
- item.parent = this.rollBG[i][j];
- item.active = false;
- this.elementNode[i][j][k] = item;
- this.elementJS[i][j][k] = item.getComponent("LBItem");
- }
- let kuang = cc.instantiate(this.kuangClone);
- kuang.active = false;
- kuang.x = this.rollBG[i][j].x;
- kuang.y = 0;
- kuang.parent = rollNode;
- this.kuangNode[i][j] = kuang;
- let mask = cc.instantiate(this.maskClone);
- mask.active = false;
- mask.x = this.rollBG[i][j].x;
- mask.y = 0;
- mask.parent = rollNode;
- this.maskNode[i][j] = mask;
- }
- }
- }
- },
- //更新剩余次数.
- upLeftTimes(val){
- this.leftLabel.string = val;
- this.rightLabel.string = val;
- if(val == 3){
- ScenceManager.Instance().getGameComponent().playEffect("sunadd");
- this.leftAni.node.active = true;
- this.leftAni.setAnimation(0, "a3", false);
- this.rightAni.node.active = true;
- this.rightAni.setAnimation(0, "a3", false);
- }
- },
- showSubgame(firstData, firstValueData,sunData){
- console.log('sun2Data: ', firstData, firstValueData, sunData);
- this.unCheck = false;
- this.firstData = firstData;
- this.firstValueData = firstValueData;
- this.sunData = sunData;
- this.upLeftTimes(this.surTimes);
- this.newGolds = []; //存储金币元素.
- for(let i=0; i < GameProtocol.MAX_ROW_NUM; i++){
- for(let j=0; j < GameProtocol.MAX_COL_NUM; j++){
- //随机生成.
- for(let k=0; k < this.maxItemLen; k++){
- let tempValue = this.getRandomValue();
- this.elementJS[i][j][k].setValue(tempValue, this.itemSpines[tempValue], 0);
- }
- //给界面展示的元素赋值.
- this.elementJS[i][j][5].setValue(this.firstData[i][j], this.itemSpines[this.firstData[i][j]], this.firstValueData[i][j]);
- if(this.isSunGold(this.firstData[i][j])){
- this.needRolls[i][j] = false;
- this.kuangNode[i][j].active = true;
- this.kuangNode[i][j].getComponent(sp.Skeleton).setAnimation(0, "a2", true);
- }else{
- this.kuangNode[i][j].active = false;
- this.needRolls[i][j] = true;
- this.maskNode[i][j].active = true;
- }
- }
- }
- },
- rolls(){
- this.surTimes -= 1;
- if(this.nowIndex >= this.sunData.length){ //停止滚动
- this.rollEnd();
- return;
- }
- this.newGolds = [];
- this.upLeftTimes(this.surTimes);
- let index =0;
- for(let i=0; i< GameProtocol.MAX_COL_NUM; i++){
- for(let j=0; j < GameProtocol.MAX_ROW_NUM; j++){
- if(this.needRolls[j][i]){ //非金币元素才会滚动
- this.rollItem(this.rollBG[j][i], j, i, this.sunData[this.nowIndex].m_desk_data[j][i], this.sunData[this.nowIndex].m_desk_value[j][i], index++);
- }
- }
- }
- cc.tween(this.node)
- .delay(index * 0.15+2) //延迟能确保上面的滚动能结束
- .call(()=>{
- for(let k=0; k < this.newGolds.length; k++){
- let i = this.newGolds[k].i;
- let j = this.newGolds[k].j;
- this.needRolls[i][j] = false;
- this.kuangNode[i][j].active = true;
- this.kuangNode[i][j].getComponent(sp.Skeleton).setAnimation(0, "a2", true);
- }
- if(this.newGolds.length >0){ //有新金币产出
- this.surTimes = 2;
- }
- })
- .delay(0.2)
- .call(()=>{
- this.nowIndex += 1;
- this.rolls();
- })
- .start();
- },
- rollItem(tNode, i, j, tarItem, tarValue, idx){
- // console.log('tNode: ', tNode, i, j, tarItem, tarValue, idx);
- this.elementJS[i][j][1].setValue(tarItem, this.itemSpines[tarItem], tarValue);
- // this.elementJS[i][j][5].setValue(tarItem, this.itemSpines[tarItem], tarValue);
- tNode.y = 0;
- tNode.stopAllActions();
- if(this.isSunGold(tarItem)){
- this.newGolds.push({'i': i, 'j': j});
- }
- let preTime = 0.5;
- let times = idx*0.1 + preTime*3;
- let repT = Math.floor(times/preTime);
- let desPos = idx%5;
- cc.tween(tNode)
- .sequence(
- cc.tween().call(()=>{ tNode.y = 0 }),
- cc.tween().to(preTime, {y: -4 * this.sizec})
- )
- .repeat(repT)
- .call(()=>{
- tNode.y = 0;
- this.elementJS[i][j][5-desPos].setValue(tarItem, this.itemSpines[tarItem], tarValue);
- })
- .to(times-repT*preTime, {y: -desPos*this.sizec})
- .call(()=>{
- if(this.isSunGold(tarItem)){
- this.elementJS[i][j][5-desPos].showGoldLight();
- this.maskNode[i][j].active = false;
- ScenceManager.Instance().getGameComponent().playEffect("suncoin");
- }
- })
- .start();
- },
- rollEnd(){
- this.unCheck = true;
- for(let i = 0; i < GameProtocol.MAX_ROW_NUM; ++i) {
- for(let j = 0; j < GameProtocol.MAX_COL_NUM; ++j) {
- this.kuangNode[i][j].active = false;
- this.maskNode[i][j].active = false;
- }
- }
- let gameJS = ScenceManager.Instance().getGameComponent();
- let index = 0;
- for(let i=0; i < GameProtocol.MAX_COL_NUM; i++){
- for(let j=0; j < GameProtocol.MAX_ROW_NUM; j++){
- if(!this.needRolls[j][i]){
- let dy = Math.floor(this.rollBG[j][i].y/this.sizec)+5;
- let nnode = this.elementNode[j][i][dy];
- let label = cc.instantiate(nnode.getChildByName("goldLabel"));
- label.parent = this.node;
- label.x = arr_posX[i];
- label.y = (1-j)*this.sizec+45;
- nnode.getChildByName("goldLabel").active = false;
- cc.tween(label)
- .delay(index*0.3+0.5)
- .call(()=>{
- this.elementJS[j][i][dy].playGetCoinAni();
- })
- .to(0.2, {scale: 1.5, y: label.y+50})
- .call(()=>{
- gameJS.doCoinAni();
- })
- .to(0.4, {x: 0, y:-290, scale: 1})
- .call(()=>{
- gameJS.addCoinGet(this.sunData[this.sunData.length-1].m_desk_value[j][i]);
- })
- .to(0.1, {opacity: 0})
- .start()
- index++;
- }
- }
- }
- cc.tween(this.node)
- .delay(index*0.3+1)
- .call(()=>{
- gameJS.sunGameEnd();
- this.initData();
- })
- .start()
- },
- getRandomValue() {
- return Math.floor(Math.random()*100)%10;
- },
- isSunGold(val) {
- return val == GameProtocol.SUN_ICON;
- },
- update (dt) {
- if(this.unCheck) return;
- for(let i=0; i < GameProtocol.MAX_ROW_NUM; i++){
- for(let j=0; j < GameProtocol.MAX_COL_NUM; j++){
- for(let k=0; k < this.maxItemLen; k++){
- let dy = this.elementNode[i][j][k].y + this.rollBG[i][j].y;
- this.elementNode[i][j][k].active = (dy > -2*this.sizec) && (dy < 2*this.sizec);
- }
- }
- }
- },
- });
|