Commit 6d7c75d5 authored by 汪欢's avatar 汪欢

Merge branch 'dev' of http://gitlab2.dui88.com/laoqifeng/zeroing-libs into dev

parents 69017731 a0bb5b71
No preview for this file type
This diff is collapsed.
...@@ -50,10 +50,21 @@ function launchWithCustomModule(customModule) { ...@@ -50,10 +50,21 @@ function launchWithCustomModule(customModule) {
picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png" picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png"
}); });
}, 500); const d = engine.gameStage.sceneContainer.getChildAt(0);
engine.gameStage.sceneContainer.getChildAt(0).x = (d.stage.width-props.W)/2;
engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1500);
setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', {
picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png"
// picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png"
});
}, 10000);
}); });
engine.globalEvent.addEventListener('pictures-time-update', (e) => { engine.globalEvent.addEventListener('pictures-time-update', (e) => {
console.log(e.type, e.data); // console.log(e.type, e.data);
}); });
engine.globalEvent.addEventListener('pictures-game-fail', (e) => { engine.globalEvent.addEventListener('pictures-game-fail', (e) => {
console.log(e.type, e.data); console.log(e.type, e.data);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
function injectProps(p) { function injectProps(p) {
engine.injectProp(props, p); engine.injectProp(props, p);
} }
//# sourceMappingURL=props.js.map
var picMap = {}; var picMap = {};
var posMap = {}; var posMap = {};
...@@ -59,6 +60,7 @@ ...@@ -59,6 +60,7 @@
posMap[url] = pos.concat([]); posMap[url] = pos.concat([]);
return [spr, pos]; return [spr, pos];
}); });
//# sourceMappingURL=qietu.js.map
function getTexture(uuid) { function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid); return engine.Texture.from(getAssetByUUID(uuid).uuid);
...@@ -76,6 +78,7 @@ ...@@ -76,6 +78,7 @@
return .5 - Math.random(); return .5 - Math.random();
}); });
} }
//# sourceMappingURL=utils.js.map
var MAX_COL; var MAX_COL;
var MAX_ROW; var MAX_ROW;
...@@ -94,6 +97,14 @@ ...@@ -94,6 +97,14 @@
return _this; return _this;
} }
GameView.prototype.start = function () { GameView.prototype.start = function () {
var _this = this;
if (this.pictures) {
for (var _i = 0, _a = this.pictures; _i < _a.length; _i++) {
var pic = _a[_i];
if (pic && pic.parent)
pic.parent.removeChild(pic);
}
}
console.log('on start'); console.log('on start');
engine.globalEvent.dispatchEvent('pictures-time-update', { engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(), second: this.getSecond(),
...@@ -111,15 +122,17 @@ ...@@ -111,15 +122,17 @@
for (; i < len; i++) { for (; i < len; i++) {
this.dragPic = this.pictures[i]; this.dragPic = this.pictures[i];
this.pictures[i].addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDown, this); this.pictures[i].addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDown, this);
var _a = posList[i], x = _a[0], y = _a[1]; var _b = posList[i], x = _b[0], y = _b[1];
this.dragPic.x = x; this.dragPic.x = x;
this.dragPic.y = y; this.dragPic.y = y;
} }
this._timer = setInterval(function () {
_this.onTimer();
}, 10);
}; };
GameView.prototype.onTimer = function () { GameView.prototype.onTimer = function () {
this._timeCounter += 0.01; this._timeCounter += 0.01;
this._timeCounter = this.afterPointTwo(this._timeCounter); this._timeCounter = this.afterPointTwo(this._timeCounter);
console.log(this._timeCounter);
engine.globalEvent.dispatchEvent('pictures-time-update', { engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(), second: this.getSecond(),
}); });
...@@ -222,19 +235,16 @@ ...@@ -222,19 +235,16 @@
}; };
GameView.prototype.onSuccess = function () { GameView.prototype.onSuccess = function () {
console.log('拼图成功!'); console.log('拼图成功!');
engine.globalEvent.dispatchEvent('pictures-game-success', { time: this._timeCounter });
this.stop(); this.stop();
engine.globalEvent.dispatchEvent('pictures-game-success', {});
}; };
GameView.prototype.onMove = function (e) { GameView.prototype.onMove = function (e) {
this.dragPic.x = e.stageX - this.localPicX; this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2;
this.dragPic.y = e.stageY - this.localPicY; this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
console.log('fuck on this.stage.height', this.stage.height);
this.centerX = this.dragPic.x + w / 2; this.centerX = this.dragPic.x + w / 2;
this.centerY = this.dragPic.y + h / 2; this.centerY = this.dragPic.y + h / 2;
}; };
GameView.prototype.onClk = function (e) {
this._timeCounter = 0;
this.start();
};
return GameView; return GameView;
}(engine.Container)); }(engine.Container));
...@@ -257,6 +267,7 @@ ...@@ -257,6 +267,7 @@
}; };
return GameWrapper; return GameWrapper;
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) { function index (props) {
prepareProps(); prepareProps();
...@@ -264,6 +275,7 @@ ...@@ -264,6 +275,7 @@
var instance = new GameWrapper(); var instance = new GameWrapper();
return instance; return instance;
} }
//# sourceMappingURL=index.js.map
return index; return index;
......
This diff is collapsed.
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
"MAX_COL": { "MAX_COL": {
"alias": "图片分成几列", "alias": "图片分成几列",
"type": "number", "type": "number",
"default": 3 "default": 2
}, },
"MAX_ROW": { "MAX_ROW": {
"alias": "图片分成几行", "alias": "图片分成几行",
"type": "number", "type": "number",
"default": 4 "default": 2
}, },
"W": { "W": {
"alias": "图片的宽度", "alias": "图片的宽度",
...@@ -22,6 +22,16 @@ ...@@ -22,6 +22,16 @@
"type": "number", "type": "number",
"default": 827 "default": 827
}, },
"OFFSET_X": {
"alias": "OFFSET_X",
"type": "number",
"default": 0
},
"OFFSET_Y": {
"alias": "OFFSET_Y",
"type": "number",
"default": 0
},
"GAP": { "GAP": {
"alias": "图片间隙", "alias": "图片间隙",
"type": "number", "type": "number",
...@@ -30,7 +40,7 @@ ...@@ -30,7 +40,7 @@
"GAME_TIME": { "GAME_TIME": {
"alias": "游戏时间", "alias": "游戏时间",
"type": "number", "type": "number",
"default": 20 "default": 50
} }
}, },
......
...@@ -7,6 +7,8 @@ import qietu from "./qietu"; ...@@ -7,6 +7,8 @@ import qietu from "./qietu";
import { getIndexFromRC, getRandomArray, getTextureByName } from "./utils"; import { getIndexFromRC, getRandomArray, getTextureByName } from "./utils";
import ObjectPool = engine.ObjectPool; import ObjectPool = engine.ObjectPool;
// let OFFSET_X;
// let OFFSET_Y;
let MAX_COL; let MAX_COL;
let MAX_ROW; let MAX_ROW;
let W; let W;
...@@ -22,6 +24,13 @@ export default class GameView extends engine.Container { ...@@ -22,6 +24,13 @@ export default class GameView extends engine.Container {
private _timeCounter = 0; private _timeCounter = 0;
start() { start() {
if (this.pictures) {
for (const pic of this.pictures) {
if (pic && pic.parent)
pic.parent.removeChild(pic);
}
}
console.log('on start') console.log('on start')
engine.globalEvent.dispatchEvent('pictures-time-update', { engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(), second: this.getSecond(),
...@@ -56,9 +65,9 @@ export default class GameView extends engine.Container { ...@@ -56,9 +65,9 @@ export default class GameView extends engine.Container {
} }
// this._timer = setInterval(() => { this._timer = setInterval(() => {
// this.onTimer(); this.onTimer();
// }, 10) }, 10)
} }
...@@ -67,7 +76,7 @@ export default class GameView extends engine.Container { ...@@ -67,7 +76,7 @@ export default class GameView extends engine.Container {
this._timeCounter += 0.01; this._timeCounter += 0.01;
this._timeCounter = this.afterPointTwo(this._timeCounter); this._timeCounter = this.afterPointTwo(this._timeCounter);
// this._timeCounter = Math.floor((this._timeCounter + 0.1) * 10) / 10; // this._timeCounter = Math.floor((this._timeCounter + 0.1) * 10) / 10;
console.log(this._timeCounter) // console.log(this._timeCounter)
engine.globalEvent.dispatchEvent('pictures-time-update', { engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(), second: this.getSecond(),
...@@ -81,12 +90,12 @@ export default class GameView extends engine.Container { ...@@ -81,12 +90,12 @@ export default class GameView extends engine.Container {
} }
} }
afterPointTwo(n){ afterPointTwo(n) {
var floatN = parseFloat(n); var floatN = parseFloat(n);
if(isNaN(floatN)){ if (isNaN(floatN)) {
return ; return;
} }
floatN = Math.round(floatN * 100) /100; floatN = Math.round(floatN * 100) / 100;
return floatN; return floatN;
} }
...@@ -96,7 +105,6 @@ export default class GameView extends engine.Container { ...@@ -96,7 +105,6 @@ export default class GameView extends engine.Container {
} }
stop() { stop() {
// this.countTime = 0
this._timeCounter = 0; this._timeCounter = 0;
clearInterval(this._timer); clearInterval(this._timer);
...@@ -119,7 +127,7 @@ export default class GameView extends engine.Container { ...@@ -119,7 +127,7 @@ export default class GameView extends engine.Container {
centerX: number; centerX: number;
centerY: number; centerY: number;
pictures; pictures: engine.Sprite[];
// 点击图片时的一维数组索引 // 点击图片时的一维数组索引
index; index;
...@@ -128,7 +136,7 @@ export default class GameView extends engine.Container { ...@@ -128,7 +136,7 @@ export default class GameView extends engine.Container {
indexJ: number; indexJ: number;
rightList: engine.Sprite[]; rightList: engine.Sprite[];
private picturesWrapper: engine.Sprite; private picturesWrapper: engine.Sprite;
private guideHole: engine.Sprite; private guideHole: engine.Sprite;
...@@ -141,6 +149,8 @@ export default class GameView extends engine.Container { ...@@ -141,6 +149,8 @@ export default class GameView extends engine.Container {
MAX_COL = props.MAX_COL; MAX_COL = props.MAX_COL;
MAX_ROW = props.MAX_ROW; MAX_ROW = props.MAX_ROW;
GAME_TIME = props.GAME_TIME; GAME_TIME = props.GAME_TIME;
// OFFSET_X = props.OFFSET_X;
// OFFSET_Y = props.OFFSET_Y;
W = props.W; W = props.W;
H = props.H; H = props.H;
GAP = props.GAP; GAP = props.GAP;
...@@ -155,6 +165,9 @@ export default class GameView extends engine.Container { ...@@ -155,6 +165,9 @@ export default class GameView extends engine.Container {
this.picturesWrapper = parent; this.picturesWrapper = parent;
this.addChild(parent); this.addChild(parent);
// this.picturesWrapper.x = OFFSET_X;
// this.picturesWrapper.y = OFFSET_Y;
// 添加按钮 // 添加按钮
// const btn = new engine.Rect(); // const btn = new engine.Rect();
// btn.width = 200; // btn.width = 200;
...@@ -223,19 +236,19 @@ export default class GameView extends engine.Container { ...@@ -223,19 +236,19 @@ export default class GameView extends engine.Container {
this.onMove, this.onMove,
this this
); );
// 拖动的图片的中心位置在图片之外,回到原来的位置 // 拖动的图片的中心位置在图片之外,回到原来的位置
if(this.centerY < 0 || this.centerX < 0){ if (this.centerY < 0 || this.centerX < 0) {
this.dragPic.x = this.distanceX this.dragPic.x = this.distanceX
this.dragPic.y = this.distanceY this.dragPic.y = this.distanceY
} }
this.picturesWrapper.addChild(this.guideHole); this.picturesWrapper.addChild(this.guideHole);
// 判断图片是否进入另一张图片的范围内 // 判断图片是否进入另一张图片的范围内
// 要交换的图片第几行第几列 // 要交换的图片第几行第几列
let curJ = Math.floor(this.centerX / (w + GAP)) ; let curJ = Math.floor(this.centerX / (w + GAP));
let curI = Math.floor(this.centerY / (h + GAP)) ; let curI = Math.floor(this.centerY / (h + GAP));
// 点击图片的位置 // 点击图片的位置
...@@ -267,7 +280,7 @@ export default class GameView extends engine.Container { ...@@ -267,7 +280,7 @@ export default class GameView extends engine.Container {
this.pictures[dragPicIndex] = dropPic; this.pictures[dragPicIndex] = dropPic;
// 图片中心还是在原来的位置 // 图片中心还是在原来的位置
if(dragPicIndex === dropPicIndex){ if (dragPicIndex === dropPicIndex) {
this.dragPic.x = this.distanceX this.dragPic.x = this.distanceX
this.dragPic.y = this.distanceY this.dragPic.y = this.distanceY
} }
...@@ -284,7 +297,7 @@ export default class GameView extends engine.Container { ...@@ -284,7 +297,7 @@ export default class GameView extends engine.Container {
this.onSuccess(); this.onSuccess();
} }
}else{ } else {
this.dragPic.x = this.distanceX this.dragPic.x = this.distanceX
this.dragPic.y = this.distanceY this.dragPic.y = this.distanceY
} }
...@@ -298,14 +311,16 @@ export default class GameView extends engine.Container { ...@@ -298,14 +311,16 @@ export default class GameView extends engine.Container {
private onSuccess() { private onSuccess() {
console.log('拼图成功!'); console.log('拼图成功!');
engine.globalEvent.dispatchEvent('pictures-game-success', { time: this._timeCounter });
this.stop(); this.stop();
engine.globalEvent.dispatchEvent('pictures-game-success', {});
} }
onMove(e: engine.MouseEvent) { onMove(e: engine.MouseEvent) {
// 当前图片的位置 // 当前图片的位置
this.dragPic.x = e.stageX - this.localPicX; this.dragPic.x = e.stageX - this.localPicX - (750-props.W)/2;
this.dragPic.y = e.stageY - this.localPicY; this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
console.log('fuck on this.stage.height', this.stage.height)
// console.log(this.dragPic.x, this.dragPic.y)
// 当前图片的中心位置 // 当前图片的中心位置
this.centerX = this.dragPic.x + w / 2; this.centerX = this.dragPic.x + w / 2;
...@@ -313,13 +328,13 @@ export default class GameView extends engine.Container { ...@@ -313,13 +328,13 @@ export default class GameView extends engine.Container {
} }
onClk(e){ // onClk(e){
// 重置时间 // // 重置时间
this._timeCounter = 0; // this._timeCounter = 0;
//重置图片顺序 // //重置图片顺序
this.start();
} // }
} }
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