Commit 53727adb authored by wildfirecode's avatar wildfirecode

1

parent 56c43ab8
{
"name": "口红机",
"desc": "口红机模块",
"name": "拼图",
"desc": "拼图模块1.0",
"props": {
"playerPositionY": {
"alias": "玩家Y轴位置",
"MAX_COL": {
"alias": "图片分成几列",
"type": "number",
"default": 900
"default": 2
},
"rainScore": {
"alias": "接中雨滴获得分数",
"MAX_ROW": {
"alias": "图片分成几行",
"type": "number",
"default": 1
"default": 2
},
"stoneScore": {
"alias": "接中石块获得分数",
"W": {
"alias": "图片的宽度",
"type": "number",
"default": -1
"default": 600
},
"speed": {
"alias": "道具掉落初始速度",
"H": {
"alias": "图片的高度",
"type": "number",
"default": 10
"default": 600
},
"maxSpeed": {
"alias": "道具掉落速度上限",
"GAP": {
"alias": "图片间隙",
"type": "number",
"default": 3
"default": 10
},
"gameOverCondition": {
"alias": "游戏结束条件(1:接到炸弹死亡,2:分数负数或接到炸弹死亡)",
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 1
"default": 10
}
},
"assets": [
{
"name": "玩家icon",
"name": "测试资源",
"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": {
......@@ -104,27 +68,26 @@
}
},
"out": {
"pictures-score-update": {
"alias": "分数更新",
"data": {
"score": "分数"
}
},
"pictures-time-update": {
"alias": "倒计时更新",
"data": {
"time": "剩余时间"
}
},
"pictures-game-over": {
"pictures-game-fail": {
"alias": "游戏结束",
"data": {
"score": "分数",
"reason": "结束原因(1:时间到了,2:玩家死亡)"
"reason": "结束原因(1:时间到了)"
}
},
"pictures-game-success": {
"alias": "游戏成功",
"data": {
"time": "游戏消耗时间"
}
}
}
},
"id": "pictures",
"code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof 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\tfunction getIndexFromRC(row, col, maxCol) {\r\n\t var index = row * maxCol + col;\r\n\t return index;\r\n\t}\r\n\tfunction 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\tvar 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\tvar MAX_COL = 3;\r\n\tvar MAX_ROW = 3;\r\n\tvar W = 600;\r\n\tvar H = 600;\r\n\tvar GAP = 10;\r\n\tvar w = W / MAX_COL;\r\n\tvar h = H / MAX_ROW;\r\n\tvar 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\tvar 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\tvar props = {};\r\n\tfunction prepareProps() {\r\n\t var metaProps = getProps();\r\n\t engine.injectProp(props, metaProps);\r\n\t}\r\n\tfunction injectProps(p) {\r\n\t engine.injectProp(props, p);\r\n\t}\r\n\t//# sourceMappingURL=props.js.map\n\n\tfunction 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\treturn index;\n\n})));\n"
"code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof 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\tvar props = {};\n\tfunction prepareProps() {\n\t var metaProps = getProps();\n\t engine.injectProp(props, metaProps);\n\t}\n\tfunction injectProps(p) {\n\t engine.injectProp(props, p);\n\t}\n\t//# sourceMappingURL=props.js.map\n\n\tvar 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\tfunction getIndexFromRC(row, col, maxCol) {\n\t var index = row * maxCol + col;\n\t return index;\n\t}\n\tfunction 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\tvar MAX_COL;\n\tvar MAX_ROW;\n\tvar W;\n\tvar H;\n\tvar GAP;\n\tvar GAME_TIME;\n\tvar w;\n\tvar h;\n\tvar 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\tvar 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\tfunction 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\treturn index;\n\n})));\n"
}
......@@ -17,7 +17,7 @@ function launchWithCustomModule(customModule) {
//engine.registerCustomCodeModule(customModule);
engine.registerCustomModule(customId, window[customId]);
const {props: propsOption, assets} = customModule;
const { props: propsOption, assets } = customModule;
let props = engine.computeProps(customModuleProps, propsOption);
const customModuleIns = {
id: customId,
......@@ -46,21 +46,19 @@ function launchWithCustomModule(customModule) {
}, 100);
setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-reset', {
"goodsProbability": [0.8,0.1,0.1],
"countDown": 30,
"acceleratedSpeed":0.1
engine.globalEvent.dispatchEvent('pictures-start', {
picUrl: "http://yun.duiba.com.cn/aurora/assets/fb06e66c26f17b00f677367bd7571a1aa9b1ade4.png"
});
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) => {
engine.globalEvent.addEventListener('pictures-game-fail', (e) => {
console.log(e.type, e.data);
});
engine.globalEvent.addEventListener('pictures-game-over', (e) => {
engine.globalEvent.addEventListener('pictures-game-success', (e) => {
console.log(e.type, e.data);
});
}
......
......@@ -22,7 +22,7 @@
height: 100%;
overflow: hidden;
position: absolute;
background-color: red;
background-color: gray;
}
.game-container{
width: 100%;
......
......@@ -4,15 +4,15 @@
(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;
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function getRandomArray(array) {
array.sort(function () {
return .5 - Math.random();
});
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
var qietu = (function (parent, url, MAX_COL, MAX_ROW) {
var W = 600;
......@@ -51,40 +51,45 @@
for (var row = 0; row < MAX_ROW; row++) {
_loop_1(row);
}
console.log(spr);
return [spr, pos];
});
//# sourceMappingURL=qietu.js.map
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;
function getIndexFromRC(row, col, maxCol) {
var index = row * maxCol + col;
return index;
}
function getRandomArray(array) {
array.sort(function () {
return .5 - Math.random();
});
}
//# sourceMappingURL=utils.js.map
var MAX_COL;
var MAX_ROW;
var W;
var H;
var GAP;
var GAME_TIME;
var w;
var h;
var GameView = (function (_super) {
tslib.__extends(GameView, _super);
function GameView() {
var _this = _super.call(this) || this;
_this._timeCounter = 0;
_this.countTime = 10;
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this;
}
GameView.prototype.createRects = function () { };
GameView.prototype.setup = function () {
GameView.prototype.start = 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);
console.log('on start');
engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(),
});
var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
this.pictures = result[0];
this.rightList = this.pictures.concat([]);
var posList = result[1];
......@@ -92,7 +97,6 @@
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);
......@@ -100,10 +104,47 @@
this.dragPic.x = x;
this.dragPic.y = y;
}
this._timer = setInterval(function () {
_this.onTimer();
}, 1000);
};
GameView.prototype.onTimer = function () {
this._timeCounter++;
engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(),
});
if (this.getSecond() == 0) {
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1
});
}
};
GameView.prototype.getSecond = function () {
return GAME_TIME - this._timeCounter;
};
GameView.prototype.stop = function () {
this._timeCounter = 0;
clearInterval(this._timer);
};
GameView.prototype.createRects = function () { };
GameView.prototype.setup = function () {
MAX_COL = props.MAX_COL;
MAX_ROW = props.MAX_ROW;
GAME_TIME = props.GAME_TIME;
W = props.W;
H = props.H;
GAP = props.GAP;
w = W / MAX_COL;
h = H / MAX_ROW;
console.log('onSteup', props);
var parent = new engine.Sprite();
this.picturesWrapper = parent;
this.addChild(parent);
};
GameView.prototype.onDown = function (e) {
console.log(e);
this.dragPic = e.target;
this.picturesWrapper.addChild(this.dragPic);
this.localPicX = e.localX / MAX_COL;
this.localPicY = e.localY / MAX_ROW;
this.distanceX = this.dragPic.x;
......@@ -122,7 +163,6 @@
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;
......@@ -142,19 +182,21 @@
}
}
if (result) {
console.log('拼图成功!');
this.onSuccess();
}
}
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
};
GameView.prototype.onSuccess = function () {
console.log('拼图成功!');
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-success', {});
};
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));
......@@ -163,22 +205,22 @@
tslib.__extends(GameWrapper, _super);
function GameWrapper() {
var _this = _super.call(this) || this;
engine.globalEvent.addEventListener('pictures-start', _this.start, _this);
engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this);
var gameView = _this._gameView = new GameView();
_this.addChild(gameView);
console.log("hello world.");
return _this;
}
GameWrapper.prototype.start = function (event) {
injectProps(event.data);
this._gameView.start();
};
GameWrapper.prototype.stop = function (event) {
this._gameView.stop();
};
return GameWrapper;
}(engine.Container));
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=GameWrapper.js.map
function index (props) {
prepareProps();
......@@ -186,6 +228,7 @@
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
......
{"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,EAAE,CAAC;MAC1B,CAAC,CAAC;CACJ;;ACjCA,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,CAAC;KACf,IAAM,GAAG,GAAG,EAAE,CAAA;6BAEL,GAAG;iCACD,GAAG;aAEV,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;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AC,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
{"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","export default (parent, url,MAX_COL,MAX_ROW) => {\n\n const W = 600;\n const H = 600;\n const GAP = 10;\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.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 // 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 } 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.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\n createRects() { }\n setup() {\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 // 判断图片是否进入另一张图片的范围内\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,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,CAAC;KACf,IAAM,GAAG,GAAG,EAAE,CAAA;6BAEL,GAAG;iCACD,GAAG;aAEV,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;aAC3C,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAEhB,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC;aAC3B,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC;aAC3B,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aACvB,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,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AAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;MAEvC;KAEH,eAAC;CAAD,CAAC,CArOqC,MAAM,CAAC,SAAS,GAqOrD;;CChPD;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;;;;;;;;;"}
\ No newline at end of file
{
"name": "口红机",
"desc": "口红机模块",
"name": "拼图",
"desc": "拼图模块1.0",
"props": {
"playerPositionY": {
"alias": "玩家Y轴位置",
"MAX_COL": {
"alias": "图片分成几列",
"type": "number",
"default": 900
"default": 2
},
"rainScore": {
"alias": "接中雨滴获得分数",
"MAX_ROW": {
"alias": "图片分成几行",
"type": "number",
"default": 1
"default": 2
},
"stoneScore": {
"alias": "接中石块获得分数",
"W": {
"alias": "图片的宽度",
"type": "number",
"default": -1
"default": 600
},
"speed": {
"alias": "道具掉落初始速度",
"H": {
"alias": "图片的高度",
"type": "number",
"default": 10
"default": 600
},
"maxSpeed": {
"alias": "道具掉落速度上限",
"GAP": {
"alias": "图片间隙",
"type": "number",
"default": 3
"default": 10
},
"gameOverCondition": {
"alias": "游戏结束条件(1:接到炸弹死亡,2:分数负数或接到炸弹死亡)",
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 1
"default": 10
}
},
"assets": [
{
"name": "玩家icon",
"name": "测试资源",
"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": {
......@@ -105,23 +69,22 @@
}
},
"out": {
"pictures-score-update": {
"alias": "分数更新",
"data": {
"score":"分数"
}
},
"pictures-time-update": {
"alias": "倒计时更新",
"data": {
"time":"剩余时间"
}
},
"pictures-game-over": {
"pictures-game-fail": {
"alias": "游戏结束",
"data": {
"score":"分数",
"reason": "结束原因(1:时间到了,2:玩家死亡)"
"reason": "结束原因(1:时间到了)"
}
},
"pictures-game-success": {
"alias": "游戏成功",
"data": {
"time": "游戏消耗时间"
}
}
}
......
......@@ -3,22 +3,83 @@
*/
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";
import { getIndexFromRC, getRandomArray } from "./utils";
import ObjectPool = engine.ObjectPool;
const MAX_COL = 3;
const MAX_ROW = 3;
const W = 600;
const H = 600;
const GAP = 10;
let MAX_COL;
let MAX_ROW;
let W;
let H;
let GAP;
let GAME_TIME;
// 每张图片宽
const w = W / MAX_COL;
let w;
// 每张图片高
const h = H / MAX_ROW;
let h;
export default class GameView extends engine.Container {
private _timer;
private _timeCounter = 0;
start() {
console.log('on start')
engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(),
});
// 图片一维数组
const result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
this.pictures = result[0];
this.rightList = this.pictures.concat([]);
const posList = result[1];
getRandomArray(this.pictures);
let i = 0;
let len;
len = this.pictures.length;
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;
}
this._timer = setInterval(() => {
this.onTimer();
}, 1000)
}
onTimer() {
this._timeCounter++;
engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(),
});
if (this.getSecond() == 0) {
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1
});
}
}
getSecond() {
return GAME_TIME - this._timeCounter;
}
stop() {
this._timeCounter = 0;
clearInterval(this._timer);
}
constructor() {
super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
......@@ -37,7 +98,6 @@ export default class GameView extends engine.Container {
centerY: number;
pictures;
// curPic
// 点击图片时的索引
index;
......@@ -46,67 +106,37 @@ export default class GameView extends engine.Container {
rightList: engine.Sprite[];
// 倒计时时间
countTime = 10
countTime = 10;
private picturesWrapper: engine.Sprite;
createRects() {}
createRects() { }
setup() {
// debugger;
const url =
"http://yun.duiba.com.cn/aurora/assets/fb06e66c26f17b00f677367bd7571a1aa9b1ade4.png";
// 图片容器
MAX_COL = props.MAX_COL;
MAX_ROW = props.MAX_ROW;
GAME_TIME = props.GAME_TIME;
W = props.W;
H = props.H;
GAP = props.GAP;
// 每张图片宽
w = W / MAX_COL;
// 每张图片高
h = H / MAX_ROW;
console.log('onSteup', props);
const parent = new engine.Sprite();
this.picturesWrapper = parent;
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)
// console.log(e);
// 创建一个图片对象接收当前位置信息
this.dragPic = e.target;
this.picturesWrapper.addChild(this.dragPic);
// let currentpic = this.currentPic;
// 鼠标的偏移量
this.localPicX = e.localX / MAX_COL;
this.localPicY = e.localY / MAX_ROW;
......@@ -137,7 +167,6 @@ export default class GameView extends engine.Container {
}
stageOnUp(e) {
this.stage.removeEventListener(
engine.MouseEvent.MOUSE_MOVE,
......@@ -145,7 +174,6 @@ export default class GameView extends engine.Container {
this
);
// 判断图片是否进入另一张图片的范围内
// 图片第几行第几列
let curJ = Math.floor(this.centerX / (w + GAP));
......@@ -155,12 +183,10 @@ export default class GameView extends engine.Container {
// 点击图片的位置
if (curJ < MAX_COL && curI < MAX_ROW) {
// 要交换的图片
// console.log(this.pictures[this.index]);
// 获取交互图片的索引值
let index = getIndexFromRC(curI, curJ, MAX_COL);
console.log(index);
// console.log(index);
//要交换的图片
let dropPic = this.pictures[index];
......@@ -191,13 +217,11 @@ export default class GameView extends engine.Container {
}
if (result) {
console.log('拼图成功!')
this.onSuccess();
}
}
this.stage.removeEventListener(
engine.MouseEvent.MOUSE_UP,
this.stageOnUp,
......@@ -205,6 +229,12 @@ export default class GameView extends engine.Container {
);
}
private onSuccess() {
console.log('拼图成功!');
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-success', {});
}
onMove(e: engine.MouseEvent) {
// 当前图片的位置
this.dragPic.x = e.stageX - this.localPicX;
......@@ -214,15 +244,6 @@ export default class GameView extends engine.Container {
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("====================================");
}
}
......@@ -3,11 +3,11 @@
*/
import GameView from "./GameView";
import {injectProps} from "../props";
import { injectProps } from "../props";
export class GameWrapper extends engine.Container {
private _status;
// private _status;
private _gameView: GameView;
......@@ -17,13 +17,24 @@ export class GameWrapper extends engine.Container {
constructor() {
super();
engine.globalEvent.addEventListener('pictures-start', this.start, this);
engine.globalEvent.addEventListener('pictures-stop', this.stop, this);
//创建实例
let gameView = this._gameView = new GameView();
this.addChild(gameView);
console.log("hello world.");
}
start(event: engine.Event) {
injectProps(event.data);
// this._status = 1;
this._gameView.start();
}
stop(event: engine.Event) {
this._gameView.stop();
}
}
......@@ -36,6 +36,6 @@ export default (parent, url,MAX_COL,MAX_ROW) => {
});
}
}
console.log(spr);
// console.log(spr);
return [spr,pos];
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment