Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-libs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
zeroing-libs
Commits
bea870f5
Commit
bea870f5
authored
Jul 13, 2020
by
zjz1994
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码暂存
parent
426cdc81
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
654 additions
and
85 deletions
+654
-85
xiaoxiaole.json
dist/customs/xiaoxiaole.json
+7
-1
Player.ts
src/custom/bjxd-game/src/game/Player.ts
+1
-1
main.js
src/custom/xiaoxiaole/debug/main.js
+325
-45
main.js.map
src/custom/xiaoxiaole/debug/main.js.map
+1
-1
meta.json
src/custom/xiaoxiaole/meta.json
+6
-0
GameView.ts
src/custom/xiaoxiaole/src/game/GameView.ts
+265
-29
MapData.ts
src/custom/xiaoxiaole/src/game/MapData.ts
+2
-0
Element.ts
src/custom/xiaoxiaole/src/game/ele/Element.ts
+47
-8
No files found.
dist/customs/xiaoxiaole.json
View file @
bea870f5
...
...
@@ -50,6 +50,12 @@
"url"
:
"//yun.duiba.com.cn/aurora/assets/a3ce52a41ed53ccfa7ce404dbc10102961c4a805.png"
,
"uuid"
:
"selected"
,
"ext"
:
".png"
},
{
"name"
:
"房子动画"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/f55c640d40911934c7c5cf01f4fc1940ffb4e16c.svga"
,
"uuid"
:
"homeani"
,
"ext"
:
".svga"
}
],
"events"
:
{
...
...
@@ -89,5 +95,5 @@
}
},
"id"
:
"xiaoxiaole"
,
"code"
:
"(function (global, factory) {
\n\t
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n\t
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n\t
(global = global || self, global.xiaoxiaole = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
function getTexture(uuid) {
\r\n\t
return engine.Texture.from(getAssetByUUID(uuid).uuid);
\r\n\t
}
\r\n\t
function getTextureByName(name) {
\r\n\t
return getTexture(engine.getAssetByName(name).uuid);
\r\n\t
}
\
n\n\t
var Element = (function (_super) {
\r\n\t
tslib.__extends(Element, _super);
\r\n\t
function Element() {
\r\n\t
var _this = _super.call(this) || this;
\r\n\t
_this.width = MapData.itemsize;
\r\n\t
_this.height = MapData.itemsize;
\r\n\t
_this.eimage = new engine.Image();
\r\n\t
_this.addChild(_this.eimage);
\r\n\t
_this.touch = true;
\r\n\t
_this.addEventListener(engine.MouseEvent.CLICK, _this.selectele, _this);
\r\n\t
return _this;
\r\n\t
}
\r\n\t
Object.defineProperty(Element.prototype,
\"
touch
\"
, {
\r\n\t
set: function (touch) {
\r\n\t
this.mouseEnabled = touch;
\r\n\t
this.mouseChildren = touch;
\r\n\t
},
\r\n\t
enumerable: true,
\r\n\t
configurable: true
\r\n\t
});
\r\n\t
Element.prototype.init = function (type) {
\r\n\t
this.scaleX = 1;
\r\n\t
this.scaleY = 1;
\r\n\t
this.type = type;
\r\n\t
var ename = MapData.getEtypeImgName(type);
\r\n\t
this.eimage.texture = getTextureByName(ename);
\r\n\t
var imgwid = this.eimage.texture.width;
\r\n\t
var imghei = this.eimage.texture.height;
\r\n\t
this.eimage.x = (this.width - imgwid) / 2;
\r\n\t
this.eimage.y = (this.height - imghei) / 2;
\r\n\t
};
\r\n\t
Element.prototype.setrc = function (r, c) {
\r\n\t
this.inrow = r;
\r\n\t
this.incol = c;
\r\n\t
};
\r\n\t
Element.prototype.selectele = function (e) {
\r\n\t
engine.globalEvent.dispatchEvent(GameEvent.SelectEle, {
\r\n\t
r: this.inrow,
\r\n\t
c: this.incol
\r\n\t
});
\r\n\t
};
\r\n\t
Object.defineProperty(Element.prototype,
\"
factor
\"
, {
\r\n\t
get: function () {
\r\n\t
return 0;
\r\n\t
},
\r\n\t
set: function (value) {
\r\n\t
this.x = (1 - value) * (1 - value) * this.p1x + 2 * value * (1 - value) * this.c1x + value * value * this.p2x;
\r\n\t
this.y = (1 - value) * (1 - value) * this.p1y + 2 * value * (1 - value) * this.c1y + value * value * this.p2y;
\r\n\t
var mscale = (1 - value) * (1 - value) * 1 + 2 * value * (1 - value) * 0.6 + value * value * 0;
\r\n\t
this.scaleX = mscale;
\r\n\t
this.scaleY = mscale;
\r\n\t
},
\r\n\t
enumerable: true,
\r\n\t
configurable: true
\r\n\t
});
\r\n\t
Element.prototype.flyToHome = function (tx, ty, time) {
\r\n\t
var _this = this;
\r\n\t
this.p1x = this.x;
\r\n\t
this.p1y = this.y;
\r\n\t
this.c1x = (this.p1x - tx) / 4 + tx;
\r\n\t
this.c1y = ty;
\r\n\t
this.p2x = tx;
\r\n\t
this.p2y = ty;
\r\n\t
engine.Tween.get(this).to({
\r\n\t
factor: 1
\r\n\t
}, time)
\r\n\t
.call(function () {
\r\n\t
var nodeparent = _this.parent;
\r\n\t
nodeparent && nodeparent.removeChild(_this);
\r\n\t
MapData.recoverEle(_this);
\r\n\t
});
\r\n\t
};
\r\n\t
Element.prototype.changePos = function () {
\r\n\t
};
\r\n\t
return Element;
\r\n\t
}(engine.Container));
\n\n\t
var ElementType;
\r\n\t
(function (ElementType) {
\r\n\t
ElementType[ElementType[
\"
btiger
\"
] = 1] =
\"
btiger
\"
;
\r\n\t
ElementType[ElementType[
\"
gtiger
\"
] = 2] =
\"
gtiger
\"
;
\r\n\t
ElementType[ElementType[
\"
monkey
\"
] = 3] =
\"
monkey
\"
;
\r\n\t
ElementType[ElementType[
\"
bird
\"
] = 4] =
\"
bird
\"
;
\r\n\t
ElementType[ElementType[
\"
koala
\"
] = 5] =
\"
koala
\"
;
\r\n\t
})(ElementType || (ElementType = {}));
\r\n\t
var GameEvent;
\r\n\t
(function (GameEvent) {
\r\n\t
GameEvent[
\"
SelectEle
\"
] =
\"
SelectEle
\"
;
\r\n\t
})(GameEvent || (GameEvent = {}));
\r\n\t
var MapData = (function () {
\r\n\t
function MapData() {
\r\n\t
}
\r\n\t
MapData.getRy = function (r) {
\r\n\t
return this.paddingb + r * (this.itemsize + this.paddingi);
\r\n\t
};
\r\n\t
MapData.getCx = function (c) {
\r\n\t
return this.paddingb + c * (this.itemsize + this.paddingi);
\r\n\t
};
\r\n\t
MapData.getRCPos = function (r, c) {
\r\n\t
var x = this.getCx(c);
\r\n\t
var y = this.getRy(r);
\r\n\t
return [x, y];
\r\n\t
};
\r\n\t
MapData.adaptElePos = function (pos, wid, hei) {
\r\n\t
var x = pos[0] + (this.itemsize - wid) / 2;
\r\n\t
var y = pos[1] + (this.itemsize - hei) / 2;
\r\n\t
return [x, y];
\r\n\t
};
\r\n\t
MapData.getEtypeImgName = function (type) {
\r\n\t
var ename;
\r\n\t
switch (type) {
\r\n\t
case ElementType.btiger:
\r\n\t
ename =
\"
白虎
\"
;
\r\n\t
break;
\r\n\t
case ElementType.gtiger:
\r\n\t
ename =
\"
雌虎
\"
;
\r\n\t
break;
\r\n\t
case ElementType.monkey:
\r\n\t
ename =
\"
猴子
\"
;
\r\n\t
break;
\r\n\t
case ElementType.bird:
\r\n\t
ename =
\"
鸟
\"
;
\r\n\t
break;
\r\n\t
case ElementType.koala:
\r\n\t
ename =
\"
树熊
\"
;
\r\n\t
break;
\r\n\t
default:
\r\n\t
console.error(
\"
未定义元素类型
\"
);
\r\n\t
break;
\r\n\t
}
\r\n\t
return ename;
\r\n\t
};
\r\n\t
MapData.getRandEtype = function () {
\r\n\t
var eletypeArr = [ElementType.btiger, ElementType.gtiger, ElementType.monkey, ElementType.bird, ElementType.koala];
\r\n\t
var etype = eletypeArr[Math.floor(Math.random() * eletypeArr.length)];
\r\n\t
return etype;
\r\n\t
};
\r\n\t
MapData.getOneEle = function (type) {
\r\n\t
var ele;
\r\n\t
if (this.elePool.length > 0) {
\r\n\t
ele = this.elePool.shift();
\r\n\t
}
\r\n\t
else {
\r\n\t
ele = new Element();
\r\n\t
}
\r\n\t
ele.name =
\"
ele_
\"
+ this.eleidx;
\r\n\t
this.eleidx += 1;
\r\n\t
ele.init(type);
\r\n\t
return ele;
\r\n\t
};
\r\n\t
MapData.recoverEle = function (ele) {
\r\n\t
this.elePool.push(ele);
\r\n\t
};
\r\n\t
MapData.getDistance = function (p1, p2) {
\r\n\t
var p1x = p1[0];
\r\n\t
var p1y = p1[1];
\r\n\t
var p2x = p2[0];
\r\n\t
var p2y = p2[1];
\r\n\t
var dis = Math.sqrt(Math.pow(p1x - p2x, 2) + Math.pow(p1y - p2y, 2));
\r\n\t
return dis;
\r\n\t
};
\r\n\t
MapData.itemsize = 129;
\r\n\t
MapData.paddingb = 10;
\r\n\t
MapData.paddingi = 5;
\r\n\t
MapData.row = 5;
\r\n\t
MapData.col = 5;
\r\n\t
MapData.posData = {};
\r\n\t
MapData.eleidx = 1;
\r\n\t
MapData.elePool = [];
\r\n\t
return MapData;
\r\n\t
}());
\n\n\t
var GameView = (function (_super) {
\r\n\t
tslib.__extends(GameView, _super);
\r\n\t
function GameView() {
\r\n\t
var _this = _super.call(this) || this;
\r\n\t
_this.lattices = {};
\r\n\t
_this.eliminateArr = [];
\r\n\t
_this.selectArr = [];
\r\n\t
_this.conty = 140;
\r\n\t
_this.homex = 528;
\r\n\t
_this.anispeed = 860;
\r\n\t
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
\r\n\t
return _this;
\r\n\t
}
\r\n\t
GameView.prototype.setup = function () {
\r\n\t
this.selectimg = new engine.Image(getTextureByName(
\"
选中框
\"
));
\r\n\t
this.selectimg.mouseEnabled = false;
\r\n\t
var row = MapData.row;
\r\n\t
var col = MapData.col;
\r\n\t
this.homeimg = new engine.Image(getTextureByName(
\"
房子
\"
));
\r\n\t
this.addChild(this.homeimg);
\r\n\t
this.homeimg.x = this.homex;
\r\n\t
this.container = new engine.Container();
\r\n\t
this.addChild(this.container);
\r\n\t
this.container.y = this.conty;
\r\n\t
this.anicontainer = new engine.Container();
\r\n\t
this.addChild(this.anicontainer);
\r\n\t
this.anicontainer.mouseEnabled = false;
\r\n\t
this.anicontainer.mouseChildren = false;
\r\n\t
var map = new engine.Image(getTextureByName(
\"
底图
\"
));
\r\n\t
this.container.addChild(map);
\r\n\t
for (var r = 0; r < row; r++) {
\r\n\t
for (var c = 0; c < col; c++) {
\r\n\t
var rcpos = MapData.getRCPos(r, c);
\r\n\t
MapData.posData[r +
\"
_
\"
+ c] = rcpos;
\r\n\t
}
\r\n\t
}
\r\n\t
this.tanix = this.homex + this.homeimg.texture.width / 2;
\r\n\t
this.taniy = this.homeimg.texture.height / 2;
\r\n\t
engine.globalEvent.addEventListener(GameEvent.SelectEle, this.selectele, this);
\r\n\t
this.removeEventListener(engine.Event.ADDED_TO_STAGE, this.setup, this);
\r\n\t
};
\r\n\t
GameView.prototype.init = function () {
\r\n\t
this.initContainer();
\r\n\t
};
\r\n\t
GameView.prototype.reset = function () {
\r\n\t
};
\r\n\t
GameView.prototype.start = function () {
\r\n\t
};
\r\n\t
GameView.prototype.initContainer = function () {
\r\n\t
this.lattices = {};
\r\n\t
var testdata = [
\r\n\t
[1, 2, 5, 3, 4],
\r\n\t
[3, 1, 2, 4, 5],
\r\n\t
[2, 5, 3, 4, 1],
\r\n\t
[5, 4, 1, 2, 3],
\r\n\t
[4, 1, 3, 5, 2],
\r\n\t
];
\r\n\t
for (var r = 0; r < testdata.length; r++) {
\r\n\t
var rdata = testdata[r];
\r\n\t
for (var c = 0; c < rdata.length; c++) {
\r\n\t
var rctype = rdata[c];
\r\n\t
var rcele = MapData.getOneEle(rctype);
\r\n\t
var rcpos = MapData.getRCPos(r, c);
\r\n\t
this.container.addChild(rcele);
\r\n\t
rcele.x = rcpos[0];
\r\n\t
rcele.y = rcpos[1];
\r\n\t
var rcidx = r +
\"
_
\"
+ c;
\r\n\t
this.lattices[rcidx] = rcele.name;
\r\n\t
this.setLatticeEleRc(rcidx);
\r\n\t
}
\r\n\t
}
\r\n\t
this.checkEliminate();
\r\n\t
this.attionEliminate();
\r\n\t
};
\r\n\t
GameView.prototype.setLatticeEleRc = function (rcidx) {
\r\n\t
var rename = this.lattices[rcidx];
\r\n\t
var rcnode = this.container.getChildByName(rename);
\r\n\t
var er = Number(rcidx.split(
\"
_
\"
)[0]);
\r\n\t
var ec = Number(rcidx.split(
\"
_
\"
)[1]);
\r\n\t
rcnode.setrc(er, ec);
\r\n\t
};
\r\n\t
GameView.prototype.selectele = function (e) {
\r\n\t
var data = e.data;
\r\n\t
var sr = data.r;
\r\n\t
var sc = data.c;
\r\n\t
var sname = sr +
\"
_
\"
+ sc;
\r\n\t
if (this.selectArr.length == 0) {
\r\n\t
this.selectArr.push(sname);
\r\n\t
}
\r\n\t
else if (this.selectArr.length == 1) {
\r\n\t
var aselect = this.selectArr[0];
\r\n\t
var asr = aselect.split(
\"
_
\"
)[0];
\r\n\t
var asc = aselect.split(
\"
_
\"
)[1];
\r\n\t
if ((sr == asr && Math.abs(sc - asc) == 1) || (sc == asc && Math.abs(sr - asr) == 1)) {
\r\n\t
this.selectArr.push(sname);
\r\n\t
}
\r\n\t
else {
\r\n\t
this.selectArr[0] = sname;
\r\n\t
}
\r\n\t
}
\r\n\t
if (this.selectArr.length == 1) {
\r\n\t
this.setSelectShow();
\r\n\t
}
\r\n\t
else if (this.selectArr.length == 2) {
\r\n\t
this.changeElePos();
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.setSelectShow = function () {
\r\n\t
var rcname = this.selectArr[0];
\r\n\t
var r = rcname.split(
\"
_
\"
)[0];
\r\n\t
var c = rcname.split(
\"
_
\"
)[1];
\r\n\t
var rcpos = MapData.getRCPos(r, c);
\r\n\t
this.container.addChild(this.selectimg);
\r\n\t
this.selectimg.x = rcpos[0];
\r\n\t
this.selectimg.y = rcpos[1];
\r\n\t
};
\r\n\t
GameView.prototype.changeElePos = function () {
\r\n\t
var _this = this;
\r\n\t
this.container.removeChild(this.selectimg);
\r\n\t
this.changeEnable(false);
\r\n\t
var sname1 = this.selectArr[0];
\r\n\t
var sname2 = this.selectArr[1];
\r\n\t
var sename1 = this.lattices[sname1];
\r\n\t
var sename2 = this.lattices[sname2];
\r\n\t
this.lattices[sname1] = sename2;
\r\n\t
this.lattices[sname2] = sename1;
\r\n\t
this.setLatticeEleRc(sname1);
\r\n\t
this.setLatticeEleRc(sname2);
\r\n\t
this.checkEliminate();
\r\n\t
var snode1 = this.container.getChildByName(sename1);
\r\n\t
var snode2 = this.container.getChildByName(sename2);
\r\n\t
var snode1x = snode1.x;
\r\n\t
var snode1y = snode1.y;
\r\n\t
var snode2x = snode2.x;
\r\n\t
var snode2y = snode2.y;
\r\n\t
var changetime = Math.ceil((MapData.itemsize / this.anispeed) * 2 * 1000);
\r\n\t
if (this.eliminateArr.length > 0) {
\r\n\t
engine.Tween.get(snode1).to({
\r\n\t
x: snode2x,
\r\n\t
y: snode2y
\r\n\t
}, changetime);
\r\n\t
engine.Tween.get(snode2).to({
\r\n\t
x: snode1x,
\r\n\t
y: snode1y
\r\n\t
}, changetime)
\r\n\t
.call(function () {
\r\n\t
_this.eliminate();
\r\n\t
});
\r\n\t
}
\r\n\t
else {
\r\n\t
engine.Tween.get(snode1).to({
\r\n\t
x: snode2x,
\r\n\t
y: snode2y
\r\n\t
}, changetime)
\r\n\t
.wait(100)
\r\n\t
.to({
\r\n\t
x: snode1x,
\r\n\t
y: snode1y
\r\n\t
}, changetime);
\r\n\t
engine.Tween.get(snode2).to({
\r\n\t
x: snode1x,
\r\n\t
y: snode1y
\r\n\t
}, changetime)
\r\n\t
.wait(100)
\r\n\t
.to({
\r\n\t
x: snode2x,
\r\n\t
y: snode2y
\r\n\t
}, changetime)
\r\n\t
.call(function () {
\r\n\t
_this.lattices[sname1] = sename1;
\r\n\t
_this.lattices[sname2] = sename2;
\r\n\t
_this.setLatticeEleRc(sname1);
\r\n\t
_this.setLatticeEleRc(sname2);
\r\n\t
_this.selectArr = new Array();
\r\n\t
_this.changeEnable(true);
\r\n\t
});
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.eliminate = function () {
\r\n\t
for (var i = 0; i < this.eliminateArr.length; i++) {
\r\n\t
var ielidata = this.eliminateArr[i];
\r\n\t
var ielidxname = ielidata.idxname;
\r\n\t
var ielitype = ielidata.type;
\r\n\t
var ieliname = this.lattices[ielidxname];
\r\n\t
var ielinode = this.container.getChildByName(ieliname);
\r\n\t
var ielix = ielinode.x;
\r\n\t
var ieliy = ielinode.y;
\r\n\t
this.container.removeChild(ielinode);
\r\n\t
MapData.recoverEle(ielinode);
\r\n\t
this.lattices[ielidxname] =
\"
empty
\"
;
\r\n\t
this.goHomeAni(ielitype, ielix, ieliy);
\r\n\t
}
\r\n\t
this.fall();
\r\n\t
};
\r\n\t
GameView.prototype.fall = function () {
\r\n\t
return tslib.__awaiter(this, void 0, void 0, function () {
\r\n\t
var fallData, fcutr, fc, r, c, idxname, elename, frcname, fetype, fele, cutr, fepos, fallPromise, _loop_1, this_1, f;
\r\n\t
return tslib.__generator(this, function (_a) {
\r\n\t
switch (_a.label) {
\r\n\t
case 0:
\r\n\t
fallData = new Array();
\r\n\t
fcutr = new Array();
\r\n\t
for (fc = 0; fc < MapData.col; fc++) {
\r\n\t
fcutr.push(-1);
\r\n\t
}
\r\n\t
for (r = MapData.row - 1; r > -1; r--) {
\r\n\t
for (c = MapData.col - 1; c > -1; c--) {
\r\n\t
idxname = r +
\"
_
\"
+ c;
\r\n\t
elename = this.lattices[idxname];
\r\n\t
if (elename ==
\"
empty
\"
) {
\r\n\t
frcname = this.getFallRcEle(r, c);
\r\n\t
if (!frcname) {
\r\n\t
fetype = MapData.getRandEtype();
\r\n\t
fele = MapData.getOneEle(fetype);
\r\n\t
cutr = fcutr[c];
\r\n\t
fepos = MapData.getRCPos(cutr, c);
\r\n\t
fcutr[c] = cutr - 1;
\r\n\t
this.container.addChild(fele);
\r\n\t
fele.x = fepos[0];
\r\n\t
fele.y = fepos[1];
\r\n\t
frcname = fele.name;
\r\n\t
}
\r\n\t
this.lattices[idxname] = frcname;
\r\n\t
this.setLatticeEleRc(idxname);
\r\n\t
fallData.push({
\r\n\t
rcname: frcname,
\r\n\t
trow: r,
\r\n\t
tcol: c
\r\n\t
});
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
fallPromise = new Array();
\r\n\t
_loop_1 = function (f) {
\r\n\t
var fdata = fallData[f];
\r\n\t
var frcname = fdata.rcname;
\r\n\t
var ftrow = fdata.trow;
\r\n\t
var ftcol = fdata.tcol;
\r\n\t
var ftpos = MapData.getRCPos(ftrow, ftcol);
\r\n\t
var frcnode = this_1.container.getChildByName(frcname);
\r\n\t
var nepos = [frcnode.x, frcnode.y];
\r\n\t
var fdis = MapData.getDistance(ftpos, nepos);
\r\n\t
var ftime = Math.ceil((fdis / this_1.anispeed) * 1000);
\r\n\t
var ifallpromise = new Promise(function (res) {
\r\n\t
engine.Tween.get(frcnode)
\r\n\t
.to({
\r\n\t
x: ftpos[0],
\r\n\t
y: ftpos[1]
\r\n\t
}, ftime).call(function () {
\r\n\t
res();
\r\n\t
});
\r\n\t
});
\r\n\t
fallPromise.push(ifallpromise);
\r\n\t
};
\r\n\t
this_1 = this;
\r\n\t
for (f = 0; f < fallData.length; f++) {
\r\n\t
_loop_1(f);
\r\n\t
}
\r\n\t
return [4, Promise.all(fallPromise)];
\r\n\t
case 1:
\r\n\t
_a.sent();
\r\n\t
this.checkEliminate();
\r\n\t
if (this.eliminateArr.length > 0) {
\r\n\t
return [2, this.eliminate()];
\r\n\t
}
\r\n\t
else {
\r\n\t
this.selectArr = new Array();
\r\n\t
this.changeEnable(true);
\r\n\t
}
\r\n\t
return [2];
\r\n\t
}
\r\n\t
});
\r\n\t
});
\r\n\t
};
\r\n\t
GameView.prototype.goHomeAni = function (ielitype, ielix, ieliy) {
\r\n\t
var aniele = MapData.getOneEle(ielitype);
\r\n\t
var anix = ielix;
\r\n\t
var aniy = ieliy + this.conty;
\r\n\t
this.anicontainer.addChild(aniele);
\r\n\t
aniele.touch = false;
\r\n\t
aniele.x = anix;
\r\n\t
aniele.y = aniy;
\r\n\t
var anidis = MapData.getDistance([this.tanix, this.taniy], [anix, aniy]);
\r\n\t
var anitime = Math.ceil((anidis / this.anispeed) * 1000);
\r\n\t
aniele.flyToHome(this.tanix, this.taniy, anitime);
\r\n\t
};
\r\n\t
GameView.prototype.changeEnable = function (v) {
\r\n\t
for (var key in this.lattices) {
\r\n\t
var kname = this.lattices[key];
\r\n\t
var ele = this.container.getChildByName(kname);
\r\n\t
ele.touch = v;
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.attionEliminate = function () {
\r\n\t
var attiondata;
\r\n\t
for (var r = MapData.row - 1; r > -1; r--) {
\r\n\t
for (var c = MapData.col - 1; c > -1; c--) {
\r\n\t
var checktype = this.getEleTypeByRc(r, c);
\r\n\t
var edatarow = this.getEliminateRow(r, c);
\r\n\t
var edatacol = this.getEliminateCol(r, c);
\r\n\t
if (edatarow.length > 2 || edatacol.length > 2) {
\r\n\t
console.error(
\"
啥情况,检查----------------
\"
);
\r\n\t
}
\r\n\t
if (edatarow.length == 2) {
\r\n\t
console.log(
\"
横向查找
\"
, edatarow);
\r\n\t
var releidx1 = edatarow[0];
\r\n\t
var releidx2 = edatarow[1];
\r\n\t
var relerow1 = Number(releidx1.split(
\"
_
\"
)[0]);
\r\n\t
var relerow2 = Number(releidx2.split(
\"
_
\"
)[0]);
\r\n\t
var relecol = Number(releidx1.split(
\"
_
\"
)[1]);
\r\n\t
var downrow = relerow1 + 1;
\r\n\t
var uprow = relerow2 - 1;
\r\n\t
var rightcol = relecol + 1;
\r\n\t
var leftcol = relecol - 1;
\r\n\t
if (downrow < MapData.row) {
\r\n\t
if (rightcol < MapData.col) {
\r\n\t
var nexttype = this.getEleTypeByRc(downrow, rightcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [downrow +
\"
_
\"
+ relecol, downrow +
\"
_
\"
+ rightcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (leftcol > -1) {
\r\n\t
var nexttype = this.getEleTypeByRc(downrow, leftcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [downrow +
\"
_
\"
+ relecol, downrow +
\"
_
\"
+ leftcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
if (uprow > -1) {
\r\n\t
if (rightcol < MapData.col) {
\r\n\t
var nexttype = this.getEleTypeByRc(uprow, rightcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [uprow +
\"
_
\"
+ relecol, uprow +
\"
_
\"
+ rightcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (leftcol > -1) {
\r\n\t
var nexttype = this.getEleTypeByRc(uprow, leftcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [uprow +
\"
_
\"
+ relecol, uprow +
\"
_
\"
+ leftcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
if (edatacol.length == 2) {
\r\n\t
console.log(
\"
竖向查找
\"
, edatacol);
\r\n\t
var releidx1 = edatarow[0];
\r\n\t
var releidx2 = edatarow[1];
\r\n\t
var relerow = Number(releidx1.split(
\"
_
\"
)[0]);
\r\n\t
var relecol1 = Number(releidx1.split(
\"
_
\"
)[1]);
\r\n\t
var relecol2 = Number(releidx2.split(
\"
_
\"
)[1]);
\r\n\t
console.log(
\"
竖向检查啦啦啦
\"
, relerow, relecol1, relecol2);
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
console.log(
\"
相邻检测--------------
\"
, attiondata);
\r\n\t
};
\r\n\t
GameView.prototype.checkEliminate = function () {
\r\n\t
this.eliminateArr = new Array();
\r\n\t
for (var r = MapData.row - 1; r > -1; r--) {
\r\n\t
for (var c = MapData.col - 1; c > -1; c--) {
\r\n\t
var edata = this.getEliminate(r, c);
\r\n\t
if (edata) {
\r\n\t
var etype = edata.etype;
\r\n\t
var earr = edata.arr;
\r\n\t
this.checkAddEli(etype, earr);
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.getEliminateRow = function (x, y) {
\r\n\t
var checktype = this.getEleTypeByRc(x, y);
\r\n\t
var relearr = new Array();
\r\n\t
relearr.push(x +
\"
_
\"
+ y);
\r\n\t
for (var r = x - 1; r > -1; r--) {
\r\n\t
var reletype = this.getEleTypeByRc(r, y);
\r\n\t
if (checktype == reletype) {
\r\n\t
relearr.push(r +
\"
_
\"
+ y);
\r\n\t
}
\r\n\t
else {
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
return relearr;
\r\n\t
};
\r\n\t
GameView.prototype.getEliminateCol = function (x, y) {
\r\n\t
var checktype = this.getEleTypeByRc(x, y);
\r\n\t
var celearr = new Array();
\r\n\t
celearr.push(x +
\"
_
\"
+ y);
\r\n\t
for (var c = y - 1; c > -1; c--) {
\r\n\t
var celetype = this.getEleTypeByRc(x, c);
\r\n\t
if (checktype == celetype) {
\r\n\t
celearr.push(x +
\"
_
\"
+ c);
\r\n\t
}
\r\n\t
else {
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
return celearr;
\r\n\t
};
\r\n\t
GameView.prototype.getEliminate = function (x, y) {
\r\n\t
var checktype = this.getEleTypeByRc(x, y);
\r\n\t
var relearr = this.getEliminateRow(x, y);
\r\n\t
var celearr = this.getEliminateCol(x, y);
\r\n\t
var eliminatearr = new Array();
\r\n\t
if (relearr.length >= 3) {
\r\n\t
eliminatearr.push.apply(eliminatearr, relearr);
\r\n\t
}
\r\n\t
if (celearr.length >= 3) {
\r\n\t
eliminatearr.push.apply(eliminatearr, celearr);
\r\n\t
}
\r\n\t
if (eliminatearr.length > 0) {
\r\n\t
return {
\r\n\t
etype: checktype,
\r\n\t
arr: eliminatearr
\r\n\t
};
\r\n\t
}
\r\n\t
else {
\r\n\t
return false;
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.getEleTypeByRc = function (r, c) {
\r\n\t
var rc = r +
\"
_
\"
+ c;
\r\n\t
var elename = this.lattices[rc];
\r\n\t
var ele = this.container.getChildByName(elename);
\r\n\t
var eletype = ele.type;
\r\n\t
return eletype;
\r\n\t
};
\r\n\t
GameView.prototype.checkAddEli = function (etype, earr) {
\r\n\t
for (var e = 0; e < earr.length; e++) {
\r\n\t
var ename = earr[e];
\r\n\t
var needadd = true;
\r\n\t
for (var i = 0; i < this.eliminateArr.length; i++) {
\r\n\t
var ielidata = this.eliminateArr[i];
\r\n\t
var ielidxname = ielidata.idxname;
\r\n\t
if (ielidxname == ename) {
\r\n\t
needadd = false;
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (needadd) {
\r\n\t
this.eliminateArr.push({
\r\n\t
idxname: ename,
\r\n\t
type: etype
\r\n\t
});
\r\n\t
}
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.getFallRcEle = function (r, c) {
\r\n\t
for (var fr = r - 1; fr > -1; fr--) {
\r\n\t
var frc = fr +
\"
_
\"
+ c;
\r\n\t
var frcname = this.lattices[frc];
\r\n\t
if (frcname !=
\"
empty
\"
) {
\r\n\t
this.lattices[frc] =
\"
empty
\"
;
\r\n\t
return frcname;
\r\n\t
}
\r\n\t
}
\r\n\t
return false;
\r\n\t
};
\r\n\t
return GameView;
\r\n\t
}(engine.Container));
\n\n\t
var GameWrapper = (function (_super) {
\r\n\t
tslib.__extends(GameWrapper, _super);
\r\n\t
function GameWrapper() {
\r\n\t
var _this = _super.call(this) || this;
\r\n\t
_this._gameView = new GameView();
\r\n\t
_this.addChild(_this._gameView);
\r\n\t
engine.globalEvent.addEventListener('game-init', _this.init, _this);
\r\n\t
engine.globalEvent.addEventListener('game-reset', _this.reset, _this);
\r\n\t
engine.globalEvent.addEventListener('game-start', _this.start, _this);
\r\n\t
return _this;
\r\n\t
}
\r\n\t
GameWrapper.prototype.init = function () {
\r\n\t
this._gameView.init();
\r\n\t
};
\r\n\t
GameWrapper.prototype.reset = function () {
\r\n\t
this._gameView.reset();
\r\n\t
};
\r\n\t
GameWrapper.prototype.start = function () {
\r\n\t
this._gameView.start();
\r\n\t
};
\r\n\t
return GameWrapper;
\r\n\t
}(engine.Container));
\n\n\t
var props = {};
\r\n\t
function prepareProps() {
\r\n\t
var metaProps = getProps();
\r\n\t
engine.injectProp(props, metaProps);
\r\n\t
}
\r\n\t
function injectProps(p) {
\r\n\t
engine.injectProp(props, p);
\r\n\t
}
\n\n\t
function index (props) {
\r\n\t
prepareProps();
\r\n\t
injectProps(props);
\r\n\t
var instance = new GameWrapper();
\r\n\t
return instance;
\r\n\t
}
\n\n\t
return index;
\n\n
})));
\n
"
"code"
:
"(function (global, factory) {
\n\t
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n\t
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n\t
(global = global || self, global.xiaoxiaole = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
function getTexture(uuid) {
\r\n\t
return engine.Texture.from(getAssetByUUID(uuid).uuid);
\r\n\t
}
\r\n\t
function getTextureByName(name) {
\r\n\t
return getTexture(engine.getAssetByName(name).uuid);
\r\n\t
}
\
r\n\t
function createSvga(name, anchorName) {
\r\n\t
var inst = new svga.Svga();
\r\n\t
inst.source = 'asset://' + engine.getAssetByName(name).uuid;
\r\n\t
return inst;
\r\n\t
}
\r\n\t
//# sourceMappingURL=utils.js.map
\n\n\t
var Element = (function (_super) {
\r\n\t
tslib.__extends(Element, _super);
\r\n\t
function Element() {
\r\n\t
var _this = _super.call(this) || this;
\r\n\t
_this.width = MapData.itemsize;
\r\n\t
_this.height = MapData.itemsize;
\r\n\t
_this.anchorX = MapData.itemsize / 2;
\r\n\t
_this.anchorY = MapData.itemsize;
\r\n\t
_this.eimage = new engine.Image();
\r\n\t
_this.addChild(_this.eimage);
\r\n\t
_this.touch = true;
\r\n\t
_this.addEventListener(engine.MouseEvent.CLICK, _this.selectele, _this);
\r\n\t
return _this;
\r\n\t
}
\r\n\t
Object.defineProperty(Element.prototype,
\"
touch
\"
, {
\r\n\t
set: function (touch) {
\r\n\t
this.mouseEnabled = touch;
\r\n\t
this.mouseChildren = touch;
\r\n\t
},
\r\n\t
enumerable: true,
\r\n\t
configurable: true
\r\n\t
});
\r\n\t
Element.prototype.init = function (type) {
\r\n\t
this.scaleX = 1;
\r\n\t
this.scaleY = 1;
\r\n\t
this.type = type;
\r\n\t
var ename = MapData.getEtypeImgName(type);
\r\n\t
this.eimage.texture = getTextureByName(ename);
\r\n\t
var imgwid = this.eimage.texture.width;
\r\n\t
var imghei = this.eimage.texture.height;
\r\n\t
this.eimage.x = (this.width - imgwid) / 2;
\r\n\t
this.eimage.y = (this.height - imghei) / 2;
\r\n\t
};
\r\n\t
Element.prototype.setrc = function (r, c) {
\r\n\t
this.inrow = r;
\r\n\t
this.incol = c;
\r\n\t
};
\r\n\t
Element.prototype.selectele = function (e) {
\r\n\t
engine.globalEvent.dispatchEvent(GameEvent.SelectEle, {
\r\n\t
r: this.inrow,
\r\n\t
c: this.incol
\r\n\t
});
\r\n\t
};
\r\n\t
Object.defineProperty(Element.prototype,
\"
factor
\"
, {
\r\n\t
get: function () {
\r\n\t
return 0;
\r\n\t
},
\r\n\t
set: function (value) {
\r\n\t
this.x = (1 - value) * (1 - value) * this.p1x + 2 * value * (1 - value) * this.c1x + value * value * this.p2x;
\r\n\t
this.y = (1 - value) * (1 - value) * this.p1y + 2 * value * (1 - value) * this.c1y + value * value * this.p2y;
\r\n\t
var mscale = (1 - value) * (1 - value) * 1 + 2 * value * (1 - value) * 0.6 + value * value * 0.35;
\r\n\t
this.scaleX = mscale;
\r\n\t
this.scaleY = mscale;
\r\n\t
},
\r\n\t
enumerable: true,
\r\n\t
configurable: true
\r\n\t
});
\r\n\t
Element.prototype.flyToHome = function (tx, ty, time) {
\r\n\t
var _this = this;
\r\n\t
this.p1x = this.x;
\r\n\t
this.p1y = this.y + 20;
\r\n\t
this.c1x = (this.p1x - tx) / 4 + tx;
\r\n\t
this.c1y = ty;
\r\n\t
this.p2x = tx;
\r\n\t
this.p2y = ty;
\r\n\t
engine.Tween.get(this).to({
\r\n\t
scaleX: 1.1,
\r\n\t
scaleY: 1.1
\r\n\t
}, 200)
\r\n\t
.to({
\r\n\t
scaleX: 1.1,
\r\n\t
scaleY: 0.88
\r\n\t
}, 100)
\r\n\t
.to({
\r\n\t
scaleX: 0.98,
\r\n\t
scaleY: 0.98,
\r\n\t
y: this.y + 20
\r\n\t
}, 100)
\r\n\t
.call(function () {
\r\n\t
engine.Tween.get(_this).to({
\r\n\t
factor: 1
\r\n\t
}, 450)
\r\n\t
.call(function () {
\r\n\t
var nodeparent = _this.parent;
\r\n\t
nodeparent && nodeparent.removeChild(_this);
\r\n\t
MapData.recoverEle(_this);
\r\n\t
});
\r\n\t
});
\r\n\t
};
\r\n\t
Element.prototype.changePos = function (tpos) {
\r\n\t
var _this = this;
\r\n\t
var nx = this.x;
\r\n\t
var ny = this.y;
\r\n\t
var tx = tpos[0];
\r\n\t
var ty = tpos[1];
\r\n\t
var dis = MapData.getDistance([nx, ny], tpos);
\r\n\t
var time = Math.ceil(dis / MapData.anispeed * 1000);
\r\n\t
var pro = new Promise(function (res) {
\r\n\t
engine.Tween.get(_this, { loop: false }).to({
\r\n\t
x: tx,
\r\n\t
y: ty
\r\n\t
}, time)
\r\n\t
.call(function () {
\r\n\t
console.log(
\"
单个移动完毕
\"
);
\r\n\t
res();
\r\n\t
});
\r\n\t
});
\r\n\t
return pro;
\r\n\t
};
\r\n\t
return Element;
\r\n\t
}(engine.Container));
\r\n\t
//# sourceMappingURL=Element.js.map
\n\n\t
var ElementType;
\r\n\t
(function (ElementType) {
\r\n\t
ElementType[ElementType[
\"
btiger
\"
] = 1] =
\"
btiger
\"
;
\r\n\t
ElementType[ElementType[
\"
gtiger
\"
] = 2] =
\"
gtiger
\"
;
\r\n\t
ElementType[ElementType[
\"
monkey
\"
] = 3] =
\"
monkey
\"
;
\r\n\t
ElementType[ElementType[
\"
bird
\"
] = 4] =
\"
bird
\"
;
\r\n\t
ElementType[ElementType[
\"
koala
\"
] = 5] =
\"
koala
\"
;
\r\n\t
})(ElementType || (ElementType = {}));
\r\n\t
var GameEvent;
\r\n\t
(function (GameEvent) {
\r\n\t
GameEvent[
\"
SelectEle
\"
] =
\"
SelectEle
\"
;
\r\n\t
})(GameEvent || (GameEvent = {}));
\r\n\t
var MapData = (function () {
\r\n\t
function MapData() {
\r\n\t
}
\r\n\t
MapData.getRy = function (r) {
\r\n\t
return this.paddingb + r * (this.itemsize + this.paddingi);
\r\n\t
};
\r\n\t
MapData.getCx = function (c) {
\r\n\t
return this.paddingb + c * (this.itemsize + this.paddingi);
\r\n\t
};
\r\n\t
MapData.getRCPos = function (r, c) {
\r\n\t
var x = this.getCx(c);
\r\n\t
var y = this.getRy(r);
\r\n\t
return [x, y];
\r\n\t
};
\r\n\t
MapData.adaptElePos = function (pos, wid, hei) {
\r\n\t
var x = pos[0] + (this.itemsize - wid) / 2;
\r\n\t
var y = pos[1] + (this.itemsize - hei) / 2;
\r\n\t
return [x, y];
\r\n\t
};
\r\n\t
MapData.getEtypeImgName = function (type) {
\r\n\t
var ename;
\r\n\t
switch (type) {
\r\n\t
case ElementType.btiger:
\r\n\t
ename =
\"
白虎
\"
;
\r\n\t
break;
\r\n\t
case ElementType.gtiger:
\r\n\t
ename =
\"
雌虎
\"
;
\r\n\t
break;
\r\n\t
case ElementType.monkey:
\r\n\t
ename =
\"
猴子
\"
;
\r\n\t
break;
\r\n\t
case ElementType.bird:
\r\n\t
ename =
\"
鸟
\"
;
\r\n\t
break;
\r\n\t
case ElementType.koala:
\r\n\t
ename =
\"
树熊
\"
;
\r\n\t
break;
\r\n\t
default:
\r\n\t
console.error(
\"
未定义元素类型
\"
);
\r\n\t
break;
\r\n\t
}
\r\n\t
return ename;
\r\n\t
};
\r\n\t
MapData.getRandEtype = function () {
\r\n\t
var eletypeArr = [ElementType.btiger, ElementType.gtiger, ElementType.monkey, ElementType.bird, ElementType.koala];
\r\n\t
var etype = eletypeArr[Math.floor(Math.random() * eletypeArr.length)];
\r\n\t
return etype;
\r\n\t
};
\r\n\t
MapData.getOneEle = function (type) {
\r\n\t
var ele;
\r\n\t
if (this.elePool.length > 0) {
\r\n\t
ele = this.elePool.shift();
\r\n\t
}
\r\n\t
else {
\r\n\t
ele = new Element();
\r\n\t
}
\r\n\t
ele.name =
\"
ele_
\"
+ this.eleidx;
\r\n\t
this.eleidx += 1;
\r\n\t
ele.init(type);
\r\n\t
return ele;
\r\n\t
};
\r\n\t
MapData.recoverEle = function (ele) {
\r\n\t
this.elePool.push(ele);
\r\n\t
};
\r\n\t
MapData.getDistance = function (p1, p2) {
\r\n\t
var p1x = p1[0];
\r\n\t
var p1y = p1[1];
\r\n\t
var p2x = p2[0];
\r\n\t
var p2y = p2[1];
\r\n\t
var dis = Math.sqrt(Math.pow(p1x - p2x, 2) + Math.pow(p1y - p2y, 2));
\r\n\t
return dis;
\r\n\t
};
\r\n\t
MapData.itemsize = 129;
\r\n\t
MapData.paddingb = 10;
\r\n\t
MapData.paddingi = 5;
\r\n\t
MapData.row = 5;
\r\n\t
MapData.col = 5;
\r\n\t
MapData.posData = {};
\r\n\t
MapData.eleidx = 1;
\r\n\t
MapData.elePool = [];
\r\n\t
MapData.anispeed = 860;
\r\n\t
return MapData;
\r\n\t
}());
\r\n\t
//# sourceMappingURL=MapData.js.map
\n\n\t
var GameView = (function (_super) {
\r\n\t
tslib.__extends(GameView, _super);
\r\n\t
function GameView() {
\r\n\t
var _this = _super.call(this) || this;
\r\n\t
_this.lattices = {};
\r\n\t
_this.eliminateArr = [];
\r\n\t
_this.selectArr = [];
\r\n\t
_this.conty = 140;
\r\n\t
_this.homex = 528;
\r\n\t
_this.homey = -40;
\r\n\t
_this.ination = false;
\r\n\t
_this.canation = true;
\r\n\t
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
\r\n\t
return _this;
\r\n\t
}
\r\n\t
GameView.prototype.setup = function () {
\r\n\t
this.selectimg = new engine.Image(getTextureByName(
\"
选中框
\"
));
\r\n\t
this.selectimg.mouseEnabled = false;
\r\n\t
var row = MapData.row;
\r\n\t
var col = MapData.col;
\r\n\t
this.homeimg = createSvga(
\"
房子动画
\"
);
\r\n\t
this.addChild(this.homeimg);
\r\n\t
this.homeimg.x = this.homex;
\r\n\t
this.homeimg.y = -40;
\r\n\t
this.homeimg.stop();
\r\n\t
console.log(
\"
房子动画
\"
, this.homeimg);
\r\n\t
this.container = new engine.Container();
\r\n\t
this.addChild(this.container);
\r\n\t
this.container.y = this.conty;
\r\n\t
var maskimg = new engine.Graphics();
\r\n\t
this.container.addChild(maskimg);
\r\n\t
this.container.mask = maskimg;
\r\n\t
maskimg.moveTo(0, 0);
\r\n\t
maskimg.beginFill(0);
\r\n\t
maskimg.lineTo(681, 0);
\r\n\t
maskimg.lineTo(681, 679);
\r\n\t
maskimg.lineTo(0, 679);
\r\n\t
maskimg.lineTo(0, 0);
\r\n\t
maskimg.endFill();
\r\n\t
this.anicontainer = new engine.Container();
\r\n\t
this.addChild(this.anicontainer);
\r\n\t
this.anicontainer.mouseEnabled = false;
\r\n\t
this.anicontainer.mouseChildren = false;
\r\n\t
var map = new engine.Image(getTextureByName(
\"
底图
\"
));
\r\n\t
this.container.addChild(map);
\r\n\t
for (var r = 0; r < row; r++) {
\r\n\t
for (var c = 0; c < col; c++) {
\r\n\t
var rcpos = MapData.getRCPos(r, c);
\r\n\t
MapData.posData[r +
\"
_
\"
+ c] = rcpos;
\r\n\t
}
\r\n\t
}
\r\n\t
this.tanix = this.homex + 146 / 2 - MapData.itemsize / 3;
\r\n\t
this.taniy = this.homey + 120 / 2;
\r\n\t
engine.globalEvent.addEventListener(GameEvent.SelectEle, this.selectele, this);
\r\n\t
this.removeEventListener(engine.Event.ADDED_TO_STAGE, this.setup, this);
\r\n\t
this.lastframeTime = Date.now();
\r\n\t
this.lastatime = Date.now();
\r\n\t
this.addEventListener(engine.Event.ENTER_FRAME, this.onUpdate, this);
\r\n\t
};
\r\n\t
GameView.prototype.playComp = function () {
\r\n\t
console.log(
\"
动画播放完毕
\"
);
\r\n\t
this.homeimg.stop(1);
\r\n\t
};
\r\n\t
GameView.prototype.init = function () {
\r\n\t
this.initContainer();
\r\n\t
};
\r\n\t
GameView.prototype.reset = function () {
\r\n\t
};
\r\n\t
GameView.prototype.start = function () {
\r\n\t
};
\r\n\t
GameView.prototype.onUpdate = function () {
\r\n\t
var ntime = Date.now();
\r\n\t
var passtime = ntime - this.lastframeTime;
\r\n\t
if (ntime - this.lastatime >= 5000 && !this.ination && this.canation && this.selectArr.length == 0) {
\r\n\t
this.attionEliShow();
\r\n\t
}
\r\n\t
if (this.homeimg) {
\r\n\t
var curframe = this.homeimg.currentFrame;
\r\n\t
if (curframe == this.homeimg.totalFrames) {
\r\n\t
this.homeimg.gotoAndStop(1);
\r\n\t
}
\r\n\t
}
\r\n\t
this.lastframeTime = ntime;
\r\n\t
};
\r\n\t
GameView.prototype.initContainer = function () {
\r\n\t
this.lattices = {};
\r\n\t
var testdata = [
\r\n\t
[1, 2, 5, 3, 3],
\r\n\t
[3, 1, 4, 4, 5],
\r\n\t
[2, 5, 3, 5, 1],
\r\n\t
[5, 4, 1, 2, 3],
\r\n\t
[4, 1, 3, 5, 2],
\r\n\t
];
\r\n\t
for (var r = 0; r < testdata.length; r++) {
\r\n\t
var rdata = testdata[r];
\r\n\t
for (var c = 0; c < rdata.length; c++) {
\r\n\t
var rctype = rdata[c];
\r\n\t
var rcele = MapData.getOneEle(rctype);
\r\n\t
var rcpos = MapData.getRCPos(r, c);
\r\n\t
this.container.addChild(rcele);
\r\n\t
rcele.x = rcpos[0];
\r\n\t
rcele.y = rcpos[1];
\r\n\t
var rcidx = r +
\"
_
\"
+ c;
\r\n\t
this.lattices[rcidx] = rcele.name;
\r\n\t
this.setLatticeEleRc(rcidx);
\r\n\t
}
\r\n\t
}
\r\n\t
this.checkEliminate();
\r\n\t
this.fall();
\r\n\t
};
\r\n\t
GameView.prototype.setLatticeEleRc = function (rcidx) {
\r\n\t
var rename = this.lattices[rcidx];
\r\n\t
var rcnode = this.container.getChildByName(rename);
\r\n\t
var er = Number(rcidx.split(
\"
_
\"
)[0]);
\r\n\t
var ec = Number(rcidx.split(
\"
_
\"
)[1]);
\r\n\t
rcnode.setrc(er, ec);
\r\n\t
};
\r\n\t
GameView.prototype.selectele = function (e) {
\r\n\t
var data = e.data;
\r\n\t
var sr = data.r;
\r\n\t
var sc = data.c;
\r\n\t
var sname = sr +
\"
_
\"
+ sc;
\r\n\t
if (this.ination) {
\r\n\t
this.ination = false;
\r\n\t
this.lastatime = Date.now();
\r\n\t
var arrcidx1 = this.attiondata[0];
\r\n\t
var arrcidx2 = this.attiondata[1];
\r\n\t
var atname1 = this.lattices[arrcidx1];
\r\n\t
var atname2 = this.lattices[arrcidx2];
\r\n\t
var atnode1 = this.container.getChildByName(atname1);
\r\n\t
var atnode2 = this.container.getChildByName(atname2);
\r\n\t
var atpos1 = MapData.getRCPos(arrcidx1.split(
\"
_
\"
)[0], arrcidx1.split(
\"
_
\"
)[1]);
\r\n\t
var atpos2 = MapData.getRCPos(arrcidx2.split(
\"
_
\"
)[0], arrcidx2.split(
\"
_
\"
)[1]);
\r\n\t
engine.Tween.removeTweens(atnode1);
\r\n\t
engine.Tween.removeTweens(atnode2);
\r\n\t
atnode1.x = atpos1[0];
\r\n\t
atnode1.y = atpos1[1];
\r\n\t
atnode2.x = atpos2[0];
\r\n\t
atnode2.y = atpos2[1];
\r\n\t
}
\r\n\t
if (this.selectArr.length == 0) {
\r\n\t
this.selectArr.push(sname);
\r\n\t
}
\r\n\t
else if (this.selectArr.length == 1) {
\r\n\t
var aselect = this.selectArr[0];
\r\n\t
var asr = aselect.split(
\"
_
\"
)[0];
\r\n\t
var asc = aselect.split(
\"
_
\"
)[1];
\r\n\t
if ((sr == asr && Math.abs(sc - asc) == 1) || (sc == asc && Math.abs(sr - asr) == 1)) {
\r\n\t
this.selectArr.push(sname);
\r\n\t
}
\r\n\t
else {
\r\n\t
if (sr == asr && sc == asc) {
\r\n\t
this.selectArr = new Array();
\r\n\t
this.anicontainer.removeChild(this.selectimg);
\r\n\t
}
\r\n\t
else {
\r\n\t
this.selectArr[0] = sname;
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
if (this.selectArr.length == 1) {
\r\n\t
this.setSelectShow();
\r\n\t
}
\r\n\t
else if (this.selectArr.length == 2) {
\r\n\t
this.changeElePos();
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.setSelectShow = function () {
\r\n\t
var rcname = this.selectArr[0];
\r\n\t
var r = rcname.split(
\"
_
\"
)[0];
\r\n\t
var c = rcname.split(
\"
_
\"
)[1];
\r\n\t
var rcpos = MapData.getRCPos(r, c);
\r\n\t
this.anicontainer.addChild(this.selectimg);
\r\n\t
this.selectimg.x = rcpos[0];
\r\n\t
this.selectimg.y = rcpos[1] + this.conty;
\r\n\t
};
\r\n\t
GameView.prototype.changeElePos = function () {
\r\n\t
var _this = this;
\r\n\t
this.anicontainer.removeChild(this.selectimg);
\r\n\t
this.changeEnable(false);
\r\n\t
var sname1 = this.selectArr[0];
\r\n\t
var sname2 = this.selectArr[1];
\r\n\t
var sename1 = this.lattices[sname1];
\r\n\t
var sename2 = this.lattices[sname2];
\r\n\t
this.lattices[sname1] = sename2;
\r\n\t
this.lattices[sname2] = sename1;
\r\n\t
this.setLatticeEleRc(sname1);
\r\n\t
this.setLatticeEleRc(sname2);
\r\n\t
this.checkEliminate();
\r\n\t
var snode1 = this.container.getChildByName(sename1);
\r\n\t
var snode2 = this.container.getChildByName(sename2);
\r\n\t
var snode1x = snode1.x;
\r\n\t
var snode1y = snode1.y;
\r\n\t
var snode2x = snode2.x;
\r\n\t
var snode2y = snode2.y;
\r\n\t
var changetime = Math.ceil((MapData.itemsize / MapData.anispeed) * 2 * 1000);
\r\n\t
if (this.eliminateArr.length > 0) {
\r\n\t
engine.Tween.get(snode1).to({
\r\n\t
x: snode2x,
\r\n\t
y: snode2y
\r\n\t
}, changetime);
\r\n\t
engine.Tween.get(snode2).to({
\r\n\t
x: snode1x,
\r\n\t
y: snode1y
\r\n\t
}, changetime)
\r\n\t
.call(function () {
\r\n\t
_this.eliminate();
\r\n\t
});
\r\n\t
}
\r\n\t
else {
\r\n\t
engine.Tween.get(snode1).to({
\r\n\t
x: snode2x,
\r\n\t
y: snode2y
\r\n\t
}, changetime)
\r\n\t
.wait(100)
\r\n\t
.to({
\r\n\t
x: snode1x,
\r\n\t
y: snode1y
\r\n\t
}, changetime);
\r\n\t
engine.Tween.get(snode2).to({
\r\n\t
x: snode1x,
\r\n\t
y: snode1y
\r\n\t
}, changetime)
\r\n\t
.wait(100)
\r\n\t
.to({
\r\n\t
x: snode2x,
\r\n\t
y: snode2y
\r\n\t
}, changetime)
\r\n\t
.call(function () {
\r\n\t
_this.lattices[sname1] = sename1;
\r\n\t
_this.lattices[sname2] = sename2;
\r\n\t
_this.setLatticeEleRc(sname1);
\r\n\t
_this.setLatticeEleRc(sname2);
\r\n\t
_this.selectArr = new Array();
\r\n\t
_this.changeEnable(true);
\r\n\t
});
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.eliminate = function () {
\r\n\t
return tslib.__awaiter(this, void 0, void 0, function () {
\r\n\t
var i, ielidata, ielidxname, ielitype, ieliname, ielinode, ielix, ieliy;
\r\n\t
return tslib.__generator(this, function (_a) {
\r\n\t
switch (_a.label) {
\r\n\t
case 0:
\r\n\t
for (i = 0; i < this.eliminateArr.length; i++) {
\r\n\t
ielidata = this.eliminateArr[i];
\r\n\t
ielidxname = ielidata.idxname;
\r\n\t
ielitype = ielidata.type;
\r\n\t
ieliname = this.lattices[ielidxname];
\r\n\t
ielinode = this.container.getChildByName(ieliname);
\r\n\t
ielix = ielinode.x;
\r\n\t
ieliy = ielinode.y;
\r\n\t
this.container.removeChild(ielinode);
\r\n\t
MapData.recoverEle(ielinode);
\r\n\t
this.lattices[ielidxname] =
\"
empty
\"
;
\r\n\t
this.goHomeAni(ielitype, ielix, ieliy);
\r\n\t
}
\r\n\t
return [4, new Promise(function (res) {
\r\n\t
setTimeout(function () {
\r\n\t
res();
\r\n\t
}, 800);
\r\n\t
})];
\r\n\t
case 1:
\r\n\t
_a.sent();
\r\n\t
this.fall();
\r\n\t
return [4, new Promise(function (res1) {
\r\n\t
setTimeout(function () {
\r\n\t
res1();
\r\n\t
}, 550);
\r\n\t
})];
\r\n\t
case 2:
\r\n\t
_a.sent();
\r\n\t
this.homeimg.play();
\r\n\t
return [2];
\r\n\t
}
\r\n\t
});
\r\n\t
});
\r\n\t
};
\r\n\t
GameView.prototype.fall = function () {
\r\n\t
return tslib.__awaiter(this, void 0, void 0, function () {
\r\n\t
var fallData, fcutr, fc, r, c, idxname, elename, frcname, fetype, fele, cutr, fepos, fallPromise, _loop_1, this_1, f, isdiedata;
\r\n\t
return tslib.__generator(this, function (_a) {
\r\n\t
switch (_a.label) {
\r\n\t
case 0:
\r\n\t
fallData = new Array();
\r\n\t
fcutr = new Array();
\r\n\t
for (fc = 0; fc < MapData.col; fc++) {
\r\n\t
fcutr.push(-1);
\r\n\t
}
\r\n\t
for (r = MapData.row - 1; r > -1; r--) {
\r\n\t
for (c = MapData.col - 1; c > -1; c--) {
\r\n\t
idxname = r +
\"
_
\"
+ c;
\r\n\t
elename = this.lattices[idxname];
\r\n\t
if (elename ==
\"
empty
\"
) {
\r\n\t
frcname = this.getFallRcEle(r, c);
\r\n\t
if (!frcname) {
\r\n\t
fetype = MapData.getRandEtype();
\r\n\t
fele = MapData.getOneEle(fetype);
\r\n\t
cutr = fcutr[c];
\r\n\t
fepos = MapData.getRCPos(cutr, c);
\r\n\t
fcutr[c] = cutr - 1;
\r\n\t
this.container.addChild(fele);
\r\n\t
fele.x = fepos[0];
\r\n\t
fele.y = fepos[1];
\r\n\t
frcname = fele.name;
\r\n\t
}
\r\n\t
this.lattices[idxname] = frcname;
\r\n\t
this.setLatticeEleRc(idxname);
\r\n\t
fallData.push({
\r\n\t
rcname: frcname,
\r\n\t
trow: r,
\r\n\t
tcol: c
\r\n\t
});
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
fallPromise = new Array();
\r\n\t
_loop_1 = function (f) {
\r\n\t
var fdata = fallData[f];
\r\n\t
var frcname = fdata.rcname;
\r\n\t
var ftrow = fdata.trow;
\r\n\t
var ftcol = fdata.tcol;
\r\n\t
var ftpos = MapData.getRCPos(ftrow, ftcol);
\r\n\t
var frcnode = this_1.container.getChildByName(frcname);
\r\n\t
var nepos = [frcnode.x, frcnode.y];
\r\n\t
var fdis = MapData.getDistance(ftpos, nepos);
\r\n\t
var ftime = Math.ceil((fdis / MapData.anispeed) * 1000);
\r\n\t
var ifallpromise = new Promise(function (res) {
\r\n\t
engine.Tween.get(frcnode)
\r\n\t
.to({
\r\n\t
x: ftpos[0],
\r\n\t
y: ftpos[1]
\r\n\t
}, ftime)
\r\n\t
.to({
\r\n\t
scaleY: 0.85
\r\n\t
}, 80)
\r\n\t
.to({
\r\n\t
scaleY: 1
\r\n\t
}, 80)
\r\n\t
.call(function () {
\r\n\t
res();
\r\n\t
});
\r\n\t
});
\r\n\t
fallPromise.push(ifallpromise);
\r\n\t
};
\r\n\t
this_1 = this;
\r\n\t
for (f = 0; f < fallData.length; f++) {
\r\n\t
_loop_1(f);
\r\n\t
}
\r\n\t
return [4, Promise.all(fallPromise)];
\r\n\t
case 1:
\r\n\t
_a.sent();
\r\n\t
this.checkEliminate();
\r\n\t
if (this.eliminateArr.length > 0) {
\r\n\t
return [2, this.eliminate()];
\r\n\t
}
\r\n\t
else {
\r\n\t
this.selectArr = new Array();
\r\n\t
isdiedata = this.attionEliminate();
\r\n\t
if (isdiedata && isdiedata.length == 2) {
\r\n\t
this.changeEnable(true);
\r\n\t
}
\r\n\t
else {
\r\n\t
this.solveDieMap();
\r\n\t
}
\r\n\t
}
\r\n\t
return [2];
\r\n\t
}
\r\n\t
});
\r\n\t
});
\r\n\t
};
\r\n\t
GameView.prototype.goHomeAni = function (ielitype, ielix, ieliy) {
\r\n\t
var aniele = MapData.getOneEle(ielitype);
\r\n\t
aniele.alpha = 0;
\r\n\t
var anix = ielix;
\r\n\t
var aniy = ieliy + this.conty;
\r\n\t
this.anicontainer.addChild(aniele);
\r\n\t
aniele.touch = false;
\r\n\t
aniele.x = anix;
\r\n\t
aniele.y = aniy;
\r\n\t
aniele.alpha = 1;
\r\n\t
var anidis = MapData.getDistance([this.tanix, this.taniy], [anix, aniy]);
\r\n\t
var anitime = Math.ceil((anidis / MapData.anispeed) * 1000);
\r\n\t
aniele.flyToHome(this.tanix, this.taniy, anitime);
\r\n\t
};
\r\n\t
GameView.prototype.changeEnable = function (v) {
\r\n\t
for (var key in this.lattices) {
\r\n\t
var kname = this.lattices[key];
\r\n\t
var ele = this.container.getChildByName(kname);
\r\n\t
ele.touch = v;
\r\n\t
}
\r\n\t
if (v) {
\r\n\t
this.lastatime = Date.now();
\r\n\t
}
\r\n\t
this.canation = v;
\r\n\t
};
\r\n\t
GameView.prototype.attionEliShow = function () {
\r\n\t
var attiondata = this.attionEliminate();
\r\n\t
if (attiondata && attiondata.length == 2) {
\r\n\t
this.ination = true;
\r\n\t
console.log(
\"
可以提示
\"
);
\r\n\t
this.attiondata = [attiondata[0], attiondata[1]];
\r\n\t
var atname1 = this.lattices[attiondata[0]];
\r\n\t
var atname2 = this.lattices[attiondata[1]];
\r\n\t
var atnode1 = this.container.getChildByName(atname1);
\r\n\t
var atnode2 = this.container.getChildByName(atname2);
\r\n\t
var atx1 = atnode1.x;
\r\n\t
var aty1 = atnode1.y;
\r\n\t
var atx2 = atnode2.x;
\r\n\t
var aty2 = atnode2.y;
\r\n\t
var lerpnum = 0.1;
\r\n\t
var atpos1 = [(atx2 - atx1) * lerpnum + atx1, (aty2 - aty1) * lerpnum + aty1];
\r\n\t
var atpos2 = [(atx1 - atx2) * lerpnum + atx2, (aty1 - aty2) * lerpnum + aty2];
\r\n\t
engine.Tween.get(atnode1, {
\r\n\t
loop: true
\r\n\t
}).to({
\r\n\t
x: atpos1[0],
\r\n\t
y: atpos1[1]
\r\n\t
}, 500)
\r\n\t
.to({
\r\n\t
x: atx1,
\r\n\t
y: aty1
\r\n\t
}, 500);
\r\n\t
engine.Tween.get(atnode2, { loop: true })
\r\n\t
.to({
\r\n\t
x: atpos2[0],
\r\n\t
y: atpos2[1]
\r\n\t
}, 500)
\r\n\t
.to({
\r\n\t
x: atx2,
\r\n\t
y: aty2
\r\n\t
}, 500);
\r\n\t
}
\r\n\t
else {
\r\n\t
this.solveDieMap();
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.solveDieMap = function () {
\r\n\t
this.changeEnable(false);
\r\n\t
console.error(
\"
死图调整
\"
);
\r\n\t
console.log(this.lattices);
\r\n\t
var elearr = new Array();
\r\n\t
for (var key in this.lattices) {
\r\n\t
var keyval = this.lattices[key];
\r\n\t
elearr.push(keyval);
\r\n\t
}
\r\n\t
for (var key in this.lattices) {
\r\n\t
var changeval = elearr.splice(Math.floor(Math.random() * elearr.length), 1)[0];
\r\n\t
this.lattices[key] = changeval;
\r\n\t
}
\r\n\t
var isdiedata = this.attionEliminate();
\r\n\t
if (isdiedata && isdiedata.length == 2) {
\r\n\t
console.error(
\"
可以复活了,转移位置
\"
);
\r\n\t
this.changeToFuHuoPos();
\r\n\t
}
\r\n\t
else {
\r\n\t
console.error(
\"
依然死亡,寻求复活
\"
);
\r\n\t
return this.solveDieMap();
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.changeToFuHuoPos = function () {
\r\n\t
return tslib.__awaiter(this, void 0, void 0, function () {
\r\n\t
var prolist, key, keyval, keynode, keynodex, keynodey, tpos, ipro;
\r\n\t
return tslib.__generator(this, function (_a) {
\r\n\t
switch (_a.label) {
\r\n\t
case 0:
\r\n\t
prolist = new Array();
\r\n\t
for (key in this.lattices) {
\r\n\t
keyval = this.lattices[key];
\r\n\t
keynode = this.container.getChildByName(keyval);
\r\n\t
keynodex = keynode.x;
\r\n\t
keynodey = keynode.y;
\r\n\t
tpos = MapData.getRCPos(key.split(
\"
_
\"
)[0], key.split(
\"
_
\"
)[1]);
\r\n\t
ipro = keynode.changePos(tpos);
\r\n\t
prolist.push(ipro);
\r\n\t
this.setLatticeEleRc(key);
\r\n\t
}
\r\n\t
return [4, Promise.all(prolist)];
\r\n\t
case 1:
\r\n\t
_a.sent();
\r\n\t
console.error(
\"
死亡转移完毕
\"
);
\r\n\t
this.changeEnable(true);
\r\n\t
return [2];
\r\n\t
}
\r\n\t
});
\r\n\t
});
\r\n\t
};
\r\n\t
GameView.prototype.attionEliminate = function () {
\r\n\t
var attiondata;
\r\n\t
for (var r = MapData.row - 1; r > -1; r--) {
\r\n\t
if (attiondata && attiondata.length == 2) {
\r\n\t
break;
\r\n\t
}
\r\n\t
for (var c = MapData.col - 1; c > -1; c--) {
\r\n\t
var checktype = this.getEleTypeByRc(r, c);
\r\n\t
var edatarow = this.getEliminateRow(r, c);
\r\n\t
var edatacol = this.getEliminateCol(r, c);
\r\n\t
if (edatarow.length > 2 || edatacol.length > 2) {
\r\n\t
console.error(
\"
啥情况,检查----------------
\"
);
\r\n\t
}
\r\n\t
if (edatarow.length == 2) {
\r\n\t
console.log(
\"
横向查找
\"
, edatarow, checktype);
\r\n\t
var releidx1 = edatarow[0];
\r\n\t
var releidx2 = edatarow[1];
\r\n\t
var relerow1 = Number(releidx1.split(
\"
_
\"
)[0]);
\r\n\t
var relerow2 = Number(releidx2.split(
\"
_
\"
)[0]);
\r\n\t
var relecol = Number(releidx1.split(
\"
_
\"
)[1]);
\r\n\t
var downrow = relerow1 + 1;
\r\n\t
var uprow = relerow2 - 1;
\r\n\t
var rightcol = relecol + 1;
\r\n\t
var leftcol = relecol - 1;
\r\n\t
if (downrow < MapData.row) {
\r\n\t
if (rightcol < MapData.col) {
\r\n\t
var nexttype = this.getEleTypeByRc(downrow, rightcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [downrow +
\"
_
\"
+ relecol, downrow +
\"
_
\"
+ rightcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (leftcol > -1) {
\r\n\t
var nexttype = this.getEleTypeByRc(downrow, leftcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [downrow +
\"
_
\"
+ relecol, downrow +
\"
_
\"
+ leftcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
if (uprow > -1) {
\r\n\t
if (rightcol < MapData.col) {
\r\n\t
var nexttype = this.getEleTypeByRc(uprow, rightcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [uprow +
\"
_
\"
+ relecol, uprow +
\"
_
\"
+ rightcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (leftcol > -1) {
\r\n\t
var nexttype = this.getEleTypeByRc(uprow, leftcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [uprow +
\"
_
\"
+ relecol, uprow +
\"
_
\"
+ leftcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
if (edatacol.length == 2) {
\r\n\t
console.log(
\"
竖向查找
\"
, edatacol, checktype);
\r\n\t
var releidx1 = edatacol[0];
\r\n\t
var releidx2 = edatacol[1];
\r\n\t
var relerow = Number(releidx1.split(
\"
_
\"
)[0]);
\r\n\t
var relecol1 = Number(releidx1.split(
\"
_
\"
)[1]);
\r\n\t
var relecol2 = Number(releidx2.split(
\"
_
\"
)[1]);
\r\n\t
var rightcol = relecol1 + 1;
\r\n\t
var leftcol = relecol2 - 1;
\r\n\t
var uprow = relerow - 1;
\r\n\t
var downrow = relerow + 1;
\r\n\t
if (leftcol > -1) {
\r\n\t
if (uprow > -1) {
\r\n\t
var nexttype = this.getEleTypeByRc(uprow, leftcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [relerow +
\"
_
\"
+ leftcol, uprow +
\"
_
\"
+ leftcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (downrow < MapData.row) {
\r\n\t
var nexttype = this.getEleTypeByRc(downrow, leftcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [relerow +
\"
_
\"
+ leftcol, downrow +
\"
_
\"
+ leftcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
if (rightcol < MapData.col) {
\r\n\t
if (uprow > -1) {
\r\n\t
var nexttype = this.getEleTypeByRc(uprow, rightcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [relerow +
\"
_
\"
+ rightcol, uprow +
\"
_
\"
+ rightcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (downrow < MapData.row) {
\r\n\t
var nexttype = this.getEleTypeByRc(downrow, rightcol);
\r\n\t
if (nexttype == checktype) {
\r\n\t
attiondata = [relerow +
\"
_
\"
+ rightcol, downrow +
\"
_
\"
+ rightcol];
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
console.log(
\"
相邻检测--------------
\"
, attiondata);
\r\n\t
return attiondata;
\r\n\t
};
\r\n\t
GameView.prototype.checkEliminate = function () {
\r\n\t
this.eliminateArr = new Array();
\r\n\t
for (var r = MapData.row - 1; r > -1; r--) {
\r\n\t
for (var c = MapData.col - 1; c > -1; c--) {
\r\n\t
var edata = this.getEliminate(r, c);
\r\n\t
if (edata) {
\r\n\t
var etype = edata.etype;
\r\n\t
var earr = edata.arr;
\r\n\t
this.checkAddEli(etype, earr);
\r\n\t
}
\r\n\t
}
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.getEliminateRow = function (x, y) {
\r\n\t
var checktype = this.getEleTypeByRc(x, y);
\r\n\t
var relearr = new Array();
\r\n\t
relearr.push(x +
\"
_
\"
+ y);
\r\n\t
for (var r = x - 1; r > -1; r--) {
\r\n\t
var reletype = this.getEleTypeByRc(r, y);
\r\n\t
if (checktype == reletype) {
\r\n\t
relearr.push(r +
\"
_
\"
+ y);
\r\n\t
}
\r\n\t
else {
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
return relearr;
\r\n\t
};
\r\n\t
GameView.prototype.getEliminateCol = function (x, y) {
\r\n\t
var checktype = this.getEleTypeByRc(x, y);
\r\n\t
var celearr = new Array();
\r\n\t
celearr.push(x +
\"
_
\"
+ y);
\r\n\t
for (var c = y - 1; c > -1; c--) {
\r\n\t
var celetype = this.getEleTypeByRc(x, c);
\r\n\t
if (checktype == celetype) {
\r\n\t
celearr.push(x +
\"
_
\"
+ c);
\r\n\t
}
\r\n\t
else {
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
return celearr;
\r\n\t
};
\r\n\t
GameView.prototype.getEliminate = function (x, y) {
\r\n\t
var checktype = this.getEleTypeByRc(x, y);
\r\n\t
var relearr = this.getEliminateRow(x, y);
\r\n\t
var celearr = this.getEliminateCol(x, y);
\r\n\t
var eliminatearr = new Array();
\r\n\t
if (relearr.length >= 3) {
\r\n\t
eliminatearr.push.apply(eliminatearr, relearr);
\r\n\t
}
\r\n\t
if (celearr.length >= 3) {
\r\n\t
eliminatearr.push.apply(eliminatearr, celearr);
\r\n\t
}
\r\n\t
if (eliminatearr.length > 0) {
\r\n\t
return {
\r\n\t
etype: checktype,
\r\n\t
arr: eliminatearr
\r\n\t
};
\r\n\t
}
\r\n\t
else {
\r\n\t
return false;
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.getEleTypeByRc = function (r, c) {
\r\n\t
var rc = r +
\"
_
\"
+ c;
\r\n\t
var elename = this.lattices[rc];
\r\n\t
var ele = this.container.getChildByName(elename);
\r\n\t
var eletype = ele.type;
\r\n\t
return eletype;
\r\n\t
};
\r\n\t
GameView.prototype.checkAddEli = function (etype, earr) {
\r\n\t
for (var e = 0; e < earr.length; e++) {
\r\n\t
var ename = earr[e];
\r\n\t
var needadd = true;
\r\n\t
for (var i = 0; i < this.eliminateArr.length; i++) {
\r\n\t
var ielidata = this.eliminateArr[i];
\r\n\t
var ielidxname = ielidata.idxname;
\r\n\t
if (ielidxname == ename) {
\r\n\t
needadd = false;
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (needadd) {
\r\n\t
this.eliminateArr.push({
\r\n\t
idxname: ename,
\r\n\t
type: etype
\r\n\t
});
\r\n\t
}
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.getFallRcEle = function (r, c) {
\r\n\t
for (var fr = r - 1; fr > -1; fr--) {
\r\n\t
var frc = fr +
\"
_
\"
+ c;
\r\n\t
var frcname = this.lattices[frc];
\r\n\t
if (frcname !=
\"
empty
\"
) {
\r\n\t
this.lattices[frc] =
\"
empty
\"
;
\r\n\t
return frcname;
\r\n\t
}
\r\n\t
}
\r\n\t
return false;
\r\n\t
};
\r\n\t
return GameView;
\r\n\t
}(engine.Container));
\n\n\t
var GameWrapper = (function (_super) {
\r\n\t
tslib.__extends(GameWrapper, _super);
\r\n\t
function GameWrapper() {
\r\n\t
var _this = _super.call(this) || this;
\r\n\t
_this._gameView = new GameView();
\r\n\t
_this.addChild(_this._gameView);
\r\n\t
engine.globalEvent.addEventListener('game-init', _this.init, _this);
\r\n\t
engine.globalEvent.addEventListener('game-reset', _this.reset, _this);
\r\n\t
engine.globalEvent.addEventListener('game-start', _this.start, _this);
\r\n\t
return _this;
\r\n\t
}
\r\n\t
GameWrapper.prototype.init = function () {
\r\n\t
this._gameView.init();
\r\n\t
};
\r\n\t
GameWrapper.prototype.reset = function () {
\r\n\t
this._gameView.reset();
\r\n\t
};
\r\n\t
GameWrapper.prototype.start = function () {
\r\n\t
this._gameView.start();
\r\n\t
};
\r\n\t
return GameWrapper;
\r\n\t
}(engine.Container));
\r\n\t
//# sourceMappingURL=GameWrapper.js.map
\n\n\t
var props = {};
\r\n\t
function prepareProps() {
\r\n\t
var metaProps = getProps();
\r\n\t
engine.injectProp(props, metaProps);
\r\n\t
}
\r\n\t
function injectProps(p) {
\r\n\t
engine.injectProp(props, p);
\r\n\t
}
\r\n\t
//# sourceMappingURL=props.js.map
\n\n\t
function index (props) {
\r\n\t
prepareProps();
\r\n\t
injectProps(props);
\r\n\t
var instance = new GameWrapper();
\r\n\t
return instance;
\r\n\t
}
\r\n\t
//# sourceMappingURL=index.js.map
\n\n\t
return index;
\n\n
})));
\n
"
}
src/custom/bjxd-game/src/game/Player.ts
View file @
bea870f5
...
...
@@ -16,7 +16,7 @@ export class Player extends engine.Container{
this
.
_container
.
addChild
(
this
.
playerNode
);
this
.
playerNode
.
y
=
this
.
playery
;
this
.
playerNode
.
x
=
pierWidth
/
2
-
50
;
this
.
playerNode
.
play
();
this
.
playerNode
.
stop
();
this
.
_container
.
visible
=
false
;
}
...
...
src/custom/xiaoxiaole/debug/main.js
View file @
bea870f5
...
...
@@ -10,6 +10,12 @@
function
getTextureByName
(
name
)
{
return
getTexture
(
engine
.
getAssetByName
(
name
).
uuid
);
}
function
createSvga
(
name
,
anchorName
)
{
var
inst
=
new
svga
.
Svga
();
inst
.
source
=
'asset://'
+
engine
.
getAssetByName
(
name
).
uuid
;
return
inst
;
}
//# sourceMappingURL=utils.js.map
var
Element
=
(
function
(
_super
)
{
tslib
.
__extends
(
Element
,
_super
);
...
...
@@ -17,6 +23,8 @@
var
_this
=
_super
.
call
(
this
)
||
this
;
_this
.
width
=
MapData
.
itemsize
;
_this
.
height
=
MapData
.
itemsize
;
_this
.
anchorX
=
MapData
.
itemsize
/
2
;
_this
.
anchorY
=
MapData
.
itemsize
;
_this
.
eimage
=
new
engine
.
Image
();
_this
.
addChild
(
_this
.
eimage
);
_this
.
touch
=
true
;
...
...
@@ -59,7 +67,7 @@
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
;
var
mscale
=
(
1
-
value
)
*
(
1
-
value
)
*
1
+
2
*
value
*
(
1
-
value
)
*
0.6
+
value
*
value
*
0
.35
;
this
.
scaleX
=
mscale
;
this
.
scaleY
=
mscale
;
},
...
...
@@ -69,24 +77,58 @@
Element
.
prototype
.
flyToHome
=
function
(
tx
,
ty
,
time
)
{
var
_this
=
this
;
this
.
p1x
=
this
.
x
;
this
.
p1y
=
this
.
y
;
this
.
p1y
=
this
.
y
+
20
;
this
.
c1x
=
(
this
.
p1x
-
tx
)
/
4
+
tx
;
this
.
c1y
=
ty
;
this
.
p2x
=
tx
;
this
.
p2y
=
ty
;
engine
.
Tween
.
get
(
this
).
to
({
scaleX
:
1.1
,
scaleY
:
1.1
},
200
)
.
to
({
scaleX
:
1.1
,
scaleY
:
0.88
},
100
)
.
to
({
scaleX
:
0.98
,
scaleY
:
0.98
,
y
:
this
.
y
+
20
},
100
)
.
call
(
function
()
{
engine
.
Tween
.
get
(
_this
).
to
({
factor
:
1
},
time
)
},
450
)
.
call
(
function
()
{
var
nodeparent
=
_this
.
parent
;
nodeparent
&&
nodeparent
.
removeChild
(
_this
);
MapData
.
recoverEle
(
_this
);
});
});
};
Element
.
prototype
.
changePos
=
function
()
{
Element
.
prototype
.
changePos
=
function
(
tpos
)
{
var
_this
=
this
;
var
nx
=
this
.
x
;
var
ny
=
this
.
y
;
var
tx
=
tpos
[
0
];
var
ty
=
tpos
[
1
];
var
dis
=
MapData
.
getDistance
([
nx
,
ny
],
tpos
);
var
time
=
Math
.
ceil
(
dis
/
MapData
.
anispeed
*
1000
);
var
pro
=
new
Promise
(
function
(
res
)
{
engine
.
Tween
.
get
(
_this
,
{
loop
:
false
}).
to
({
x
:
tx
,
y
:
ty
},
time
)
.
call
(
function
()
{
console
.
log
(
"单个移动完毕"
);
res
();
});
});
return
pro
;
};
return
Element
;
}(
engine
.
Container
));
//# sourceMappingURL=Element.js.map
var
ElementType
;
(
function
(
ElementType
)
{
...
...
@@ -180,8 +222,10 @@
MapData
.
posData
=
{};
MapData
.
eleidx
=
1
;
MapData
.
elePool
=
[];
MapData
.
anispeed
=
860
;
return
MapData
;
}());
//# sourceMappingURL=MapData.js.map
var
GameView
=
(
function
(
_super
)
{
tslib
.
__extends
(
GameView
,
_super
);
...
...
@@ -192,7 +236,9 @@
_this
.
selectArr
=
[];
_this
.
conty
=
140
;
_this
.
homex
=
528
;
_this
.
anispeed
=
860
;
_this
.
homey
=
-
40
;
_this
.
ination
=
false
;
_this
.
canation
=
true
;
_this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
_this
.
setup
,
_this
);
return
_this
;
}
...
...
@@ -201,12 +247,25 @@
this
.
selectimg
.
mouseEnabled
=
false
;
var
row
=
MapData
.
row
;
var
col
=
MapData
.
col
;
this
.
homeimg
=
new
engine
.
Image
(
getTextureByName
(
"房子"
)
);
this
.
homeimg
=
createSvga
(
"房子动画"
);
this
.
addChild
(
this
.
homeimg
);
this
.
homeimg
.
x
=
this
.
homex
;
this
.
homeimg
.
y
=
-
40
;
this
.
homeimg
.
stop
();
console
.
log
(
"房子动画"
,
this
.
homeimg
);
this
.
container
=
new
engine
.
Container
();
this
.
addChild
(
this
.
container
);
this
.
container
.
y
=
this
.
conty
;
var
maskimg
=
new
engine
.
Graphics
();
this
.
container
.
addChild
(
maskimg
);
this
.
container
.
mask
=
maskimg
;
maskimg
.
moveTo
(
0
,
0
);
maskimg
.
beginFill
(
0
);
maskimg
.
lineTo
(
681
,
0
);
maskimg
.
lineTo
(
681
,
679
);
maskimg
.
lineTo
(
0
,
679
);
maskimg
.
lineTo
(
0
,
0
);
maskimg
.
endFill
();
this
.
anicontainer
=
new
engine
.
Container
();
this
.
addChild
(
this
.
anicontainer
);
this
.
anicontainer
.
mouseEnabled
=
false
;
...
...
@@ -219,10 +278,17 @@
MapData
.
posData
[
r
+
"_"
+
c
]
=
rcpos
;
}
}
this
.
tanix
=
this
.
homex
+
this
.
homeimg
.
texture
.
width
/
2
;
this
.
taniy
=
this
.
home
img
.
texture
.
height
/
2
;
this
.
tanix
=
this
.
homex
+
146
/
2
-
MapData
.
itemsize
/
3
;
this
.
taniy
=
this
.
home
y
+
120
/
2
;
engine
.
globalEvent
.
addEventListener
(
GameEvent
.
SelectEle
,
this
.
selectele
,
this
);
this
.
removeEventListener
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
setup
,
this
);
this
.
lastframeTime
=
Date
.
now
();
this
.
lastatime
=
Date
.
now
();
this
.
addEventListener
(
engine
.
Event
.
ENTER_FRAME
,
this
.
onUpdate
,
this
);
};
GameView
.
prototype
.
playComp
=
function
()
{
console
.
log
(
"动画播放完毕"
);
this
.
homeimg
.
stop
(
1
);
};
GameView
.
prototype
.
init
=
function
()
{
this
.
initContainer
();
...
...
@@ -231,12 +297,26 @@
};
GameView
.
prototype
.
start
=
function
()
{
};
GameView
.
prototype
.
onUpdate
=
function
()
{
var
ntime
=
Date
.
now
();
var
passtime
=
ntime
-
this
.
lastframeTime
;
if
(
ntime
-
this
.
lastatime
>=
5000
&&
!
this
.
ination
&&
this
.
canation
&&
this
.
selectArr
.
length
==
0
)
{
this
.
attionEliShow
();
}
if
(
this
.
homeimg
)
{
var
curframe
=
this
.
homeimg
.
currentFrame
;
if
(
curframe
==
this
.
homeimg
.
totalFrames
)
{
this
.
homeimg
.
gotoAndStop
(
1
);
}
}
this
.
lastframeTime
=
ntime
;
};
GameView
.
prototype
.
initContainer
=
function
()
{
this
.
lattices
=
{};
var
testdata
=
[
[
1
,
2
,
5
,
3
,
4
],
[
3
,
1
,
2
,
4
,
5
],
[
2
,
5
,
3
,
4
,
1
],
[
1
,
2
,
5
,
3
,
3
],
[
3
,
1
,
4
,
4
,
5
],
[
2
,
5
,
3
,
5
,
1
],
[
5
,
4
,
1
,
2
,
3
],
[
4
,
1
,
3
,
5
,
2
],
];
...
...
@@ -255,7 +335,7 @@
}
}
this
.
checkEliminate
();
this
.
attionEliminate
();
this
.
fall
();
};
GameView
.
prototype
.
setLatticeEleRc
=
function
(
rcidx
)
{
var
rename
=
this
.
lattices
[
rcidx
];
...
...
@@ -269,6 +349,24 @@
var
sr
=
data
.
r
;
var
sc
=
data
.
c
;
var
sname
=
sr
+
"_"
+
sc
;
if
(
this
.
ination
)
{
this
.
ination
=
false
;
this
.
lastatime
=
Date
.
now
();
var
arrcidx1
=
this
.
attiondata
[
0
];
var
arrcidx2
=
this
.
attiondata
[
1
];
var
atname1
=
this
.
lattices
[
arrcidx1
];
var
atname2
=
this
.
lattices
[
arrcidx2
];
var
atnode1
=
this
.
container
.
getChildByName
(
atname1
);
var
atnode2
=
this
.
container
.
getChildByName
(
atname2
);
var
atpos1
=
MapData
.
getRCPos
(
arrcidx1
.
split
(
"_"
)[
0
],
arrcidx1
.
split
(
"_"
)[
1
]);
var
atpos2
=
MapData
.
getRCPos
(
arrcidx2
.
split
(
"_"
)[
0
],
arrcidx2
.
split
(
"_"
)[
1
]);
engine
.
Tween
.
removeTweens
(
atnode1
);
engine
.
Tween
.
removeTweens
(
atnode2
);
atnode1
.
x
=
atpos1
[
0
];
atnode1
.
y
=
atpos1
[
1
];
atnode2
.
x
=
atpos2
[
0
];
atnode2
.
y
=
atpos2
[
1
];
}
if
(
this
.
selectArr
.
length
==
0
)
{
this
.
selectArr
.
push
(
sname
);
}
...
...
@@ -279,10 +377,16 @@
if
((
sr
==
asr
&&
Math
.
abs
(
sc
-
asc
)
==
1
)
||
(
sc
==
asc
&&
Math
.
abs
(
sr
-
asr
)
==
1
))
{
this
.
selectArr
.
push
(
sname
);
}
else
{
if
(
sr
==
asr
&&
sc
==
asc
)
{
this
.
selectArr
=
new
Array
();
this
.
anicontainer
.
removeChild
(
this
.
selectimg
);
}
else
{
this
.
selectArr
[
0
]
=
sname
;
}
}
}
if
(
this
.
selectArr
.
length
==
1
)
{
this
.
setSelectShow
();
}
...
...
@@ -295,13 +399,13 @@
var
r
=
rcname
.
split
(
"_"
)[
0
];
var
c
=
rcname
.
split
(
"_"
)[
1
];
var
rcpos
=
MapData
.
getRCPos
(
r
,
c
);
this
.
container
.
addChild
(
this
.
selectimg
);
this
.
ani
container
.
addChild
(
this
.
selectimg
);
this
.
selectimg
.
x
=
rcpos
[
0
];
this
.
selectimg
.
y
=
rcpos
[
1
];
this
.
selectimg
.
y
=
rcpos
[
1
]
+
this
.
conty
;
};
GameView
.
prototype
.
changeElePos
=
function
()
{
var
_this
=
this
;
this
.
container
.
removeChild
(
this
.
selectimg
);
this
.
ani
container
.
removeChild
(
this
.
selectimg
);
this
.
changeEnable
(
false
);
var
sname1
=
this
.
selectArr
[
0
];
var
sname2
=
this
.
selectArr
[
1
];
...
...
@@ -318,7 +422,7 @@
var
snode1y
=
snode1
.
y
;
var
snode2x
=
snode2
.
x
;
var
snode2y
=
snode2
.
y
;
var
changetime
=
Math
.
ceil
((
MapData
.
itemsize
/
this
.
anispeed
)
*
2
*
1000
);
var
changetime
=
Math
.
ceil
((
MapData
.
itemsize
/
MapData
.
anispeed
)
*
2
*
1000
);
if
(
this
.
eliminateArr
.
length
>
0
)
{
engine
.
Tween
.
get
(
snode1
).
to
({
x
:
snode2x
,
...
...
@@ -362,24 +466,48 @@
}
};
GameView
.
prototype
.
eliminate
=
function
()
{
for
(
var
i
=
0
;
i
<
this
.
eliminateArr
.
length
;
i
++
)
{
var
ielidata
=
this
.
eliminateArr
[
i
];
var
ielidxname
=
ielidata
.
idxname
;
var
ielitype
=
ielidata
.
type
;
var
ieliname
=
this
.
lattices
[
ielidxname
];
var
ielinode
=
this
.
container
.
getChildByName
(
ieliname
);
var
ielix
=
ielinode
.
x
;
var
ieliy
=
ielinode
.
y
;
return
tslib
.
__awaiter
(
this
,
void
0
,
void
0
,
function
()
{
var
i
,
ielidata
,
ielidxname
,
ielitype
,
ieliname
,
ielinode
,
ielix
,
ieliy
;
return
tslib
.
__generator
(
this
,
function
(
_a
)
{
switch
(
_a
.
label
)
{
case
0
:
for
(
i
=
0
;
i
<
this
.
eliminateArr
.
length
;
i
++
)
{
ielidata
=
this
.
eliminateArr
[
i
];
ielidxname
=
ielidata
.
idxname
;
ielitype
=
ielidata
.
type
;
ieliname
=
this
.
lattices
[
ielidxname
];
ielinode
=
this
.
container
.
getChildByName
(
ieliname
);
ielix
=
ielinode
.
x
;
ieliy
=
ielinode
.
y
;
this
.
container
.
removeChild
(
ielinode
);
MapData
.
recoverEle
(
ielinode
);
this
.
lattices
[
ielidxname
]
=
"empty"
;
this
.
goHomeAni
(
ielitype
,
ielix
,
ieliy
);
}
return
[
4
,
new
Promise
(
function
(
res
)
{
setTimeout
(
function
()
{
res
();
},
800
);
})];
case
1
:
_a
.
sent
();
this
.
fall
();
return
[
4
,
new
Promise
(
function
(
res1
)
{
setTimeout
(
function
()
{
res1
();
},
550
);
})];
case
2
:
_a
.
sent
();
this
.
homeimg
.
play
();
return
[
2
];
}
});
});
};
GameView
.
prototype
.
fall
=
function
()
{
return
tslib
.
__awaiter
(
this
,
void
0
,
void
0
,
function
()
{
var
fallData
,
fcutr
,
fc
,
r
,
c
,
idxname
,
elename
,
frcname
,
fetype
,
fele
,
cutr
,
fepos
,
fallPromise
,
_loop_1
,
this_1
,
f
;
var
fallData
,
fcutr
,
fc
,
r
,
c
,
idxname
,
elename
,
frcname
,
fetype
,
fele
,
cutr
,
fepos
,
fallPromise
,
_loop_1
,
this_1
,
f
,
isdiedata
;
return
tslib
.
__generator
(
this
,
function
(
_a
)
{
switch
(
_a
.
label
)
{
case
0
:
...
...
@@ -425,13 +553,20 @@
var
frcnode
=
this_1
.
container
.
getChildByName
(
frcname
);
var
nepos
=
[
frcnode
.
x
,
frcnode
.
y
];
var
fdis
=
MapData
.
getDistance
(
ftpos
,
nepos
);
var
ftime
=
Math
.
ceil
((
fdis
/
this_1
.
anispeed
)
*
1000
);
var
ftime
=
Math
.
ceil
((
fdis
/
MapData
.
anispeed
)
*
1000
);
var
ifallpromise
=
new
Promise
(
function
(
res
)
{
engine
.
Tween
.
get
(
frcnode
)
.
to
({
x
:
ftpos
[
0
],
y
:
ftpos
[
1
]
},
ftime
).
call
(
function
()
{
},
ftime
)
.
to
({
scaleY
:
0.85
},
80
)
.
to
({
scaleY
:
1
},
80
)
.
call
(
function
()
{
res
();
});
});
...
...
@@ -450,8 +585,14 @@
}
else
{
this
.
selectArr
=
new
Array
();
isdiedata
=
this
.
attionEliminate
();
if
(
isdiedata
&&
isdiedata
.
length
==
2
)
{
this
.
changeEnable
(
true
);
}
else
{
this
.
solveDieMap
();
}
}
return
[
2
];
}
});
...
...
@@ -459,14 +600,16 @@
};
GameView
.
prototype
.
goHomeAni
=
function
(
ielitype
,
ielix
,
ieliy
)
{
var
aniele
=
MapData
.
getOneEle
(
ielitype
);
aniele
.
alpha
=
0
;
var
anix
=
ielix
;
var
aniy
=
ieliy
+
this
.
conty
;
this
.
anicontainer
.
addChild
(
aniele
);
aniele
.
touch
=
false
;
aniele
.
x
=
anix
;
aniele
.
y
=
aniy
;
aniele
.
alpha
=
1
;
var
anidis
=
MapData
.
getDistance
([
this
.
tanix
,
this
.
taniy
],
[
anix
,
aniy
]);
var
anitime
=
Math
.
ceil
((
anidis
/
this
.
anispeed
)
*
1000
);
var
anitime
=
Math
.
ceil
((
anidis
/
MapData
.
anispeed
)
*
1000
);
aniele
.
flyToHome
(
this
.
tanix
,
this
.
taniy
,
anitime
);
};
GameView
.
prototype
.
changeEnable
=
function
(
v
)
{
...
...
@@ -475,10 +618,108 @@
var
ele
=
this
.
container
.
getChildByName
(
kname
);
ele
.
touch
=
v
;
}
if
(
v
)
{
this
.
lastatime
=
Date
.
now
();
}
this
.
canation
=
v
;
};
GameView
.
prototype
.
attionEliShow
=
function
()
{
var
attiondata
=
this
.
attionEliminate
();
if
(
attiondata
&&
attiondata
.
length
==
2
)
{
this
.
ination
=
true
;
console
.
log
(
"可以提示"
);
this
.
attiondata
=
[
attiondata
[
0
],
attiondata
[
1
]];
var
atname1
=
this
.
lattices
[
attiondata
[
0
]];
var
atname2
=
this
.
lattices
[
attiondata
[
1
]];
var
atnode1
=
this
.
container
.
getChildByName
(
atname1
);
var
atnode2
=
this
.
container
.
getChildByName
(
atname2
);
var
atx1
=
atnode1
.
x
;
var
aty1
=
atnode1
.
y
;
var
atx2
=
atnode2
.
x
;
var
aty2
=
atnode2
.
y
;
var
lerpnum
=
0.1
;
var
atpos1
=
[(
atx2
-
atx1
)
*
lerpnum
+
atx1
,
(
aty2
-
aty1
)
*
lerpnum
+
aty1
];
var
atpos2
=
[(
atx1
-
atx2
)
*
lerpnum
+
atx2
,
(
aty1
-
aty2
)
*
lerpnum
+
aty2
];
engine
.
Tween
.
get
(
atnode1
,
{
loop
:
true
}).
to
({
x
:
atpos1
[
0
],
y
:
atpos1
[
1
]
},
500
)
.
to
({
x
:
atx1
,
y
:
aty1
},
500
);
engine
.
Tween
.
get
(
atnode2
,
{
loop
:
true
})
.
to
({
x
:
atpos2
[
0
],
y
:
atpos2
[
1
]
},
500
)
.
to
({
x
:
atx2
,
y
:
aty2
},
500
);
}
else
{
this
.
solveDieMap
();
}
};
GameView
.
prototype
.
solveDieMap
=
function
()
{
this
.
changeEnable
(
false
);
console
.
error
(
"死图调整"
);
console
.
log
(
this
.
lattices
);
var
elearr
=
new
Array
();
for
(
var
key
in
this
.
lattices
)
{
var
keyval
=
this
.
lattices
[
key
];
elearr
.
push
(
keyval
);
}
for
(
var
key
in
this
.
lattices
)
{
var
changeval
=
elearr
.
splice
(
Math
.
floor
(
Math
.
random
()
*
elearr
.
length
),
1
)[
0
];
this
.
lattices
[
key
]
=
changeval
;
}
var
isdiedata
=
this
.
attionEliminate
();
if
(
isdiedata
&&
isdiedata
.
length
==
2
)
{
console
.
error
(
"可以复活了,转移位置"
);
this
.
changeToFuHuoPos
();
}
else
{
console
.
error
(
"依然死亡,寻求复活"
);
return
this
.
solveDieMap
();
}
};
GameView
.
prototype
.
changeToFuHuoPos
=
function
()
{
return
tslib
.
__awaiter
(
this
,
void
0
,
void
0
,
function
()
{
var
prolist
,
key
,
keyval
,
keynode
,
keynodex
,
keynodey
,
tpos
,
ipro
;
return
tslib
.
__generator
(
this
,
function
(
_a
)
{
switch
(
_a
.
label
)
{
case
0
:
prolist
=
new
Array
();
for
(
key
in
this
.
lattices
)
{
keyval
=
this
.
lattices
[
key
];
keynode
=
this
.
container
.
getChildByName
(
keyval
);
keynodex
=
keynode
.
x
;
keynodey
=
keynode
.
y
;
tpos
=
MapData
.
getRCPos
(
key
.
split
(
"_"
)[
0
],
key
.
split
(
"_"
)[
1
]);
ipro
=
keynode
.
changePos
(
tpos
);
prolist
.
push
(
ipro
);
this
.
setLatticeEleRc
(
key
);
}
return
[
4
,
Promise
.
all
(
prolist
)];
case
1
:
_a
.
sent
();
console
.
error
(
"死亡转移完毕"
);
this
.
changeEnable
(
true
);
return
[
2
];
}
});
});
};
GameView
.
prototype
.
attionEliminate
=
function
()
{
var
attiondata
;
for
(
var
r
=
MapData
.
row
-
1
;
r
>
-
1
;
r
--
)
{
if
(
attiondata
&&
attiondata
.
length
==
2
)
{
break
;
}
for
(
var
c
=
MapData
.
col
-
1
;
c
>
-
1
;
c
--
)
{
var
checktype
=
this
.
getEleTypeByRc
(
r
,
c
);
var
edatarow
=
this
.
getEliminateRow
(
r
,
c
);
...
...
@@ -487,7 +728,7 @@
console
.
error
(
"啥情况,检查----------------"
);
}
if
(
edatarow
.
length
==
2
)
{
console
.
log
(
"横向查找"
,
edatarow
);
console
.
log
(
"横向查找"
,
edatarow
,
checktype
);
var
releidx1
=
edatarow
[
0
];
var
releidx2
=
edatarow
[
1
];
var
relerow1
=
Number
(
releidx1
.
split
(
"_"
)[
0
]);
...
...
@@ -531,17 +772,53 @@
}
}
if
(
edatacol
.
length
==
2
)
{
console
.
log
(
"竖向查找"
,
edatacol
);
var
releidx1
=
edata
row
[
0
];
var
releidx2
=
edata
row
[
1
];
console
.
log
(
"竖向查找"
,
edatacol
,
checktype
);
var
releidx1
=
edata
col
[
0
];
var
releidx2
=
edata
col
[
1
];
var
relerow
=
Number
(
releidx1
.
split
(
"_"
)[
0
]);
var
relecol1
=
Number
(
releidx1
.
split
(
"_"
)[
1
]);
var
relecol2
=
Number
(
releidx2
.
split
(
"_"
)[
1
]);
console
.
log
(
"竖向检查啦啦啦"
,
relerow
,
relecol1
,
relecol2
);
var
rightcol
=
relecol1
+
1
;
var
leftcol
=
relecol2
-
1
;
var
uprow
=
relerow
-
1
;
var
downrow
=
relerow
+
1
;
if
(
leftcol
>
-
1
)
{
if
(
uprow
>
-
1
)
{
var
nexttype
=
this
.
getEleTypeByRc
(
uprow
,
leftcol
);
if
(
nexttype
==
checktype
)
{
attiondata
=
[
relerow
+
"_"
+
leftcol
,
uprow
+
"_"
+
leftcol
];
break
;
}
}
if
(
downrow
<
MapData
.
row
)
{
var
nexttype
=
this
.
getEleTypeByRc
(
downrow
,
leftcol
);
if
(
nexttype
==
checktype
)
{
attiondata
=
[
relerow
+
"_"
+
leftcol
,
downrow
+
"_"
+
leftcol
];
break
;
}
}
}
if
(
rightcol
<
MapData
.
col
)
{
if
(
uprow
>
-
1
)
{
var
nexttype
=
this
.
getEleTypeByRc
(
uprow
,
rightcol
);
if
(
nexttype
==
checktype
)
{
attiondata
=
[
relerow
+
"_"
+
rightcol
,
uprow
+
"_"
+
rightcol
];
break
;
}
}
if
(
downrow
<
MapData
.
row
)
{
var
nexttype
=
this
.
getEleTypeByRc
(
downrow
,
rightcol
);
if
(
nexttype
==
checktype
)
{
attiondata
=
[
relerow
+
"_"
+
rightcol
,
downrow
+
"_"
+
rightcol
];
break
;
}
}
}
}
}
}
console
.
log
(
"相邻检测--------------"
,
attiondata
);
return
attiondata
;
};
GameView
.
prototype
.
checkEliminate
=
function
()
{
this
.
eliminateArr
=
new
Array
();
...
...
@@ -670,6 +947,7 @@
};
return
GameWrapper
;
}(
engine
.
Container
));
//# sourceMappingURL=GameWrapper.js.map
var
props
=
{};
function
prepareProps
()
{
...
...
@@ -679,6 +957,7 @@
function
injectProps
(
p
)
{
engine
.
injectProp
(
props
,
p
);
}
//# sourceMappingURL=props.js.map
function
index
(
props
)
{
prepareProps
();
...
...
@@ -686,6 +965,7 @@
var
instance
=
new
GameWrapper
();
return
instance
;
}
//# sourceMappingURL=index.js.map
return
index
;
...
...
src/custom/xiaoxiaole/debug/main.js.map
View file @
bea870f5
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/custom/xiaoxiaole/meta.json
View file @
bea870f5
...
...
@@ -52,6 +52,12 @@
"url"
:
"//yun.duiba.com.cn/aurora/assets/a3ce52a41ed53ccfa7ce404dbc10102961c4a805.png"
,
"uuid"
:
"selected"
,
"ext"
:
".png"
},
{
"name"
:
"房子动画"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/f55c640d40911934c7c5cf01f4fc1940ffb4e16c.svga"
,
"uuid"
:
"homeani"
,
"ext"
:
".svga"
}
],
"events"
:
{
...
...
src/custom/xiaoxiaole/src/game/GameView.ts
View file @
bea870f5
...
...
@@ -3,9 +3,8 @@
*/
import
{
props
}
from
"../props"
;
import
{
playSound
,
createSvga
}
from
"./utils"
;
import
{
playSound
,
createSvga
,
getTextureByName
}
from
"./utils"
;
import
ObjectPool
=
engine
.
ObjectPool
;
import
{
getTextureByName
}
from
"./utils"
;
import
MapData
,
{
GameEvent
}
from
"./MapData"
;
import
Element
from
"./ele/Element"
;
...
...
@@ -31,14 +30,22 @@ export default class GameView extends engine.Container {
selectimg
:
engine
.
Image
;
//屋子
homeimg
:
engine
.
Image
;
homeimg
;
conty
=
140
;
homex
=
528
;
homey
=
-
40
;
tanix
;
taniy
;
anispeed
=
860
;
//5秒不操作,给提示
lastframeTime
;
attiondata
;
lastatime
;
ination
=
false
;
canation
=
true
;
setup
()
{
this
.
selectimg
=
new
engine
.
Image
(
getTextureByName
(
"选中框"
));
...
...
@@ -47,13 +54,26 @@ export default class GameView extends engine.Container {
let
row
=
MapData
.
row
;
let
col
=
MapData
.
col
;
this
.
homeimg
=
new
engine
.
Image
(
getTextureByName
(
"房子"
)
);
this
.
homeimg
=
createSvga
(
"房子动画"
);
this
.
addChild
(
this
.
homeimg
);
this
.
homeimg
.
x
=
this
.
homex
;
this
.
homeimg
.
y
=
-
40
;
this
.
homeimg
.
stop
();
console
.
log
(
"房子动画"
,
this
.
homeimg
);
this
.
container
=
new
engine
.
Container
();
this
.
addChild
(
this
.
container
);
this
.
container
.
y
=
this
.
conty
;
let
maskimg
=
new
engine
.
Graphics
();
this
.
container
.
addChild
(
maskimg
);
this
.
container
.
mask
=
maskimg
;
maskimg
.
moveTo
(
0
,
0
);
maskimg
.
beginFill
(
0
);
maskimg
.
lineTo
(
681
,
0
);
maskimg
.
lineTo
(
681
,
679
);
maskimg
.
lineTo
(
0
,
679
);
maskimg
.
lineTo
(
0
,
0
);
maskimg
.
endFill
();
this
.
anicontainer
=
new
engine
.
Container
();
this
.
addChild
(
this
.
anicontainer
);
...
...
@@ -73,11 +93,19 @@ export default class GameView extends engine.Container {
MapData
.
posData
[
r
+
"_"
+
c
]
=
rcpos
;
}
}
this
.
tanix
=
this
.
homex
+
this
.
homeimg
.
texture
.
width
/
2
;
this
.
taniy
=
this
.
home
img
.
texture
.
height
/
2
;
this
.
tanix
=
this
.
homex
+
146
/
2
-
MapData
.
itemsize
/
3
;
this
.
taniy
=
this
.
home
y
+
120
/
2
;
// - MapData.itemsize
/2;
engine
.
globalEvent
.
addEventListener
(
GameEvent
.
SelectEle
,
this
.
selectele
,
this
);
this
.
removeEventListener
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
setup
,
this
);
this
.
lastframeTime
=
Date
.
now
();
this
.
lastatime
=
Date
.
now
();
this
.
addEventListener
(
engine
.
Event
.
ENTER_FRAME
,
this
.
onUpdate
,
this
);
}
playComp
(){
console
.
log
(
"动画播放完毕"
);
this
.
homeimg
.
stop
(
1
);
}
init
(){
...
...
@@ -89,13 +117,27 @@ export default class GameView extends engine.Container {
start
(){
}
onUpdate
(){
let
ntime
=
Date
.
now
();
let
passtime
=
ntime
-
this
.
lastframeTime
;
if
(
ntime
-
this
.
lastatime
>=
5000
&&!
this
.
ination
&&
this
.
canation
&&
this
.
selectArr
.
length
==
0
){
this
.
attionEliShow
();
}
if
(
this
.
homeimg
){
let
curframe
=
this
.
homeimg
.
currentFrame
;
if
(
curframe
==
this
.
homeimg
.
totalFrames
){
this
.
homeimg
.
gotoAndStop
(
1
);
}
}
this
.
lastframeTime
=
ntime
;
}
initContainer
(){
this
.
lattices
=
{};
let
testdata
=
[
[
1
,
2
,
5
,
3
,
4
],
[
3
,
1
,
2
,
4
,
5
],
[
2
,
5
,
3
,
4
,
1
],
[
1
,
2
,
5
,
3
,
3
],
[
3
,
1
,
4
,
4
,
5
],
[
2
,
5
,
3
,
5
,
1
],
[
5
,
4
,
1
,
2
,
3
],
[
4
,
1
,
3
,
5
,
2
],
]
...
...
@@ -117,8 +159,7 @@ export default class GameView extends engine.Container {
}
this
.
checkEliminate
();
this
.
attionEliminate
();
this
.
fall
();
}
//关联
setLatticeEleRc
(
rcidx
){
...
...
@@ -134,6 +175,29 @@ export default class GameView extends engine.Container {
let
sr
=
data
.
r
;
let
sc
=
data
.
c
;
let
sname
=
sr
+
"_"
+
sc
;
if
(
this
.
ination
){
this
.
ination
=
false
;
this
.
lastatime
=
Date
.
now
();
let
arrcidx1
=
this
.
attiondata
[
0
];
let
arrcidx2
=
this
.
attiondata
[
1
];
let
atname1
=
this
.
lattices
[
arrcidx1
];
let
atname2
=
this
.
lattices
[
arrcidx2
];
let
atnode1
:
Element
=
this
.
container
.
getChildByName
(
atname1
);
let
atnode2
:
Element
=
this
.
container
.
getChildByName
(
atname2
);
let
atpos1
=
MapData
.
getRCPos
(
arrcidx1
.
split
(
"_"
)[
0
],
arrcidx1
.
split
(
"_"
)[
1
]);
let
atpos2
=
MapData
.
getRCPos
(
arrcidx2
.
split
(
"_"
)[
0
],
arrcidx2
.
split
(
"_"
)[
1
]);
engine
.
Tween
.
removeTweens
(
atnode1
);
engine
.
Tween
.
removeTweens
(
atnode2
);
atnode1
.
x
=
atpos1
[
0
];
atnode1
.
y
=
atpos1
[
1
];
atnode2
.
x
=
atpos2
[
0
];
atnode2
.
y
=
atpos2
[
1
];
}
if
(
this
.
selectArr
.
length
==
0
){
// console.log("选中元素",data);
this
.
selectArr
.
push
(
sname
);
...
...
@@ -144,10 +208,16 @@ export default class GameView extends engine.Container {
if
((
sr
==
asr
&&
Math
.
abs
(
sc
-
asc
)
==
1
)
||
(
sc
==
asc
&&
Math
.
abs
(
sr
-
asr
)
==
1
)){
this
.
selectArr
.
push
(
sname
);
}
else
{
//重选自己,取消选择,否则选中新的
if
(
sr
==
asr
&&
sc
==
asc
){
this
.
selectArr
=
new
Array
();
this
.
anicontainer
.
removeChild
(
this
.
selectimg
);
}
else
{
this
.
selectArr
[
0
]
=
sname
;
}
}
}
if
(
this
.
selectArr
.
length
==
1
){
this
.
setSelectShow
();
...
...
@@ -161,14 +231,14 @@ export default class GameView extends engine.Container {
let
c
=
rcname
.
split
(
"_"
)[
1
];
let
rcpos
=
MapData
.
getRCPos
(
r
,
c
);
this
.
container
.
addChild
(
this
.
selectimg
);
this
.
ani
container
.
addChild
(
this
.
selectimg
);
this
.
selectimg
.
x
=
rcpos
[
0
];
this
.
selectimg
.
y
=
rcpos
[
1
];
this
.
selectimg
.
y
=
rcpos
[
1
]
+
this
.
conty
;
}
changeElePos
(){
this
.
container
.
removeChild
(
this
.
selectimg
);
this
.
ani
container
.
removeChild
(
this
.
selectimg
);
this
.
changeEnable
(
false
);
let
sname1
=
this
.
selectArr
[
0
];
...
...
@@ -195,7 +265,7 @@ export default class GameView extends engine.Container {
let
snode2x
=
snode2
.
x
;
let
snode2y
=
snode2
.
y
;
let
changetime
=
Math
.
ceil
((
MapData
.
itemsize
/
this
.
anispeed
)
*
2
*
1000
)
let
changetime
=
Math
.
ceil
((
MapData
.
itemsize
/
MapData
.
anispeed
)
*
2
*
1000
)
if
(
this
.
eliminateArr
.
length
>
0
){
engine
.
Tween
.
get
(
snode1
).
to
({
x
:
snode2x
,
...
...
@@ -241,7 +311,7 @@ export default class GameView extends engine.Container {
}
//消除
eliminate
(){
async
eliminate
(){
for
(
let
i
=
0
;
i
<
this
.
eliminateArr
.
length
;
i
++
){
let
ielidata
=
this
.
eliminateArr
[
i
];
let
ielidxname
=
ielidata
.
idxname
;
...
...
@@ -258,7 +328,20 @@ export default class GameView extends engine.Container {
//元素层消除,动画层添加
this
.
goHomeAni
(
ielitype
,
ielix
,
ieliy
);
}
await
new
Promise
(
res
=>
{
setTimeout
(
function
(){
res
();
},
800
);
})
this
.
fall
();
await
new
Promise
(
res1
=>
{
setTimeout
(
function
(){
res1
();
},
550
)
})
this
.
homeimg
.
play
()
}
//掉落
async
fall
(){
...
...
@@ -312,14 +395,21 @@ export default class GameView extends engine.Container {
let
nepos
=
[
frcnode
.
x
,
frcnode
.
y
];
let
fdis
=
MapData
.
getDistance
(
ftpos
,
nepos
);
let
ftime
=
Math
.
ceil
((
fdis
/
this
.
anispeed
)
*
1000
);
let
ftime
=
Math
.
ceil
((
fdis
/
MapData
.
anispeed
)
*
1000
);
let
ifallpromise
=
new
Promise
(
res
=>
{
engine
.
Tween
.
get
(
frcnode
)
.
to
({
x
:
ftpos
[
0
],
y
:
ftpos
[
1
]
},
ftime
).
call
(()
=>
{
},
ftime
)
.
to
({
scaleY
:
0.85
},
80
)
.
to
({
scaleY
:
1
},
80
)
.
call
(()
=>
{
res
();
})
})
...
...
@@ -332,11 +422,20 @@ export default class GameView extends engine.Container {
return
this
.
eliminate
();
}
else
{
//一次操作完毕
this
.
selectArr
=
new
Array
();
let
isdiedata
=
this
.
attionEliminate
();
if
(
isdiedata
&&
isdiedata
.
length
==
2
){
//没死
this
.
changeEnable
(
true
);
}
else
{
//死图处理
this
.
solveDieMap
();
}
//检查死图
}
}
goHomeAni
(
ielitype
,
ielix
,
ieliy
){
let
aniele
=
MapData
.
getOneEle
(
ielitype
);
aniele
.
alpha
=
0
;
let
anix
=
ielix
;
let
aniy
=
ieliy
+
this
.
conty
;
this
.
anicontainer
.
addChild
(
aniele
);
...
...
@@ -344,9 +443,11 @@ export default class GameView extends engine.Container {
aniele
.
x
=
anix
;
aniele
.
y
=
aniy
;
aniele
.
alpha
=
1
;
let
anidis
=
MapData
.
getDistance
([
this
.
tanix
,
this
.
taniy
],[
anix
,
aniy
]);
let
anitime
=
Math
.
ceil
((
anidis
/
this
.
anispeed
)
*
1000
);
let
anitime
=
Math
.
ceil
((
anidis
/
MapData
.
anispeed
)
*
1000
);
aniele
.
flyToHome
(
this
.
tanix
,
this
.
taniy
,
anitime
);
// engine.Tween.get(aniele)
...
...
@@ -365,12 +466,109 @@ export default class GameView extends engine.Container {
let
ele
:
Element
=
this
.
container
.
getChildByName
(
kname
);
ele
.
touch
=
v
;
}
if
(
v
){
this
.
lastatime
=
Date
.
now
();
}
this
.
canation
=
v
;
}
//相邻显性提示
attionEliShow
(){
let
attiondata
=
this
.
attionEliminate
();
if
(
attiondata
&&
attiondata
.
length
==
2
){
this
.
ination
=
true
;
console
.
log
(
"可以提示"
);
this
.
attiondata
=
[
attiondata
[
0
],
attiondata
[
1
]];
let
atname1
=
this
.
lattices
[
attiondata
[
0
]];
let
atname2
=
this
.
lattices
[
attiondata
[
1
]];
let
atnode1
:
Element
=
this
.
container
.
getChildByName
(
atname1
);
let
atnode2
:
Element
=
this
.
container
.
getChildByName
(
atname2
);
let
atx1
=
atnode1
.
x
;
let
aty1
=
atnode1
.
y
;
let
atx2
=
atnode2
.
x
;
let
aty2
=
atnode2
.
y
;
let
lerpnum
=
0.1
;
let
atpos1
=
[(
atx2
-
atx1
)
*
lerpnum
+
atx1
,(
aty2
-
aty1
)
*
lerpnum
+
aty1
];
let
atpos2
=
[(
atx1
-
atx2
)
*
lerpnum
+
atx2
,(
aty1
-
aty2
)
*
lerpnum
+
aty2
];
engine
.
Tween
.
get
(
atnode1
,{
loop
:
true
}).
to
({
x
:
atpos1
[
0
],
y
:
atpos1
[
1
]
},
500
)
.
to
({
x
:
atx1
,
y
:
aty1
},
500
);
engine
.
Tween
.
get
(
atnode2
,{
loop
:
true
})
.
to
({
x
:
atpos2
[
0
],
y
:
atpos2
[
1
]
},
500
)
.
to
({
x
:
atx2
,
y
:
aty2
},
500
);
}
else
{
//死图处理
this
.
solveDieMap
();
}
}
//死图调整
solveDieMap
(){
this
.
changeEnable
(
false
);
console
.
error
(
"死图调整"
);
console
.
log
(
this
.
lattices
);
let
elearr
=
new
Array
();
for
(
let
key
in
this
.
lattices
){
let
keyval
=
this
.
lattices
[
key
];
elearr
.
push
(
keyval
);
}
for
(
let
key
in
this
.
lattices
){
let
changeval
=
elearr
.
splice
(
Math
.
floor
(
Math
.
random
()
*
elearr
.
length
),
1
)[
0
];
this
.
lattices
[
key
]
=
changeval
;
}
let
isdiedata
=
this
.
attionEliminate
();
if
(
isdiedata
&&
isdiedata
.
length
==
2
){
console
.
error
(
"可以复活了,转移位置"
);
this
.
changeToFuHuoPos
();
}
else
{
console
.
error
(
"依然死亡,寻求复活"
);
return
this
.
solveDieMap
();
}
}
//转移到复活pos
async
changeToFuHuoPos
(){
let
prolist
=
new
Array
();
for
(
let
key
in
this
.
lattices
){
let
keyval
=
this
.
lattices
[
key
];
var
keynode
:
Element
=
this
.
container
.
getChildByName
(
keyval
);
let
keynodex
=
keynode
.
x
;
let
keynodey
=
keynode
.
y
;
let
tpos
=
MapData
.
getRCPos
(
key
.
split
(
"_"
)[
0
],
key
.
split
(
"_"
)[
1
]);
let
ipro
=
keynode
.
changePos
(
tpos
);
prolist
.
push
(
ipro
);
this
.
setLatticeEleRc
(
key
);
}
await
Promise
.
all
(
prolist
)
console
.
error
(
"死亡转移完毕"
);
this
.
changeEnable
(
true
);
}
//相邻检测
attionEliminate
(){
let
attiondata
;
for
(
let
r
=
MapData
.
row
-
1
;
r
>-
1
;
r
--
){
if
(
attiondata
&&
attiondata
.
length
==
2
){
break
;
}
for
(
let
c
=
MapData
.
col
-
1
;
c
>-
1
;
c
--
){
let
checktype
=
this
.
getEleTypeByRc
(
r
,
c
);
...
...
@@ -381,7 +579,7 @@ export default class GameView extends engine.Container {
console
.
error
(
"啥情况,检查----------------"
);
}
if
(
edatarow
.
length
==
2
){
console
.
log
(
"横向查找"
,
edatarow
);
console
.
log
(
"横向查找"
,
edatarow
,
checktype
);
let
releidx1
=
edatarow
[
0
];
let
releidx2
=
edatarow
[
1
];
...
...
@@ -398,7 +596,7 @@ export default class GameView extends engine.Container {
if
(
rightcol
<
MapData
.
col
){
let
nexttype
=
this
.
getEleTypeByRc
(
downrow
,
rightcol
);
if
(
nexttype
==
checktype
){
attiondata
=
[
downrow
+
"_"
+
relecol
,
downrow
+
"_"
+
rightcol
]
attiondata
=
[
downrow
+
"_"
+
relecol
,
downrow
+
"_"
+
rightcol
]
;
break
;
}
}
...
...
@@ -444,20 +642,58 @@ export default class GameView extends engine.Container {
// }
}
if
(
edatacol
.
length
==
2
){
console
.
log
(
"竖向查找"
,
edatacol
);
let
releidx1
=
edata
row
[
0
];
let
releidx2
=
edata
row
[
1
];
console
.
log
(
"竖向查找"
,
edatacol
,
checktype
);
let
releidx1
=
edata
col
[
0
];
let
releidx2
=
edata
col
[
1
];
let
relerow
=
Number
(
releidx1
.
split
(
"_"
)[
0
]);
let
relecol1
=
Number
(
releidx1
.
split
(
"_"
)[
1
]);
let
relecol2
=
Number
(
releidx2
.
split
(
"_"
)[
1
]);
console
.
log
(
"竖向检查啦啦啦"
,
relerow
,
relecol1
,
relecol2
);
let
rightcol
=
relecol1
+
1
;
let
leftcol
=
relecol2
-
1
;
let
uprow
=
relerow
-
1
;
let
downrow
=
relerow
+
1
;
if
(
leftcol
>-
1
){
if
(
uprow
>-
1
){
let
nexttype
=
this
.
getEleTypeByRc
(
uprow
,
leftcol
);
if
(
nexttype
==
checktype
){
attiondata
=
[
relerow
+
"_"
+
leftcol
,
uprow
+
"_"
+
leftcol
];
break
;
}
}
if
(
downrow
<
MapData
.
row
){
let
nexttype
=
this
.
getEleTypeByRc
(
downrow
,
leftcol
);
if
(
nexttype
==
checktype
){
attiondata
=
[
relerow
+
"_"
+
leftcol
,
downrow
+
"_"
+
leftcol
];
break
;
}
}
}
if
(
rightcol
<
MapData
.
col
){
if
(
uprow
>-
1
){
let
nexttype
=
this
.
getEleTypeByRc
(
uprow
,
rightcol
);
if
(
nexttype
==
checktype
){
attiondata
=
[
relerow
+
"_"
+
rightcol
,
uprow
+
"_"
+
rightcol
];
break
;
}
}
if
(
downrow
<
MapData
.
row
){
let
nexttype
=
this
.
getEleTypeByRc
(
downrow
,
rightcol
);
if
(
nexttype
==
checktype
){
attiondata
=
[
relerow
+
"_"
+
rightcol
,
downrow
+
"_"
+
rightcol
];
break
;
}
}
}
// console.log("竖向检查啦啦啦",relerow,relecol1,relecol2);
}
}
}
console
.
log
(
"相邻检测--------------"
,
attiondata
);
return
attiondata
;
}
//检测消除
checkEliminate
(){
...
...
src/custom/xiaoxiaole/src/game/MapData.ts
View file @
bea870f5
...
...
@@ -26,6 +26,8 @@ export default class MapData{
};
static
eleidx
=
1
;
static
elePool
=
[];
static
anispeed
=
860
;
static
getRy
(
r
){
return
this
.
paddingb
+
r
*
(
this
.
itemsize
+
this
.
paddingi
);
}
...
...
src/custom/xiaoxiaole/src/game/ele/Element.ts
View file @
bea870f5
...
...
@@ -16,6 +16,10 @@ export default class Element extends engine.Container{
this
.
width
=
MapData
.
itemsize
;
this
.
height
=
MapData
.
itemsize
;
this
.
anchorX
=
MapData
.
itemsize
/
2
;
// this.anchorY = MapData.itemsize/2;
this
.
anchorY
=
MapData
.
itemsize
;
this
.
eimage
=
new
engine
.
Image
();
this
.
addChild
(
this
.
eimage
);
this
.
touch
=
true
;
...
...
@@ -55,7 +59,7 @@ export default class Element extends engine.Container{
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
;
var
mscale
=
(
1
-
value
)
*
(
1
-
value
)
*
1
+
2
*
value
*
(
1
-
value
)
*
0.6
+
value
*
value
*
0
.35
;
this
.
scaleX
=
mscale
;
this
.
scaleY
=
mscale
;
}
...
...
@@ -70,7 +74,7 @@ export default class Element extends engine.Container{
//飞到小屋
flyToHome
(
tx
,
ty
,
time
){
this
.
p1x
=
this
.
x
;
this
.
p1y
=
this
.
y
;
this
.
p1y
=
this
.
y
+
20
;
this
.
c1x
=
(
this
.
p1x
-
tx
)
/
4
+
tx
;
this
.
c1y
=
ty
;
...
...
@@ -78,17 +82,52 @@ export default class Element extends engine.Container{
this
.
p2x
=
tx
;
this
.
p2y
=
ty
;
engine
.
Tween
.
get
(
this
).
to
({
scaleX
:
1.1
,
scaleY
:
1.1
},
200
)
.
to
({
scaleX
:
1.1
,
scaleY
:
0.88
},
100
)
.
to
({
scaleX
:
0.98
,
scaleY
:
0.98
,
y
:
this
.
y
+
20
},
100
)
.
call
(()
=>
{
engine
.
Tween
.
get
(
this
).
to
({
factor
:
1
},
time
)
},
450
)
.
call
(()
=>
{
let
nodeparent
:
engine
.
Container
=
this
.
parent
;
nodeparent
&&
nodeparent
.
removeChild
(
this
);
MapData
.
recoverEle
(
this
);
})
})
}
changePos
(){
changePos
(
tpos
:
Array
<
number
>
){
let
nx
=
this
.
x
;
let
ny
=
this
.
y
;
let
tx
=
tpos
[
0
];
let
ty
=
tpos
[
1
];
let
dis
=
MapData
.
getDistance
([
nx
,
ny
],
tpos
);
let
time
=
Math
.
ceil
(
dis
/
MapData
.
anispeed
*
1000
);
let
pro
=
new
Promise
(
res
=>
{
engine
.
Tween
.
get
(
this
,{
loop
:
false
}).
to
({
x
:
tx
,
y
:
ty
},
time
)
.
call
(()
=>
{
console
.
log
(
"单个移动完毕"
);
res
();
})
})
return
pro
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment