Commit 5303505f authored by wildfirecode's avatar wildfirecode

1

parent eeb207d3
No preview for this file type
......@@ -85,5 +85,5 @@
}
},
"id": "pictures",
"code": "\"use strict\";var tslib=require(\"tslib\"),props={};function prepareProps(){var t=getProps();engine.injectProp(props,t)}function injectProps(t){engine.injectProp(props,t)}var OFFSET_X,MAX_COL,MAX_ROW,W,H,GAP,GAME_TIME,w,h,picMap={},posMap={},qietu=function(n,r,o,a){if(picMap[r])return[picMap[r],posMap[r]];for(var h=props.W,c=props.H,p=props.GAP,u=[],d=[],t=function(s){for(var t=function(e){var i=engine.Sprite.fromImage(r);u.push(i),i.scaleX=1/o,i.scaleY=1/a,n.addChild(i),i.x=e*(h/o+p),i.y=s*(c/a+p),d.push([i.x,i.y]),i.addEventListener(engine.Event.COMPLETE,function(){var t=new Float32Array([e/o,s/a,(e+1)/o,s/a,(e+1)/o,(s+1)/a,e/o,(s+1)/a]);i.uvs=t})},e=0;e<o;e++)t(e)},e=0;e<a;e++)t(e);return picMap[r]=u.concat([]),posMap[r]=d.concat([]),[u,d]};function getTexture(t){return engine.Texture.from(getAssetByUUID(t).uuid)}function getTextureByName(t){return getTexture(engine.getAssetByName(t).uuid)}function getIndexFromRC(t,e,i){return t*i+e}function getRandomArray(t){t.sort(function(){return.5-Math.random()})}var GameView=function(e){function t(){var t=e.call(this)||this;return t._timeCounter=0,t.once(engine.Event.ADDED_TO_STAGE,t.setup,t),t}return tslib.__extends(t,e),t.prototype.start=function(){var t=this;if(this.pictures)for(var e=0,i=this.pictures;e<i.length;e++){var s=i[e];s&&s.parent&&s.parent.removeChild(s)}console.log(\"on start\"),engine.globalEvent.dispatchEvent(\"pictures-time-update\",{second:this.getSecond()});var n=qietu(this.picturesWrapper,props.picUrl,MAX_COL,MAX_ROW);this.picturesWrapper.addChild(this.guideHole),this.pictures=n[0],this.rightList=this.pictures.concat([]);var r=n[1];getRandomArray(this.pictures);var o,a=0;for(o=this.pictures.length;a<o;a++){this.dragPic=this.pictures[a],this.pictures[a].addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onDown,this);var h=r[a],c=h[0],p=h[1];this.dragPic.x=c,this.dragPic.y=p}this._timer=setInterval(function(){t.onTimer()},10)},t.prototype.onTimer=function(){this._timeCounter+=.01,this._timeCounter=this.afterPointTwo(this._timeCounter),engine.globalEvent.dispatchEvent(\"pictures-time-update\",{second:this.getSecond()}),0==this.getSecond()&&(this.stop(),engine.globalEvent.dispatchEvent(\"pictures-game-fail\",{reason:1}))},t.prototype.afterPointTwo=function(t){var e=parseFloat(t);if(!isNaN(e))return e=Math.round(100*e)/100},t.prototype.getSecond=function(){return GAME_TIME-this._timeCounter},t.prototype.stop=function(){this._timeCounter=0,clearInterval(this._timer)},t.prototype.createRects=function(){},t.prototype.setup=function(){this.guideHole=new engine.Image(getTextureByName(\"遮罩\")),this.guideHole.mouseChildren=this.guideHole.mouseEnabled=!1,MAX_COL=props.MAX_COL,MAX_ROW=props.MAX_ROW,GAME_TIME=props.GAME_TIME,OFFSET_X=props.OFFSET_X,W=props.W,H=props.H,GAP=props.GAP,w=W/MAX_COL,h=H/MAX_ROW,console.log(\"onSteup\",props);var t=new engine.Sprite;this.picturesWrapper=t,this.addChild(t)},t.prototype.onDown=function(t){this.dragPic=t.target,this.picturesWrapper.addChild(this.dragPic),this.localPicX=t.localX/MAX_COL,this.localPicY=t.localY/MAX_ROW,this.distanceX=this.dragPic.x,this.distanceY=this.dragPic.y,this.indexJ=Math.floor(this.distanceX/(w+GAP)),this.indexI=Math.floor(this.distanceY/(h+GAP)),this.index=this.indexI*MAX_COL+this.indexJ,this.centerX=Math.floor(t.clientX/w)*w+w/2,this.centerY=Math.floor(t.clientY/h)*h+w/2,this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),this.stage.addEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.stageOnUp=function(t){this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),(this.centerY<0||this.centerX<0)&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY),this.picturesWrapper.addChild(this.guideHole);var e=Math.floor(this.centerX/(w+GAP)),i=Math.floor(this.centerY/(h+GAP));if(e<MAX_COL&&i<MAX_ROW){var s=getIndexFromRC(i,e,MAX_COL),n=this.pictures[s],r=n.x,o=n.y;n.x=this.distanceX,n.y=this.distanceY,this.dragPic.x=r,this.dragPic.y=o;var a=this.pictures.indexOf(n),c=this.pictures.indexOf(this.dragPic);this.pictures[a]=this.dragPic,this.pictures[c]=n,c===a&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY);for(var p=!0,u=0;u<this.rightList.length;u++)if(this.rightList[u]!=this.pictures[u]){p=!1;break}p&&this.onSuccess()}else this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY;this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.onSuccess=function(){console.log(\"拼图成功!\"),engine.globalEvent.dispatchEvent(\"pictures-game-success\",{time:this._timeCounter}),this.stop()},t.prototype.onMove=function(t){this.dragPic.x=t.stageX-this.localPicX-OFFSET_X,this.dragPic.y=t.stageY-this.localPicY-(1624-this.stage.height)/2-this.y,this.centerX=this.dragPic.x+w/2,this.centerY=this.dragPic.y+h/2},t}(engine.Container),GameWrapper=function(i){function t(){var t=i.call(this)||this;engine.globalEvent.addEventListener(\"pictures-start\",t.start,t),engine.globalEvent.addEventListener(\"pictures-stop\",t.stop,t);var e=t._gameView=new GameView;return t.addChild(e),t}return tslib.__extends(t,i),t.prototype.start=function(t){injectProps(t.data),this._gameView.start()},t.prototype.stop=function(t){this._gameView.stop()},t}(engine.Container);function index(t){return prepareProps(),injectProps(t),new GameWrapper}module.exports=index;\n"
"code": "\"use strict\";var tslib=require(\"tslib\"),props={};function prepareProps(){var t=getProps();engine.injectProp(props,t)}function injectProps(t){engine.injectProp(props,t)}var MAX_COL,MAX_ROW,W,H,GAP,GAME_TIME,w,h,picMap={},posMap={},qietu=function(n,r,o,a){if(picMap[r])return[picMap[r],posMap[r]];for(var h=props.W,c=props.H,p=props.GAP,u=[],d=[],t=function(s){for(var t=function(e){var i=engine.Sprite.fromImage(r);u.push(i),i.scaleX=1/o,i.scaleY=1/a,n.addChild(i),i.x=e*(h/o+p),i.y=s*(c/a+p),d.push([i.x,i.y]),i.addEventListener(engine.Event.COMPLETE,function(){var t=new Float32Array([e/o,s/a,(e+1)/o,s/a,(e+1)/o,(s+1)/a,e/o,(s+1)/a]);i.uvs=t})},e=0;e<o;e++)t(e)},e=0;e<a;e++)t(e);return picMap[r]=u.concat([]),posMap[r]=d.concat([]),[u,d]};function getTexture(t){return engine.Texture.from(getAssetByUUID(t).uuid)}function getTextureByName(t){return getTexture(engine.getAssetByName(t).uuid)}function getIndexFromRC(t,e,i){return t*i+e}function getRandomArray(t){t.sort(function(){return.5-Math.random()})}var GameView=function(e){function t(){var t=e.call(this)||this;return t._timeCounter=0,t.once(engine.Event.ADDED_TO_STAGE,t.setup,t),t}return tslib.__extends(t,e),t.prototype.start=function(){var t=this;if(this.pictures)for(var e=0,i=this.pictures;e<i.length;e++){var s=i[e];s&&s.parent&&s.parent.removeChild(s)}console.log(\"on start\"),engine.globalEvent.dispatchEvent(\"pictures-time-update\",{second:this.getSecond()});var n=qietu(this.picturesWrapper,props.picUrl,MAX_COL,MAX_ROW);this.picturesWrapper.addChild(this.guideHole),this.pictures=n[0],this.rightList=this.pictures.concat([]);var r=n[1];getRandomArray(this.pictures);var o,a=0;for(o=this.pictures.length;a<o;a++){this.dragPic=this.pictures[a],this.pictures[a].addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onDown,this);var h=r[a],c=h[0],p=h[1];this.dragPic.x=c,this.dragPic.y=p}this._timer=setInterval(function(){t.onTimer()},10)},t.prototype.onTimer=function(){this._timeCounter+=.01,this._timeCounter=this.afterPointTwo(this._timeCounter),engine.globalEvent.dispatchEvent(\"pictures-time-update\",{second:this.getSecond()}),0==this.getSecond()&&(this.stop(),engine.globalEvent.dispatchEvent(\"pictures-game-fail\",{reason:1}))},t.prototype.afterPointTwo=function(t){var e=parseFloat(t);if(!isNaN(e))return e=Math.round(100*e)/100},t.prototype.getSecond=function(){return GAME_TIME-this._timeCounter},t.prototype.stop=function(){this._timeCounter=0,clearInterval(this._timer)},t.prototype.createRects=function(){},t.prototype.setup=function(){this.guideHole=new engine.Image(getTextureByName(\"遮罩\")),this.guideHole.mouseChildren=this.guideHole.mouseEnabled=!1,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 t=new engine.Sprite;this.picturesWrapper=t,this.addChild(t)},t.prototype.onDown=function(t){this.dragPic=t.target,this.picturesWrapper.addChild(this.dragPic),this.localPicX=t.localX/MAX_COL,this.localPicY=t.localY/MAX_ROW,this.distanceX=this.dragPic.x,this.distanceY=this.dragPic.y,this.indexJ=Math.floor(this.distanceX/(w+GAP)),this.indexI=Math.floor(this.distanceY/(h+GAP)),this.index=this.indexI*MAX_COL+this.indexJ,this.centerX=Math.floor(t.clientX/w)*w+w/2,this.centerY=Math.floor(t.clientY/h)*h+w/2,this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),this.stage.addEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.stageOnUp=function(t){this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),(this.centerY<0||this.centerX<0)&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY),this.picturesWrapper.addChild(this.guideHole);var e=Math.floor(this.centerX/(w+GAP)),i=Math.floor(this.centerY/(h+GAP));if(e<MAX_COL&&i<MAX_ROW){var s=getIndexFromRC(i,e,MAX_COL),n=this.pictures[s],r=n.x,o=n.y;n.x=this.distanceX,n.y=this.distanceY,this.dragPic.x=r,this.dragPic.y=o;var a=this.pictures.indexOf(n),c=this.pictures.indexOf(this.dragPic);this.pictures[a]=this.dragPic,this.pictures[c]=n,c===a&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY);for(var p=!0,u=0;u<this.rightList.length;u++)if(this.rightList[u]!=this.pictures[u]){p=!1;break}p&&this.onSuccess()}else this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY;this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.onSuccess=function(){console.log(\"拼图成功!\"),engine.globalEvent.dispatchEvent(\"pictures-game-success\",{time:this._timeCounter}),this.stop()},t.prototype.onMove=function(t){this.dragPic.x=t.stageX-this.localPicX-(750-props.W)/2,this.dragPic.y=t.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.centerY=this.dragPic.y+h/2},t}(engine.Container),GameWrapper=function(i){function t(){var t=i.call(this)||this;engine.globalEvent.addEventListener(\"pictures-start\",t.start,t),engine.globalEvent.addEventListener(\"pictures-stop\",t.stop,t);var e=t._gameView=new GameView;return t.addChild(e),t}return tslib.__extends(t,i),t.prototype.start=function(t){injectProps(t.data),this._gameView.start()},t.prototype.stop=function(t){this._gameView.stop()},t}(engine.Container);function index(t){return prepareProps(),injectProps(t),new GameWrapper}module.exports=index;\n"
}
"use strict";var tslib=require("tslib"),props={};function prepareProps(){var t=getProps();engine.injectProp(props,t)}function injectProps(t){engine.injectProp(props,t)}var OFFSET_X,MAX_COL,MAX_ROW,W,H,GAP,GAME_TIME,w,h,picMap={},posMap={},qietu=function(n,r,o,a){if(picMap[r])return[picMap[r],posMap[r]];for(var h=props.W,c=props.H,p=props.GAP,u=[],d=[],t=function(s){for(var t=function(e){var i=engine.Sprite.fromImage(r);u.push(i),i.scaleX=1/o,i.scaleY=1/a,n.addChild(i),i.x=e*(h/o+p),i.y=s*(c/a+p),d.push([i.x,i.y]),i.addEventListener(engine.Event.COMPLETE,function(){var t=new Float32Array([e/o,s/a,(e+1)/o,s/a,(e+1)/o,(s+1)/a,e/o,(s+1)/a]);i.uvs=t})},e=0;e<o;e++)t(e)},e=0;e<a;e++)t(e);return picMap[r]=u.concat([]),posMap[r]=d.concat([]),[u,d]};function getTexture(t){return engine.Texture.from(getAssetByUUID(t).uuid)}function getTextureByName(t){return getTexture(engine.getAssetByName(t).uuid)}function getIndexFromRC(t,e,i){return t*i+e}function getRandomArray(t){t.sort(function(){return.5-Math.random()})}var GameView=function(e){function t(){var t=e.call(this)||this;return t._timeCounter=0,t.once(engine.Event.ADDED_TO_STAGE,t.setup,t),t}return tslib.__extends(t,e),t.prototype.start=function(){var t=this;if(this.pictures)for(var e=0,i=this.pictures;e<i.length;e++){var s=i[e];s&&s.parent&&s.parent.removeChild(s)}console.log("on start"),engine.globalEvent.dispatchEvent("pictures-time-update",{second:this.getSecond()});var n=qietu(this.picturesWrapper,props.picUrl,MAX_COL,MAX_ROW);this.picturesWrapper.addChild(this.guideHole),this.pictures=n[0],this.rightList=this.pictures.concat([]);var r=n[1];getRandomArray(this.pictures);var o,a=0;for(o=this.pictures.length;a<o;a++){this.dragPic=this.pictures[a],this.pictures[a].addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onDown,this);var h=r[a],c=h[0],p=h[1];this.dragPic.x=c,this.dragPic.y=p}this._timer=setInterval(function(){t.onTimer()},10)},t.prototype.onTimer=function(){this._timeCounter+=.01,this._timeCounter=this.afterPointTwo(this._timeCounter),engine.globalEvent.dispatchEvent("pictures-time-update",{second:this.getSecond()}),0==this.getSecond()&&(this.stop(),engine.globalEvent.dispatchEvent("pictures-game-fail",{reason:1}))},t.prototype.afterPointTwo=function(t){var e=parseFloat(t);if(!isNaN(e))return e=Math.round(100*e)/100},t.prototype.getSecond=function(){return GAME_TIME-this._timeCounter},t.prototype.stop=function(){this._timeCounter=0,clearInterval(this._timer)},t.prototype.createRects=function(){},t.prototype.setup=function(){this.guideHole=new engine.Image(getTextureByName("遮罩")),this.guideHole.mouseChildren=this.guideHole.mouseEnabled=!1,MAX_COL=props.MAX_COL,MAX_ROW=props.MAX_ROW,GAME_TIME=props.GAME_TIME,OFFSET_X=props.OFFSET_X,W=props.W,H=props.H,GAP=props.GAP,w=W/MAX_COL,h=H/MAX_ROW,console.log("onSteup",props);var t=new engine.Sprite;this.picturesWrapper=t,this.addChild(t)},t.prototype.onDown=function(t){this.dragPic=t.target,this.picturesWrapper.addChild(this.dragPic),this.localPicX=t.localX/MAX_COL,this.localPicY=t.localY/MAX_ROW,this.distanceX=this.dragPic.x,this.distanceY=this.dragPic.y,this.indexJ=Math.floor(this.distanceX/(w+GAP)),this.indexI=Math.floor(this.distanceY/(h+GAP)),this.index=this.indexI*MAX_COL+this.indexJ,this.centerX=Math.floor(t.clientX/w)*w+w/2,this.centerY=Math.floor(t.clientY/h)*h+w/2,this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),this.stage.addEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.stageOnUp=function(t){this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),(this.centerY<0||this.centerX<0)&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY),this.picturesWrapper.addChild(this.guideHole);var e=Math.floor(this.centerX/(w+GAP)),i=Math.floor(this.centerY/(h+GAP));if(e<MAX_COL&&i<MAX_ROW){var s=getIndexFromRC(i,e,MAX_COL),n=this.pictures[s],r=n.x,o=n.y;n.x=this.distanceX,n.y=this.distanceY,this.dragPic.x=r,this.dragPic.y=o;var a=this.pictures.indexOf(n),c=this.pictures.indexOf(this.dragPic);this.pictures[a]=this.dragPic,this.pictures[c]=n,c===a&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY);for(var p=!0,u=0;u<this.rightList.length;u++)if(this.rightList[u]!=this.pictures[u]){p=!1;break}p&&this.onSuccess()}else this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY;this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.onSuccess=function(){console.log("拼图成功!"),engine.globalEvent.dispatchEvent("pictures-game-success",{time:this._timeCounter}),this.stop()},t.prototype.onMove=function(t){this.dragPic.x=t.stageX-this.localPicX-OFFSET_X,this.dragPic.y=t.stageY-this.localPicY-(1624-this.stage.height)/2-this.y,this.centerX=this.dragPic.x+w/2,this.centerY=this.dragPic.y+h/2},t}(engine.Container),GameWrapper=function(i){function t(){var t=i.call(this)||this;engine.globalEvent.addEventListener("pictures-start",t.start,t),engine.globalEvent.addEventListener("pictures-stop",t.stop,t);var e=t._gameView=new GameView;return t.addChild(e),t}return tslib.__extends(t,i),t.prototype.start=function(t){injectProps(t.data),this._gameView.start()},t.prototype.stop=function(t){this._gameView.stop()},t}(engine.Container);function index(t){return prepareProps(),injectProps(t),new GameWrapper}module.exports=index;
"use strict";var tslib=require("tslib"),props={};function prepareProps(){var t=getProps();engine.injectProp(props,t)}function injectProps(t){engine.injectProp(props,t)}var MAX_COL,MAX_ROW,W,H,GAP,GAME_TIME,w,h,picMap={},posMap={},qietu=function(n,r,o,a){if(picMap[r])return[picMap[r],posMap[r]];for(var h=props.W,c=props.H,p=props.GAP,u=[],d=[],t=function(s){for(var t=function(e){var i=engine.Sprite.fromImage(r);u.push(i),i.scaleX=1/o,i.scaleY=1/a,n.addChild(i),i.x=e*(h/o+p),i.y=s*(c/a+p),d.push([i.x,i.y]),i.addEventListener(engine.Event.COMPLETE,function(){var t=new Float32Array([e/o,s/a,(e+1)/o,s/a,(e+1)/o,(s+1)/a,e/o,(s+1)/a]);i.uvs=t})},e=0;e<o;e++)t(e)},e=0;e<a;e++)t(e);return picMap[r]=u.concat([]),posMap[r]=d.concat([]),[u,d]};function getTexture(t){return engine.Texture.from(getAssetByUUID(t).uuid)}function getTextureByName(t){return getTexture(engine.getAssetByName(t).uuid)}function getIndexFromRC(t,e,i){return t*i+e}function getRandomArray(t){t.sort(function(){return.5-Math.random()})}var GameView=function(e){function t(){var t=e.call(this)||this;return t._timeCounter=0,t.once(engine.Event.ADDED_TO_STAGE,t.setup,t),t}return tslib.__extends(t,e),t.prototype.start=function(){var t=this;if(this.pictures)for(var e=0,i=this.pictures;e<i.length;e++){var s=i[e];s&&s.parent&&s.parent.removeChild(s)}console.log("on start"),engine.globalEvent.dispatchEvent("pictures-time-update",{second:this.getSecond()});var n=qietu(this.picturesWrapper,props.picUrl,MAX_COL,MAX_ROW);this.picturesWrapper.addChild(this.guideHole),this.pictures=n[0],this.rightList=this.pictures.concat([]);var r=n[1];getRandomArray(this.pictures);var o,a=0;for(o=this.pictures.length;a<o;a++){this.dragPic=this.pictures[a],this.pictures[a].addEventListener(engine.MouseEvent.MOUSE_DOWN,this.onDown,this);var h=r[a],c=h[0],p=h[1];this.dragPic.x=c,this.dragPic.y=p}this._timer=setInterval(function(){t.onTimer()},10)},t.prototype.onTimer=function(){this._timeCounter+=.01,this._timeCounter=this.afterPointTwo(this._timeCounter),engine.globalEvent.dispatchEvent("pictures-time-update",{second:this.getSecond()}),0==this.getSecond()&&(this.stop(),engine.globalEvent.dispatchEvent("pictures-game-fail",{reason:1}))},t.prototype.afterPointTwo=function(t){var e=parseFloat(t);if(!isNaN(e))return e=Math.round(100*e)/100},t.prototype.getSecond=function(){return GAME_TIME-this._timeCounter},t.prototype.stop=function(){this._timeCounter=0,clearInterval(this._timer)},t.prototype.createRects=function(){},t.prototype.setup=function(){this.guideHole=new engine.Image(getTextureByName("遮罩")),this.guideHole.mouseChildren=this.guideHole.mouseEnabled=!1,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 t=new engine.Sprite;this.picturesWrapper=t,this.addChild(t)},t.prototype.onDown=function(t){this.dragPic=t.target,this.picturesWrapper.addChild(this.dragPic),this.localPicX=t.localX/MAX_COL,this.localPicY=t.localY/MAX_ROW,this.distanceX=this.dragPic.x,this.distanceY=this.dragPic.y,this.indexJ=Math.floor(this.distanceX/(w+GAP)),this.indexI=Math.floor(this.distanceY/(h+GAP)),this.index=this.indexI*MAX_COL+this.indexJ,this.centerX=Math.floor(t.clientX/w)*w+w/2,this.centerY=Math.floor(t.clientY/h)*h+w/2,this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),this.stage.addEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.stageOnUp=function(t){this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE,this.onMove,this),(this.centerY<0||this.centerX<0)&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY),this.picturesWrapper.addChild(this.guideHole);var e=Math.floor(this.centerX/(w+GAP)),i=Math.floor(this.centerY/(h+GAP));if(e<MAX_COL&&i<MAX_ROW){var s=getIndexFromRC(i,e,MAX_COL),n=this.pictures[s],r=n.x,o=n.y;n.x=this.distanceX,n.y=this.distanceY,this.dragPic.x=r,this.dragPic.y=o;var a=this.pictures.indexOf(n),c=this.pictures.indexOf(this.dragPic);this.pictures[a]=this.dragPic,this.pictures[c]=n,c===a&&(this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY);for(var p=!0,u=0;u<this.rightList.length;u++)if(this.rightList[u]!=this.pictures[u]){p=!1;break}p&&this.onSuccess()}else this.dragPic.x=this.distanceX,this.dragPic.y=this.distanceY;this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP,this.stageOnUp,this)},t.prototype.onSuccess=function(){console.log("拼图成功!"),engine.globalEvent.dispatchEvent("pictures-game-success",{time:this._timeCounter}),this.stop()},t.prototype.onMove=function(t){this.dragPic.x=t.stageX-this.localPicX-(750-props.W)/2,this.dragPic.y=t.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.centerY=this.dragPic.y+h/2},t}(engine.Container),GameWrapper=function(i){function t(){var t=i.call(this)||this;engine.globalEvent.addEventListener("pictures-start",t.start,t),engine.globalEvent.addEventListener("pictures-stop",t.stop,t);var e=t._gameView=new GameView;return t.addChild(e),t}return tslib.__extends(t,i),t.prototype.start=function(t){injectProps(t.data),this._gameView.start()},t.prototype.stop=function(t){this._gameView.stop()},t}(engine.Container);function index(t){return prepareProps(),injectProps(t),new GameWrapper}module.exports=index;
......@@ -7,8 +7,8 @@ import qietu from "./qietu";
import { getIndexFromRC, getRandomArray, getTextureByName } from "./utils";
import ObjectPool = engine.ObjectPool;
let OFFSET_X;
let OFFSET_Y;
// let OFFSET_X;
// let OFFSET_Y;
let MAX_COL;
let MAX_ROW;
let W;
......@@ -146,8 +146,8 @@ export default class GameView extends engine.Container {
MAX_COL = props.MAX_COL;
MAX_ROW = props.MAX_ROW;
GAME_TIME = props.GAME_TIME;
OFFSET_X = props.OFFSET_X;
OFFSET_Y = props.OFFSET_Y;
// OFFSET_X = props.OFFSET_X;
// OFFSET_Y = props.OFFSET_Y;
W = props.W;
H = props.H;
GAP = props.GAP;
......@@ -314,9 +314,9 @@ export default class GameView extends engine.Container {
onMove(e: engine.MouseEvent) {
// 当前图片的位置
this.dragPic.x = e.stageX - this.localPicX - OFFSET_X;
this.dragPic.y = e.stageY - this.localPicY - (1624 - this.stage.height) / 2 - (1624-OFFSET_Y)/2;
console.log('fuck on move',OFFSET_Y)
this.dragPic.x = e.stageX - this.localPicX - (750-props.W)/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)
// 当前图片的中心位置
......
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