Commit 80fa00a4 authored by zjz1994's avatar zjz1994

优化炮台

parent 251bce34
......@@ -161,6 +161,7 @@ let svgaParser;
//三个toast和bonusTime
const movieClips: any = {};
let cannoblockdata:any = null;
let cannomvdata:any = null;
let cannofire1mvdata:any = null;
let cannolightmvdata:any = null;
......@@ -297,7 +298,11 @@ export default class MainScene extends Scene {
private stepNumber: StepNumber;
//新增炮台,地图上所有的炮台
cannoArr:Array<{idx:number,ele:Element}> = [];
// cannoArr:Array<{idx:number,ele:Element}> = [];
//本地图炮台总数
cannonums:number = 0;
//新增调整
cannoidxArr:Array<number> = [];
//每个炮台对应的特效
cannoEffect:Array<any> = [];
//准备发射的炮台
......@@ -423,7 +428,9 @@ export default class MainScene extends Scene {
this.lollipopMark = false;
this.hasEliminatedElements = new Array();
this.scoreAnis = new Array();
this.cannoArr = new Array();
// this.cannoArr = new Array();
this.cannonums = 0;
this.cannoidxArr = new Array();
this.cannoEffect = new Array();
this.readyCannoArr = new Array();
this.fireteamCannoArr = new Array();
......@@ -550,8 +557,6 @@ export default class MainScene extends Scene {
var svgas = ["amazing", "great", "wonderful", "bonusTime"];
//如果有节日的加
if (this.festivalTarget) svgas.push("redBombLight");
//到时候用炮台石头的替换todo
svgas.push("cannoblock");
for (let i = 0; i < svgas.length; i++) {
if (movieClips[svgas[i]]) continue;
......@@ -560,8 +565,6 @@ export default class MainScene extends Scene {
svgaParser.load(resPath + 'resource/assets/svgas/' + svgas[i] + ".svga", (videoItem) => {
var mv = new window["SVGA"].EgretMovieClip(videoItem);
mv.lockStep = true;
if(svgas[i]=="cannoblock"){
}
if (svgas[i] != "bonusTime") {
mv.x = (750 - 520) / 2;
mv.y = 500;
......@@ -590,20 +593,26 @@ export default class MainScene extends Scene {
cannomvdata = videoItem;
})
}
//炮台石头
if(cannoblockdata){
}else{
svgaParser.load(resPath + 'resource/assets/svgas/cannoblock.svga',(videoItem)=>{
cannoblockdata = videoItem;
})
}
}
/**
* 一个炮台有三个附属动画
*/
initCannoSvgas(arr:Array<{idx:number,ele:Element}>){
initCannoSvgas(icanno:Element,icannobianhao:number){
var resPath = getResPath();
this.cannoEffect = new Array();
if (!svgaParser) svgaParser = new window["SVGA"].Parser();
var svgas = ["cannofire1","cannolight","cannoparticle"];//新增大炮的动画
for(let i=0;i<arr.length;i++){
let icanno:Element = arr[i].ele;
var svgas = ["cannofire1","cannolight"];//,"cannoparticle"];//新增大炮的动画
let icannoidx = icanno.index;
let icannodir:forwardDirection = icanno._cannoDir;
let icannolpos = Tool.getPositionByIndex(arr[i].idx);
let icannolpos = Tool.getPositionByIndex(icannoidx);
let icannowpos = this.elementContainer.localToGlobal(icannolpos[0],icannolpos[1]);
let icannobox:eui.Group = new eui.Group;
......@@ -615,11 +624,10 @@ export default class MainScene extends Scene {
icannobox.anchorOffsetY = icannoboxhei/2;
let effectobj = {};
this.cannoEffect[i] = effectobj;
this.cannoEffect[i]["box"] = icannobox;
this.cannoEffect[icannobianhao] = effectobj;
this.cannoEffect[icannobianhao]["box"] = icannobox;
this.effectContainer.addChild(icannobox);
this.addChild(icannobox);
icannobox.x = icannowpos.x;
icannobox.y = icannowpos.y;
let roanum = Tool.getCannoRoaByDir(icannodir);
......@@ -629,16 +637,25 @@ export default class MainScene extends Scene {
for(let j=0;j<svgas.length;j++){
let jsvgname = svgas[j];
let mvdata:any;
let mv:any;
if(jsvgname=="cannofire1"){
mvdata = cannofire1mvdata;
mv = Pool.takeOut(RecoverName.CANNOFIRE);
}else if(jsvgname=="cannolight"){
mvdata = cannolightmvdata;
mv = Pool.takeOut(RecoverName.CANNOLIGHT);
}else if(jsvgname=="cannoparticle"){
console.error("新特效大炮不再使用particle");
mvdata = cannoparticlemvdata;
}
if(mvdata){
let mv = new window["SVGA"].EgretMovieClip(mvdata);
this.initCannoMv(mv,jsvgname,i);
// console.log("复用mvdata,免加载");
if(!mv){
mv = new window["SVGA"].EgretMovieClip(mvdata);
}else{
// console.log("复用了炮台动画");
}
this.initCannoMv(mv,jsvgname,icannobianhao);
}else{
svgaParser.load(resPath + 'resource/assets/svgas/' + jsvgname + ".svga", (videoItem) => {
let mv = new window["SVGA"].EgretMovieClip(videoItem);
......@@ -650,14 +667,13 @@ export default class MainScene extends Scene {
}else if(jsvgname=="cannoparticle"&&!cannoparticlemvdata){
cannoparticlemvdata = videoItem;
}
this.initCannoMv(mv,jsvgname,i);
this.initCannoMv(mv,jsvgname,icannobianhao);
},function(error){
console.log("炮台svg加载失败",jsvgname);
})
}
}
}
}
/**
* 加载猩猩脚印
*/
......@@ -711,9 +727,40 @@ export default class MainScene extends Scene {
}
}else if(curframe==25){
var icannoidx = target["cannoidx"];
var icanno = this.cannoArr[icannoidx].ele;
var icanno:Element = this.getCannoByBianhao(icannoidx);
if(icanno){
this.callBackFireCanno(icanno);
}else{
console.error("未找到对应大炮,检查");
}
}
}
//该遍历之后尽量简化下todo
getCannoByBianhao(cannoidx:number):Element{
var canno:Element;
// console.log("获取大炮",cannoidx,this.cannoidxArr);
for(var i=0;i<this.cannoidxArr.length;i++){
var ilattice = this.lattices[this.cannoidxArr[i]];
if(ilattice&&ilattice.element&&ilattice.element.type==ElementType.CANNO){
var icannobianhao = ilattice.element.cannobianhao;
if(cannoidx==icannobianhao){
canno = ilattice.element;
break;
}
}
}
// for(var i=0;i<this.lattices.length;i++){
// var ilattice = this.lattices[i];
// if(ilattice&&ilattice.element&&ilattice.element.type==ElementType.CANNO){
// var icannobianhao = ilattice.element.cannobianhao;
// if(cannoidx==icannobianhao){
// canno = ilattice.element;
// break;
// }
// }
// }
return canno;
}
listenCnlight(e){
var target = e.target;
......@@ -724,9 +771,13 @@ export default class MainScene extends Scene {
target.parent.removeChild(target);
}
var icannoidx = target["cannoidx"];
var icanno = this.cannoArr[icannoidx].ele;
var icanno = this.getCannoByBianhao(icannoidx);
if(icanno){
var anmstat = icanno._cannoStat;
icanno.changeMvPlay(anmstat);
}else{
console.error("未找到对应大炮,检查");
}
}
}
listenCnparticle(e){
......@@ -751,6 +802,19 @@ export default class MainScene extends Scene {
*/
selectPlayCannoEffect(idx:number,name:string){
if(this.cannoEffect&&this.cannoEffect[idx]&&this.cannoEffect[idx][name]){
//当前黑洞仅转移炮台位置,不会调整大炮方向,所以仅仅调整特效box位置即可
var icanno = this.getCannoByBianhao(idx);
if(icanno){
let icannoidx = icanno.index;
let icannodir:forwardDirection = icanno._cannoDir;
let icannolpos = Tool.getPositionByIndex(icannoidx);
let icannowpos = this.elementContainer.localToGlobal(icannolpos[0],icannolpos[1]);
this.cannoEffect[idx]["box"].x = icannowpos.x;
this.cannoEffect[idx]["box"].y = icannowpos.y;
}else{
console.error("未找到对应大炮,检查");
}
if(!this.cannoEffect[idx][name].visible){
this.cannoEffect[idx][name].visible = true;
}
......@@ -1040,7 +1104,8 @@ export default class MainScene extends Scene {
//初始化地图元素
initElement() {
this.cannoArr = new Array();
this.cannonums = 0;
this.cannoEffect = new Array();
//没有就根据地图格子随机元素
var elements = this.chapterData.map.elements || Tool.setNumber01(this.chapterData.map.lattices.slice());
//猩猩初始时加入
......@@ -1188,25 +1253,25 @@ export default class MainScene extends Scene {
canno.y = p[1];
this.elementContainer.addChild(canno);
this.lattices[i].element = canno;
this.cannoArr.push({
idx:i,
ele:canno
});
var dirType = Tool.getCannoDir(elements[i]);
canno.resetToCannoView(dirType,this);
let cannobianhao:number = this.cannonums;
//添加大炮
if(cannomvdata){
canno.createCanno(cannomvdata);
canno.createCanno(cannomvdata,cannobianhao);
}else{
if (!svgaParser) svgaParser = new window["SVGA"].Parser();
svgaParser.load(resPath + 'resource/assets/svgas/canno1.svga',(videoItem)=>{
if(!cannomvdata){
cannomvdata = videoItem;
}
canno.createCanno(cannomvdata);
canno.createCanno(cannomvdata,cannobianhao);
})
}
this.cannonums += 1;
this.cannoidxArr.push(i);
//给大炮附加发射等特效
this.initCannoSvgas(canno,cannobianhao);
break;
case ElementConfigType.CANNO_BLOCK:
let canno_block:Element = Tool.getElement(ElementType.CANNO_BLOCK);
......@@ -1306,7 +1371,6 @@ export default class MainScene extends Scene {
break
}
}
this.initCannoSvgas(this.cannoArr);
}
havecreate:Array<number> = [];
//创建猩猩
......@@ -1511,6 +1575,27 @@ export default class MainScene extends Scene {
this.reCoverAllLattice();
//回收炮台相关动画
for(var i=0;i<this.cannoEffect.length;i++){
var icannoeffect = this.cannoEffect[i];
var icannoeffectfire = icannoeffect['cannofire1'];
var icannoeffectlight = icannoeffect['cannolight'];
if(icannoeffectfire){
if(icannoeffectfire.parent){
icannoeffectfire.parent.removeChild(icannoeffectfire);
}
icannoeffectfire.removeEventListener(egret.Event.ENTER_FRAME,this.listenCnfire,this);
Pool.recover(RecoverName.CANNOFIRE,icannoeffectfire);
}
if(icannoeffectlight){
if(icannoeffectlight.parent){
icannoeffectlight.parent.removeChild(icannoeffectlight);
}
icannoeffectlight.removeEventListener(egret.Event.ENTER_FRAME,this.listenCnlight,this);
Pool.recover(RecoverName.CANNOLIGHT,icannoeffectlight);
}
}
this.cannoEffect = new Array();
}
onEnterFrame() {
......@@ -1600,13 +1685,6 @@ export default class MainScene extends Scene {
onTap_quitBtn() {
PanelCtrl.instance.show("quit", {level: this.chapter});
}
// testchangeShow(num:number){
// var cannoele = this.cannoArr[0].ele;
// var cur = cannoele.cannoMoveClip.currentFrame;
// cur += num*10;
// cannoele.cannoMoveClip.gotoAndStop(cur);
// console.log(cannoele.cannoMoveClip.currentFrame);
// }
onTap_boomBtn() {
// this.pongoPaiKuang(38);
// return;
......@@ -1779,7 +1857,7 @@ export default class MainScene extends Scene {
}
//新大炮充能
var pcannostatArr = new Array();
for(var np=0;np<this.cannoArr.length;np++){
for(var np=0;np<this.cannonums;np++){
var pcannodata = {
ineffect:false,
addnum:0,
......@@ -2642,7 +2720,7 @@ export default class MainScene extends Scene {
pcannostatArr = data;
}else{
pcannostatArr = new Array();
for(var p=0;p<this.cannoArr.length;p++){
for(var p=0;p<this.cannonums;p++){
var pcannodata = {
ineffect:false,
addnum:0,
......@@ -2696,7 +2774,7 @@ export default class MainScene extends Scene {
npadd = npaddnum;
}
}
var npcanno = this.cannoArr[np].ele;
var npcanno = this.getCannoByBianhao(np);
for(var ap=0;ap<npadd;ap++){
var lastpcannostatnum:number = npcanno._cannoStat
npcanno.addOneCannoStat();
......@@ -2822,14 +2900,15 @@ export default class MainScene extends Scene {
//炮台充能发射
var emitcanno:Element;
if(this.readyCannoArr.length>0){
// var readyCannoIdx = this.readyCannoArr[0];
// emitcanno = this.cannoArr[readyCannoIdx].ele;
this.fireteamCannoArr = new Array();
for(var p=0;p<this.readyCannoArr.length;p++){
var preadyCannoIdx = this.readyCannoArr[p];
var pemitcanno = this.cannoArr[preadyCannoIdx].ele;
var pemitcanno = this.getCannoByBianhao(preadyCannoIdx);
if(pemitcanno){
this.fireCanno(pemitcanno);
}else{
console.error("未找到对应大炮,检查");
}
}
return;
}
......@@ -3012,79 +3091,20 @@ export default class MainScene extends Scene {
//大炮发射
fireCanno(canno:Element){
// var cannodir = canno._cannoDir;
// var cannorow = canno.row;
// var cannocol = canno.column;
// var cannoFireArr:number[] = new Array();
// if(cannodir==forwardDirection.left){
// for(var i=cannocol;i>=0;i--){
// var iemitidx = Tool.rcToIndex(cannorow,i);
// cannoFireArr.push(iemitidx);
// }
// }else if(cannodir==forwardDirection.up){
// for(var i=cannorow;i>=0;i--){
// var iemitidx = Tool.rcToIndex(i,cannocol);
// cannoFireArr.push(iemitidx);
// }
// }else if(cannodir==forwardDirection.right){
// for(var i=cannocol;i<Tool.colNum;i++){
// var iemitidx = Tool.rcToIndex(cannorow,i);
// cannoFireArr.push(iemitidx);
// }
// }else if(cannodir==forwardDirection.down){
// for(var i=cannorow;i<Tool.rowNum;i++){
// var iemitidx = Tool.rcToIndex(i,cannocol);
// cannoFireArr.push(iemitidx);
// }
// }
// //特效消除猩猩--炮弹
// var lockPongoArr:Array<{idx:number,part:string}> = new Array();
// for(var j=0;j<cannoFireArr.length;j++){
// var jemitidx = cannoFireArr[j];
// var lat = this.lattices[jemitidx];
// var caneliminate = Tool.judgeEliminate(lat);
// var iscannoblock = Tool.judgeIscannoBlock(lat);
// if(lat&&(caneliminate||iscannoblock)){
// if(this.eliminatedElements.indexOf(jemitidx)==-1){
// this.eliminatedElements.push(jemitidx);
// }
// //加分
// if(iscannoblock){
// // console.log("炮台石头消除");
// break;
// }
// }
// //提前消除了,需要修改成炮台的消除时消除
// if(lat&&lat.element){
// var isbreak = this.solveOneTxPgEle(lat.element.row,lat.element.column,lockPongoArr);
// }
// }
canno.fireCanno();
// var cannoidx = canno.index;
// var cannoarridx = this.getCannoArrByIdx(cannoidx);
// this.selectPlayCannoEffect(cannoarridx,"cannoparticle");
// setTimeout(()=>{
// this.eliminate();
// this.readyCannoArr.shift();
// canno.resetCannoStat();
// },200);
// this.solvePongoEle(lockPongoArr);
}
getCannoArrByIdx(cannoidx:number){
var arridx:number = 0;
for(var i=0;i<this.cannoArr.length;i++){
var icannoidx = this.cannoArr[i].idx;
for(var i=0;i<this.cannonums;i++){
var icanno = this.getCannoByBianhao(i);
if(icanno){
var icannoidx = icanno.index;
if(icannoidx==cannoidx){
arridx = i;
break;
}
}
}
return arridx;
}
/**
......@@ -3151,30 +3171,16 @@ export default class MainScene extends Scene {
this.eliminate();
for(var i=0;i<this.readyCannoArr.length;i++){
var preadyCannoIdx = this.readyCannoArr[i];
var pemitcanno = this.cannoArr[preadyCannoIdx].ele;
var pemitcanno = this.getCannoByBianhao(preadyCannoIdx);
if(pemitcanno){
pemitcanno.resetCannoStat();
}else{
console.error("未找到对应大炮,检查");
}
}
this.readyCannoArr = new Array();
this.fireteamCannoArr = new Array();
}
// this.readyCannoArr.shift();
// canno.resetCannoStat();
// if(this.readyCannoArr.length==1){
// this.eliminate();
// }
// let cannoidx = canno.index;
// // setTimeout(()=>{
// for(let i=0;i<this.readyCannoArr.length;i++){
// let ireadycannoidx = this.cannoArr[this.readyCannoArr[i]].idx;
// if(ireadycannoidx==cannoidx){
// this.readyCannoArr.splice(i,1);
// break;
// }
// }
// canno.resetCannoStat();
// // },150)
}
checkAllBlock() {
// this.lattices.filter(item => item.block).forEach((item) => {
......@@ -4895,8 +4901,14 @@ export default class MainScene extends Scene {
removeCannoBlock(index:number){
this.removeOperation(index);
//炮台石头的动效
var blockmv = movieClips["cannoblock"];
var blockmv = Pool.takeOut(RecoverName.CANNOBLOCKANI);//movieClips["cannoblock"];
if(!blockmv){
blockmv = new window["SVGA"].EgretMovieClip(cannoblockdata);
}else{
// console.log("复用炮台石头");
}
if(blockmv){
blockmv.addEventListener(egret.Event.COMPLETE,this.playBlockComp,this);
var blpos = Tool.getPositionByIndex(index);
var bwpos = this.elementContainer.localToGlobal(blpos[0],blpos[1]);
var blockwid = 112;
......@@ -4908,6 +4920,14 @@ export default class MainScene extends Scene {
blockmv.gotoAndPlay(1,1);
}
}
playBlockComp(e){
e.target.stop();
if(e.target.parent){
e.target.removeEventListener(egret.Event.COMPLETE,this.playBlockComp,this);
e.target.parent.removeChild(e.target);
Pool.recover(RecoverName.CANNOBLOCKANI,e.target);
}
}
/**
* 猩猩的移除
*/
......@@ -5003,31 +5023,6 @@ export default class MainScene extends Scene {
//置空格子的element,
this.lattices[index].element = null;
//返回下,有地方要用
//炮台充能
// console.log("消除元素类型",eletype,eleffectype);
// for(let p=0;p<this.cannoArr.length;p++){
// let pcannoidx = this.cannoArr[p].idx;
// var isnext = Tool.checkNebByidx(pcannoidx,index);
// if(isnext&&Tool.judgeChosen(ele)){
// var pcannoele = this.cannoArr[p].ele;
// var lastpcannostatnum:number = pcannoele._cannoStat
// pcannoele.addOneCannoStat();
// var newpcannostatnum:number = pcannoele._cannoStat
// if(newpcannostatnum>lastpcannostatnum){
// // console.log('炮台充能------'+p,lastpcannostatnum,newpcannostatnum);
// this.selectPlayCannoEffect(p,"cannolight");
// }
// var pcannostat = pcannoele.checkCannoStat();
// if(pcannostat){
// if(this.readyCannoArr.indexOf(p)==-1){
// this.readyCannoArr.push(p);
// }
// }
// }
// }
//消除
return ele
......@@ -5113,7 +5108,9 @@ export default class MainScene extends Scene {
//相邻加
addCannoStatByNext(cannoid:number,eleidx:number){
if (!this.lattices[eleidx] || !this.lattices[eleidx].element) return false;
var cannoidx:number = this.cannoArr[cannoid].idx;
var canno = this.getCannoByBianhao(cannoid);
if(canno){
var cannoidx:number = canno.index;
var isnext = Tool.checkNebByidx(cannoidx,eleidx);
var ele = this.lattices[eleidx].element;
if(isnext&&Tool.judgeChosen(ele)){
......@@ -5121,15 +5118,22 @@ export default class MainScene extends Scene {
}else{
return false;
}
}else{
console.error("未找到对应大炮,检查");
return false;
}
}
//横向特效加
addCannoStatByHor(cannoid:number,row:number,col:number){
var cannoidx:number = this.cannoArr[cannoid].idx;
var canno = this.getCannoByBianhao(cannoid);
var addhor:boolean = false;
if(canno){
var cannoidx:number = canno.index;
var cannorc = Tool.indexToRc(cannoidx);
var cannorow = cannorc[0];
var cannocol = cannorc[1];
var addhor:boolean = false;
if(cannocol>col){
for(var i=col;i<Tool.colNum;i++){
var eleidx = Tool.rcToIndex(row,i);
......@@ -5181,16 +5185,22 @@ export default class MainScene extends Scene {
addhor = true;
}
}
}else{
console.error("未找到对应大炮,检查");
}
return addhor;
}
//竖向特效加
addCannoStatByVer(cannoid:number,row:number,col:number){
var cannoidx:number = this.cannoArr[cannoid].idx;
var canno = this.getCannoByBianhao(cannoid);
var addver:boolean = false;
if(canno){
var cannoidx:number = canno.index;
var cannorc = Tool.indexToRc(cannoidx);
var cannorow = cannorc[0];
var cannocol = cannorc[1];
var addver:boolean = false;
if(cannorow>row){
for(var i=row;i<Tool.rowNum;i++){
var eleidx = Tool.rcToIndex(i,col);
......@@ -5242,6 +5252,10 @@ export default class MainScene extends Scene {
addver = true;
}
}
}else{
console.error("未找到对应大炮,检查");
}
return addver;
}
......
......@@ -563,6 +563,7 @@ export class Element extends eui.Component {
// }
return true;
}
//此处回收
addDisable(){
if(this.inPongoPart&&this.inPongoPart=="tl"){
if(this.pongoMoveClip&&this.pongoMoveClip.parent){
......@@ -576,6 +577,15 @@ export class Element extends eui.Component {
}
egret.ticker.$stopTick(this.update,this);
}
if(this.cannoMoveClip){
if(this.cannoMoveClip.parent){
this.cannoMoveClip.parent.removeChild(this.cannoMoveClip);
}
this.cannoMoveClip.removeEventListener(egret.Event.ENTER_FRAME,this.toFrameAni,this);
Pool.recover(RecoverName.CANNO,this.cannoMoveClip);
this.cannoMoveClip = null;
}
}
......@@ -883,18 +893,16 @@ export class Element extends eui.Component {
this.addChild(this.festivalEle)
}
}
//大炮编号
cannobianhao:number;
//添加炮台
createCanno(videoItem:any){
createCanno(videoItem:any,cannobianhao:number){
this.cannobianhao = cannobianhao;
if(this.type==ElementType.CANNO&&videoItem){
this.cannoMoveClip = Pool.takeOut(RecoverName.CANNO);
if(this.cannoMoveClip){
if(this.cannoMoveClip.parent){
this.cannoMoveClip.parent.removeChild(this.cannoMoveClip);
}
this.initCannoMoveClidp();
return;
}
else{
}else{
this.cannoMoveClip = new window["SVGA"].EgretMovieClip(videoItem);
this.initCannoMoveClidp();
}
......
......@@ -84,4 +84,10 @@ export enum RecoverName {
ICE_BLOCK = 'ICE_BLOCK',
DARK_ICE_BLOCK = 'DARK_ICE_BLOCK',
//部分动画的
CANNOBLOCKANI = 'CANNOBLOCKANI',//炮台石头破碎
CANNO = 'CANNO',//炮台
CANNOFIRE = 'CANNOFIRE',//炮台发射
CANNOLIGHT = 'CANNOLIGHT'//炮台聚能
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment