Commit 634f2330 authored by 汪欢's avatar 汪欢

拼图1.0版本

parent 2984fe79
...@@ -56,14 +56,14 @@ function launchWithCustomModule(customModule) { ...@@ -56,14 +56,14 @@ function launchWithCustomModule(customModule) {
engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2; engine.gameStage.sceneContainer.getChildAt(0).y = (d.stage.height-props.H)/2;
}, 1000); }, 1000);
// setTimeout(() => { setTimeout(() => {
// engine.globalEvent.dispatchEvent('pictures-start', { engine.globalEvent.dispatchEvent('pictures-start', {
// picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png", picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
// // picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png" // picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png"
// blockUrl: "888" blockUrl: "888"
// }); });
// }, 5*1000); }, 30*1000);
}); });
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);
......
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
second: this.getSecond(), second: this.getSecond(),
}); });
if (this.getSecond() == 0) { if (this.getSecond() == 0) {
GAME_TIME = props.GAME_TIME;
this.stop(); this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', { engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1 reason: 1
...@@ -164,7 +165,6 @@ ...@@ -164,7 +165,6 @@
return GAME_TIME; return GAME_TIME;
}; };
GameView.prototype.stop = function () { GameView.prototype.stop = function () {
GAME_TIME = props.GAME_TIME;
clearInterval(this._timer); clearInterval(this._timer);
var len = this.pictures.length; var len = this.pictures.length;
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
...@@ -258,11 +258,9 @@ ...@@ -258,11 +258,9 @@
this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2; this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
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;
console.log(this.centerX, this.centerY, "center");
}; };
return GameView; return GameView;
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=GameView.js.map
var GameWrapper = (function (_super) { var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super); tslib.__extends(GameWrapper, _super);
......
This diff is collapsed.
...@@ -19,11 +19,13 @@ let GAME_TIME; ...@@ -19,11 +19,13 @@ let GAME_TIME;
let w; let w;
// 每张图片高 // 每张图片高
let h; let h;
export default class GameView extends engine.Container { export default class GameView extends engine.Container {
private _timer; private _timer;
private _timeCounter = 0; private _timeCounter = 0;
start() { start() {
if (!this.guideHole) { if (!this.guideHole) {
this.guideHole = new engine.Image(); this.guideHole = new engine.Image();
this.guideHole.source = 'asset://' + props.blockUrl; this.guideHole.source = 'asset://' + props.blockUrl;
...@@ -94,6 +96,7 @@ export default class GameView extends engine.Container { ...@@ -94,6 +96,7 @@ export default class GameView extends engine.Container {
}); });
if (this.getSecond() == 0) { if (this.getSecond() == 0) {
GAME_TIME = props.GAME_TIME
this.stop(); this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', { engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1 reason: 1
...@@ -121,7 +124,7 @@ export default class GameView extends engine.Container { ...@@ -121,7 +124,7 @@ export default class GameView extends engine.Container {
} }
stop() { stop() {
GAME_TIME = props.GAME_TIME // GAME_TIME = props.GAME_TIME
clearInterval(this._timer); clearInterval(this._timer);
let len = this.pictures.length; let len = this.pictures.length;
for(let i=0;i<len;i++){ for(let i=0;i<len;i++){
...@@ -216,22 +219,12 @@ export default class GameView extends engine.Container { ...@@ -216,22 +219,12 @@ export default class GameView extends engine.Container {
this.distanceY = this.dragPic.y; 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.indexJ = Math.floor((this.distanceX) / (w + GAP)); this.indexJ = Math.floor((this.distanceX) / (w + GAP));
this.indexI = Math.floor((this.distanceY) / (h + GAP)); this.indexI = Math.floor((this.distanceY) / (h + GAP));
this.index = (this.indexI) * MAX_COL + this.indexJ; this.index = (this.indexI) * MAX_COL + this.indexJ;
// 图片的中心位置
// this.centerX = e.clientX + w / 2;
// this.centerY = e.clientY + h / 2;
// this.centerX = Math.floor(e.clientX / w) * w + w / 2; // this.centerX = Math.floor(e.clientX / w) * w + w / 2;
// this.centerY = Math.floor(e.clientY / h) * h + h / 2; // this.centerY = Math.floor(e.clientY / h) * h + h / 2;
...@@ -275,15 +268,14 @@ export default class GameView extends engine.Container { ...@@ -275,15 +268,14 @@ export default class GameView extends engine.Container {
this.dragPic.x = this.distanceX ; this.dragPic.x = this.distanceX ;
this.dragPic.y = this.distanceY ; this.dragPic.y = this.distanceY ;
} }
// 判断图片是否进入另一张图片的范围内
// 要交换的图片第几行第几列
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));
this.picturesWrapper.addChild(this.guideHole); this.picturesWrapper.addChild(this.guideHole);
// 判断图片是否进入另一张图片的范围内
// 要交换的图片第几行第几列
// 点击图片的位置 // 点击图片的位置
...@@ -343,19 +335,17 @@ export default class GameView extends engine.Container { ...@@ -343,19 +335,17 @@ export default class GameView extends engine.Container {
console.log('拼图成功!'); console.log('拼图成功!');
engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME }); engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME });
this.stop(); this.stop();
} }
onMove(e: engine.MouseEvent) { onMove(e: engine.MouseEvent) {
// 当前图片的位置 // 当前图片的位置
this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2; this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2;
this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2; 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;
this.centerY = this.dragPic.y + h / 2; this.centerY = this.dragPic.y + h / 2;
console.log(this.centerX,this.centerY,"center")
} }
// onClk(e){ // onClk(e){
......
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