Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-libs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
zeroing-libs
Commits
f1e47180
Commit
f1e47180
authored
Jun 11, 2020
by
wildfirecode
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
4af19acb
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
180 additions
and
770 deletions
+180
-770
recycling.json
dist/customs/recycling.json
+55
-0
app.js
src/custom/recycling/debug/app.js
+52
-66
main.js
src/custom/recycling/debug/main.js
+1
-305
main.js.map
src/custom/recycling/debug/main.js.map
+1
-1
meta.json
src/custom/recycling/meta.json
+51
-88
GameView.ts
src/custom/recycling/src/game/GameView.ts
+18
-306
GameWrapper.ts
src/custom/recycling/src/game/GameWrapper.ts
+2
-4
No files found.
dist/customs/recycling.json
0 → 100644
View file @
f1e47180
{
"name"
:
"垃圾分类"
,
"desc"
:
"垃圾分类1.0"
,
"props"
:
{
"MAX_COL"
:
{
"alias"
:
"图片分成几列"
,
"type"
:
"number"
,
"default"
:
3
}
},
"assets"
:
[
{
"name"
:
"playBg"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/76b9491f50eaf51ae2becf9958d96a93770854ee.jpg"
,
"uuid"
:
"888"
,
"ext"
:
".jpg"
}
],
"events"
:
{
"in"
:
{
"recycling-start"
:
{
"alias"
:
"开始"
,
"data"
:
{
"picUrl"
:
"图片路径"
,
"blockUrl"
:
"blockUrl"
}
},
"recycling-stop"
:
{
"alias"
:
"停止"
}
},
"out"
:
{
"recycling-time-update"
:
{
"alias"
:
"倒计时更新"
,
"data"
:
{
"time"
:
"剩余时间"
}
},
"recycling-game-fail"
:
{
"alias"
:
"游戏结束"
,
"data"
:
{
"reason"
:
"结束原因(1:时间到了)"
}
},
"recycling-game-success"
:
{
"alias"
:
"游戏成功"
,
"data"
:
{
"time"
:
"游戏消耗时间"
}
}
}
},
"id"
:
"recycling"
,
"code"
:
"
\"
use strict
\"
;var tslib=require(
\"
tslib
\"
);function getTexture(e){return engine.Texture.from(getAssetByUUID(e).uuid)}function getTextureByName(e){return getTexture(engine.getAssetByName(e).uuid)}var props={};function prepareProps(){var e=getProps();engine.injectProp(props,e)}function injectProps(e){engine.injectProp(props,e)}var GameView=function(t){function e(){var e=t.call(this)||this;return e._timeCounter=0,e.once(engine.Event.ADDED_TO_STAGE,e.setup,e),e}return tslib.__extends(e,t),e.prototype.start=function(){var e=new engine.Sprite(getTextureByName(
\"
playBg
\"
));this.addChild(e)},e.prototype.getSecond=function(){return 0},e.prototype.onTimer=function(){engine.globalEvent.dispatchEvent(
\"
recycling-time-update
\"
,{second:this.getSecond()}),0==this.getSecond()&&(this.stop(),engine.globalEvent.dispatchEvent(
\"
recycling-game-fail
\"
,{reason:1}))},e.prototype.stop=function(){},e.prototype.createRects=function(){},e.prototype.setup=function(){console.log(
\"
onSteup
\"
,props);var e=new engine.Sprite;this.addChild(e)},e.prototype.onDown=function(e){},e.prototype.stageOnUp=function(e){},e.prototype.onSuccess=function(){},e.prototype.onMove=function(e){},e}(engine.Container),GameWrapper=function(n){function e(){var e=n.call(this)||this;engine.globalEvent.addEventListener(
\"
recycling-start
\"
,e.start,e),engine.globalEvent.addEventListener(
\"
recycling-stop
\"
,e.stop,e);var t=e._gameView=new GameView;return e.addChild(t),e}return tslib.__extends(e,n),e.prototype.start=function(e){injectProps(e.data),this._gameView.start()},e.prototype.stop=function(e){this._gameView.stop()},e}(engine.Container);function index(e){return prepareProps(),injectProps(e),new GameWrapper}module.exports=index;
\n
"
}
src/custom/recycling/debug/app.js
View file @
f1e47180
...
@@ -2,84 +2,70 @@
...
@@ -2,84 +2,70 @@
* Created by renjianfeng on 2020-03-13.
* Created by renjianfeng on 2020-03-13.
*/
*/
const
customId
=
'
pictures
'
;
const
customId
=
'
recycling
'
;
(
async
function
()
{
(
async
function
()
{
let
customModule
=
await
fetch
(
`../meta.json`
);
let
customModule
=
await
fetch
(
`../meta.json`
);
customModule
=
await
customModule
.
json
();
customModule
=
await
customModule
.
json
();
console
.
log
(
customModule
);
console
.
log
(
customModule
);
await
loadAssets
(
customModule
.
assets
);
await
loadAssets
(
customModule
.
assets
);
launchWithCustomModule
(
customModule
);
launchWithCustomModule
(
customModule
);
})();
})();
function
launchWithCustomModule
(
customModule
)
{
function
launchWithCustomModule
(
customModule
)
{
//engine.registerCustomCodeModule(customModule);
//engine.registerCustomCodeModule(customModule);
engine
.
registerCustomModule
(
customId
,
window
[
customId
]);
engine
.
registerCustomModule
(
customId
,
window
[
customId
]);
const
{
props
:
propsOption
,
assets
}
=
customModule
;
const
{
props
:
propsOption
,
assets
}
=
customModule
;
let
props
=
engine
.
computeProps
(
customModuleProps
,
propsOption
);
let
props
=
engine
.
computeProps
(
customModuleProps
,
propsOption
);
const
customModuleIns
=
{
const
customModuleIns
=
{
id
:
customId
,
id
:
customId
,
props
,
props
,
assets
,
assets
,
};
};
engine
.
registerCustomModules
([
customModuleIns
]);
engine
.
registerCustomModules
([
customModuleIns
]);
engine
.
launchWithConfig
({
engine
.
launchWithConfig
({
options
:
{
options
:
{
entrySceneView
:
'entry'
,
entrySceneView
:
'entry'
,
},
},
assets
:
[],
assets
:
[],
views
:
[{
views
:
[{
name
:
'entry'
,
name
:
'entry'
,
type
:
'node'
,
type
:
'node'
,
properties
:
{
properties
:
{
x
:
0
,
x
:
0
,
y
:
0
,
y
:
0
,
}
}
}],
}],
customs
:
[],
customs
:
[],
},
null
,
function
()
{
},
null
,
function
()
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
engine
.
addCustomModule
(
customId
,
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
));
engine
.
addCustomModule
(
customId
,
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
));
},
100
);
},
100
);
setTimeout
(()
=>
{
setTimeout
(()
=>
{
engine
.
globalEvent
.
dispatchEvent
(
'pictures-start'
,
{
engine
.
globalEvent
.
dispatchEvent
(
'recycling-start'
,
{});
picUrl
:
"http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png"
,
blockUrl
:
"888"
,
});
const
d
=
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
);
const
d
=
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
);
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
).
x
=
(
d
.
stage
.
width
-
props
.
W
)
/
2
;
},
1000
);
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
).
y
=
(
d
.
stage
.
height
-
props
.
H
)
/
2
;
});
},
1000
);
engine
.
globalEvent
.
addEventListener
(
'recycling-time-update'
,
(
e
)
=>
{
// console.log(e.type, e.data);
// setTimeout(() => {
});
// engine.globalEvent.dispatchEvent('pictures-start', {
engine
.
globalEvent
.
addEventListener
(
'recycling-game-fail'
,
(
e
)
=>
{
// picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
console
.
log
(
e
.
type
,
e
.
data
);
// // picUrl: "http://yun.duiba.com.cn/aurora/assets/d23e73d37ec01931e48cbd0a4095367044c5675c.png"
});
// blockUrl: "888"
engine
.
globalEvent
.
addEventListener
(
'recycling-game-success'
,
(
e
)
=>
{
// });
console
.
log
(
e
.
type
,
e
.
data
);
});
// }, 30*1000);
});
engine
.
globalEvent
.
addEventListener
(
'pictures-time-update'
,
(
e
)
=>
{
// console.log(e.type, e.data);
});
engine
.
globalEvent
.
addEventListener
(
'pictures-game-fail'
,
(
e
)
=>
{
console
.
log
(
e
.
type
,
e
.
data
);
});
engine
.
globalEvent
.
addEventListener
(
'pictures-game-success'
,
(
e
)
=>
{
console
.
log
(
e
.
type
,
e
.
data
);
});
}
}
function
getAssetByUUID
(
uuid
)
{
function
getAssetByUUID
(
uuid
)
{
return
engine
.
resolveCustomAsset
(
customId
,
uuid
);
return
engine
.
resolveCustomAsset
(
customId
,
uuid
);
}
}
function
getProps
()
{
function
getProps
()
{
return
engine
.
getProps
(
customId
);
return
engine
.
getProps
(
customId
);
}
}
\ No newline at end of file
src/custom/recycling/debug/main.js
View file @
f1e47180
This diff is collapsed.
Click to expand it.
src/custom/recycling/debug/main.js.map
View file @
f1e47180
This diff is collapsed.
Click to expand it.
src/custom/recycling/meta.json
View file @
f1e47180
{
{
"name"
:
"拼图"
,
"name"
:
"垃圾分类"
,
"desc"
:
"拼图模块1.0"
,
"desc"
:
"垃圾分类1.0"
,
"props"
:
{
"props"
:
{
"MAX_COL"
:
{
"MAX_COL"
:
{
"alias"
:
"图片分成几列"
,
"alias"
:
"图片分成几列"
,
"type"
:
"number"
,
"type"
:
"number"
,
"default"
:
3
"default"
:
3
},
}
"MAX_ROW"
:
{
"alias"
:
"图片分成几行"
,
},
"type"
:
"number"
,
"assets"
:
[{
"default"
:
4
"name"
:
"playBg"
,
},
"url"
:
"//yun.duiba.com.cn/aurora/assets/76b9491f50eaf51ae2becf9958d96a93770854ee.jpg"
,
"W"
:
{
"uuid"
:
"888"
,
"alias"
:
"图片的宽度"
,
"ext"
:
".jpg"
"type"
:
"number"
,
}],
"default"
:
618
"events"
:
{
},
"in"
:
{
"H"
:
{
"alias"
:
"图片的高度"
,
"recycling-start"
:
{
"type"
:
"number"
,
"alias"
:
"开始"
,
"default"
:
827
"data"
:
{
},
"picUrl"
:
"图片路径"
,
"OFFSET_X"
:
{
"blockUrl"
:
"blockUrl"
"alias"
:
"OFFSET_X"
,
}
"type"
:
"number"
,
},
"default"
:
0
"recycling-stop"
:
{
},
"alias"
:
"停止"
"OFFSET_Y"
:
{
}
"alias"
:
"OFFSET_Y"
,
},
"type"
:
"number"
,
"out"
:
{
"default"
:
0
"recycling-time-update"
:
{
},
"alias"
:
"倒计时更新"
,
"GAP"
:
{
"data"
:
{
"alias"
:
"图片间隙"
,
"time"
:
"剩余时间"
"type"
:
"number"
,
}
"default"
:
0
},
},
"recycling-game-fail"
:
{
"GAME_TIME"
:
{
"alias"
:
"游戏结束"
,
"alias"
:
"游戏时间"
,
"data"
:
{
"type"
:
"number"
,
"reason"
:
"结束原因(1:时间到了)"
"default"
:
5
}
}
},
"recycling-game-success"
:
{
},
"alias"
:
"游戏成功"
,
"assets"
:
[
"data"
:
{
{
"time"
:
"游戏消耗时间"
"name"
:
"遮罩"
,
}
"url"
:
"//yun.duiba.com.cn/aurora/assets/5b3e30496b2d9fdafb0cf3835fd6704ce10e45b4.png"
,
}
"uuid"
:
"888"
,
}
"ext"
:
".png"
}
}
],
"events"
:
{
"in"
:
{
"pictures-start"
:
{
"alias"
:
"开始"
,
"data"
:
{
"picUrl"
:
"图片路径"
,
"blockUrl"
:
"blockUrl"
}
},
"pictures-stop"
:
{
"alias"
:
"停止"
}
},
"out"
:
{
"pictures-time-update"
:
{
"alias"
:
"倒计时更新"
,
"data"
:
{
"time"
:
"剩余时间"
}
},
"pictures-game-fail"
:
{
"alias"
:
"游戏结束"
,
"data"
:
{
"reason"
:
"结束原因(1:时间到了)"
}
},
"pictures-game-success"
:
{
"alias"
:
"游戏成功"
,
"data"
:
{
"time"
:
"游戏消耗时间"
}
}
}
}
}
}
\ No newline at end of file
src/custom/recycling/src/game/GameView.ts
View file @
f1e47180
...
@@ -2,367 +2,79 @@
...
@@ -2,367 +2,79 @@
* Created by rockyl on 2018/8/16.
* Created by rockyl on 2018/8/16.
*/
*/
import
{
getTextureByName
}
from
"../../../recycling/src/game/utils"
;
import
{
props
}
from
"../props"
;
import
{
props
}
from
"../props"
;
import
qietu
from
"./qietu"
;
import
{
getIndexFromRC
,
getRandomArray
,
getTexture
}
from
"./utils"
;
import
ObjectPool
=
engine
.
ObjectPool
;
// let OFFSET_X;
// let OFFSET_Y;
let
MAX_COL
;
let
MAX_ROW
;
let
W
;
let
H
;
let
GAP
;
let
GAME_TIME
;
// 每张图片宽
let
w
;
// 每张图片高
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
()
{
constructor
()
{
super
();
if
(
!
this
.
guideHole
)
{
this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
setup
,
this
);
this
.
guideHole
=
new
engine
.
Image
();
}
this
.
guideHole
.
source
=
'asset://'
+
props
.
blockUrl
;
this
.
guideHole
.
mouseChildren
=
this
.
guideHole
.
mouseEnabled
=
false
;
}
if
(
this
.
pictures
)
{
for
(
const
pic
of
this
.
pictures
)
{
if
(
pic
&&
pic
.
parent
)
pic
.
parent
.
removeChild
(
pic
);
}
}
start
()
{
const
bg
=
new
engine
.
Sprite
(
getTextureByName
(
'playBg'
));
this
.
addChild
(
bg
);
return
;
console
.
log
(
'on start'
)
console
.
log
(
'on start'
)
engine
.
globalEvent
.
dispatchEvent
(
'pictures-time-update'
,
{
engine
.
globalEvent
.
dispatchEvent
(
'recycling-time-update'
,
{
second
:
this
.
getSecond
(),
second
:
this
.
getSecond
(),
});
});
// 图片一维数组
const
result
=
qietu
(
this
.
picturesWrapper
,
props
.
picUrl
,
MAX_COL
,
MAX_ROW
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
console
.
log
(
this
.
picturesWrapper
)
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
.
_timer
=
setInterval
(()
=>
{
this
.
onTimer
();
this
.
onTimer
();
},
10
)
},
10
00
)
}
}
onTimer
()
{
getSecond
()
{
return
0
}
// 以GAME_TIME为标准
GAME_TIME
-=
0.01
GAME_TIME
=
this
.
afterPointTwo
(
GAME_TIME
);
GAME_TIME
=
GAME_TIME
.
toFixed
(
2
)
if
(
GAME_TIME
<
10
)
{
GAME_TIME
=
'0'
+
GAME_TIME
}
// console.log(GAME_TIME);
onTimer
()
{
engine
.
globalEvent
.
dispatchEvent
(
'
pictures
-time-update'
,
{
engine
.
globalEvent
.
dispatchEvent
(
'
recycling
-time-update'
,
{
second
:
this
.
getSecond
(),
second
:
this
.
getSecond
(),
});
});
if
(
this
.
getSecond
()
==
0
)
{
if
(
this
.
getSecond
()
==
0
)
{
GAME_TIME
=
props
.
GAME_TIME
//
GAME_TIME = props.GAME_TIME
this
.
stop
();
this
.
stop
();
engine
.
globalEvent
.
dispatchEvent
(
'
pictures
-game-fail'
,
{
engine
.
globalEvent
.
dispatchEvent
(
'
recycling
-game-fail'
,
{
reason
:
1
reason
:
1
});
});
}
}
}
}
afterPointTwo
(
n
)
{
var
floatN
=
parseFloat
(
n
);
if
(
isNaN
(
floatN
))
{
return
;
}
floatN
=
Math
.
round
(
floatN
*
100
)
/
100
;
return
floatN
;
}
getSecond
()
{
return
GAME_TIME
}
stop
()
{
stop
()
{
// GAME_TIME = props.GAME_TIME
clearInterval
(
this
.
_timer
);
let
len
=
this
.
pictures
.
length
;
for
(
let
i
=
0
;
i
<
len
;
i
++
){
this
.
pictures
[
i
].
removeAllEventListener
();
}
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
}
constructor
()
{
super
();
this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
setup
,
this
);
}
}
//当前图片对象
dragPic
;
// 鼠标在当前图片上的位置
localPicX
;
localPicY
;
// 拖动的图片最开始的位置(左上角为准)
distanceX
;
distanceY
;
// 图片中心的位置
centerX
:
number
;
centerY
:
number
;
pictures
:
engine
.
Sprite
[];
// 点击图片时的一维数组索引
index
;
// 计算目标图片行和列的位置
indexI
:
number
;
indexJ
:
number
;
rightList
:
engine
.
Sprite
[];
private
picturesWrapper
:
engine
.
Sprite
;
private
guideHole
:
engine
.
Image
;
createRects
()
{
}
createRects
()
{
}
setup
()
{
setup
()
{
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;
W
=
props
.
W
;
H
=
props
.
H
;
GAP
=
props
.
GAP
;
// 每张图片宽
w
=
W
/
MAX_COL
;
// 每张图片高
h
=
H
/
MAX_ROW
;
console
.
log
(
'onSteup'
,
props
);
console
.
log
(
'onSteup'
,
props
);
const
parent
=
new
engine
.
Sprite
();
const
parent
=
new
engine
.
Sprite
();
this
.
picturesWrapper
=
parent
;
this
.
addChild
(
parent
);
this
.
addChild
(
parent
);
// this.picturesWrapper.x = OFFSET_X;
// this.picturesWrapper.y = OFFSET_Y;
// 添加按钮
// const btn = new engine.Rect();
// btn.width = 200;
// btn.height = 100;
// btn.stage.top = 1000;
// btn.stage.left = 350;
// btn.fillColor = 'cyan';
// this.addChild(btn)
// btn.addEventListener(engine.MouseEvent.CLICK,this.onClk,this)
}
}
onDown
(
e
:
engine
.
MouseEvent
)
{
onDown
(
e
:
engine
.
MouseEvent
)
{
// console.log(e);
let
stageLeft
=
(
750
-
props
.
W
)
/
2
let
stageTop
=
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
// 创建一个图片对象接收当前位置信息
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
;
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(e.clientX / w) * w + w / 2;
// this.centerY = Math.floor(e.clientY / h) * h + h / 2;
this
.
centerX
=
Math
.
floor
((
e
.
clientX
-
stageLeft
)
/
w
)
*
w
+
w
/
2
;
this
.
centerY
=
Math
.
floor
((
e
.
clientY
-
stageTop
)
/
h
)
*
h
+
h
/
2
;
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
}
}
listenStageOn
=
1
;
stageOnUp
(
e
)
{
stageOnUp
(
e
)
{
let
stageLeft
=
(
750
-
props
.
W
)
/
2
let
stageTop
=
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
// 拖动的图片的中心位置在图片之外,回到原来的位置
if
(
this
.
centerY
<
stageTop
||
this
.
centerX
<
stageLeft
)
{
this
.
dragPic
.
x
=
this
.
distanceX
;
this
.
dragPic
.
y
=
this
.
distanceY
;
}
// 判断图片是否进入另一张图片的范围内
// 要交换的图片第几行第几列
let
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
let
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
// 点击图片的位置
if
(
0
<=
curJ
&&
curJ
<
(
MAX_COL
)
&&
0
<=
curI
&&
curI
<
(
MAX_ROW
))
{
// 获取交互图片的索引值
let
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
// console.log(index);
//要交换的图片
let
dropPic
=
this
.
pictures
[
index
];
let
dropPicX
=
dropPic
.
x
+
stageLeft
;
let
dropPicy
=
dropPic
.
y
+
stageTop
;
dropPic
.
x
=
this
.
distanceX
;
dropPic
.
y
=
this
.
distanceY
;
this
.
dragPic
.
x
=
dropPicX
-
stageLeft
;
this
.
dragPic
.
y
=
dropPicy
-
stageTop
;
// 交换之后索引也需要交换
const
dropPicIndex
=
this
.
pictures
.
indexOf
(
dropPic
);
const
dragPicIndex
=
this
.
pictures
.
indexOf
(
this
.
dragPic
);
this
.
pictures
[
dropPicIndex
]
=
this
.
dragPic
;
this
.
pictures
[
dragPicIndex
]
=
dropPic
;
// 图片中心还是在原来的位置
if
(
dragPicIndex
===
dropPicIndex
)
{
this
.
dragPic
.
x
=
this
.
distanceX
this
.
dragPic
.
y
=
this
.
distanceY
}
let
result
=
true
;
for
(
let
j
=
0
;
j
<
this
.
rightList
.
length
;
j
++
)
{
if
(
this
.
rightList
[
j
]
!=
this
.
pictures
[
j
])
{
result
=
false
;
break
;
}
}
if
(
result
)
{
this
.
onSuccess
();
}
}
else
{
this
.
dragPic
.
x
=
this
.
distanceX
this
.
dragPic
.
y
=
this
.
distanceY
}
}
}
private
onSuccess
()
{
private
onSuccess
()
{
console
.
log
(
'拼图成功!'
);
engine
.
globalEvent
.
dispatchEvent
(
'pictures-game-success'
,
{
time
:
GAME_TIME
});
this
.
stop
();
}
}
onMove
(
e
:
engine
.
MouseEvent
)
{
onMove
(
e
:
engine
.
MouseEvent
)
{
// 当前图片的位置
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
.
centerX
=
this
.
dragPic
.
x
+
w
/
2
;
this
.
centerY
=
this
.
dragPic
.
y
+
h
/
2
;
}
}
// onClk(e){
// // 重置时间
// this._timeCounter = 0;
// //重置图片顺序
// }
}
}
src/custom/recycling/src/game/GameWrapper.ts
View file @
f1e47180
...
@@ -17,8 +17,8 @@ export class GameWrapper extends engine.Container {
...
@@ -17,8 +17,8 @@ export class GameWrapper extends engine.Container {
constructor
()
{
constructor
()
{
super
();
super
();
engine
.
globalEvent
.
addEventListener
(
'
pictures
-start'
,
this
.
start
,
this
);
engine
.
globalEvent
.
addEventListener
(
'
recycling
-start'
,
this
.
start
,
this
);
engine
.
globalEvent
.
addEventListener
(
'
pictures
-stop'
,
this
.
stop
,
this
);
engine
.
globalEvent
.
addEventListener
(
'
recycling
-stop'
,
this
.
stop
,
this
);
//创建实例
//创建实例
let
gameView
=
this
.
_gameView
=
new
GameView
();
let
gameView
=
this
.
_gameView
=
new
GameView
();
...
@@ -29,8 +29,6 @@ export class GameWrapper extends engine.Container {
...
@@ -29,8 +29,6 @@ export class GameWrapper extends engine.Container {
start
(
event
:
engine
.
Event
)
{
start
(
event
:
engine
.
Event
)
{
injectProps
(
event
.
data
);
injectProps
(
event
.
data
);
// this._status = 1;
this
.
_gameView
.
start
();
this
.
_gameView
.
start
();
}
}
stop
(
event
:
engine
.
Event
)
{
stop
(
event
:
engine
.
Event
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment