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
3f49b0e4
Commit
3f49b0e4
authored
Jun 03, 2020
by
汪欢
Browse files
Options
Browse Files
Download
Plain Diff
拼图0.2
parents
6d9121cd
942737e1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
79 additions
and
69 deletions
+79
-69
.DS_Store
dist/.DS_Store
+0
-0
pictures.json
dist/customs/pictures.json
+13
-27
app.js
src/custom/pictures/debug/app.js
+1
-1
main.js
src/custom/pictures/debug/main.js
+20
-8
main.js.map
src/custom/pictures/debug/main.js.map
+5
-1
meta.json
src/custom/pictures/meta.json
+15
-24
GameView.ts
src/custom/pictures/src/game/GameView.ts
+9
-2
qietu.ts
src/custom/pictures/src/game/qietu.ts
+16
-6
No files found.
dist/.DS_Store
View file @
3f49b0e4
No preview for this file type
dist/customs/pictures.json
View file @
3f49b0e4
...
@@ -5,27 +5,27 @@
...
@@ -5,27 +5,27 @@
"MAX_COL"
:
{
"MAX_COL"
:
{
"alias"
:
"图片分成几列"
,
"alias"
:
"图片分成几列"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
2
"default"
:
3
},
},
"MAX_ROW"
:
{
"MAX_ROW"
:
{
"alias"
:
"图片分成几行"
,
"alias"
:
"图片分成几行"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
2
"default"
:
4
},
},
"W"
:
{
"W"
:
{
"alias"
:
"图片的宽度"
,
"alias"
:
"图片的宽度"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
6
00
"default"
:
6
18
},
},
"H"
:
{
"H"
:
{
"alias"
:
"图片的高度"
,
"alias"
:
"图片的高度"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
600
"default"
:
827
},
},
"GAP"
:
{
"GAP"
:
{
"alias"
:
"图片间隙"
,
"alias"
:
"图片间隙"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
1
0
"default"
:
0
},
},
"GAME_TIME"
:
{
"GAME_TIME"
:
{
"alias"
:
"游戏时间"
,
"alias"
:
"游戏时间"
,
...
@@ -35,36 +35,22 @@
...
@@ -35,36 +35,22 @@
},
},
"assets"
:
[
"assets"
:
[
{
{
"name"
:
"
测试资源
"
,
"name"
:
"
遮罩
"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/5
0a7212a113175fa18c866b005d98f07c558dc77
.png"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/5
b3e30496b2d9fdafb0cf3835fd6704ce10e45b4
.png"
,
"uuid"
:
"66f23d13-82a5-4cec-9496-301ec240d087"
,
"uuid"
:
"66f23d13-82a5-4cec-9496-301ec240d087"
,
"ext"
:
".png"
"ext"
:
".png"
}
}
],
],
"events"
:
{
"events"
:
{
"in"
:
{
"in"
:
{
"pictures-
rese
t"
:
{
"pictures-
star
t"
:
{
"alias"
:
"
重置
"
,
"alias"
:
"
开始
"
,
"data"
:
{
"data"
:
{
"goodsProbability"
:
"[0.2,0.5,0.3]道具概率(雨滴、石头、炸弹),所有概率相加为1"
,
"picUrl"
:
"图片路径"
"countDown"
:
"倒计时(s)"
,
"acceleratedSpeed"
:
"道具掉落加速度(单位:每秒)"
}
}
},
},
"pictures-start"
:
{
"pictures-stop"
:
{
"alias"
:
"开始"
"alias"
:
"停止"
},
"pictures-revive"
:
{
"alias"
:
"复活"
},
"pictures-pause"
:
{
"alias"
:
"暂停"
},
"pictures-resume"
:
{
"alias"
:
"恢复"
},
"pictures-clear"
:
{
"alias"
:
"清空,通过reset事件恢复"
}
}
},
},
"out"
:
{
"out"
:
{
...
@@ -89,5 +75,5 @@
...
@@ -89,5 +75,5 @@
}
}
},
},
"id"
:
"pictures"
,
"id"
:
"pictures"
,
"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.pictures = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
var props = {};
\n\t
function prepareProps() {
\n\t
var metaProps = getProps();
\n\t
engine.injectProp(props, metaProps);
\n\t
}
\n\t
function injectProps(p) {
\n\t
engine.injectProp(props, p);
\n\t
}
\n\
t
//# sourceMappingURL=props.js.map
\n\n\t
var qietu = (function (parent, url, MAX_COL, MAX_ROW) {
\n\t
var W = 600;
\n\t
var H = 600;
\n\t
var GAP = 10;
\n\t
var spr = [];
\n\t
var pos = [];
\n\t
var _loop_1 = function (row) {
\n\t
var _loop_2 = function (col) {
\n\t
var child = engine.Sprite.fromImage(url);
\n\t
spr.push(child);
\n\t
child.scaleX = 1 / MAX_COL;
\n\t
child.scaleY = 1 / MAX_ROW;
\n\t
parent.addChild(child);
\n\t
child.x = col * (W / MAX_COL + GAP);
\n\t
child.y = row * (H / MAX_ROW + GAP);
\n\t
pos.push([child.x, child.y]);
\n\t
child.addEventListener(engine.Event.COMPLETE, function () {
\n\t
var uvs = new Float32Array([
\n\t
col / MAX_COL,
\n\t
row / MAX_ROW,
\n\t
(col + 1) / MAX_COL,
\n\t
row / MAX_ROW,
\n\t
(col + 1) / MAX_COL,
\n\t
(row + 1) / MAX_ROW,
\n\t
col / MAX_COL,
\n\t
(row + 1) / MAX_ROW,
\n\t
]);
\n\t
child.uvs = uvs;
\n\t
});
\n\t
};
\n\t
for (var col = 0; col < MAX_COL; col++) {
\n\t
_loop_2(col);
\n\t
}
\n\t
};
\n\t
for (var row = 0; row < MAX_ROW; row++) {
\n\t
_loop_1(row);
\n\t
}
\n\t
return [spr, pos];
\n\t
});
\n\t
//# sourceMappingURL=qietu.js.map
\n\n\t
function getIndexFromRC(row, col, maxCol) {
\n\t
var index = row * maxCol + col;
\n\t
return index;
\n\t
}
\n\t
function getRandomArray(array) {
\n\t
array.sort(function () {
\n\t
return .5 - Math.random();
\n\t
});
\n\t
}
\n\t
//# sourceMappingURL=utils.js.map
\n\n\t
var MAX_COL;
\n\t
var MAX_ROW;
\n\t
var W;
\n\t
var H;
\n\t
var GAP;
\n\t
var GAME_TIME;
\n\t
var w;
\n\t
var h;
\n\t
var GameView = (function (_super) {
\n\t
tslib.__extends(GameView, _super);
\n\t
function GameView() {
\n\t
var _this = _super.call(this) || this;
\n\t
_this._timeCounter = 0;
\n\t
_this.countTime = 10;
\n\t
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
\n\t
return _this;
\n\t
}
\n\t
GameView.prototype.start = function () {
\n\t
var _this = this;
\n\t
console.log('on start');
\n\t
engine.globalEvent.dispatchEvent('pictures-time-update', {
\n\t
second: this.getSecond(),
\n\t
});
\n\t
var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
\n\t
this.pictures = result[0];
\n\t
this.rightList = this.pictures.concat([]);
\n\t
var posList = result[1];
\n\t
getRandomArray(this.pictures);
\n\t
var i = 0;
\n\t
var len;
\n\t
len = this.pictures.length;
\n\t
for (; i < len; i++) {
\n\t
this.dragPic = this.pictures[i];
\n\t
this.pictures[i].addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDown, this);
\n\t
var _a = posList[i], x = _a[0], y = _a[1];
\n\t
this.dragPic.x = x;
\n\t
this.dragPic.y = y;
\n\t
}
\n\t
this._timer = setInterval(function () {
\n\t
_this.onTimer();
\n\t
}, 1000);
\n\t
};
\n\t
GameView.prototype.onTimer = function () {
\n\t
this._timeCounter++;
\n\t
engine.globalEvent.dispatchEvent('pictures-time-update', {
\n\t
second: this.getSecond(),
\n\t
});
\n\t
if (this.getSecond() == 0) {
\n\t
this.stop();
\n\t
engine.globalEvent.dispatchEvent('pictures-game-fail', {
\n\t
reason: 1
\n\t
});
\n\t
}
\n\t
};
\n\t
GameView.prototype.getSecond = function () {
\n\t
return GAME_TIME - this._timeCounter;
\n\t
};
\n\t
GameView.prototype.stop = function () {
\n\t
this._timeCounter = 0;
\n\t
clearInterval(this._timer);
\n\t
};
\n\t
GameView.prototype.createRects = function () { };
\n\t
GameView.prototype.setup = function () {
\n\t
MAX_COL = props.MAX_COL;
\n\t
MAX_ROW = props.MAX_ROW;
\n\t
GAME_TIME = props.GAME_TIME;
\n\t
W = props.W;
\n\t
H = props.H;
\n\t
GAP = props.GAP;
\n\t
w = W / MAX_COL;
\n\t
h = H / MAX_ROW;
\n\t
console.log('onSteup', props);
\n\t
var parent = new engine.Sprite();
\n\t
this.picturesWrapper = parent;
\n\t
this.addChild(parent);
\n\t
};
\n\t
GameView.prototype.onDown = function (e) {
\n\t
this.dragPic = e.target;
\n\t
this.picturesWrapper.addChild(this.dragPic);
\n\t
this.localPicX = e.localX / MAX_COL;
\n\t
this.localPicY = e.localY / MAX_ROW;
\n\t
this.distanceX = this.dragPic.x;
\n\t
this.distanceY = this.dragPic.y;
\n\t
this.indexI = this.distanceX / (w + GAP);
\n\t
this.indexJ = this.distanceY / (h + GAP);
\n\t
this.index = (this.indexI - 1) * MAX_COL + this.indexJ;
\n\t
this.centerX = e.clientX + w / 2;
\n\t
this.centerY = e.clientY + h / 2;
\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\n\t
};
\n\t
GameView.prototype.stageOnUp = function (e) {
\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\n\t
var curJ = Math.floor(this.centerX / (w + GAP));
\n\t
var curI = Math.floor(this.centerY / (h + GAP));
\n\t
if (curJ < MAX_COL && curI < MAX_ROW) {
\n\t
var index = getIndexFromRC(curI, curJ, MAX_COL);
\n\t
var dropPic = this.pictures[index];
\n\t
var dropPicX = dropPic.x;
\n\t
var dropPicy = dropPic.y;
\n\t
dropPic.x = this.distanceX;
\n\t
dropPic.y = this.distanceY;
\n\t
this.dragPic.x = dropPicX;
\n\t
this.dragPic.y = dropPicy;
\n\t
var dropPicIndex = this.pictures.indexOf(dropPic);
\n\t
var dragPicIndex = this.pictures.indexOf(this.dragPic);
\n\t
this.pictures[dropPicIndex] = this.dragPic;
\n\t
this.pictures[dragPicIndex] = dropPic;
\n\t
var result = true;
\n\t
for (var j = 0; j < this.rightList.length; j++) {
\n\t
if (this.rightList[j] != this.pictures[j]) {
\n\t
result = false;
\n\t
break;
\n\t
}
\n\t
}
\n\t
if (result) {
\n\t
this.onSuccess();
\n\t
}
\n\t
}
\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\n\t
};
\n\t
GameView.prototype.onSuccess = function () {
\n\t
console.log('拼图成功!');
\n\t
this.stop();
\n\t
engine.globalEvent.dispatchEvent('pictures-game-success', {});
\n\t
};
\n\t
GameView.prototype.onMove = function (e) {
\n\t
this.dragPic.x = e.stageX - this.localPicX;
\n\t
this.dragPic.y = e.stageY - this.localPicY;
\n\t
this.centerX = this.dragPic.x + w / 2;
\n\t
this.centerY = this.dragPic.y + h / 2;
\n\t
};
\n\t
return GameView;
\n\t
}(engine.Container));
\n\n\t
var GameWrapper = (function (_super) {
\n\t
tslib.__extends(GameWrapper, _super);
\n\t
function GameWrapper() {
\n\t
var _this = _super.call(this) || this;
\n\t
engine.globalEvent.addEventListener('pictures-start', _this.start, _this);
\n\t
engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this);
\n\t
var gameView = _this._gameView = new GameView();
\n\t
_this.addChild(gameView);
\n\t
return _this;
\n\t
}
\n\t
GameWrapper.prototype.start = function (event) {
\n\t
injectProps(event.data);
\n\t
this._gameView.start();
\n\t
};
\n\t
GameWrapper.prototype.stop = function (event) {
\n\t
this._gameView.stop();
\n\t
};
\n\t
return GameWrapper;
\n\t
}(engine.Container));
\n\t
//# sourceMappingURL=GameWrapper.js.map
\n\n\t
function index (props) {
\n\t
prepareProps();
\n\t
injectProps(props);
\n\t
var instance = new GameWrapper();
\n\t
return instance;
\n\t
}
\n\t
//# sourceMappingURL=index.js.map
\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.pictures = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
var props = {};
\n\t
function prepareProps() {
\n\t
var metaProps = getProps();
\n\t
engine.injectProp(props, metaProps);
\n\t
}
\n\t
function injectProps(p) {
\n\t
engine.injectProp(props, p);
\n\t
}
\n\
n\t
var picMap = {};
\n\t
var posMap = {};
\n\t
var qietu = (function (parent, url, MAX_COL, MAX_ROW) {
\n\t
if (picMap[url]) {
\n\t
return [picMap[url], posMap[url]];
\n\t
}
\n\t
var W = props.W;
\n\t
var H = props.H;
\n\t
var GAP = props.GAP;
\n\t
var spr = [];
\n\t
var pos = [];
\n\t
var _loop_1 = function (row) {
\n\t
var _loop_2 = function (col) {
\n\t
var child = engine.Sprite.fromImage(url);
\n\t
spr.push(child);
\n\t
child.scaleX = 1 / MAX_COL;
\n\t
child.scaleY = 1 / MAX_ROW;
\n\t
parent.addChild(child);
\n\t
child.x = col * (W / MAX_COL + GAP);
\n\t
child.y = row * (H / MAX_ROW + GAP);
\n\t
pos.push([child.x, child.y]);
\n\t
child.addEventListener(engine.Event.COMPLETE, function () {
\n\t
var uvs = new Float32Array([
\n\t
col / MAX_COL,
\n\t
row / MAX_ROW,
\n\t
(col + 1) / MAX_COL,
\n\t
row / MAX_ROW,
\n\t
(col + 1) / MAX_COL,
\n\t
(row + 1) / MAX_ROW,
\n\t
col / MAX_COL,
\n\t
(row + 1) / MAX_ROW,
\n\t
]);
\n\t
child.uvs = uvs;
\n\t
});
\n\t
};
\n\t
for (var col = 0; col < MAX_COL; col++) {
\n\t
_loop_2(col);
\n\t
}
\n\t
};
\n\t
for (var row = 0; row < MAX_ROW; row++) {
\n\t
_loop_1(row);
\n\t
}
\n\t
picMap[url] = spr.concat([]);
\n\t
posMap[url] = pos.concat([]);
\n\t
return [spr, pos];
\n\t
});
\n\n\t
function getTexture(uuid) {
\n\t
return engine.Texture.from(getAssetByUUID(uuid).uuid);
\n\t
}
\n\t
function getTextureByName(name) {
\n\t
return getTexture(engine.getAssetByName(name).uuid);
\n\t
}
\n\t
function getIndexFromRC(row, col, maxCol) {
\n\t
var index = row * maxCol + col;
\n\t
return index;
\n\t
}
\n\t
function getRandomArray(array) {
\n\t
array.sort(function () {
\n\t
return .5 - Math.random();
\n\t
});
\n\t
}
\n\n\t
var MAX_COL;
\n\t
var MAX_ROW;
\n\t
var W;
\n\t
var H;
\n\t
var GAP;
\n\t
var GAME_TIME;
\n\t
var w;
\n\t
var h;
\n\t
var GameView = (function (_super) {
\n\t
tslib.__extends(GameView, _super);
\n\t
function GameView() {
\n\t
var _this = _super.call(this) || this;
\n\t
_this._timeCounter = 0;
\n\t
_this.countTime = 10;
\n\t
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
\n\t
return _this;
\n\t
}
\n\t
GameView.prototype.start = function () {
\n\t
var _this = this;
\n\t
console.log('on start');
\n\t
engine.globalEvent.dispatchEvent('pictures-time-update', {
\n\t
second: this.getSecond(),
\n\t
});
\n\t
var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
\n\t
this.picturesWrapper.addChild(this.guideHole);
\n\t
this.pictures = result[0];
\n\t
this.rightList = this.pictures.concat([]);
\n\t
var posList = result[1];
\n\t
getRandomArray(this.pictures);
\n\t
var i = 0;
\n\t
var len;
\n\t
len = this.pictures.length;
\n\t
for (; i < len; i++) {
\n\t
this.dragPic = this.pictures[i];
\n\t
this.pictures[i].addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDown, this);
\n\t
var _a = posList[i], x = _a[0], y = _a[1];
\n\t
this.dragPic.x = x;
\n\t
this.dragPic.y = y;
\n\t
}
\n\t
this._timer = setInterval(function () {
\n\t
_this.onTimer();
\n\t
}, 1000);
\n\t
};
\n\t
GameView.prototype.onTimer = function () {
\n\t
this._timeCounter++;
\n\t
engine.globalEvent.dispatchEvent('pictures-time-update', {
\n\t
second: this.getSecond(),
\n\t
});
\n\t
if (this.getSecond() == 0) {
\n\t
this.stop();
\n\t
engine.globalEvent.dispatchEvent('pictures-game-fail', {
\n\t
reason: 1
\n\t
});
\n\t
}
\n\t
};
\n\t
GameView.prototype.getSecond = function () {
\n\t
return GAME_TIME - this._timeCounter;
\n\t
};
\n\t
GameView.prototype.stop = function () {
\n\t
this._timeCounter = 0;
\n\t
clearInterval(this._timer);
\n\t
};
\n\t
GameView.prototype.createRects = function () { };
\n\t
GameView.prototype.setup = function () {
\n\t
this.guideHole = new engine.Image(getTextureByName('遮罩'));
\n\t
this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false;
\n\t
MAX_COL = props.MAX_COL;
\n\t
MAX_ROW = props.MAX_ROW;
\n\t
GAME_TIME = props.GAME_TIME;
\n\t
W = props.W;
\n\t
H = props.H;
\n\t
GAP = props.GAP;
\n\t
w = W / MAX_COL;
\n\t
h = H / MAX_ROW;
\n\t
console.log('onSteup', props);
\n\t
var parent = new engine.Sprite();
\n\t
this.picturesWrapper = parent;
\n\t
this.addChild(parent);
\n\t
};
\n\t
GameView.prototype.onDown = function (e) {
\n\t
this.dragPic = e.target;
\n\t
this.picturesWrapper.addChild(this.dragPic);
\n\t
this.localPicX = e.localX / MAX_COL;
\n\t
this.localPicY = e.localY / MAX_ROW;
\n\t
this.distanceX = this.dragPic.x;
\n\t
this.distanceY = this.dragPic.y;
\n\t
this.indexI = this.distanceX / (w + GAP);
\n\t
this.indexJ = this.distanceY / (h + GAP);
\n\t
this.index = (this.indexI - 1) * MAX_COL + this.indexJ;
\n\t
this.centerX = e.clientX + w / 2;
\n\t
this.centerY = e.clientY + h / 2;
\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\n\t
};
\n\t
GameView.prototype.stageOnUp = function (e) {
\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\n\t
this.picturesWrapper.addChild(this.guideHole);
\n\t
var curJ = Math.floor(this.centerX / (w + GAP));
\n\t
var curI = Math.floor(this.centerY / (h + GAP));
\n\t
if (curJ < MAX_COL && curI < MAX_ROW) {
\n\t
var index = getIndexFromRC(curI, curJ, MAX_COL);
\n\t
var dropPic = this.pictures[index];
\n\t
var dropPicX = dropPic.x;
\n\t
var dropPicy = dropPic.y;
\n\t
dropPic.x = this.distanceX;
\n\t
dropPic.y = this.distanceY;
\n\t
this.dragPic.x = dropPicX;
\n\t
this.dragPic.y = dropPicy;
\n\t
var dropPicIndex = this.pictures.indexOf(dropPic);
\n\t
var dragPicIndex = this.pictures.indexOf(this.dragPic);
\n\t
this.pictures[dropPicIndex] = this.dragPic;
\n\t
this.pictures[dragPicIndex] = dropPic;
\n\t
var result = true;
\n\t
for (var j = 0; j < this.rightList.length; j++) {
\n\t
if (this.rightList[j] != this.pictures[j]) {
\n\t
result = false;
\n\t
break;
\n\t
}
\n\t
}
\n\t
if (result) {
\n\t
this.onSuccess();
\n\t
}
\n\t
}
\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\n\t
};
\n\t
GameView.prototype.onSuccess = function () {
\n\t
console.log('拼图成功!');
\n\t
this.stop();
\n\t
engine.globalEvent.dispatchEvent('pictures-game-success', {});
\n\t
};
\n\t
GameView.prototype.onMove = function (e) {
\n\t
this.dragPic.x = e.stageX - this.localPicX;
\n\t
this.dragPic.y = e.stageY - this.localPicY;
\n\t
this.centerX = this.dragPic.x + w / 2;
\n\t
this.centerY = this.dragPic.y + h / 2;
\n\t
};
\n\t
return GameView;
\n\t
}(engine.Container));
\n\n\t
var GameWrapper = (function (_super) {
\n\t
tslib.__extends(GameWrapper, _super);
\n\t
function GameWrapper() {
\n\t
var _this = _super.call(this) || this;
\n\t
engine.globalEvent.addEventListener('pictures-start', _this.start, _this);
\n\t
engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this);
\n\t
var gameView = _this._gameView = new GameView();
\n\t
_this.addChild(gameView);
\n\t
return _this;
\n\t
}
\n\t
GameWrapper.prototype.start = function (event) {
\n\t
injectProps(event.data);
\n\t
this._gameView.start();
\n\t
};
\n\t
GameWrapper.prototype.stop = function (event) {
\n\t
this._gameView.stop();
\n\t
};
\n\t
return GameWrapper;
\n\t
}(engine.Container));
\n\n\t
function index (props) {
\n\t
prepareProps();
\n\t
injectProps(props);
\n\t
var instance = new GameWrapper();
\n\t
return instance;
\n\t
}
\n\n\t
return index;
\n\n
})));
\n
"
}
}
src/custom/pictures/debug/app.js
View file @
3f49b0e4
...
@@ -47,7 +47,7 @@ function launchWithCustomModule(customModule) {
...
@@ -47,7 +47,7 @@ function launchWithCustomModule(customModule) {
setTimeout
(()
=>
{
setTimeout
(()
=>
{
engine
.
globalEvent
.
dispatchEvent
(
'pictures-start'
,
{
engine
.
globalEvent
.
dispatchEvent
(
'pictures-start'
,
{
picUrl
:
"http://yun.duiba.com.cn/aurora/assets/
fb06e66c26f17b00f677367bd7571a1aa9b1ade4
.png"
picUrl
:
"http://yun.duiba.com.cn/aurora/assets/
e1593b97c27077b85b92f7eaaeae1ed64a1eb79a
.png"
});
});
},
500
);
},
500
);
...
...
src/custom/pictures/debug/main.js
View file @
3f49b0e4
...
@@ -12,12 +12,16 @@
...
@@ -12,12 +12,16 @@
function
injectProps
(
p
)
{
function
injectProps
(
p
)
{
engine
.
injectProp
(
props
,
p
);
engine
.
injectProp
(
props
,
p
);
}
}
//# sourceMappingURL=props.js.map
var
picMap
=
{};
var
posMap
=
{};
var
qietu
=
(
function
(
parent
,
url
,
MAX_COL
,
MAX_ROW
)
{
var
qietu
=
(
function
(
parent
,
url
,
MAX_COL
,
MAX_ROW
)
{
var
W
=
600
;
if
(
picMap
[
url
])
{
var
H
=
600
;
return
[
picMap
[
url
],
posMap
[
url
]];
var
GAP
=
10
;
}
var
W
=
props
.
W
;
var
H
=
props
.
H
;
var
GAP
=
props
.
GAP
;
var
spr
=
[];
var
spr
=
[];
var
pos
=
[];
var
pos
=
[];
var
_loop_1
=
function
(
row
)
{
var
_loop_1
=
function
(
row
)
{
...
@@ -51,10 +55,17 @@
...
@@ -51,10 +55,17 @@
for
(
var
row
=
0
;
row
<
MAX_ROW
;
row
++
)
{
for
(
var
row
=
0
;
row
<
MAX_ROW
;
row
++
)
{
_loop_1
(
row
);
_loop_1
(
row
);
}
}
picMap
[
url
]
=
spr
.
concat
([]);
posMap
[
url
]
=
pos
.
concat
([]);
return
[
spr
,
pos
];
return
[
spr
,
pos
];
});
});
//# sourceMappingURL=qietu.js.map
function
getTexture
(
uuid
)
{
return
engine
.
Texture
.
from
(
getAssetByUUID
(
uuid
).
uuid
);
}
function
getTextureByName
(
name
)
{
return
getTexture
(
engine
.
getAssetByName
(
name
).
uuid
);
}
function
getIndexFromRC
(
row
,
col
,
maxCol
)
{
function
getIndexFromRC
(
row
,
col
,
maxCol
)
{
var
index
=
row
*
maxCol
+
col
;
var
index
=
row
*
maxCol
+
col
;
return
index
;
return
index
;
...
@@ -64,7 +75,6 @@
...
@@ -64,7 +75,6 @@
return
.
5
-
Math
.
random
();
return
.
5
-
Math
.
random
();
});
});
}
}
//# sourceMappingURL=utils.js.map
var
MAX_COL
;
var
MAX_COL
;
var
MAX_ROW
;
var
MAX_ROW
;
...
@@ -89,6 +99,7 @@
...
@@ -89,6 +99,7 @@
second
:
this
.
getSecond
(),
second
:
this
.
getSecond
(),
});
});
var
result
=
qietu
(
this
.
picturesWrapper
,
props
.
picUrl
,
MAX_COL
,
MAX_ROW
);
var
result
=
qietu
(
this
.
picturesWrapper
,
props
.
picUrl
,
MAX_COL
,
MAX_ROW
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
this
.
pictures
=
result
[
0
];
this
.
pictures
=
result
[
0
];
this
.
rightList
=
this
.
pictures
.
concat
([]);
this
.
rightList
=
this
.
pictures
.
concat
([]);
var
posList
=
result
[
1
];
var
posList
=
result
[
1
];
...
@@ -138,6 +149,8 @@
...
@@ -138,6 +149,8 @@
};
};
GameView
.
prototype
.
createRects
=
function
()
{
};
GameView
.
prototype
.
createRects
=
function
()
{
};
GameView
.
prototype
.
setup
=
function
()
{
GameView
.
prototype
.
setup
=
function
()
{
this
.
guideHole
=
new
engine
.
Image
(
getTextureByName
(
'遮罩'
));
this
.
guideHole
.
mouseChildren
=
this
.
guideHole
.
mouseEnabled
=
false
;
MAX_COL
=
props
.
MAX_COL
;
MAX_COL
=
props
.
MAX_COL
;
MAX_ROW
=
props
.
MAX_ROW
;
MAX_ROW
=
props
.
MAX_ROW
;
GAME_TIME
=
props
.
GAME_TIME
;
GAME_TIME
=
props
.
GAME_TIME
;
...
@@ -168,6 +181,7 @@
...
@@ -168,6 +181,7 @@
};
};
GameView
.
prototype
.
stageOnUp
=
function
(
e
)
{
GameView
.
prototype
.
stageOnUp
=
function
(
e
)
{
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
var
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
var
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
var
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
var
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
if
(
curJ
<
MAX_COL
&&
curI
<
MAX_ROW
)
{
if
(
curJ
<
MAX_COL
&&
curI
<
MAX_ROW
)
{
...
@@ -237,7 +251,6 @@
...
@@ -237,7 +251,6 @@
};
};
return
GameWrapper
;
return
GameWrapper
;
}(
engine
.
Container
));
}(
engine
.
Container
));
//# sourceMappingURL=GameWrapper.js.map
function
index
(
props
)
{
function
index
(
props
)
{
prepareProps
();
prepareProps
();
...
@@ -245,7 +258,6 @@
...
@@ -245,7 +258,6 @@
var
instance
=
new
GameWrapper
();
var
instance
=
new
GameWrapper
();
return
instance
;
return
instance
;
}
}
//# sourceMappingURL=index.js.map
return
index
;
return
index
;
...
...
src/custom/pictures/debug/main.js.map
View file @
3f49b0e4
{"version":3,"file":"index.js","sources":["src/custom/pictures/src/props.ts","src/custom/pictures/src/game/qietu.ts","src/custom/pictures/src/game/utils.ts","src/custom/pictures/src/game/GameView.ts","src/custom/pictures/src/game/GameWrapper.ts","src/custom/pictures/src/index.ts"],"sourcesContent":["/**\r\n * Created by rockyl on 2020-01-21.\r\n */\r\n\r\nexport let props: any = {};\r\n\r\nexport function prepareProps() {\r\n\tlet metaProps = getProps();\r\n\r\n\tengine.injectProp(props, metaProps);\r\n}\r\n\r\nexport function injectProps(p) {\r\n\tengine.injectProp(props, p);\r\n}\r\n","export default (parent, url,MAX_COL,MAX_ROW) => {\r\n\r\n const W = 600;\r\n const H = 600;\r\n const GAP = 10;\r\n\r\n const spr = [];\r\n const pos = []\r\n\r\n for (let row = 0; row < MAX_ROW; row++) {\r\n for (let col = 0; col < MAX_COL; col++) {\r\n\r\n const child = engine.Sprite.fromImage(url);\r\n spr.push(child);\r\n\r\n child.scaleX = 1 / MAX_COL;\r\n child.scaleY = 1 / MAX_ROW;\r\n parent.addChild(child);\r\n child.x = col * (W / MAX_COL + GAP);\r\n child.y = row * (H / MAX_ROW + GAP);\r\n pos.push([child.x,child.y]);\r\n child.addEventListener(engine.Event.COMPLETE, () => {\r\n const uvs = new Float32Array([\r\n col / MAX_COL,\r\n row / MAX_ROW,\r\n (col + 1) / MAX_COL,\r\n row / MAX_ROW,\r\n (col + 1) / MAX_COL,\r\n (row + 1) / MAX_ROW,\r\n col / MAX_COL,\r\n (row + 1) / MAX_ROW,\r\n ]);\r\n\r\n child.uvs = uvs;\r\n // spr.push(child);\r\n });\r\n }\r\n }\r\n // console.log(spr);\r\n return [spr,pos];\r\n};\r\n","/**\r\n * Created by rockyl on 2020-01-21.\r\n */\r\n\r\nexport function getTexture(uuid) {\r\n\treturn engine.Texture.from(getAssetByUUID(uuid).uuid);\r\n}\r\n\r\nexport function getTextureByName(name) {\r\n\treturn getTexture(engine.getAssetByName(name).uuid);\r\n}\r\n\r\nexport function playSound(name) {\r\n\tengine.playSound(engine.getAssetByName(name).uuid, {keep: true});\r\n}\r\nexport function createSvga(name, anchorName?) {\r\n\tlet inst = new svga.Svga();\r\n\tinst.source = 'asset://' + engine.getAssetByName(name).uuid;\r\n\treturn inst;\r\n}\r\n\r\nexport function getIndexFromRC(row,col,maxCol){\r\n\tlet index = row * maxCol + col \r\n\treturn index\r\n}\r\n\r\n\r\n\r\n\r\nexport function getRandomArray(array){\r\n\tarray.sort(function() {\r\n\t\treturn .5 - Math.random();\r\n\t});\r\n}","/**\r\n * Created by rockyl on 2018/8/16.\r\n */\r\n\r\nimport { props } from \"../props\";\r\nimport qietu from \"./qietu\";\r\nimport { getIndexFromRC, getRandomArray } from \"./utils\";\r\nimport ObjectPool = engine.ObjectPool;\r\n\r\nlet MAX_COL;\r\nlet MAX_ROW;\r\nlet W;\r\nlet H;\r\nlet GAP;\r\nlet GAME_TIME;\r\n// 每张图片宽\r\nlet w;\r\n// 每张图片高\r\nlet h;\r\nexport default class GameView extends engine.Container {\r\n private _timer;\r\n private _timeCounter = 0;\r\n\r\n // 倒计时时间\r\n // private countTime = 20;\r\n\r\n start() {\r\n console.log('on start')\r\n engine.globalEvent.dispatchEvent('pictures-time-update', {\r\n second: this.getSecond(),\r\n });\r\n\r\n // 图片一维数组\r\n const result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);\r\n this.pictures = result[0];\r\n this.rightList = this.pictures.concat([]);\r\n const posList = result[1];\r\n getRandomArray(this.pictures);\r\n\r\n let i = 0;\r\n let len;\r\n len = this.pictures.length;\r\n \r\n\r\n for (; i < len; i++) {\r\n this.dragPic = this.pictures[i];\r\n this.pictures[i].addEventListener(\r\n engine.MouseEvent.MOUSE_DOWN,\r\n this.onDown,\r\n this\r\n );\r\n const [x, y] = posList[i];\r\n this.dragPic.x = x;\r\n this.dragPic.y = y;\r\n }\r\n\r\n this._timer = setInterval(() => {\r\n this.onTimer();\r\n }, 10)\r\n }\r\n\r\n\r\n onTimer() {\r\n // this._timeCounter++;\r\n this._timeCounter += 0.01;\r\n this._timeCounter = this.afterPointTwo(this._timeCounter);\r\n // this._timeCounter = Math.floor((this._timeCounter + 0.1) * 10) / 10;\r\n console.log(this._timeCounter)\r\n\r\n engine.globalEvent.dispatchEvent('pictures-time-update', {\r\n second: this.getSecond(),\r\n });\r\n\r\n if (this.getSecond() == 0) {\r\n this.stop();\r\n engine.globalEvent.dispatchEvent('pictures-game-fail', {\r\n reason: 1\r\n });\r\n }\r\n }\r\n\r\n afterPointTwo(n){\r\n var floatN = parseFloat(n);\r\n if(isNaN(floatN)){\r\n return ;\r\n }\r\n floatN = Math.round(floatN * 100) /100;\r\n return floatN;\r\n }\r\n\r\n getSecond() {\r\n return GAME_TIME - this._timeCounter;\r\n // return GAME_TIME - this.countTime;\r\n }\r\n\r\n stop() {\r\n // this.countTime = 0\r\n\r\n this._timeCounter = 0;\r\n clearInterval(this._timer);\r\n }\r\n\r\n constructor() {\r\n super();\r\n this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);\r\n }\r\n\r\n //当前图片对象\r\n dragPic;\r\n\r\n localPicX;\r\n localPicY;\r\n\r\n distanceX;\r\n distanceY;\r\n\r\n centerX: number;\r\n centerY: number;\r\n\r\n pictures;\r\n\r\n // 点击图片时的索引\r\n index;\r\n indexI: number;\r\n indexJ: number;\r\n rightList: engine.Sprite[];\r\n\r\n \r\n\r\n private picturesWrapper: engine.Sprite;\r\n\r\n createRects() { }\r\n setup() {\r\n MAX_COL = props.MAX_COL;\r\n MAX_ROW = props.MAX_ROW;\r\n GAME_TIME = props.GAME_TIME;\r\n W = props.W;\r\n H = props.H;\r\n GAP = props.GAP;\r\n // 每张图片宽\r\n w = W / MAX_COL;\r\n // 每张图片高\r\n h = H / MAX_ROW;\r\n\r\n console.log('onSteup', props);\r\n\r\n const parent = new engine.Sprite();\r\n this.picturesWrapper = parent;\r\n this.addChild(parent);\r\n }\r\n\r\n onDown(e: engine.MouseEvent) {\r\n // console.log(e);\r\n\r\n // 创建一个图片对象接收当前位置信息\r\n this.dragPic = e.target;\r\n this.picturesWrapper.addChild(this.dragPic);\r\n\r\n // 鼠标的偏移量\r\n this.localPicX = e.localX / MAX_COL;\r\n this.localPicY = e.localY / MAX_ROW;\r\n\r\n // 最开始图片的位置\r\n this.distanceX = this.dragPic.x;\r\n this.distanceY = this.dragPic.y;\r\n\r\n // 最开始点击的图片的索引值\r\n this.indexI = this.distanceX / (w + GAP);\r\n this.indexJ = this.distanceY / (h + GAP);\r\n this.index = (this.indexI - 1) * MAX_COL + this.indexJ;\r\n\r\n // 图片的中心位置\r\n this.centerX = e.clientX + w / 2;\r\n this.centerY = e.clientY + h / 2;\r\n\r\n this.stage.addEventListener(\r\n engine.MouseEvent.MOUSE_MOVE,\r\n this.onMove,\r\n this\r\n );\r\n this.stage.addEventListener(\r\n engine.MouseEvent.MOUSE_UP,\r\n this.stageOnUp,\r\n this\r\n );\r\n\r\n }\r\n\r\n stageOnUp(e) {\r\n this.stage.removeEventListener(\r\n engine.MouseEvent.MOUSE_MOVE,\r\n this.onMove,\r\n this\r\n );\r\n\r\n // 判断图片是否进入另一张图片的范围内\r\n // 图片第几行第几列\r\n let curJ = Math.floor(this.centerX / (w + GAP));\r\n let curI = Math.floor(this.centerY / (h + GAP));\r\n\r\n\r\n // 点击图片的位置\r\n\r\n if (curJ < MAX_COL && curI < MAX_ROW) {\r\n\r\n // 获取交互图片的索引值\r\n let index = getIndexFromRC(curI, curJ, MAX_COL);\r\n // console.log(index);\r\n\r\n //要交换的图片\r\n let dropPic = this.pictures[index];\r\n\r\n let dropPicX = dropPic.x;\r\n let dropPicy = dropPic.y;\r\n\r\n dropPic.x = this.distanceX;\r\n dropPic.y = this.distanceY;\r\n\r\n this.dragPic.x = dropPicX;\r\n this.dragPic.y = dropPicy;\r\n\r\n // 交换之后索引也需要交换\r\n\r\n const dropPicIndex = this.pictures.indexOf(dropPic);\r\n const dragPicIndex = this.pictures.indexOf(this.dragPic);\r\n\r\n this.pictures[dropPicIndex] = this.dragPic;\r\n this.pictures[dragPicIndex] = dropPic;\r\n\r\n // 图片还是在原来的位置\r\n if(dragPicIndex === dropPicIndex){\r\n this.dragPic.x = this.distanceX\r\n this.dragPic.y = this.distanceY\r\n }\r\n\r\n let result = true;\r\n for (let j = 0; j < this.rightList.length; j++) {\r\n if (this.rightList[j] != this.pictures[j]) {\r\n result = false;\r\n break;\r\n }\r\n }\r\n\r\n if (result) {\r\n this.onSuccess();\r\n\r\n }\r\n }else{\r\n this.dragPic.x = this.distanceX\r\n this.dragPic.y = this.distanceY\r\n }\r\n\r\n this.stage.removeEventListener(\r\n engine.MouseEvent.MOUSE_UP,\r\n this.stageOnUp,\r\n this\r\n );\r\n }\r\n\r\n private onSuccess() {\r\n console.log('拼图成功!');\r\n this.stop();\r\n engine.globalEvent.dispatchEvent('pictures-game-success', {});\r\n }\r\n\r\n onMove(e: engine.MouseEvent) {\r\n // 当前图片的位置\r\n this.dragPic.x = e.stageX - this.localPicX;\r\n this.dragPic.y = e.stageY - this.localPicY;\r\n\r\n // 当前图片的中心位置\r\n this.centerX = this.dragPic.x + w / 2;\r\n this.centerY = this.dragPic.y + h / 2;\r\n\r\n }\r\n\r\n}\r\n","/**\r\n * Created by rockyl on 2020-01-09.\r\n */\r\n\r\nimport GameView from \"./GameView\";\r\nimport { injectProps } from \"../props\";\r\n\r\n\r\nexport class GameWrapper extends engine.Container {\r\n\t// private _status;\r\n\tprivate _gameView: GameView;\r\n\r\n\r\n\r\n\r\n\r\n\tconstructor() {\r\n\t\tsuper();\r\n\r\n\t\tengine.globalEvent.addEventListener('pictures-start', this.start, this);\r\n\t\tengine.globalEvent.addEventListener('pictures-stop', this.stop, this);\r\n\r\n\t\t//创建实例\r\n\t\tlet gameView = this._gameView = new GameView();\r\n\t\tthis.addChild(gameView);\r\n\r\n\t}\r\n\r\n\tstart(event: engine.Event) {\r\n\t\tinjectProps(event.data);\r\n\r\n\t\t// this._status = 1;\r\n\r\n\t\tthis._gameView.start();\r\n\t}\r\n\tstop(event: engine.Event) {\r\n\t\t\r\n\t\tthis._gameView.stop();\r\n\t}\r\n}\r\n","/**\r\n * Created by rockyl on 2019-11-20.\r\n */\r\n\r\nimport {GameWrapper} from \"./game/GameWrapper\";\r\nimport {injectProps, prepareProps} from \"./props\";\r\n\r\nexport default function (props) {\r\n\tprepareProps();\r\n\tinjectProps(props);\r\n\r\n\tlet instance = new GameWrapper();\r\n\t\r\n\treturn instance;\r\n}\r\n"],"names":["__extends"],"mappings":";;;;;;CAIO,IAAI,KAAK,GAAQ,EAAE,CAAC;UAEX,YAAY;KAC3B,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;KAE3B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CACrC,CAAC;UAEe,WAAW,CAAC,CAAC;KAC5B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7B,CAAC;;;ACdD,cAAe,UAAC,MAAM,EAAE,GAAG,EAAC,OAAO,EAAC,OAAO;KAEzC,IAAM,CAAC,GAAG,GAAG,CAAC;KACd,IAAM,CAAC,GAAG,GAAG,CAAC;KACd,IAAM,GAAG,GAAG,EAAE,CAAC;KAEf,IAAM,GAAG,GAAG,EAAE,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AEH,eAAC;CAAD,CAAC,CAjQqC,MAAM,CAAC,SAAS,GAiQrD;;CC5QD;KAAiCA,qCAAgB;KAQhD;SAAA,YACC,iBAAO,SASP;SAPA,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,CAAC;SACxE,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,eAAe,EAAE,KAAI,CAAC,IAAI,EAAE,KAAI,CAAC,CAAC;SAGtE,IAAI,QAAQ,GAAG,KAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,EAAE,CAAC;SAC/C,KAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;;MAExB;KAED,2BAAK,GAAL,UAAM,KAAmB;SACxB,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SAIxB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;MACvB;KACD,0BAAI,GAAJ,UAAK,KAAmB;SAEvB,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;MACtB;KACF,kBAAC;CAAD,CAAC,CA/BgC,MAAM,CAAC,SAAS,GA+BhD;;;iBChCwB,KAAK;KAC7B,YAAY,EAAE,CAAC;KACf,WAAW,CAAC,KAAK,CAAC,CAAC;KAEnB,IAAI,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;KAEjC,OAAO,QAAQ,CAAC;CACjB,CAAC;;;;;;;;;"}
<<<<<<< HEAD
\ No newline at end of file
{"version":3,"file":"index.js","sources":["src/custom/pictures/src/props.ts","src/custom/pictures/src/game/qietu.ts","src/custom/pictures/src/game/utils.ts","src/custom/pictures/src/game/GameView.ts","src/custom/pictures/src/game/GameWrapper.ts","src/custom/pictures/src/index.ts"],"sourcesContent":["/**\r\n * Created by rockyl on 2020-01-21.\r\n */\r\n\r\nexport let props: any = {};\r\n\r\nexport function prepareProps() {\r\n\tlet metaProps = getProps();\r\n\r\n\tengine.injectProp(props, metaProps);\r\n}\r\n\r\nexport function injectProps(p) {\r\n\tengine.injectProp(props, p);\r\n}\r\n","export default (parent, url,MAX_COL,MAX_ROW) => {\r\n\r\n const W = 600;\r\n const H = 600;\r\n const GAP = 10;\r\n\r\n const spr = [];\r\n const pos = []\r\n\r\n for (let row = 0; row < MAX_ROW; row++) {\r\n for (let col = 0; col < MAX_COL; col++) {\r\n\r\n const child = engine.Sprite.fromImage(url);\r\n spr.push(child);\r\n\r\n child.scaleX = 1 / MAX_COL;\r\n child.scaleY = 1 / MAX_ROW;\r\n parent.addChild(child);\r\n child.x = col * (W / MAX_COL + GAP);\r\n child.y = row * (H / MAX_ROW + GAP);\r\n pos.push([child.x,child.y]);\r\n child.addEventListener(engine.Event.COMPLETE, () => {\r\n const uvs = new Float32Array([\r\n col / MAX_COL,\r\n row / MAX_ROW,\r\n (col + 1) / MAX_COL,\r\n row / MAX_ROW,\r\n (col + 1) / MAX_COL,\r\n (row + 1) / MAX_ROW,\r\n col / MAX_COL,\r\n (row + 1) / MAX_ROW,\r\n ]);\r\n\r\n child.uvs = uvs;\r\n // spr.push(child);\r\n });\r\n }\r\n }\r\n // console.log(spr);\r\n return [spr,pos];\r\n};\r\n","/**\r\n * Created by rockyl on 2020-01-21.\r\n */\r\n\r\nexport function getTexture(uuid) {\r\n\treturn engine.Texture.from(getAssetByUUID(uuid).uuid);\r\n}\r\n\r\nexport function getTextureByName(name) {\r\n\treturn getTexture(engine.getAssetByName(name).uuid);\r\n}\r\n\r\nexport function playSound(name) {\r\n\tengine.playSound(engine.getAssetByName(name).uuid, {keep: true});\r\n}\r\nexport function createSvga(name, anchorName?) {\r\n\tlet inst = new svga.Svga();\r\n\tinst.source = 'asset://' + engine.getAssetByName(name).uuid;\r\n\treturn inst;\r\n}\r\n\r\nexport function getIndexFromRC(row,col,maxCol){\r\n\tlet index = row * maxCol + col \r\n\treturn index\r\n}\r\n\r\n\r\n\r\n\r\nexport function getRandomArray(array){\r\n\tarray.sort(function() {\r\n\t\treturn .5 - Math.random();\r\n\t});\r\n}","/**\r\n * Created by rockyl on 2018/8/16.\r\n */\r\n\r\nimport { props } from \"../props\";\r\nimport qietu from \"./qietu\";\r\nimport { getIndexFromRC, getRandomArray } from \"./utils\";\r\nimport ObjectPool = engine.ObjectPool;\r\n\r\nlet MAX_COL;\r\nlet MAX_ROW;\r\nlet W;\r\nlet H;\r\nlet GAP;\r\nlet GAME_TIME;\r\n// 每张图片宽\r\nlet w;\r\n// 每张图片高\r\nlet h;\r\nexport default class GameView extends engine.Container {\r\n private _timer;\r\n private _timeCounter = 0;\r\n\r\n // 倒计时时间\r\n // private countTime = 20;\r\n\r\n start() {\r\n console.log('on start')\r\n engine.globalEvent.dispatchEvent('pictures-time-update', {\r\n second: this.getSecond(),\r\n });\r\n\r\n // 图片一维数组\r\n const result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);\r\n this.pictures = result[0];\r\n this.rightList = this.pictures.concat([]);\r\n const posList = result[1];\r\n getRandomArray(this.pictures);\r\n\r\n let i = 0;\r\n let len;\r\n len = this.pictures.length;\r\n \r\n\r\n for (; i < len; i++) {\r\n this.dragPic = this.pictures[i];\r\n this.pictures[i].addEventListener(\r\n engine.MouseEvent.MOUSE_DOWN,\r\n this.onDown,\r\n this\r\n );\r\n const [x, y] = posList[i];\r\n this.dragPic.x = x;\r\n this.dragPic.y = y;\r\n }\r\n\r\n this._timer = setInterval(() => {\r\n this.onTimer();\r\n }, 10)\r\n }\r\n\r\n\r\n onTimer() {\r\n // this._timeCounter++;\r\n this._timeCounter += 0.01;\r\n this._timeCounter = this.afterPointTwo(this._timeCounter);\r\n // this._timeCounter = Math.floor((this._timeCounter + 0.1) * 10) / 10;\r\n console.log(this._timeCounter)\r\n\r\n engine.globalEvent.dispatchEvent('pictures-time-update', {\r\n second: this.getSecond(),\r\n });\r\n\r\n if (this.getSecond() == 0) {\r\n this.stop();\r\n engine.globalEvent.dispatchEvent('pictures-game-fail', {\r\n reason: 1\r\n });\r\n }\r\n }\r\n\r\n afterPointTwo(n){\r\n var floatN = parseFloat(n);\r\n if(isNaN(floatN)){\r\n return ;\r\n }\r\n floatN = Math.round(floatN * 100) /100;\r\n return floatN;\r\n }\r\n\r\n getSecond() {\r\n return GAME_TIME - this._timeCounter;\r\n // return GAME_TIME - this.countTime;\r\n }\r\n\r\n stop() {\r\n // this.countTime = 0\r\n\r\n this._timeCounter = 0;\r\n clearInterval(this._timer);\r\n }\r\n\r\n constructor() {\r\n super();\r\n this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);\r\n }\r\n\r\n //当前图片对象\r\n dragPic;\r\n\r\n localPicX;\r\n localPicY;\r\n\r\n distanceX;\r\n distanceY;\r\n\r\n centerX: number;\r\n centerY: number;\r\n\r\n pictures;\r\n\r\n // 点击图片时的索引\r\n index;\r\n indexI: number;\r\n indexJ: number;\r\n rightList: engine.Sprite[];\r\n\r\n \r\n\r\n private picturesWrapper: engine.Sprite;\r\n\r\n createRects() { }\r\n setup() {\r\n MAX_COL = props.MAX_COL;\r\n MAX_ROW = props.MAX_ROW;\r\n GAME_TIME = props.GAME_TIME;\r\n W = props.W;\r\n H = props.H;\r\n GAP = props.GAP;\r\n // 每张图片宽\r\n w = W / MAX_COL;\r\n // 每张图片高\r\n h = H / MAX_ROW;\r\n\r\n console.log('onSteup', props);\r\n\r\n const parent = new engine.Sprite();\r\n this.picturesWrapper = parent;\r\n this.addChild(parent);\r\n }\r\n\r\n onDown(e: engine.MouseEvent) {\r\n // console.log(e);\r\n\r\n // 创建一个图片对象接收当前位置信息\r\n this.dragPic = e.target;\r\n this.picturesWrapper.addChild(this.dragPic);\r\n\r\n // 鼠标的偏移量\r\n this.localPicX = e.localX / MAX_COL;\r\n this.localPicY = e.localY / MAX_ROW;\r\n\r\n // 最开始图片的位置\r\n this.distanceX = this.dragPic.x;\r\n this.distanceY = this.dragPic.y;\r\n\r\n // 最开始点击的图片的索引值\r\n this.indexI = this.distanceX / (w + GAP);\r\n this.indexJ = this.distanceY / (h + GAP);\r\n this.index = (this.indexI - 1) * MAX_COL + this.indexJ;\r\n\r\n // 图片的中心位置\r\n this.centerX = e.clientX + w / 2;\r\n this.centerY = e.clientY + h / 2;\r\n\r\n this.stage.addEventListener(\r\n engine.MouseEvent.MOUSE_MOVE,\r\n this.onMove,\r\n this\r\n );\r\n this.stage.addEventListener(\r\n engine.MouseEvent.MOUSE_UP,\r\n this.stageOnUp,\r\n this\r\n );\r\n\r\n }\r\n\r\n stageOnUp(e) {\r\n this.stage.removeEventListener(\r\n engine.MouseEvent.MOUSE_MOVE,\r\n this.onMove,\r\n this\r\n );\r\n\r\n // 判断图片是否进入另一张图片的范围内\r\n // 图片第几行第几列\r\n let curJ = Math.floor(this.centerX / (w + GAP));\r\n let curI = Math.floor(this.centerY / (h + GAP));\r\n\r\n\r\n // 点击图片的位置\r\n\r\n if (curJ < MAX_COL && curI < MAX_ROW) {\r\n\r\n // 获取交互图片的索引值\r\n let index = getIndexFromRC(curI, curJ, MAX_COL);\r\n // console.log(index);\r\n\r\n //要交换的图片\r\n let dropPic = this.pictures[index];\r\n\r\n let dropPicX = dropPic.x;\r\n let dropPicy = dropPic.y;\r\n\r\n dropPic.x = this.distanceX;\r\n dropPic.y = this.distanceY;\r\n\r\n this.dragPic.x = dropPicX;\r\n this.dragPic.y = dropPicy;\r\n\r\n // 交换之后索引也需要交换\r\n\r\n const dropPicIndex = this.pictures.indexOf(dropPic);\r\n const dragPicIndex = this.pictures.indexOf(this.dragPic);\r\n\r\n this.pictures[dropPicIndex] = this.dragPic;\r\n this.pictures[dragPicIndex] = dropPic;\r\n\r\n // 图片还是在原来的位置\r\n if(dragPicIndex === dropPicIndex){\r\n this.dragPic.x = this.distanceX\r\n this.dragPic.y = this.distanceY\r\n }\r\n\r\n let result = true;\r\n for (let j = 0; j < this.rightList.length; j++) {\r\n if (this.rightList[j] != this.pictures[j]) {\r\n result = false;\r\n break;\r\n }\r\n }\r\n\r\n if (result) {\r\n this.onSuccess();\r\n\r\n }\r\n }else{\r\n this.dragPic.x = this.distanceX\r\n this.dragPic.y = this.distanceY\r\n }\r\n\r\n this.stage.removeEventListener(\r\n engine.MouseEvent.MOUSE_UP,\r\n this.stageOnUp,\r\n this\r\n );\r\n }\r\n\r\n private onSuccess() {\r\n console.log('拼图成功!');\r\n this.stop();\r\n engine.globalEvent.dispatchEvent('pictures-game-success', {});\r\n }\r\n\r\n onMove(e: engine.MouseEvent) {\r\n // 当前图片的位置\r\n this.dragPic.x = e.stageX - this.localPicX;\r\n this.dragPic.y = e.stageY - this.localPicY;\r\n\r\n // 当前图片的中心位置\r\n this.centerX = this.dragPic.x + w / 2;\r\n this.centerY = this.dragPic.y + h / 2;\r\n\r\n }\r\n\r\n}\r\n","/**\r\n * Created by rockyl on 2020-01-09.\r\n */\r\n\r\nimport GameView from \"./GameView\";\r\nimport { injectProps } from \"../props\";\r\n\r\n\r\nexport class GameWrapper extends engine.Container {\r\n\t// private _status;\r\n\tprivate _gameView: GameView;\r\n\r\n\r\n\r\n\r\n\r\n\tconstructor() {\r\n\t\tsuper();\r\n\r\n\t\tengine.globalEvent.addEventListener('pictures-start', this.start, this);\r\n\t\tengine.globalEvent.addEventListener('pictures-stop', this.stop, this);\r\n\r\n\t\t//创建实例\r\n\t\tlet gameView = this._gameView = new GameView();\r\n\t\tthis.addChild(gameView);\r\n\r\n\t}\r\n\r\n\tstart(event: engine.Event) {\r\n\t\tinjectProps(event.data);\r\n\r\n\t\t// this._status = 1;\r\n\r\n\t\tthis._gameView.start();\r\n\t}\r\n\tstop(event: engine.Event) {\r\n\t\t\r\n\t\tthis._gameView.stop();\r\n\t}\r\n}\r\n","/**\r\n * Created by rockyl on 2019-11-20.\r\n */\r\n\r\nimport {GameWrapper} from \"./game/GameWrapper\";\r\nimport {injectProps, prepareProps} from \"./props\";\r\n\r\nexport default function (props) {\r\n\tprepareProps();\r\n\tinjectProps(props);\r\n\r\n\tlet instance = new GameWrapper();\r\n\t\r\n\treturn instance;\r\n}\r\n"],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AK;KAC7B,YAAY,EAAE,CAAC;KACf,WAAW,CAAC,KAAK,CAAC,CAAC;KAEnB,IAAI,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;KAEjC,OAAO,QAAQ,CAAC;CACjB,CAAC;;;;;;;;;"}
=======
{"version":3,"file":"index.js","sources":["src/custom/pictures/src/props.ts","src/custom/pictures/src/game/qietu.ts","src/custom/pictures/src/game/utils.ts","src/custom/pictures/src/game/GameView.ts","src/custom/pictures/src/game/GameWrapper.ts","src/custom/pictures/src/index.ts"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-21.\n */\n\nexport let props: any = {};\n\nexport function prepareProps() {\n\tlet metaProps = getProps();\n\n\tengine.injectProp(props, metaProps);\n}\n\nexport function injectProps(p) {\n\tengine.injectProp(props, p);\n}\n","import { props } from \"../props\";\nconst urls = [];\nconst picMap = {};\nconst posMap = {};\nexport default (parent, url, MAX_COL, MAX_ROW) => {\n if (picMap[url]) {\n return [picMap[url], posMap[url]]\n }\n\n const W = props.W;\n const H = props.H;\n const GAP = props.GAP;\n\n const spr = [];\n const pos = []\n\n for (let row = 0; row < MAX_ROW; row++) {\n for (let col = 0; col < MAX_COL; col++) {\n\n const child = engine.Sprite.fromImage(url);\n spr.push(child);\n\n child.scaleX = 1 / MAX_COL;\n child.scaleY = 1 / MAX_ROW;\n parent.addChild(child);\n child.x = col * (W / MAX_COL + GAP);\n child.y = row * (H / MAX_ROW + GAP);\n pos.push([child.x, child.y]);\n // child.texture.addEventListener('update', () => {\n child.addEventListener(engine.Event.COMPLETE, () => {\n const uvs = new Float32Array([\n col / MAX_COL,\n row / MAX_ROW,\n (col + 1) / MAX_COL,\n row / MAX_ROW,\n (col + 1) / MAX_COL,\n (row + 1) / MAX_ROW,\n col / MAX_COL,\n (row + 1) / MAX_ROW,\n ]);\n\n child.uvs = uvs;\n // spr.push(child);\n });\n }\n }\n picMap[url] = spr.concat([]);\n posMap[url] = pos.concat([]);;\n // console.log(spr);\n return [spr, pos];\n};\n","/**\n * Created by rockyl on 2020-01-21.\n */\n\nexport function getTexture(uuid) {\n\treturn engine.Texture.from(getAssetByUUID(uuid).uuid);\n}\n\nexport function getTextureByName(name) {\n\treturn getTexture(engine.getAssetByName(name).uuid);\n}\n\nexport function playSound(name) {\n\tengine.playSound(engine.getAssetByName(name).uuid, {keep: true});\n}\nexport function createSvga(name, anchorName?) {\n\tlet inst = new svga.Svga();\n\tinst.source = 'asset://' + engine.getAssetByName(name).uuid;\n\treturn inst;\n}\n\nexport function getIndexFromRC(row,col,maxCol){\n\tlet index = row * maxCol + col \n\treturn index\n}\n\n\n\n\nexport function getRandomArray(array){\n\tarray.sort(function() {\n\t\treturn .5 - Math.random();\n\t});\n}","/**\n * Created by rockyl on 2018/8/16.\n */\n\nimport { props } from \"../props\";\nimport qietu from \"./qietu\";\nimport { getIndexFromRC, getRandomArray, getTextureByName } from \"./utils\";\nimport ObjectPool = engine.ObjectPool;\n\nlet MAX_COL;\nlet MAX_ROW;\nlet W;\nlet H;\nlet GAP;\nlet GAME_TIME;\n// 每张图片宽\nlet w;\n// 每张图片高\nlet h;\nexport default class GameView extends engine.Container {\n private _timer;\n private _timeCounter = 0;\n\n start() {\n console.log('on start')\n engine.globalEvent.dispatchEvent('pictures-time-update', {\n second: this.getSecond(),\n });\n\n // 图片一维数组\n const result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);\n this.picturesWrapper.addChild(this.guideHole);\n this.pictures = result[0];\n this.rightList = this.pictures.concat([]);\n const posList = result[1];\n getRandomArray(this.pictures);\n\n let i = 0;\n let len;\n len = this.pictures.length;\n\n\n for (; i < len; i++) {\n this.dragPic = this.pictures[i];\n this.pictures[i].addEventListener(\n engine.MouseEvent.MOUSE_DOWN,\n this.onDown,\n this\n );\n const [x, y] = posList[i];\n this.dragPic.x = x;\n this.dragPic.y = y;\n }\n\n this._timer = setInterval(() => {\n this.onTimer();\n }, 1000)\n }\n\n\n onTimer() {\n this._timeCounter++;\n engine.globalEvent.dispatchEvent('pictures-time-update', {\n second: this.getSecond(),\n });\n\n if (this.getSecond() == 0) {\n this.stop();\n engine.globalEvent.dispatchEvent('pictures-game-fail', {\n reason: 1\n });\n }\n }\n\n getSecond() {\n return GAME_TIME - this._timeCounter;\n }\n\n stop() {\n this._timeCounter = 0;\n clearInterval(this._timer);\n }\n\n constructor() {\n super();\n this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);\n }\n\n //当前图片对象\n dragPic;\n\n localPicX;\n localPicY;\n\n distanceX;\n distanceY;\n\n centerX: number;\n centerY: number;\n\n pictures;\n\n // 点击图片时的索引\n index;\n indexI: number;\n indexJ: number;\n rightList: engine.Sprite[];\n\n // 倒计时时间\n countTime = 10;\n\n private picturesWrapper: engine.Sprite;\n private guideHole: engine.Sprite;\n\n createRects() { }\n setup() {\n this.guideHole = new engine.Image(getTextureByName('遮罩'));\n this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false;\n\n MAX_COL = props.MAX_COL;\n MAX_ROW = props.MAX_ROW;\n GAME_TIME = props.GAME_TIME;\n W = props.W;\n H = props.H;\n GAP = props.GAP;\n // 每张图片宽\n w = W / MAX_COL;\n // 每张图片高\n h = H / MAX_ROW;\n\n console.log('onSteup', props);\n\n const parent = new engine.Sprite();\n this.picturesWrapper = parent;\n this.addChild(parent);\n }\n\n onDown(e: engine.MouseEvent) {\n // console.log(e);\n\n // 创建一个图片对象接收当前位置信息\n this.dragPic = e.target;\n this.picturesWrapper.addChild(this.dragPic);\n\n // 鼠标的偏移量\n this.localPicX = e.localX / MAX_COL;\n this.localPicY = e.localY / MAX_ROW;\n\n // 最开始图片的位置\n this.distanceX = this.dragPic.x;\n this.distanceY = this.dragPic.y;\n\n // 最开始点击的图片的索引值\n this.indexI = this.distanceX / (w + GAP);\n this.indexJ = this.distanceY / (h + GAP);\n this.index = (this.indexI - 1) * MAX_COL + this.indexJ;\n\n // 图片的中心位置\n this.centerX = e.clientX + w / 2;\n this.centerY = e.clientY + h / 2;\n\n this.stage.addEventListener(\n engine.MouseEvent.MOUSE_MOVE,\n this.onMove,\n this\n );\n this.stage.addEventListener(\n engine.MouseEvent.MOUSE_UP,\n this.stageOnUp,\n this\n );\n\n }\n\n stageOnUp(e) {\n this.stage.removeEventListener(\n engine.MouseEvent.MOUSE_MOVE,\n this.onMove,\n this\n );\n\n this.picturesWrapper.addChild(this.guideHole);\n\n // 判断图片是否进入另一张图片的范围内\n // 图片第几行第几列\n let curJ = Math.floor(this.centerX / (w + GAP));\n let curI = Math.floor(this.centerY / (h + GAP));\n\n\n // 点击图片的位置\n\n if (curJ < MAX_COL && curI < MAX_ROW) {\n\n // 获取交互图片的索引值\n let index = getIndexFromRC(curI, curJ, MAX_COL);\n // console.log(index);\n\n //要交换的图片\n let dropPic = this.pictures[index];\n\n let dropPicX = dropPic.x;\n let dropPicy = dropPic.y;\n\n dropPic.x = this.distanceX;\n dropPic.y = this.distanceY;\n\n this.dragPic.x = dropPicX;\n this.dragPic.y = dropPicy;\n\n // 交换之后索引也需要交换\n\n const dropPicIndex = this.pictures.indexOf(dropPic);\n const dragPicIndex = this.pictures.indexOf(this.dragPic);\n\n this.pictures[dropPicIndex] = this.dragPic;\n this.pictures[dragPicIndex] = dropPic;\n\n let result = true;\n for (let j = 0; j < this.rightList.length; j++) {\n if (this.rightList[j] != this.pictures[j]) {\n result = false;\n break;\n }\n }\n\n if (result) {\n this.onSuccess();\n\n }\n }\n\n this.stage.removeEventListener(\n engine.MouseEvent.MOUSE_UP,\n this.stageOnUp,\n this\n );\n }\n\n private onSuccess() {\n console.log('拼图成功!');\n this.stop();\n engine.globalEvent.dispatchEvent('pictures-game-success', {});\n }\n\n onMove(e: engine.MouseEvent) {\n // 当前图片的位置\n this.dragPic.x = e.stageX - this.localPicX;\n this.dragPic.y = e.stageY - this.localPicY;\n\n // 当前图片的中心位置\n this.centerX = this.dragPic.x + w / 2;\n this.centerY = this.dragPic.y + h / 2;\n\n }\n\n}\n","/**\n * Created by rockyl on 2020-01-09.\n */\n\nimport GameView from \"./GameView\";\nimport { injectProps } from \"../props\";\n\n\nexport class GameWrapper extends engine.Container {\n\t// private _status;\n\tprivate _gameView: GameView;\n\n\n\n\n\n\tconstructor() {\n\t\tsuper();\n\n\t\tengine.globalEvent.addEventListener('pictures-start', this.start, this);\n\t\tengine.globalEvent.addEventListener('pictures-stop', this.stop, this);\n\n\t\t//创建实例\n\t\tlet gameView = this._gameView = new GameView();\n\t\tthis.addChild(gameView);\n\n\t}\n\n\tstart(event: engine.Event) {\n\t\tinjectProps(event.data);\n\n\t\t// this._status = 1;\n\n\t\tthis._gameView.start();\n\t}\n\tstop(event: engine.Event) {\n\t\t\n\t\tthis._gameView.stop();\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-20.\n */\n\nimport {GameWrapper} from \"./game/GameWrapper\";\nimport {injectProps, prepareProps} from \"./props\";\n\nexport default function (props) {\n\tprepareProps();\n\tinjectProps(props);\n\n\tlet instance = new GameWrapper();\n\t\n\treturn instance;\n}\n"],"names":["__extends"],"mappings":";;;;;;CAIO,IAAI,KAAK,GAAQ,EAAE,CAAC;UAEX,YAAY;KAC3B,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;KAE3B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CACrC,CAAC;UAEe,WAAW,CAAC,CAAC;KAC5B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7B;;CCZA,IAAM,MAAM,GAAG,EAAE,CAAC;CAClB,IAAM,MAAM,GAAG,EAAE,CAAC;AAClB,cAAe,UAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO;KAC3C,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;SACf,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;MAClC;KAED,IAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;KAClB,IAAM,CAAC,GA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"
:
"number"
,
"type"
:
"number"
,
<<<<<<<
HEAD
"default"
:
3
"default"
:
3
=======
"default"
:
4
>>>>>>>
942737e103
f
614239
f
421
c
98
ab
5
a
0e18935
bc
709
},
},
"W"
:
{
"W"
:
{
"alias"
:
"图片的宽度"
,
"alias"
:
"图片的宽度"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
6
00
"default"
:
6
18
},
},
"H"
:
{
"H"
:
{
"alias"
:
"图片的高度"
,
"alias"
:
"图片的高度"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
600
"default"
:
827
},
},
"GAP"
:
{
"GAP"
:
{
"alias"
:
"图片间隙"
,
"alias"
:
"图片间隙"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
1
0
"default"
:
0
},
},
"GAME_TIME"
:
{
"GAME_TIME"
:
{
"alias"
:
"游戏时间"
,
"alias"
:
"游戏时间"
,
...
@@ -36,36 +40,23 @@
...
@@ -36,36 +40,23 @@
},
},
"assets"
:
[
"assets"
:
[
{
{
"name"
:
"
测试资源
"
,
"name"
:
"
遮罩
"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/5
0a7212a113175fa18c866b005d98f07c558dc77
.png"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/5
b3e30496b2d9fdafb0cf3835fd6704ce10e45b4
.png"
,
"uuid"
:
"66f23d13-82a5-4cec-9496-301ec240d087"
,
"uuid"
:
"66f23d13-82a5-4cec-9496-301ec240d087"
,
"ext"
:
".png"
"ext"
:
".png"
}
}
],
],
"events"
:
{
"events"
:
{
"in"
:
{
"in"
:
{
"pictures-reset"
:
{
"alias"
:
"重置"
,
"pictures-start"
:
{
"alias"
:
"开始"
,
"data"
:
{
"data"
:
{
"goodsProbability"
:
"[0.2,0.5,0.3]道具概率(雨滴、石头、炸弹),所有概率相加为1"
,
"picUrl"
:
"图片路径"
"countDown"
:
"倒计时(s)"
,
"acceleratedSpeed"
:
"道具掉落加速度(单位:每秒)"
}
}
},
},
"pictures-start"
:
{
"pictures-stop"
:
{
"alias"
:
"开始"
"alias"
:
"停止"
},
"pictures-revive"
:
{
"alias"
:
"复活"
},
"pictures-pause"
:
{
"alias"
:
"暂停"
},
"pictures-resume"
:
{
"alias"
:
"恢复"
},
"pictures-clear"
:
{
"alias"
:
"清空,通过reset事件恢复"
}
}
},
},
"out"
:
{
"out"
:
{
...
...
src/custom/pictures/src/game/GameView.ts
View file @
3f49b0e4
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
import
{
props
}
from
"../props"
;
import
{
props
}
from
"../props"
;
import
qietu
from
"./qietu"
;
import
qietu
from
"./qietu"
;
import
{
getIndexFromRC
,
getRandomArray
}
from
"./utils"
;
import
{
getIndexFromRC
,
getRandomArray
,
getTextureByName
}
from
"./utils"
;
import
ObjectPool
=
engine
.
ObjectPool
;
import
ObjectPool
=
engine
.
ObjectPool
;
let
MAX_COL
;
let
MAX_COL
;
...
@@ -32,6 +32,7 @@ export default class GameView extends engine.Container {
...
@@ -32,6 +32,7 @@ export default class GameView extends engine.Container {
// 图片一维数组
// 图片一维数组
const
result
=
qietu
(
this
.
picturesWrapper
,
props
.
picUrl
,
MAX_COL
,
MAX_ROW
);
const
result
=
qietu
(
this
.
picturesWrapper
,
props
.
picUrl
,
MAX_COL
,
MAX_ROW
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
this
.
pictures
=
result
[
0
];
this
.
pictures
=
result
[
0
];
this
.
rightList
=
this
.
pictures
.
concat
([]);
this
.
rightList
=
this
.
pictures
.
concat
([]);
const
posList
=
result
[
1
];
const
posList
=
result
[
1
];
...
@@ -40,7 +41,7 @@ export default class GameView extends engine.Container {
...
@@ -40,7 +41,7 @@ export default class GameView extends engine.Container {
let
i
=
0
;
let
i
=
0
;
let
len
;
let
len
;
len
=
this
.
pictures
.
length
;
len
=
this
.
pictures
.
length
;
for
(;
i
<
len
;
i
++
)
{
for
(;
i
<
len
;
i
++
)
{
this
.
dragPic
=
this
.
pictures
[
i
];
this
.
dragPic
=
this
.
pictures
[
i
];
...
@@ -128,9 +129,13 @@ export default class GameView extends engine.Container {
...
@@ -128,9 +129,13 @@ export default class GameView extends engine.Container {
private
picturesWrapper
:
engine
.
Sprite
;
private
picturesWrapper
:
engine
.
Sprite
;
private
guideHole
:
engine
.
Sprite
;
createRects
()
{
}
createRects
()
{
}
setup
()
{
setup
()
{
this
.
guideHole
=
new
engine
.
Image
(
getTextureByName
(
'遮罩'
));
this
.
guideHole
.
mouseChildren
=
this
.
guideHole
.
mouseEnabled
=
false
;
MAX_COL
=
props
.
MAX_COL
;
MAX_COL
=
props
.
MAX_COL
;
MAX_ROW
=
props
.
MAX_ROW
;
MAX_ROW
=
props
.
MAX_ROW
;
GAME_TIME
=
props
.
GAME_TIME
;
GAME_TIME
=
props
.
GAME_TIME
;
...
@@ -193,6 +198,8 @@ export default class GameView extends engine.Container {
...
@@ -193,6 +198,8 @@ export default class GameView extends engine.Container {
this
this
);
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
// 判断图片是否进入另一张图片的范围内
// 判断图片是否进入另一张图片的范围内
// 图片第几行第几列
// 图片第几行第几列
let
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
let
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
...
...
src/custom/pictures/src/game/qietu.ts
View file @
3f49b0e4
export
default
(
parent
,
url
,
MAX_COL
,
MAX_ROW
)
=>
{
import
{
props
}
from
"../props"
;
const
urls
=
[];
const
picMap
=
{};
const
posMap
=
{};
export
default
(
parent
,
url
,
MAX_COL
,
MAX_ROW
)
=>
{
if
(
picMap
[
url
])
{
return
[
picMap
[
url
],
posMap
[
url
]]
}
const
W
=
600
;
const
W
=
props
.
W
;
const
H
=
600
;
const
H
=
props
.
H
;
const
GAP
=
10
;
const
GAP
=
props
.
GAP
;
const
spr
=
[];
const
spr
=
[];
const
pos
=
[]
const
pos
=
[]
...
@@ -18,7 +25,8 @@ export default (parent, url,MAX_COL,MAX_ROW) => {
...
@@ -18,7 +25,8 @@ export default (parent, url,MAX_COL,MAX_ROW) => {
parent
.
addChild
(
child
);
parent
.
addChild
(
child
);
child
.
x
=
col
*
(
W
/
MAX_COL
+
GAP
);
child
.
x
=
col
*
(
W
/
MAX_COL
+
GAP
);
child
.
y
=
row
*
(
H
/
MAX_ROW
+
GAP
);
child
.
y
=
row
*
(
H
/
MAX_ROW
+
GAP
);
pos
.
push
([
child
.
x
,
child
.
y
]);
pos
.
push
([
child
.
x
,
child
.
y
]);
// child.texture.addEventListener('update', () => {
child
.
addEventListener
(
engine
.
Event
.
COMPLETE
,
()
=>
{
child
.
addEventListener
(
engine
.
Event
.
COMPLETE
,
()
=>
{
const
uvs
=
new
Float32Array
([
const
uvs
=
new
Float32Array
([
col
/
MAX_COL
,
col
/
MAX_COL
,
...
@@ -36,6 +44,8 @@ export default (parent, url,MAX_COL,MAX_ROW) => {
...
@@ -36,6 +44,8 @@ export default (parent, url,MAX_COL,MAX_ROW) => {
});
});
}
}
}
}
picMap
[
url
]
=
spr
.
concat
([]);
posMap
[
url
]
=
pos
.
concat
([]);;
// console.log(spr);
// console.log(spr);
return
[
spr
,
pos
];
return
[
spr
,
pos
];
};
};
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