Commit 30ba01b7 authored by zjz1994's avatar zjz1994

加分动画暂存

parent 7f4430e2
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -45,8 +45,14 @@ function launchWithCustomModule(customModule) { ...@@ -45,8 +45,14 @@ function launchWithCustomModule(customModule) {
}, 100); }, 100);
setTimeout(() => { setTimeout(() => {
engine.globalEvent.dispatchEvent('game-init'); engine.globalEvent.dispatchEvent('game-init',{
time:100000,
level:1
});
}, 500); }, 500);
setTimeout(() => {
engine.globalEvent.dispatchEvent('game-start');
}, 700);
}); });
} }
......
...@@ -239,6 +239,19 @@ ...@@ -239,6 +239,19 @@
this.elePool[itype].push(iele); this.elePool[itype].push(iele);
} }
} }
this.elePool["score"] = new Array();
for (var t = 0; t < 10; t++) {
var itxt = new engine.Label();
itxt.size = 66;
itxt.width = 200;
itxt.height = 70;
itxt.textAlign = engine.TEXT_ALIGN.CENTER;
itxt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
itxt.anchorY = 35;
itxt.anchorX = 100;
itxt.bold = true;
this.elePool["score"].push(itxt);
}
}; };
MapData.getOneEle = function (type) { MapData.getOneEle = function (type) {
var ele; var ele;
...@@ -260,9 +273,36 @@ ...@@ -260,9 +273,36 @@
ele.init(type); ele.init(type);
return ele; return ele;
}; };
MapData.getOneTxt = function () {
var itxt;
if (this.elePool["score"]) {
if (this.elePool["score"].length > 0) {
itxt = this.elePool["score"].shift();
}
}
else {
this.elePool["score"] = new Array();
}
if (!itxt) {
itxt = new engine.Label();
itxt.size = 66;
itxt.width = 200;
itxt.height = 70;
itxt.textAlign = engine.TEXT_ALIGN.CENTER;
itxt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
itxt.anchorY = 35;
itxt.anchorX = 100;
itxt.bold = true;
}
itxt.mouseEnabled = false;
return itxt;
};
MapData.recoverEle = function (ele, type) { MapData.recoverEle = function (ele, type) {
this.elePool[type].push(ele); this.elePool[type].push(ele);
}; };
MapData.recoverTxt = function (txt) {
this.elePool["score"].push(txt);
};
MapData.getDistance = function (p1, p2) { MapData.getDistance = function (p1, p2) {
var p1x = p1[0]; var p1x = p1[0];
var p1y = p1[1]; var p1y = p1[1];
...@@ -298,6 +338,8 @@ ...@@ -298,6 +338,8 @@
_this.canation = true; _this.canation = true;
_this._gametime = 60; _this._gametime = 60;
_this._gamestat = 2; _this._gamestat = 2;
_this._seq = 1;
_this.sptime = Date.now();
_this._score = 0; _this._score = 0;
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this); _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this; return _this;
...@@ -315,6 +357,16 @@ ...@@ -315,6 +357,16 @@
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(GameView.prototype, "seq", {
get: function () {
return this._seq;
},
set: function (num) {
this._seq = num;
},
enumerable: true,
configurable: true
});
GameView.prototype.setup = function () { GameView.prototype.setup = function () {
MapData.initPoolEle(); MapData.initPoolEle();
this.selectimg = new engine.Image(getTextureByName("选中框")); this.selectimg = new engine.Image(getTextureByName("选中框"));
...@@ -343,6 +395,8 @@ ...@@ -343,6 +395,8 @@
this.addChild(this.anicontainer); this.addChild(this.anicontainer);
this.anicontainer.mouseEnabled = false; this.anicontainer.mouseEnabled = false;
this.anicontainer.mouseChildren = false; this.anicontainer.mouseChildren = false;
this.txtcontainer = new engine.Container();
this.addChild(this.txtcontainer);
var map = new engine.Image(getTextureByName("底图")); var map = new engine.Image(getTextureByName("底图"));
this.container.addChild(map); this.container.addChild(map);
for (var r = 0; r < row; r++) { for (var r = 0; r < row; r++) {
...@@ -366,6 +420,7 @@ ...@@ -366,6 +420,7 @@
console.log("gameview-init", time, level); console.log("gameview-init", time, level);
this.score = 0; this.score = 0;
this.gametime = time; this.gametime = time;
this.seq = 1;
this.initContainer(); this.initContainer();
}; };
Object.defineProperty(GameView.prototype, "score", { Object.defineProperty(GameView.prototype, "score", {
...@@ -415,6 +470,7 @@ ...@@ -415,6 +470,7 @@
this.anicontainer.removeChild(this.selectimg); this.anicontainer.removeChild(this.selectimg);
this.selectArr = new Array(); this.selectArr = new Array();
this.gametime = time; this.gametime = time;
this.seq = 1;
this.changeEnable(false); this.changeEnable(false);
for (key in this.lattices) { for (key in this.lattices) {
rcname = this.lattices[key]; rcname = this.lattices[key];
...@@ -568,6 +624,8 @@ ...@@ -568,6 +624,8 @@
var sname = sr + "_" + sc; var sname = sr + "_" + sc;
this.unShowEleAttion(); this.unShowEleAttion();
if (this.selectArr.length == 0) { if (this.selectArr.length == 0) {
this.sptime = Date.now();
this.seqscore = 0;
this.selectArr.push(sname); this.selectArr.push(sname);
} }
else if (this.selectArr.length == 1) { else if (this.selectArr.length == 1) {
...@@ -667,6 +725,7 @@ ...@@ -667,6 +725,7 @@
_this.setLatticeEleRc(sname1); _this.setLatticeEleRc(sname1);
_this.setLatticeEleRc(sname2); _this.setLatticeEleRc(sname2);
_this.selectArr = new Array(); _this.selectArr = new Array();
_this.recordGame();
_this.changeEnable(true); _this.changeEnable(true);
}); });
} }
...@@ -690,7 +749,7 @@ ...@@ -690,7 +749,7 @@
else { else {
addscore = props.moreEscore; addscore = props.moreEscore;
} }
this.score += addscore * ielileng; this.seqscore += addscore * ielileng;
for (j = 0; j < ielidata1.length; j++) { for (j = 0; j < ielidata1.length; j++) {
ielidata = ielidata1[j]; ielidata = ielidata1[j];
ielidxname = ielidata.idxname; ielidxname = ielidata.idxname;
...@@ -705,6 +764,7 @@ ...@@ -705,6 +764,7 @@
ietype = ielinode.type; ietype = ielinode.type;
this.container.removeChild(ielinode); this.container.removeChild(ielinode);
MapData.recoverEle(ielinode, ietype); MapData.recoverEle(ielinode, ietype);
this.addScoreAni(ielix, ieliy, ietype, addscore);
this.lattices[ielidxname] = "empty"; this.lattices[ielidxname] = "empty";
this.goHomeAni(ielitype, ielix, ieliy); this.goHomeAni(ielitype, ielix, ieliy);
} }
...@@ -823,10 +883,11 @@ ...@@ -823,10 +883,11 @@
this.selectArr = new Array(); this.selectArr = new Array();
isdiedata = this.attionEliminate(); isdiedata = this.attionEliminate();
if (isdiedata && isdiedata.length == 2) { if (isdiedata && isdiedata.length == 2) {
this.recordGame();
this.changeEnable(true); this.changeEnable(true);
} }
else { else {
this.solveDieMap(); this.solveDieMap("fall");
} }
} }
return [2]; return [2];
...@@ -942,7 +1003,8 @@ ...@@ -942,7 +1003,8 @@
this.solveDieMap(); this.solveDieMap();
} }
}; };
GameView.prototype.solveDieMap = function () { GameView.prototype.solveDieMap = function (type) {
if (type === void 0) { type = "normal"; }
if (this.gamestat != 1) { if (this.gamestat != 1) {
return; return;
} }
...@@ -959,13 +1021,13 @@ ...@@ -959,13 +1021,13 @@
var isdiedata = this.attionEliminate(); var isdiedata = this.attionEliminate();
if (isdiedata && isdiedata.length == 2) { if (isdiedata && isdiedata.length == 2) {
console.error("可以复活了,转移位置"); console.error("可以复活了,转移位置");
this.changeToFuHuoPos(); this.changeToFuHuoPos(type);
} }
else { else {
return this.solveDieMap(); return this.solveDieMap();
} }
}; };
GameView.prototype.changeToFuHuoPos = function () { GameView.prototype.changeToFuHuoPos = function (type) {
return tslib.__awaiter(this, void 0, void 0, function () { return tslib.__awaiter(this, void 0, void 0, function () {
var prolist, key, keyval, keynode, keynodex, keynodey, tpos, ipro; var prolist, key, keyval, keynode, keynodex, keynodey, tpos, ipro;
return tslib.__generator(this, function (_a) { return tslib.__generator(this, function (_a) {
...@@ -993,6 +1055,9 @@ ...@@ -993,6 +1055,9 @@
this.eliminate(); this.eliminate();
} }
else { else {
if (type == "fall") {
this.recordGame();
}
this.changeEnable(true); this.changeEnable(true);
} }
return [2]; return [2];
...@@ -1000,6 +1065,18 @@ ...@@ -1000,6 +1065,18 @@
}); });
}); });
}; };
GameView.prototype.recordGame = function () {
this.eptime = Date.now();
engine.globalEvent.dispatchEvent('game-record', {
score: this.seqscore,
seq: this.seq,
sptime: this.sptime,
eptime: this.eptime
});
this.seq += 1;
this.seqscore = 0;
this.sptime = Date.now();
};
GameView.prototype.attionEliminate = function () { GameView.prototype.attionEliminate = function () {
var attiondata; var attiondata;
for (var r = MapData.row - 1; r > -1; r--) { for (var r = MapData.row - 1; r > -1; r--) {
...@@ -1336,6 +1413,62 @@ ...@@ -1336,6 +1413,62 @@
} }
return false; return false;
}; };
GameView.prototype.addScoreAni = function (ielix, ieliy, ietype, addscore) {
var _this = this;
var anitxt = MapData.getOneTxt();
anitxt.alpha = 0;
var txtcolor = "#bd882f";
switch (ietype) {
case ElementType.btiger:
txtcolor = "#ffffff";
break;
case ElementType.gtiger:
txtcolor = "#f5a900";
break;
case ElementType.monkey:
txtcolor = "#bd882f";
break;
case ElementType.bird:
txtcolor = "#54c1ef";
break;
case ElementType.koala:
txtcolor = "#c7c8c9";
break;
default:
console.error("未定义类型,检查");
break;
}
anitxt.fillColor = txtcolor;
var anix = ielix + MapData.itemsize / 2 - 100;
var aniy = ieliy + this.conty + MapData.itemsize / 2 - 35;
anitxt.text = "+" + addscore;
this.txtcontainer.addChild(anitxt);
anitxt.x = anix;
anitxt.y = aniy;
anitxt.scaleX = 0;
anitxt.scaleY = 0;
anitxt.alpha = 1;
engine.Tween.get(anitxt, { loop: false }).set({
x: anix,
y: aniy,
scaleX: 0,
scaleY: 0
})
.to({
y: aniy - 50,
scaleX: 1,
scaleY: 1,
}, 300)
.to({
y: aniy - 120,
alpha: 0
}, 500)
.call(function () {
_this.txtcontainer.removeChild(anitxt);
_this.score += addscore;
MapData.recoverTxt(anitxt);
});
};
return GameView; return GameView;
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=GameView.js.map //# sourceMappingURL=GameView.js.map
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -111,6 +111,15 @@ ...@@ -111,6 +111,15 @@
"score":"分数", "score":"分数",
"reason": "结束原因(1:时间到了,2:过关)" "reason": "结束原因(1:时间到了,2:过关)"
} }
},
"game-record": {
"alias": "游戏记录",
"data": {
"score":"操作得分",
"seq": "操作步骤号",
"sptime":"操纵开始时间",
"eptime":"操作结束时间"
}
} }
} }
} }
......
...@@ -20,6 +20,8 @@ export default class GameView extends engine.Container { ...@@ -20,6 +20,8 @@ export default class GameView extends engine.Container {
container:engine.Container; container:engine.Container;
//动画层 //动画层
anicontainer:engine.Container; anicontainer:engine.Container;
//加分文字层
txtcontainer:engine.Container;
//格子,位置-name //格子,位置-name
...@@ -59,6 +61,18 @@ export default class GameView extends engine.Container { ...@@ -59,6 +61,18 @@ export default class GameView extends engine.Container {
get gamestat(){ get gamestat(){
return this._gamestat; return this._gamestat;
} }
_seq = 1;
set seq(num){
this._seq = num;
}
get seq(){
return this._seq;
}
sptime = Date.now();
eptime;
seqscore;
setup() { setup() {
MapData.initPoolEle(); MapData.initPoolEle();
...@@ -93,6 +107,8 @@ export default class GameView extends engine.Container { ...@@ -93,6 +107,8 @@ export default class GameView extends engine.Container {
this.addChild(this.anicontainer); this.addChild(this.anicontainer);
this.anicontainer.mouseEnabled = false; this.anicontainer.mouseEnabled = false;
this.anicontainer.mouseChildren = false; this.anicontainer.mouseChildren = false;
this.txtcontainer = new engine.Container();
this.addChild(this.txtcontainer);
let map = new engine.Image(getTextureByName("底图")); let map = new engine.Image(getTextureByName("底图"));
...@@ -135,6 +151,7 @@ export default class GameView extends engine.Container { ...@@ -135,6 +151,7 @@ export default class GameView extends engine.Container {
console.log("gameview-init",time,level); console.log("gameview-init",time,level);
this.score = 0; this.score = 0;
this.gametime = time; this.gametime = time;
this.seq = 1;
this.initContainer(); this.initContainer();
} }
_score = 0; _score = 0;
...@@ -176,6 +193,8 @@ export default class GameView extends engine.Container { ...@@ -176,6 +193,8 @@ export default class GameView extends engine.Container {
this.anicontainer.removeChild(this.selectimg); this.anicontainer.removeChild(this.selectimg);
this.selectArr = new Array(); this.selectArr = new Array();
this.gametime = time; this.gametime = time;
this.seq = 1;
this.changeEnable(false); this.changeEnable(false);
for(let key in this.lattices){ for(let key in this.lattices){
...@@ -341,6 +360,8 @@ export default class GameView extends engine.Container { ...@@ -341,6 +360,8 @@ export default class GameView extends engine.Container {
if(this.selectArr.length==0){ if(this.selectArr.length==0){
// console.log("选中元素",data); // console.log("选中元素",data);
this.sptime = Date.now();
this.seqscore = 0;
this.selectArr.push(sname); this.selectArr.push(sname);
}else if(this.selectArr.length==1){ }else if(this.selectArr.length==1){
let aselect = this.selectArr[0]; let aselect = this.selectArr[0];
...@@ -453,6 +474,8 @@ export default class GameView extends engine.Container { ...@@ -453,6 +474,8 @@ export default class GameView extends engine.Container {
this.setLatticeEleRc(sname2); this.setLatticeEleRc(sname2);
this.selectArr = new Array(); this.selectArr = new Array();
this.recordGame();
this.changeEnable(true); this.changeEnable(true);
}) })
} }
...@@ -472,7 +495,8 @@ export default class GameView extends engine.Container { ...@@ -472,7 +495,8 @@ export default class GameView extends engine.Container {
addscore = props.moreEscore; addscore = props.moreEscore;
} }
// console.log("消除单个加分",addscore); // console.log("消除单个加分",addscore);
this.score += addscore*ielileng; this.seqscore += addscore*ielileng;
for(let j=0;j<ielidata1.length;j++){ for(let j=0;j<ielidata1.length;j++){
let ielidata = ielidata1[j]; let ielidata = ielidata1[j];
...@@ -489,6 +513,7 @@ export default class GameView extends engine.Container { ...@@ -489,6 +513,7 @@ export default class GameView extends engine.Container {
let ietype = ielinode.type; let ietype = ielinode.type;
this.container.removeChild(ielinode); this.container.removeChild(ielinode);
MapData.recoverEle(ielinode,ietype); MapData.recoverEle(ielinode,ietype);
this.addScoreAni(ielix,ieliy,ietype,addscore);
this.lattices[ielidxname] = "empty"; this.lattices[ielidxname] = "empty";
//元素层消除,动画层添加 //元素层消除,动画层添加
...@@ -602,9 +627,10 @@ export default class GameView extends engine.Container { ...@@ -602,9 +627,10 @@ export default class GameView extends engine.Container {
let isdiedata = this.attionEliminate(); let isdiedata = this.attionEliminate();
if(isdiedata&&isdiedata.length==2){//没死 if(isdiedata&&isdiedata.length==2){//没死
this.recordGame();
this.changeEnable(true); this.changeEnable(true);
}else{//死图处理 }else{//死图处理
this.solveDieMap(); this.solveDieMap("fall");
} }
//检查死图 //检查死图
} }
...@@ -738,7 +764,7 @@ export default class GameView extends engine.Container { ...@@ -738,7 +764,7 @@ export default class GameView extends engine.Container {
} }
} }
//死图调整 //死图调整
solveDieMap(){ solveDieMap(type="normal"){
if(this.gamestat!=1){ if(this.gamestat!=1){
return; return;
} }
...@@ -759,14 +785,14 @@ export default class GameView extends engine.Container { ...@@ -759,14 +785,14 @@ export default class GameView extends engine.Container {
let isdiedata = this.attionEliminate(); let isdiedata = this.attionEliminate();
if(isdiedata&&isdiedata.length==2){ if(isdiedata&&isdiedata.length==2){
console.error("可以复活了,转移位置"); console.error("可以复活了,转移位置");
this.changeToFuHuoPos(); this.changeToFuHuoPos(type);
}else{ }else{
// console.error("依然死亡,寻求复活"); // console.error("依然死亡,寻求复活");
return this.solveDieMap(); return this.solveDieMap();
} }
} }
//转移到复活pos //转移到复活pos
async changeToFuHuoPos(){ async changeToFuHuoPos(type){
let prolist = new Array(); let prolist = new Array();
for(let key in this.lattices){ for(let key in this.lattices){
let keyval = this.lattices[key]; let keyval = this.lattices[key];
...@@ -788,9 +814,29 @@ export default class GameView extends engine.Container { ...@@ -788,9 +814,29 @@ export default class GameView extends engine.Container {
if(this.eliminateArr.length>0){ if(this.eliminateArr.length>0){
this.eliminate(); this.eliminate();
}else{ }else{
if(type=="fall"){
this.recordGame();
}
this.changeEnable(true); this.changeEnable(true);
} }
} }
//游戏记录
recordGame(){
//操作记录
this.eptime = Date.now();
engine.globalEvent.dispatchEvent('game-record',
{
score:this.seqscore,
seq:this.seq,
sptime:this.sptime,
eptime:this.eptime
}
);
this.seq+=1;
this.seqscore = 0;
this.sptime = Date.now();
}
//相邻检测 //相邻检测
attionEliminate(){ attionEliminate(){
...@@ -1178,4 +1224,63 @@ export default class GameView extends engine.Container { ...@@ -1178,4 +1224,63 @@ export default class GameView extends engine.Container {
} }
return false; return false;
} }
addScoreAni(ielix,ieliy,ietype,addscore){
let anitxt = MapData.getOneTxt();
anitxt.alpha = 0;
let txtcolor = "#bd882f";
switch(ietype){
case ElementType.btiger:
txtcolor = "#ffffff";
break;
case ElementType.gtiger:
txtcolor = "#f5a900";
break;
case ElementType.monkey:
txtcolor = "#bd882f";
break;
case ElementType.bird:
txtcolor = "#54c1ef";
break;
case ElementType.koala:
txtcolor = "#c7c8c9";
break;
default:
console.error("未定义类型,检查");
break;
}
anitxt.fillColor = txtcolor;
let anix = ielix+MapData.itemsize/2-100;
let aniy = ieliy+this.conty+MapData.itemsize/2-35;
anitxt.text = "+"+addscore;
this.txtcontainer.addChild(anitxt);
anitxt.x = anix;
anitxt.y = aniy;
anitxt.scaleX = 0;
anitxt.scaleY = 0;
anitxt.alpha = 1;
engine.Tween.get(anitxt,{loop:false}).set({
x:anix,
y:aniy,
scaleX:0,
scaleY:0
})
.to({
y:aniy-50,
scaleX:1,
scaleY:1,
},300)
.to({
y:aniy-120,
alpha:0
},500)
.call(()=>{
this.txtcontainer.removeChild(anitxt);
this.score += addscore;
MapData.recoverTxt(anitxt);
})
}
} }
...@@ -118,6 +118,21 @@ export default class MapData{ ...@@ -118,6 +118,21 @@ export default class MapData{
this.elePool[itype].push(iele); this.elePool[itype].push(iele);
} }
} }
//得分得txt
this.elePool["score"] = new Array();
for(let t=0;t<10;t++){
let itxt = new engine.Label();
itxt.size = 66;
itxt.width = 200;
itxt.height = 70;
itxt.textAlign = engine.TEXT_ALIGN.CENTER;
itxt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
itxt.anchorY = 35;
itxt.anchorX = 100;
itxt.bold = true;
this.elePool["score"].push(itxt);
}
} }
static getOneEle(type:ElementType):Element{ static getOneEle(type:ElementType):Element{
let ele:Element; let ele:Element;
...@@ -141,9 +156,36 @@ export default class MapData{ ...@@ -141,9 +156,36 @@ export default class MapData{
ele.init(type) ele.init(type)
return ele; return ele;
} }
static getOneTxt():engine.Label{
let itxt:engine.Label;
if(this.elePool["score"]){
if(this.elePool["score"].length>0){
itxt = this.elePool["score"].shift();
}
}else{
this.elePool["score"] = new Array();
}
if(!itxt){
itxt = new engine.Label();
itxt.size = 66;
itxt.width = 200;
itxt.height = 70;
itxt.textAlign = engine.TEXT_ALIGN.CENTER;
itxt.verticalAlign = engine.VERTICAL_ALIGN.MIDDLE;
itxt.anchorY = 35;
itxt.anchorX = 100;
itxt.bold = true;
}
itxt.mouseEnabled = false;
return itxt;
}
static recoverEle(ele:Element,type:ElementType){ static recoverEle(ele:Element,type:ElementType){
this.elePool[type].push(ele); this.elePool[type].push(ele);
} }
static recoverTxt(txt:engine.Label){
this.elePool["score"].push(txt);
}
static getDistance(p1,p2){ static getDistance(p1,p2){
let p1x = p1[0]; let p1x = p1[0];
let p1y = p1[1]; let p1y = p1[1];
......
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