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
56c43ab8
Commit
56c43ab8
authored
Jun 03, 2020
by
汪欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
拼图
parent
7ebfecde
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
1014 additions
and
0 deletions
+1014
-0
pictures.json
dist/customs/pictures.json
+130
-0
pictures.rar
src/custom/pictures.rar
+0
-0
app.js
src/custom/pictures/debug/app.js
+74
-0
index.html
src/custom/pictures/debug/index.html
+51
-0
load-assets.js
src/custom/pictures/debug/load-assets.js
+52
-0
main.js
src/custom/pictures/debug/main.js
+194
-0
main.js.map
src/custom/pictures/debug/main.js.map
+1
-0
props.js
src/custom/pictures/debug/props.js
+7
-0
meta.json
src/custom/pictures/meta.json
+129
-0
GameView.ts
src/custom/pictures/src/game/GameView.ts
+228
-0
GameWrapper.ts
src/custom/pictures/src/game/GameWrapper.ts
+29
-0
object-pool-init.ts
src/custom/pictures/src/game/object-pool-init.ts
+14
-0
qietu.ts
src/custom/pictures/src/game/qietu.ts
+41
-0
utils.ts
src/custom/pictures/src/game/utils.ts
+34
-0
index.ts
src/custom/pictures/src/index.ts
+15
-0
props.ts
src/custom/pictures/src/props.ts
+15
-0
No files found.
dist/customs/pictures.json
0 → 100644
View file @
56c43ab8
{
"name"
:
"口红机"
,
"desc"
:
"口红机模块"
,
"props"
:
{
"playerPositionY"
:
{
"alias"
:
"玩家Y轴位置"
,
"type"
:
"number"
,
"default"
:
900
},
"rainScore"
:
{
"alias"
:
"接中雨滴获得分数"
,
"type"
:
"number"
,
"default"
:
1
},
"stoneScore"
:
{
"alias"
:
"接中石块获得分数"
,
"type"
:
"number"
,
"default"
:
-1
},
"speed"
:
{
"alias"
:
"道具掉落初始速度"
,
"type"
:
"number"
,
"default"
:
10
},
"maxSpeed"
:
{
"alias"
:
"道具掉落速度上限"
,
"type"
:
"number"
,
"default"
:
3
},
"gameOverCondition"
:
{
"alias"
:
"游戏结束条件(1:接到炸弹死亡,2:分数负数或接到炸弹死亡)"
,
"type"
:
"number"
,
"default"
:
1
}
},
"assets"
:
[
{
"name"
:
"玩家icon"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png"
,
"uuid"
:
"66f23d13-82a5-4cec-9496-301ec240d087"
,
"ext"
:
".png"
},
{
"name"
:
"雨滴"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png"
,
"uuid"
:
"264a6192-d7bf-45e8-8f15-6ba2c439a532"
,
"ext"
:
".png"
},
{
"name"
:
"炸弹"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png"
,
"uuid"
:
"eb88b42d-e151-4c1b-94b9-7c16f7bfac29"
,
"ext"
:
".png"
},
{
"name"
:
"石块"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png"
,
"uuid"
:
"ab1bdabc-21ba-46bf-9299-6c638f766c88"
,
"ext"
:
".png"
},
{
"name"
:
"水花"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga"
,
"uuid"
:
"b521bf94-20e1-44dd-8eca-d24996cbaeae"
,
"ext"
:
".svga"
},
{
"name"
:
"炸弹svga"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga"
,
"uuid"
:
"322edf39-805b-4e84-9d07-5573dfeebc0e"
,
"ext"
:
".svga"
},
{
"name"
:
"玩家"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga"
,
"uuid"
:
"71d8dcbc-3931-471a-b585-b3ae01b25aa6"
,
"ext"
:
".svga"
}
],
"events"
:
{
"in"
:
{
"pictures-reset"
:
{
"alias"
:
"重置"
,
"data"
:
{
"goodsProbability"
:
"[0.2,0.5,0.3]道具概率(雨滴、石头、炸弹),所有概率相加为1"
,
"countDown"
:
"倒计时(s)"
,
"acceleratedSpeed"
:
"道具掉落加速度(单位:每秒)"
}
},
"pictures-start"
:
{
"alias"
:
"开始"
},
"pictures-revive"
:
{
"alias"
:
"复活"
},
"pictures-pause"
:
{
"alias"
:
"暂停"
},
"pictures-resume"
:
{
"alias"
:
"恢复"
},
"pictures-clear"
:
{
"alias"
:
"清空,通过reset事件恢复"
}
},
"out"
:
{
"pictures-score-update"
:
{
"alias"
:
"分数更新"
,
"data"
:
{
"score"
:
"分数"
}
},
"pictures-time-update"
:
{
"alias"
:
"倒计时更新"
,
"data"
:
{
"time"
:
"剩余时间"
}
},
"pictures-game-over"
:
{
"alias"
:
"游戏结束"
,
"data"
:
{
"score"
:
"分数"
,
"reason"
:
"结束原因(1:时间到了,2:玩家死亡)"
}
}
}
},
"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
function getIndexFromRC(row, col, maxCol) {
\r\n\t
var index = row * maxCol + col;
\r\n\t
return index;
\r\n\t
}
\r\n\t
function getRandomArray(array) {
\r\n\t
array.sort(function () {
\r\n\t
return .5 - Math.random();
\r\n\t
});
\r\n\t
}
\r\n\t
//# sourceMappingURL=utils.js.map
\n\n\t
var qietu = (function (parent, url, MAX_COL, MAX_ROW) {
\r\n\t
var W = 600;
\r\n\t
var H = 600;
\r\n\t
var GAP = 10;
\r\n\t
var spr = [];
\r\n\t
var pos = [];
\r\n\t
var _loop_1 = function (row) {
\r\n\t
var _loop_2 = function (col) {
\r\n\t
var child = engine.Sprite.fromImage(url);
\r\n\t
spr.push(child);
\r\n\t
child.scaleX = 1 / MAX_COL;
\r\n\t
child.scaleY = 1 / MAX_ROW;
\r\n\t
parent.addChild(child);
\r\n\t
child.x = col * (W / MAX_COL + GAP);
\r\n\t
child.y = row * (H / MAX_ROW + GAP);
\r\n\t
pos.push([child.x, child.y]);
\r\n\t
child.addEventListener(engine.Event.COMPLETE, function () {
\r\n\t
var uvs = new Float32Array([
\r\n\t
col / MAX_COL,
\r\n\t
row / MAX_ROW,
\r\n\t
(col + 1) / MAX_COL,
\r\n\t
row / MAX_ROW,
\r\n\t
(col + 1) / MAX_COL,
\r\n\t
(row + 1) / MAX_ROW,
\r\n\t
col / MAX_COL,
\r\n\t
(row + 1) / MAX_ROW,
\r\n\t
]);
\r\n\t
child.uvs = uvs;
\r\n\t
});
\r\n\t
};
\r\n\t
for (var col = 0; col < MAX_COL; col++) {
\r\n\t
_loop_2(col);
\r\n\t
}
\r\n\t
};
\r\n\t
for (var row = 0; row < MAX_ROW; row++) {
\r\n\t
_loop_1(row);
\r\n\t
}
\r\n\t
console.log(spr);
\r\n\t
return [spr, pos];
\r\n\t
});
\r\n\t
//# sourceMappingURL=qietu.js.map
\n\n\t
var MAX_COL = 3;
\r\n\t
var MAX_ROW = 3;
\r\n\t
var W = 600;
\r\n\t
var H = 600;
\r\n\t
var GAP = 10;
\r\n\t
var w = W / MAX_COL;
\r\n\t
var h = H / MAX_ROW;
\r\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.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
\r\n\t
return _this;
\r\n\t
}
\r\n\t
GameView.prototype.createRects = function () { };
\r\n\t
GameView.prototype.setup = function () {
\r\n\t
var url =
\"
http://yun.duiba.com.cn/aurora/assets/fb06e66c26f17b00f677367bd7571a1aa9b1ade4.png
\"
;
\r\n\t
var parent = new engine.Sprite();
\r\n\t
this.addChild(parent);
\r\n\t
var result = qietu(parent, url, MAX_COL, MAX_ROW);
\r\n\t
this.pictures = result[0];
\r\n\t
this.rightList = this.pictures.concat([]);
\r\n\t
var posList = result[1];
\r\n\t
getRandomArray(this.pictures);
\r\n\t
var i = 0;
\r\n\t
var len;
\r\n\t
len = this.pictures.length;
\r\n\t
console.log(len);
\r\n\t
for (; i < len; i++) {
\r\n\t
this.dragPic = this.pictures[i];
\r\n\t
this.pictures[i].addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDown, this);
\r\n\t
var _a = posList[i], x = _a[0], y = _a[1];
\r\n\t
this.dragPic.x = x;
\r\n\t
this.dragPic.y = y;
\r\n\t
}
\r\n\t
};
\r\n\t
GameView.prototype.onDown = function (e) {
\r\n\t
console.log(e);
\r\n\t
this.dragPic = e.target;
\r\n\t
this.localPicX = e.localX / MAX_COL;
\r\n\t
this.localPicY = e.localY / MAX_ROW;
\r\n\t
this.distanceX = this.dragPic.x;
\r\n\t
this.distanceY = this.dragPic.y;
\r\n\t
this.indexI = this.distanceX / (w + GAP);
\r\n\t
this.indexJ = this.distanceY / (h + GAP);
\r\n\t
this.index = (this.indexI - 1) * MAX_COL + this.indexJ;
\r\n\t
this.centerX = e.clientX + w / 2;
\r\n\t
this.centerY = e.clientY + h / 2;
\r\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\r\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\r\n\t
};
\r\n\t
GameView.prototype.stageOnUp = function (e) {
\r\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\r\n\t
var curJ = Math.floor(this.centerX / (w + GAP));
\r\n\t
var curI = Math.floor(this.centerY / (h + GAP));
\r\n\t
var positionId = (curI - 1) * MAX_ROW + curJ;
\r\n\t
if (curJ < MAX_COL && curI < MAX_ROW) {
\r\n\t
console.log(this.pictures[positionId]);
\r\n\t
console.log(this.pictures[this.index]);
\r\n\t
var index = getIndexFromRC(curI, curJ, MAX_COL);
\r\n\t
console.log(index);
\r\n\t
var dropPic = this.pictures[index];
\r\n\t
var dropPicX = dropPic.x;
\r\n\t
var dropPicy = dropPic.y;
\r\n\t
dropPic.x = this.distanceX;
\r\n\t
dropPic.y = this.distanceY;
\r\n\t
this.dragPic.x = dropPicX;
\r\n\t
this.dragPic.y = dropPicy;
\r\n\t
var dropPicIndex = this.pictures.indexOf(dropPic);
\r\n\t
var dragPicIndex = this.pictures.indexOf(this.dragPic);
\r\n\t
this.pictures[dropPicIndex] = this.dragPic;
\r\n\t
this.pictures[dragPicIndex] = dropPic;
\r\n\t
var result = true;
\r\n\t
for (var j = 0; j < this.rightList.length; j++) {
\r\n\t
if (this.rightList[j] != this.pictures[j]) {
\r\n\t
result = false;
\r\n\t
break;
\r\n\t
}
\r\n\t
}
\r\n\t
if (result) {
\r\n\t
console.log('拼图成功!');
\r\n\t
}
\r\n\t
}
\r\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\r\n\t
};
\r\n\t
GameView.prototype.onMove = function (e) {
\r\n\t
this.dragPic.x = e.stageX - this.localPicX;
\r\n\t
this.dragPic.y = e.stageY - this.localPicY;
\r\n\t
this.centerX = this.dragPic.x + w / 2;
\r\n\t
this.centerY = this.dragPic.y + h / 2;
\r\n\t
console.log(this.centerX, this.centerY,
\"
图片中心位置
\"
);
\r\n\t
console.log(e.localX, e.localY, e.stageX, e.stageY);
\r\n\t
console.log(
\"
====================================
\"
);
\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
var gameView = _this._gameView = new GameView();
\r\n\t
_this.addChild(gameView);
\r\n\t
console.log(
\"
hello world.
\"
);
\r\n\t
return _this;
\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/pictures.rar
0 → 100644
View file @
56c43ab8
File added
src/custom/pictures/debug/app.js
0 → 100644
View file @
56c43ab8
/**
* Created by renjianfeng on 2020-03-13.
*/
const
customId
=
'pictures'
;
(
async
function
()
{
let
customModule
=
await
fetch
(
`../meta.json`
);
customModule
=
await
customModule
.
json
();
console
.
log
(
customModule
);
await
loadAssets
(
customModule
.
assets
);
launchWithCustomModule
(
customModule
);
})();
function
launchWithCustomModule
(
customModule
)
{
//engine.registerCustomCodeModule(customModule);
engine
.
registerCustomModule
(
customId
,
window
[
customId
]);
const
{
props
:
propsOption
,
assets
}
=
customModule
;
let
props
=
engine
.
computeProps
(
customModuleProps
,
propsOption
);
const
customModuleIns
=
{
id
:
customId
,
props
,
assets
,
};
engine
.
registerCustomModules
([
customModuleIns
]);
engine
.
launchWithConfig
({
options
:
{
entrySceneView
:
'entry'
,
},
assets
:
[],
views
:
[{
name
:
'entry'
,
type
:
'node'
,
properties
:
{
x
:
0
,
y
:
0
,
}
}],
customs
:
[],
},
null
,
function
()
{
setTimeout
(()
=>
{
engine
.
addCustomModule
(
customId
,
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
));
},
100
);
setTimeout
(()
=>
{
engine
.
globalEvent
.
dispatchEvent
(
'pictures-reset'
,
{
"goodsProbability"
:
[
0.8
,
0.1
,
0.1
],
"countDown"
:
30
,
"acceleratedSpeed"
:
0.1
});
engine
.
globalEvent
.
dispatchEvent
(
'pictures-start'
);
},
500
);
});
engine
.
globalEvent
.
addEventListener
(
'pictures-time-update'
,
(
e
)
=>
{
console
.
log
(
e
.
type
,
e
.
data
);
});
engine
.
globalEvent
.
addEventListener
(
'pictures-score-update'
,
(
e
)
=>
{
console
.
log
(
e
.
type
,
e
.
data
);
});
engine
.
globalEvent
.
addEventListener
(
'pictures-game-over'
,
(
e
)
=>
{
console
.
log
(
e
.
type
,
e
.
data
);
});
}
function
getAssetByUUID
(
uuid
)
{
return
engine
.
resolveCustomAsset
(
customId
,
uuid
);
}
function
getProps
()
{
return
engine
.
getProps
(
customId
);
}
src/custom/pictures/debug/index.html
0 → 100644
View file @
56c43ab8
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
美食从天而降
</title>
<meta
name=
"viewport"
content=
"width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"
/>
<meta
name=
"apple-mobile-web-app-capable"
content=
"yes"
/>
<meta
name=
"full-screen"
content=
"true"
/>
<meta
name=
"screen-orientation"
content=
"portrait"
/>
<meta
name=
"x5-fullscreen"
content=
"true"
/>
<meta
name=
"360-fullscreen"
content=
"true"
/>
<style>
html
,
body
{
padding
:
0
;
margin
:
0
;
border
:
0
;
width
:
100%
;
height
:
100%
;
overflow
:
hidden
;
position
:
absolute
;
background-color
:
red
;
}
.game-container
{
width
:
100%
;
height
:
100%
;
line-height
:
0
;
font-size
:
0
;
}
</style>
</head>
<body>
<div
id=
"game-container"
class=
"game-container"
></div>
<script
crossorigin=
"anonymous"
src=
"//yun.duiba.com.cn/editor/zeroing/libs/engine.1de84ff79dba19e949088de63aa75af51a515e5c.js"
></script>
<script
crossorigin=
"anonymous"
src=
"//yun.duiba.com.cn/editor/zeroing/libs/svga.fd3923ae6e664251ca7981801a65809cc5f36bc3.js"
></script>
<!-- <script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.ebc906f6b50b8da0a669f77027981d5f3cb560ce.js"></script> -->
<!-- <script src="http://localhost:4002/debug/engine.js"></script>
<script src="http://localhost:4003/debug/engine-svga.js"></script> -->
<!--<script src="//yun.duiba.com.cn/editor/zeroing/libs/engine.9a9dbfda4cb2dd5508ecddfe3d95dfd88063f7b5.js"></script>-->
<script
src=
"app.js"
></script>
<script
src=
"props.js"
></script>
<script
src=
"load-assets.js"
></script>
<script
src=
"main.js"
></script>
<script>
</script>
</body>
\ No newline at end of file
src/custom/pictures/debug/load-assets.js
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2020-01-21.
*/
const
assets
=
[
{
"name"
:
"玩家icon"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png"
,
"uuid"
:
"66f23d13-82a5-4cec-9496-301ec240d087"
,
"ext"
:
".png"
},
{
"name"
:
"雨滴"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png"
,
"uuid"
:
"264a6192-d7bf-45e8-8f15-6ba2c439a532"
,
"ext"
:
".png"
},
{
"name"
:
"炸弹"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png"
,
"uuid"
:
"eb88b42d-e151-4c1b-94b9-7c16f7bfac29"
,
"ext"
:
".png"
},
{
"name"
:
"石块"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png"
,
"uuid"
:
"ab1bdabc-21ba-46bf-9299-6c638f766c88"
,
"ext"
:
".png"
},
{
"name"
:
"水花"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga"
,
"uuid"
:
"b521bf94-20e1-44dd-8eca-d24996cbaeae"
,
"ext"
:
".svga"
},
{
"name"
:
"炸弹"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga"
,
"uuid"
:
"322edf39-805b-4e84-9d07-5573dfeebc0e"
,
"ext"
:
".svga"
},
{
"name"
:
"玩家"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga"
,
"uuid"
:
"71d8dcbc-3931-471a-b585-b3ae01b25aa6"
,
"ext"
:
".svga"
}
];
function
loadAssets
(
customModuleAssets
,
onProgress
,
onComplete
){
return
engine
.
loadAssets
(
assets
.
concat
(...
customModuleAssets
),
onProgress
,
onComplete
);
}
src/custom/pictures/debug/main.js
0 → 100644
View file @
56c43ab8
(
function
(
global
,
factory
)
{
typeof
exports
===
'object'
&&
typeof
module
!==
'undefined'
?
module
.
exports
=
factory
(
require
(
'tslib'
))
:
typeof
define
===
'function'
&&
define
.
amd
?
define
([
'tslib'
],
factory
)
:
(
global
=
global
||
self
,
global
.
pictures
=
factory
(
global
.
tslib
));
}(
this
,
(
function
(
tslib
)
{
'use strict'
;
function
getIndexFromRC
(
row
,
col
,
maxCol
)
{
var
index
=
row
*
maxCol
+
col
;
return
index
;
}
function
getRandomArray
(
array
)
{
array
.
sort
(
function
()
{
return
.
5
-
Math
.
random
();
});
}
var
qietu
=
(
function
(
parent
,
url
,
MAX_COL
,
MAX_ROW
)
{
var
W
=
600
;
var
H
=
600
;
var
GAP
=
10
;
var
spr
=
[];
var
pos
=
[];
var
_loop_1
=
function
(
row
)
{
var
_loop_2
=
function
(
col
)
{
var
child
=
engine
.
Sprite
.
fromImage
(
url
);
spr
.
push
(
child
);
child
.
scaleX
=
1
/
MAX_COL
;
child
.
scaleY
=
1
/
MAX_ROW
;
parent
.
addChild
(
child
);
child
.
x
=
col
*
(
W
/
MAX_COL
+
GAP
);
child
.
y
=
row
*
(
H
/
MAX_ROW
+
GAP
);
pos
.
push
([
child
.
x
,
child
.
y
]);
child
.
addEventListener
(
engine
.
Event
.
COMPLETE
,
function
()
{
var
uvs
=
new
Float32Array
([
col
/
MAX_COL
,
row
/
MAX_ROW
,
(
col
+
1
)
/
MAX_COL
,
row
/
MAX_ROW
,
(
col
+
1
)
/
MAX_COL
,
(
row
+
1
)
/
MAX_ROW
,
col
/
MAX_COL
,
(
row
+
1
)
/
MAX_ROW
,
]);
child
.
uvs
=
uvs
;
});
};
for
(
var
col
=
0
;
col
<
MAX_COL
;
col
++
)
{
_loop_2
(
col
);
}
};
for
(
var
row
=
0
;
row
<
MAX_ROW
;
row
++
)
{
_loop_1
(
row
);
}
console
.
log
(
spr
);
return
[
spr
,
pos
];
});
var
MAX_COL
=
3
;
var
MAX_ROW
=
3
;
var
W
=
600
;
var
H
=
600
;
var
GAP
=
10
;
var
w
=
W
/
MAX_COL
;
var
h
=
H
/
MAX_ROW
;
var
GameView
=
(
function
(
_super
)
{
tslib
.
__extends
(
GameView
,
_super
);
function
GameView
()
{
var
_this
=
_super
.
call
(
this
)
||
this
;
_this
.
countTime
=
10
;
_this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
_this
.
setup
,
_this
);
return
_this
;
}
GameView
.
prototype
.
createRects
=
function
()
{
};
GameView
.
prototype
.
setup
=
function
()
{
var
_this
=
this
;
var
url
=
"http://yun.duiba.com.cn/aurora/assets/fb06e66c26f17b00f677367bd7571a1aa9b1ade4.png"
;
var
parent
=
new
engine
.
Sprite
();
this
.
addChild
(
parent
);
var
timeContainer
=
new
engine
.
Rect
();
this
.
addChild
(
timeContainer
);
setTimeout
(
function
()
{
_this
.
countTime
--
;
},
1000
);
if
(
this
.
countTime
===
0
)
{
console
.
log
(
"时间到!"
);
}
var
result
=
qietu
(
parent
,
url
,
MAX_COL
,
MAX_ROW
);
this
.
pictures
=
result
[
0
];
this
.
rightList
=
this
.
pictures
.
concat
([]);
var
posList
=
result
[
1
];
getRandomArray
(
this
.
pictures
);
var
i
=
0
;
var
len
;
len
=
this
.
pictures
.
length
;
console
.
log
(
len
);
for
(;
i
<
len
;
i
++
)
{
this
.
dragPic
=
this
.
pictures
[
i
];
this
.
pictures
[
i
].
addEventListener
(
engine
.
MouseEvent
.
MOUSE_DOWN
,
this
.
onDown
,
this
);
var
_a
=
posList
[
i
],
x
=
_a
[
0
],
y
=
_a
[
1
];
this
.
dragPic
.
x
=
x
;
this
.
dragPic
.
y
=
y
;
}
};
GameView
.
prototype
.
onDown
=
function
(
e
)
{
console
.
log
(
e
);
this
.
dragPic
=
e
.
target
;
this
.
localPicX
=
e
.
localX
/
MAX_COL
;
this
.
localPicY
=
e
.
localY
/
MAX_ROW
;
this
.
distanceX
=
this
.
dragPic
.
x
;
this
.
distanceY
=
this
.
dragPic
.
y
;
this
.
indexI
=
this
.
distanceX
/
(
w
+
GAP
);
this
.
indexJ
=
this
.
distanceY
/
(
h
+
GAP
);
this
.
index
=
(
this
.
indexI
-
1
)
*
MAX_COL
+
this
.
indexJ
;
this
.
centerX
=
e
.
clientX
+
w
/
2
;
this
.
centerY
=
e
.
clientY
+
h
/
2
;
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
};
GameView
.
prototype
.
stageOnUp
=
function
(
e
)
{
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
var
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
var
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
if
(
curJ
<
MAX_COL
&&
curI
<
MAX_ROW
)
{
var
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
console
.
log
(
index
);
var
dropPic
=
this
.
pictures
[
index
];
var
dropPicX
=
dropPic
.
x
;
var
dropPicy
=
dropPic
.
y
;
dropPic
.
x
=
this
.
distanceX
;
dropPic
.
y
=
this
.
distanceY
;
this
.
dragPic
.
x
=
dropPicX
;
this
.
dragPic
.
y
=
dropPicy
;
var
dropPicIndex
=
this
.
pictures
.
indexOf
(
dropPic
);
var
dragPicIndex
=
this
.
pictures
.
indexOf
(
this
.
dragPic
);
this
.
pictures
[
dropPicIndex
]
=
this
.
dragPic
;
this
.
pictures
[
dragPicIndex
]
=
dropPic
;
var
result
=
true
;
for
(
var
j
=
0
;
j
<
this
.
rightList
.
length
;
j
++
)
{
if
(
this
.
rightList
[
j
]
!=
this
.
pictures
[
j
])
{
result
=
false
;
break
;
}
}
if
(
result
)
{
console
.
log
(
'拼图成功!'
);
}
}
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
};
GameView
.
prototype
.
onMove
=
function
(
e
)
{
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
;
this
.
centerX
=
this
.
dragPic
.
x
+
w
/
2
;
this
.
centerY
=
this
.
dragPic
.
y
+
h
/
2
;
console
.
log
(
this
.
centerX
,
this
.
centerY
,
"图片中心位置"
);
console
.
log
(
e
.
localX
,
e
.
localY
,
e
.
stageX
,
e
.
stageY
);
console
.
log
(
"===================================="
);
};
return
GameView
;
}(
engine
.
Container
));
var
GameWrapper
=
(
function
(
_super
)
{
tslib
.
__extends
(
GameWrapper
,
_super
);
function
GameWrapper
()
{
var
_this
=
_super
.
call
(
this
)
||
this
;
var
gameView
=
_this
.
_gameView
=
new
GameView
();
_this
.
addChild
(
gameView
);
console
.
log
(
"hello world."
);
return
_this
;
}
return
GameWrapper
;
}(
engine
.
Container
));
var
props
=
{};
function
prepareProps
()
{
var
metaProps
=
getProps
();
engine
.
injectProp
(
props
,
metaProps
);
}
function
injectProps
(
p
)
{
engine
.
injectProp
(
props
,
p
);
}
function
index
(
props
)
{
prepareProps
();
injectProps
(
props
);
var
instance
=
new
GameWrapper
();
return
instance
;
}
return
index
;
})));
//# sourceMappingURL=main.js.map
\ No newline at end of file
src/custom/pictures/debug/main.js.map
0 → 100644
View file @
56c43ab8
{"version":3,"file":"index.js","sources":["src/custom/pictures/src/game/utils.ts","src/custom/pictures/src/game/qietu.ts","src/custom/pictures/src/game/GameView.ts","src/custom/pictures/src/game/GameWrapper.ts","src/custom/pictures/src/props.ts","src/custom/pictures/src/index.ts"],"sourcesContent":["/**\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}","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 2018/8/16.\r\n */\r\n\r\nimport { props } from \"../props\";\r\nimport { playSound, createSvga, getIndexFromRC, getRandomArray } from \"./utils\";\r\nimport ObjectPool = engine.ObjectPool;\r\nimport { getTextureByName } from \"./utils\";\r\nimport { PoolName } from \"./object-pool-init\";\r\nimport qietu from \"./qietu\";\r\n\r\nconst MAX_COL = 3;\r\nconst MAX_ROW = 3;\r\nconst W = 600;\r\nconst H = 600;\r\nconst GAP = 10;\r\n// 每张图片宽\r\nconst w = W / MAX_COL;\r\n// 每张图片高\r\nconst h = H / MAX_ROW;\r\nexport default class GameView extends engine.Container {\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 // curPic\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 countTime = 10\r\n\r\n createRects() {}\r\n setup() {\r\n // debugger;\r\n const url =\r\n \"http://yun.duiba.com.cn/aurora/assets/fb06e66c26f17b00f677367bd7571a1aa9b1ade4.png\";\r\n // 图片容器\r\n const parent = new engine.Sprite();\r\n this.addChild(parent);\r\n\r\n\r\n // 创建一个显示时间的容器\r\n const timeContainer = new engine.Rect()\r\n this.addChild(timeContainer)\r\n\r\n setTimeout(()=>{\r\n this.countTime--;\r\n },1000)\r\n\r\n if(this.countTime === 0){\r\n console.log(\"时间到!\")\r\n }\r\n\r\n\r\n // let pictures\r\n // 图片一维数组\r\n // this.pictures = qietu(parent, url,MAX_COL,MAX_ROW);\r\n const result = qietu(parent, url, 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 j = 0;\r\n // 数组长度\r\n let len;\r\n len = this.pictures.length;\r\n console.log(len);\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 onDown(e: engine.MouseEvent) {\r\n console.log(e);\r\n // this.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this)\r\n\r\n // 创建一个图片对象接收当前位置信息\r\n this.dragPic = e.target;\r\n\r\n // let currentpic = this.currentPic;\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\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 // 图片第几行第几列\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 // console.log(this.pictures[this.index]);\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 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\t\t console.log('拼图成功!')\r\n \r\n }\r\n }\r\n\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 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 console.log(this.centerX, this.centerY, \"图片中心位置\");\r\n\r\n\r\n // 记录移动图片的位置\r\n\r\n console.log(e.localX, e.localY, e.stageX, e.stageY);\r\n console.log(\"====================================\");\r\n\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\tprivate _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\t//创建实例\r\n\t\tlet gameView = this._gameView = new GameView();\r\n\t\tthis.addChild(gameView);\r\n\r\n\t\tconsole.log(\"hello world.\");\r\n\t}\r\n\r\n\t\r\n\r\n}\r\n","/**\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","/**\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":";;;;;;UAqBgB,cAAc,CAAC,GAAG,EAAC,GAAG,EAAC,MAAM;KAC5C,IAAI,KAAK,GAAG,GAAG,GAAG,MAAM,GAAG,GAAG,CAAA;KAC9B,OAAO,KAAK,CAAA;CACb,CAAC;UAKe,cAAc,CAAC,KAAK;KACnC,KAAK,CAAC,IAAI,CAAC;SACV,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAA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C;SAExB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;;MAC5B;KAIF,kBAAC;CAAD,CAAC,CApBgC,MAAM,CAAC,SAAS,GAoBhD;;CCxBM,IAAI,KAAK,GAAQ,EAAE,CAAC;AAE3B,UAAgB,YAAY;KAC3B,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;KAE3B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CACrC,CAAC;AAED,UAAgB,WAAW,CAAC,CAAC;KAC5B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7B,CAAC;;iBCPwB,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;;;;;;;;"}
\ No newline at end of file
src/custom/pictures/debug/props.js
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2020-01-21.
*/
let
customModuleProps
=
{
};
src/custom/pictures/meta.json
0 → 100644
View file @
56c43ab8
{
"name"
:
"口红机"
,
"desc"
:
"口红机模块"
,
"props"
:
{
"playerPositionY"
:
{
"alias"
:
"玩家Y轴位置"
,
"type"
:
"number"
,
"default"
:
900
},
"rainScore"
:
{
"alias"
:
"接中雨滴获得分数"
,
"type"
:
"number"
,
"default"
:
1
},
"stoneScore"
:
{
"alias"
:
"接中石块获得分数"
,
"type"
:
"number"
,
"default"
:
-1
},
"speed"
:
{
"alias"
:
"道具掉落初始速度"
,
"type"
:
"number"
,
"default"
:
10
},
"maxSpeed"
:
{
"alias"
:
"道具掉落速度上限"
,
"type"
:
"number"
,
"default"
:
3
},
"gameOverCondition"
:
{
"alias"
:
"游戏结束条件(1:接到炸弹死亡,2:分数负数或接到炸弹死亡)"
,
"type"
:
"number"
,
"default"
:
1
}
},
"assets"
:
[
{
"name"
:
"玩家icon"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/50a7212a113175fa18c866b005d98f07c558dc77.png"
,
"uuid"
:
"66f23d13-82a5-4cec-9496-301ec240d087"
,
"ext"
:
".png"
},
{
"name"
:
"雨滴"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/8564c8c9be3aead71b05a0bab8d7d07ac3f778a1.png"
,
"uuid"
:
"264a6192-d7bf-45e8-8f15-6ba2c439a532"
,
"ext"
:
".png"
},
{
"name"
:
"炸弹"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/171e92283cd13c013ee1b76d28d252ff08815d47.png"
,
"uuid"
:
"eb88b42d-e151-4c1b-94b9-7c16f7bfac29"
,
"ext"
:
".png"
},
{
"name"
:
"石块"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/99b0af0c59fe79a415a3f032149cfacc27e3ac2c.png"
,
"uuid"
:
"ab1bdabc-21ba-46bf-9299-6c638f766c88"
,
"ext"
:
".png"
},
{
"name"
:
"水花"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/93d37b4a0e367e80e375308a6b4414d72d7666fc.svga"
,
"uuid"
:
"b521bf94-20e1-44dd-8eca-d24996cbaeae"
,
"ext"
:
".svga"
},
{
"name"
:
"炸弹svga"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/4dd18f0689c663bbcf710a7afc4d929084d97d36.svga"
,
"uuid"
:
"322edf39-805b-4e84-9d07-5573dfeebc0e"
,
"ext"
:
".svga"
},
{
"name"
:
"玩家"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/b66300c5d4f27134b0aac3dc90a3220e8ae572eb.svga"
,
"uuid"
:
"71d8dcbc-3931-471a-b585-b3ae01b25aa6"
,
"ext"
:
".svga"
}
],
"events"
:
{
"in"
:
{
"pictures-reset"
:
{
"alias"
:
"重置"
,
"data"
:
{
"goodsProbability"
:
"[0.2,0.5,0.3]道具概率(雨滴、石头、炸弹),所有概率相加为1"
,
"countDown"
:
"倒计时(s)"
,
"acceleratedSpeed"
:
"道具掉落加速度(单位:每秒)"
}
},
"pictures-start"
:
{
"alias"
:
"开始"
},
"pictures-revive"
:
{
"alias"
:
"复活"
},
"pictures-pause"
:
{
"alias"
:
"暂停"
},
"pictures-resume"
:
{
"alias"
:
"恢复"
},
"pictures-clear"
:
{
"alias"
:
"清空,通过reset事件恢复"
}
},
"out"
:
{
"pictures-score-update"
:
{
"alias"
:
"分数更新"
,
"data"
:
{
"score"
:
"分数"
}
},
"pictures-time-update"
:
{
"alias"
:
"倒计时更新"
,
"data"
:
{
"time"
:
"剩余时间"
}
},
"pictures-game-over"
:
{
"alias"
:
"游戏结束"
,
"data"
:
{
"score"
:
"分数"
,
"reason"
:
"结束原因(1:时间到了,2:玩家死亡)"
}
}
}
}
}
\ No newline at end of file
src/custom/pictures/src/game/GameView.ts
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2018/8/16.
*/
import
{
props
}
from
"../props"
;
import
{
playSound
,
createSvga
,
getIndexFromRC
,
getRandomArray
}
from
"./utils"
;
import
ObjectPool
=
engine
.
ObjectPool
;
import
{
getTextureByName
}
from
"./utils"
;
import
{
PoolName
}
from
"./object-pool-init"
;
import
qietu
from
"./qietu"
;
const
MAX_COL
=
3
;
const
MAX_ROW
=
3
;
const
W
=
600
;
const
H
=
600
;
const
GAP
=
10
;
// 每张图片宽
const
w
=
W
/
MAX_COL
;
// 每张图片高
const
h
=
H
/
MAX_ROW
;
export
default
class
GameView
extends
engine
.
Container
{
constructor
()
{
super
();
this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
setup
,
this
);
}
//当前图片对象
dragPic
;
localPicX
;
localPicY
;
distanceX
;
distanceY
;
centerX
:
number
;
centerY
:
number
;
pictures
;
// curPic
// 点击图片时的索引
index
;
indexI
:
number
;
indexJ
:
number
;
rightList
:
engine
.
Sprite
[];
// 倒计时时间
countTime
=
10
createRects
()
{}
setup
()
{
// debugger;
const
url
=
"http://yun.duiba.com.cn/aurora/assets/fb06e66c26f17b00f677367bd7571a1aa9b1ade4.png"
;
// 图片容器
const
parent
=
new
engine
.
Sprite
();
this
.
addChild
(
parent
);
// 创建一个显示时间的容器
const
timeContainer
=
new
engine
.
Rect
()
this
.
addChild
(
timeContainer
)
setTimeout
(()
=>
{
this
.
countTime
--
;
},
1000
)
if
(
this
.
countTime
===
0
){
console
.
log
(
"时间到!"
)
}
// let pictures
// 图片一维数组
// this.pictures = qietu(parent, url,MAX_COL,MAX_ROW);
const
result
=
qietu
(
parent
,
url
,
MAX_COL
,
MAX_ROW
);
this
.
pictures
=
result
[
0
];
this
.
rightList
=
this
.
pictures
.
concat
([]);
const
posList
=
result
[
1
];
getRandomArray
(
this
.
pictures
);
let
i
=
0
;
// let j = 0;
// 数组长度
let
len
;
len
=
this
.
pictures
.
length
;
console
.
log
(
len
);
for
(;
i
<
len
;
i
++
)
{
this
.
dragPic
=
this
.
pictures
[
i
];
this
.
pictures
[
i
].
addEventListener
(
engine
.
MouseEvent
.
MOUSE_DOWN
,
this
.
onDown
,
this
);
const
[
x
,
y
]
=
posList
[
i
];
this
.
dragPic
.
x
=
x
;
this
.
dragPic
.
y
=
y
;
}
}
onDown
(
e
:
engine
.
MouseEvent
)
{
console
.
log
(
e
);
// this.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this)
// 创建一个图片对象接收当前位置信息
this
.
dragPic
=
e
.
target
;
// let currentpic = this.currentPic;
// 鼠标的偏移量
this
.
localPicX
=
e
.
localX
/
MAX_COL
;
this
.
localPicY
=
e
.
localY
/
MAX_ROW
;
// 最开始图片的位置
this
.
distanceX
=
this
.
dragPic
.
x
;
this
.
distanceY
=
this
.
dragPic
.
y
;
// 最开始点击的图片的索引值
this
.
indexI
=
this
.
distanceX
/
(
w
+
GAP
);
this
.
indexJ
=
this
.
distanceY
/
(
h
+
GAP
);
this
.
index
=
(
this
.
indexI
-
1
)
*
MAX_COL
+
this
.
indexJ
;
// 图片的中心位置
this
.
centerX
=
e
.
clientX
+
w
/
2
;
this
.
centerY
=
e
.
clientY
+
h
/
2
;
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
}
stageOnUp
(
e
)
{
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
// 判断图片是否进入另一张图片的范围内
// 图片第几行第几列
let
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
let
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
// 点击图片的位置
if
(
curJ
<
MAX_COL
&&
curI
<
MAX_ROW
)
{
// 要交换的图片
// console.log(this.pictures[this.index]);
// 获取交互图片的索引值
let
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
console
.
log
(
index
);
//要交换的图片
let
dropPic
=
this
.
pictures
[
index
];
let
dropPicX
=
dropPic
.
x
;
let
dropPicy
=
dropPic
.
y
;
dropPic
.
x
=
this
.
distanceX
;
dropPic
.
y
=
this
.
distanceY
;
this
.
dragPic
.
x
=
dropPicX
;
this
.
dragPic
.
y
=
dropPicy
;
// 交换之后索引也需要交换
const
dropPicIndex
=
this
.
pictures
.
indexOf
(
dropPic
);
const
dragPicIndex
=
this
.
pictures
.
indexOf
(
this
.
dragPic
);
this
.
pictures
[
dropPicIndex
]
=
this
.
dragPic
;
this
.
pictures
[
dragPicIndex
]
=
dropPic
;
let
result
=
true
;
for
(
let
j
=
0
;
j
<
this
.
rightList
.
length
;
j
++
)
{
if
(
this
.
rightList
[
j
]
!=
this
.
pictures
[
j
])
{
result
=
false
;
break
;
}
}
if
(
result
)
{
console
.
log
(
'拼图成功!'
)
}
}
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
}
onMove
(
e
:
engine
.
MouseEvent
)
{
// 当前图片的位置
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
;
// 当前图片的中心位置
this
.
centerX
=
this
.
dragPic
.
x
+
w
/
2
;
this
.
centerY
=
this
.
dragPic
.
y
+
h
/
2
;
console
.
log
(
this
.
centerX
,
this
.
centerY
,
"图片中心位置"
);
// 记录移动图片的位置
console
.
log
(
e
.
localX
,
e
.
localY
,
e
.
stageX
,
e
.
stageY
);
console
.
log
(
"===================================="
);
}
}
src/custom/pictures/src/game/GameWrapper.ts
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2020-01-09.
*/
import
GameView
from
"./GameView"
;
import
{
injectProps
}
from
"../props"
;
export
class
GameWrapper
extends
engine
.
Container
{
private
_status
;
private
_gameView
:
GameView
;
constructor
()
{
super
();
//创建实例
let
gameView
=
this
.
_gameView
=
new
GameView
();
this
.
addChild
(
gameView
);
console
.
log
(
"hello world."
);
}
}
src/custom/pictures/src/game/object-pool-init.ts
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2020-02-03.
*/
import
{
Goods
}
from
"./Goods"
;
import
ObjectPool
=
engine
.
ObjectPool
;
export
const
PoolName
:
string
=
'goods'
;
ObjectPool
.
registerPool
(
PoolName
,
function
()
{
return
new
Goods
();
},
function
(
item
:
Goods
,
data
)
{
item
.
reset
();
});
src/custom/pictures/src/game/qietu.ts
0 → 100644
View file @
56c43ab8
export
default
(
parent
,
url
,
MAX_COL
,
MAX_ROW
)
=>
{
const
W
=
600
;
const
H
=
600
;
const
GAP
=
10
;
const
spr
=
[];
const
pos
=
[]
for
(
let
row
=
0
;
row
<
MAX_ROW
;
row
++
)
{
for
(
let
col
=
0
;
col
<
MAX_COL
;
col
++
)
{
const
child
=
engine
.
Sprite
.
fromImage
(
url
);
spr
.
push
(
child
);
child
.
scaleX
=
1
/
MAX_COL
;
child
.
scaleY
=
1
/
MAX_ROW
;
parent
.
addChild
(
child
);
child
.
x
=
col
*
(
W
/
MAX_COL
+
GAP
);
child
.
y
=
row
*
(
H
/
MAX_ROW
+
GAP
);
pos
.
push
([
child
.
x
,
child
.
y
]);
child
.
addEventListener
(
engine
.
Event
.
COMPLETE
,
()
=>
{
const
uvs
=
new
Float32Array
([
col
/
MAX_COL
,
row
/
MAX_ROW
,
(
col
+
1
)
/
MAX_COL
,
row
/
MAX_ROW
,
(
col
+
1
)
/
MAX_COL
,
(
row
+
1
)
/
MAX_ROW
,
col
/
MAX_COL
,
(
row
+
1
)
/
MAX_ROW
,
]);
child
.
uvs
=
uvs
;
// spr.push(child);
});
}
}
console
.
log
(
spr
);
return
[
spr
,
pos
];
};
src/custom/pictures/src/game/utils.ts
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2020-01-21.
*/
export
function
getTexture
(
uuid
)
{
return
engine
.
Texture
.
from
(
getAssetByUUID
(
uuid
).
uuid
);
}
export
function
getTextureByName
(
name
)
{
return
getTexture
(
engine
.
getAssetByName
(
name
).
uuid
);
}
export
function
playSound
(
name
)
{
engine
.
playSound
(
engine
.
getAssetByName
(
name
).
uuid
,
{
keep
:
true
});
}
export
function
createSvga
(
name
,
anchorName
?)
{
let
inst
=
new
svga
.
Svga
();
inst
.
source
=
'asset://'
+
engine
.
getAssetByName
(
name
).
uuid
;
return
inst
;
}
export
function
getIndexFromRC
(
row
,
col
,
maxCol
){
let
index
=
row
*
maxCol
+
col
return
index
}
export
function
getRandomArray
(
array
){
array
.
sort
(
function
()
{
return
.
5
-
Math
.
random
();
});
}
\ No newline at end of file
src/custom/pictures/src/index.ts
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2019-11-20.
*/
import
{
GameWrapper
}
from
"./game/GameWrapper"
;
import
{
injectProps
,
prepareProps
}
from
"./props"
;
export
default
function
(
props
)
{
prepareProps
();
injectProps
(
props
);
let
instance
=
new
GameWrapper
();
return
instance
;
}
src/custom/pictures/src/props.ts
0 → 100644
View file @
56c43ab8
/**
* Created by rockyl on 2020-01-21.
*/
export
let
props
:
any
=
{};
export
function
prepareProps
()
{
let
metaProps
=
getProps
();
engine
.
injectProp
(
props
,
metaProps
);
}
export
function
injectProps
(
p
)
{
engine
.
injectProp
(
props
,
p
);
}
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