Commit 403187b9 authored by zjz1994's avatar zjz1994

代码暂存

parent e0fcb941
This diff is collapsed.
...@@ -53,7 +53,36 @@ ...@@ -53,7 +53,36 @@
c: this.incol c: this.incol
}); });
}; };
Element.prototype.flyToHome = function () { Object.defineProperty(Element.prototype, "factor", {
get: function () {
return 0;
},
set: function (value) {
this.x = (1 - value) * (1 - value) * this.p1x + 2 * value * (1 - value) * this.c1x + value * value * this.p2x;
this.y = (1 - value) * (1 - value) * this.p1y + 2 * value * (1 - value) * this.c1y + value * value * this.p2y;
var mscale = (1 - value) * (1 - value) * 1 + 2 * value * (1 - value) * 0.6 + value * value * 0;
this.scaleX = mscale;
this.scaleY = mscale;
},
enumerable: true,
configurable: true
});
Element.prototype.flyToHome = function (tx, ty, time) {
var _this = this;
this.p1x = this.x;
this.p1y = this.y;
this.c1x = (this.p1x - tx) / 4 + tx;
this.c1y = ty;
this.p2x = tx;
this.p2y = ty;
engine.Tween.get(this).to({
factor: 1
}, time)
.call(function () {
var nodeparent = _this.parent;
nodeparent && nodeparent.removeChild(_this);
MapData.recoverEle(_this);
});
}; };
Element.prototype.changePos = function () { Element.prototype.changePos = function () {
}; };
...@@ -229,6 +258,7 @@ ...@@ -229,6 +258,7 @@
} }
} }
this.checkEliminate(); this.checkEliminate();
this.attionEliminate();
}; };
GameView.prototype.setLatticeEleRc = function (rcidx) { GameView.prototype.setLatticeEleRc = function (rcidx) {
var rename = this.lattices[rcidx]; var rename = this.lattices[rcidx];
...@@ -344,6 +374,7 @@ ...@@ -344,6 +374,7 @@
var ielix = ielinode.x; var ielix = ielinode.x;
var ieliy = ielinode.y; var ieliy = ielinode.y;
this.container.removeChild(ielinode); this.container.removeChild(ielinode);
MapData.recoverEle(ielinode);
this.lattices[ielidxname] = "empty"; this.lattices[ielidxname] = "empty";
this.goHomeAni(ielitype, ielix, ieliy); this.goHomeAni(ielitype, ielix, ieliy);
} }
...@@ -431,21 +462,15 @@ ...@@ -431,21 +462,15 @@
}; };
GameView.prototype.goHomeAni = function (ielitype, ielix, ieliy) { GameView.prototype.goHomeAni = function (ielitype, ielix, ieliy) {
var aniele = MapData.getOneEle(ielitype); var aniele = MapData.getOneEle(ielitype);
aniele.touch = false;
var anix = ielix; var anix = ielix;
var aniy = ieliy + this.conty; var aniy = ieliy + this.conty;
this.anicontainer.addChild(aniele); this.anicontainer.addChild(aniele);
aniele.touch = false;
aniele.x = anix; aniele.x = anix;
aniele.y = aniy; aniele.y = aniy;
var anidis = MapData.getDistance([this.tanix, this.taniy], [anix, aniy]); var anidis = MapData.getDistance([this.tanix, this.taniy], [anix, aniy]);
var anitime = Math.ceil((anidis / this.anispeed) * 1000); var anitime = Math.ceil((anidis / this.anispeed) * 1000);
engine.Tween.get(aniele) aniele.flyToHome(this.tanix, this.taniy, anitime);
.to({
x: this.tanix,
y: this.taniy,
scaleX: 0,
scaleY: 0
}, anitime);
}; };
GameView.prototype.changeEnable = function (v) { GameView.prototype.changeEnable = function (v) {
for (var key in this.lattices) { for (var key in this.lattices) {
...@@ -455,6 +480,64 @@ ...@@ -455,6 +480,64 @@
} }
}; };
GameView.prototype.attionEliminate = function () { GameView.prototype.attionEliminate = function () {
var attiondata;
for (var r = MapData.row - 1; r > -1; r--) {
for (var c = MapData.col - 1; c > -1; c--) {
var checktype = this.getEleTypeByRc(r, c);
var edatarow = this.getEliminateRow(r, c);
var edatacol = this.getEliminateCol(r, c);
if (edatarow.length > 2 || edatacol.length > 2) {
console.error("啥情况,检查----------------");
}
if (edatarow.length == 2) {
console.log("横向查找", edatarow);
var releidx1 = edatarow[0];
var releidx2 = edatarow[1];
var relerow1 = Number(releidx1.split("_")[0]);
var relerow2 = Number(releidx2.split("_")[0]);
var relecol = Number(releidx1.split("_")[1]);
var downrow = relerow1 + 1;
var uprow = relerow2 - 1;
var rightcol = relecol + 1;
var leftcol = relecol - 1;
var mayeleidxs = new Array();
if (downrow < MapData.row) {
if (rightcol < MapData.col) {
mayeleidxs.push(downrow + "_" + rightcol);
}
if (leftcol > -1) {
mayeleidxs.push(downrow + "_" + leftcol);
}
}
if (uprow > -1) {
if (rightcol < MapData.col) {
mayeleidxs.push(uprow + "_" + rightcol);
}
if (leftcol > -1) {
mayeleidxs.push(uprow + "_" + leftcol);
}
}
for (var ir = 0; ir < mayeleidxs.length; ir++) {
var iridx = mayeleidxs[ir];
var irename = this.lattices[iridx];
if (irename) {
var irerow = Number(iridx.split("_")[0]);
var irecol = Number(iridx.split("_")[1]);
var iretype = this.getEleTypeByRc(irerow, irecol);
if (iretype == checktype) {
console.log("相邻检测到了", iridx);
attiondata = iridx;
return;
}
}
}
}
if (edatacol.length == 2) {
console.log("竖向查找", edatacol);
}
}
}
console.log("相邻检测--------------", attiondata);
}; };
GameView.prototype.checkEliminate = function () { GameView.prototype.checkEliminate = function () {
this.eliminateArr = new Array(); this.eliminateArr = new Array();
...@@ -469,7 +552,7 @@ ...@@ -469,7 +552,7 @@
} }
} }
}; };
GameView.prototype.getEliminate = function (x, y) { GameView.prototype.getEliminateRow = function (x, y) {
var checktype = this.getEleTypeByRc(x, y); var checktype = this.getEleTypeByRc(x, y);
var relearr = new Array(); var relearr = new Array();
relearr.push(x + "_" + y); relearr.push(x + "_" + y);
...@@ -482,6 +565,10 @@ ...@@ -482,6 +565,10 @@
break; break;
} }
} }
return relearr;
};
GameView.prototype.getEliminateCol = function (x, y) {
var checktype = this.getEleTypeByRc(x, y);
var celearr = new Array(); var celearr = new Array();
celearr.push(x + "_" + y); celearr.push(x + "_" + y);
for (var c = y - 1; c > -1; c--) { for (var c = y - 1; c > -1; c--) {
...@@ -493,6 +580,12 @@ ...@@ -493,6 +580,12 @@
break; break;
} }
} }
return celearr;
};
GameView.prototype.getEliminate = function (x, y) {
var checktype = this.getEleTypeByRc(x, y);
var relearr = this.getEliminateRow(x, y);
var celearr = this.getEliminateCol(x, y);
var eliminatearr = new Array(); var eliminatearr = new Array();
if (relearr.length >= 3) { if (relearr.length >= 3) {
eliminatearr.push.apply(eliminatearr, relearr); eliminatearr.push.apply(eliminatearr, relearr);
...@@ -550,7 +643,6 @@ ...@@ -550,7 +643,6 @@
}; };
return GameView; return GameView;
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=GameView.js.map
var GameWrapper = (function (_super) { var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super); tslib.__extends(GameWrapper, _super);
......
This diff is collapsed.
...@@ -117,6 +117,8 @@ export default class GameView extends engine.Container { ...@@ -117,6 +117,8 @@ export default class GameView extends engine.Container {
} }
this.checkEliminate(); this.checkEliminate();
this.attionEliminate();
} }
//关联 //关联
setLatticeEleRc(rcidx){ setLatticeEleRc(rcidx){
...@@ -250,6 +252,7 @@ export default class GameView extends engine.Container { ...@@ -250,6 +252,7 @@ export default class GameView extends engine.Container {
let ielix = ielinode.x; let ielix = ielinode.x;
let ieliy = ielinode.y; let ieliy = ielinode.y;
this.container.removeChild(ielinode); this.container.removeChild(ielinode);
MapData.recoverEle(ielinode);
this.lattices[ielidxname] = "empty"; this.lattices[ielidxname] = "empty";
//元素层消除,动画层添加 //元素层消除,动画层添加
...@@ -334,23 +337,25 @@ export default class GameView extends engine.Container { ...@@ -334,23 +337,25 @@ export default class GameView extends engine.Container {
} }
goHomeAni(ielitype,ielix,ieliy){ goHomeAni(ielitype,ielix,ieliy){
let aniele = MapData.getOneEle(ielitype); let aniele = MapData.getOneEle(ielitype);
aniele.touch = false;
let anix = ielix; let anix = ielix;
let aniy = ieliy + this.conty; let aniy = ieliy + this.conty;
this.anicontainer.addChild(aniele); this.anicontainer.addChild(aniele);
aniele.touch = false;
aniele.x = anix; aniele.x = anix;
aniele.y = aniy; aniele.y = aniy;
let anidis = MapData.getDistance([this.tanix,this.taniy],[anix,aniy]); let anidis = MapData.getDistance([this.tanix,this.taniy],[anix,aniy]);
let anitime = Math.ceil((anidis/this.anispeed)*1000); let anitime = Math.ceil((anidis/this.anispeed)*1000);
engine.Tween.get(aniele) aniele.flyToHome(this.tanix,this.taniy,anitime);
.to({ // engine.Tween.get(aniele)
x:this.tanix, // .to({
y:this.taniy, // x:this.tanix,
scaleX:0, // y:this.taniy,
scaleY:0 // scaleX:0,
},anitime); // scaleY:0
// },anitime);
} }
//修改元素点击 //修改元素点击
...@@ -362,8 +367,75 @@ export default class GameView extends engine.Container { ...@@ -362,8 +367,75 @@ export default class GameView extends engine.Container {
} }
} }
//相邻检测
attionEliminate(){ attionEliminate(){
let attiondata;
for(let r=MapData.row-1;r>-1;r--){
for(let c=MapData.col-1;c>-1;c--){
let checktype = this.getEleTypeByRc(r,c);
let edatarow = this.getEliminateRow(r,c);
let edatacol = this.getEliminateCol(r,c);
if(edatarow.length>2||edatacol.length>2){
console.error("啥情况,检查----------------");
}
if(edatarow.length==2){
console.log("横向查找",edatarow);
let releidx1 = edatarow[0];
let releidx2 = edatarow[1];
let relerow1 = Number(releidx1.split("_")[0]);
let relerow2 = Number(releidx2.split("_")[0]);
let relecol = Number(releidx1.split("_")[1]);
let downrow = relerow1+1;
let uprow = relerow2-1;
let rightcol = relecol+1;
let leftcol = relecol-1;
let mayeleidxs = new Array();
if(downrow<MapData.row){
if(rightcol<MapData.col){
mayeleidxs.push(downrow+"_"+rightcol)
}
if(leftcol>-1){
mayeleidxs.push(downrow+"_"+leftcol);
}
}
if(uprow>-1){
if(rightcol<MapData.col){
mayeleidxs.push(uprow+"_"+rightcol)
}
if(leftcol>-1){
mayeleidxs.push(uprow+"_"+leftcol);
}
}
for(let ir=0;ir<mayeleidxs.length;ir++){
let iridx = mayeleidxs[ir];
let irename = this.lattices[iridx];
if(irename){
let irerow = Number(iridx.split("_")[0]);
let irecol = Number(iridx.split("_")[1]);
let iretype = this.getEleTypeByRc(irerow,irecol);
if(iretype==checktype){
console.log("相邻检测到了",iridx);
attiondata = iridx;
return;
}
}
}
}
if(edatacol.length==2){
console.log("竖向查找",edatacol);
}
}
}
console.log("相邻检测--------------",attiondata);
} }
//检测消除 //检测消除
checkEliminate(){ checkEliminate(){
...@@ -380,7 +452,7 @@ export default class GameView extends engine.Container { ...@@ -380,7 +452,7 @@ export default class GameView extends engine.Container {
} }
} }
getEliminate(x,y){ getEliminateRow(x,y){
let checktype = this.getEleTypeByRc(x,y); let checktype = this.getEleTypeByRc(x,y);
let relearr = new Array(); let relearr = new Array();
...@@ -393,7 +465,10 @@ export default class GameView extends engine.Container { ...@@ -393,7 +465,10 @@ export default class GameView extends engine.Container {
break; break;
} }
} }
return relearr;
}
getEliminateCol(x,y){
let checktype = this.getEleTypeByRc(x,y);
let celearr = new Array(); let celearr = new Array();
celearr.push(x+"_"+y); celearr.push(x+"_"+y);
for(let c=y-1;c>-1;c--){ for(let c=y-1;c>-1;c--){
...@@ -404,6 +479,14 @@ export default class GameView extends engine.Container { ...@@ -404,6 +479,14 @@ export default class GameView extends engine.Container {
break; break;
} }
} }
return celearr;
}
getEliminate(x,y){
let checktype = this.getEleTypeByRc(x,y);
let relearr = this.getEliminateRow(x,y);
let celearr = this.getEliminateCol(x,y);
let eliminatearr = new Array(); let eliminatearr = new Array();
if(relearr.length>=3){ if(relearr.length>=3){
......
...@@ -48,9 +48,44 @@ export default class Element extends engine.Container{ ...@@ -48,9 +48,44 @@ export default class Element extends engine.Container{
}) })
} }
public get factor():number {
return 0;
}
public set factor(value:number) {
this.x = (1 - value) * (1 - value) * this.p1x + 2 * value * (1 - value) * this.c1x + value * value * this.p2x;
this.y = (1 - value) * (1 - value) * this.p1y + 2 * value * (1 - value) * this.c1y + value * value * this.p2y;
var mscale = (1 - value) * (1 - value) * 1 + 2 * value * (1 - value) * 0.6 + value * value * 0;
this.scaleX = mscale;
this.scaleY = mscale;
}
p1x;
p1y;
c1x;
c1y;
p2x;
p2y;
//飞到小屋 //飞到小屋
flyToHome(){ flyToHome(tx,ty,time){
this.p1x = this.x;
this.p1y = this.y;
this.c1x = (this.p1x-tx)/4+tx;
this.c1y = ty;
this.p2x = tx;
this.p2y = ty;
engine.Tween.get(this).to({
factor:1
},time)
.call(()=>{
let nodeparent:engine.Container = this.parent;
nodeparent&&nodeparent.removeChild(this);
MapData.recoverEle(this);
})
} }
changePos(){ changePos(){
......
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