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
b5a29cf9
Commit
b5a29cf9
authored
Jun 03, 2020
by
wildfirecode
Browse files
Options
Browse Files
Download
Plain Diff
1
parents
7b6e842f
24d78c4c
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
39 deletions
+86
-39
pictures.json
dist/customs/pictures.json
+1
-1
main.js
src/custom/pictures/debug/main.js
+19
-15
main.js.map
src/custom/pictures/debug/main.js.map
+1
-1
GameView.ts
src/custom/pictures/src/game/GameView.ts
+63
-21
utils.ts
src/custom/pictures/src/game/utils.ts
+2
-1
No files found.
dist/customs/pictures.json
View file @
b5a29cf9
This diff is collapsed.
Click to expand it.
src/custom/pictures/debug/main.js
View file @
b5a29cf9
...
@@ -69,7 +69,8 @@
...
@@ -69,7 +69,8 @@
return
getTexture
(
engine
.
getAssetByName
(
name
).
uuid
);
return
getTexture
(
engine
.
getAssetByName
(
name
).
uuid
);
}
}
function
getIndexFromRC
(
row
,
col
,
maxCol
)
{
function
getIndexFromRC
(
row
,
col
,
maxCol
)
{
var
index
=
row
*
maxCol
+
col
;
var
index
;
index
=
row
*
maxCol
+
col
;
return
index
;
return
index
;
}
}
function
getRandomArray
(
array
)
{
function
getRandomArray
(
array
)
{
...
@@ -96,12 +97,13 @@
...
@@ -96,12 +97,13 @@
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
++
)
{
for
(
var
_i
=
0
,
_a
=
this
.
pictures
;
_i
<
_a
.
length
;
_i
++
)
{
var
pic
=
_a
[
_i
];
var
pic
=
_a
[
_i
];
if
(
pic
&&
pic
.
parent
)
if
(
pic
&&
pic
.
parent
)
pic
.
parent
.
removeChild
(
pic
);
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
(),
...
@@ -122,9 +124,6 @@
...
@@ -122,9 +124,6 @@
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
;
...
@@ -179,20 +178,24 @@
...
@@ -179,20 +178,24 @@
this
.
localPicY
=
e
.
localY
/
MAX_ROW
;
this
.
localPicY
=
e
.
localY
/
MAX_ROW
;
this
.
distanceX
=
this
.
dragPic
.
x
;
this
.
distanceX
=
this
.
dragPic
.
x
;
this
.
distanceY
=
this
.
dragPic
.
y
;
this
.
distanceY
=
this
.
dragPic
.
y
;
this
.
index
I
=
this
.
distanceX
/
(
w
+
GAP
);
this
.
index
J
=
Math
.
floor
(
this
.
distanceX
/
(
w
+
GAP
)
);
this
.
index
J
=
this
.
distanceY
/
(
h
+
GAP
);
this
.
index
I
=
Math
.
floor
(
this
.
distanceY
/
(
h
+
GAP
)
);
this
.
index
=
(
this
.
indexI
-
1
)
*
MAX_COL
+
this
.
indexJ
;
this
.
index
=
(
this
.
indexI
)
*
MAX_COL
+
this
.
indexJ
;
this
.
centerX
=
e
.
clientX
+
w
/
2
;
this
.
centerX
=
Math
.
floor
(
e
.
clientX
/
w
)
*
w
+
w
/
2
;
this
.
centerY
=
e
.
clientY
+
h
/
2
;
this
.
centerY
=
Math
.
floor
(
e
.
clientY
/
h
)
*
h
+
w
/
2
;
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
};
};
GameView
.
prototype
.
stageOnUp
=
function
(
e
)
{
GameView
.
prototype
.
stageOnUp
=
function
(
e
)
{
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
if
(
this
.
centerY
<
0
||
this
.
centerX
<
0
)
{
this
.
dragPic
.
x
=
this
.
distanceX
;
this
.
dragPic
.
y
=
this
.
distanceY
;
}
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
var
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
var
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
var
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
var
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
if
(
curJ
<
MAX_COL
&&
curI
<
MAX_ROW
)
{
if
(
curJ
<
(
MAX_COL
)
&&
curI
<
(
MAX_ROW
)
)
{
var
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
var
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
var
dropPic
=
this
.
pictures
[
index
];
var
dropPic
=
this
.
pictures
[
index
];
var
dropPicX
=
dropPic
.
x
;
var
dropPicX
=
dropPic
.
x
;
...
@@ -234,6 +237,7 @@
...
@@ -234,6 +237,7 @@
GameView
.
prototype
.
onMove
=
function
(
e
)
{
GameView
.
prototype
.
onMove
=
function
(
e
)
{
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
;
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
;
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
;
};
};
...
...
src/custom/pictures/debug/main.js.map
View file @
b5a29cf9
This diff is collapsed.
Click to expand it.
src/custom/pictures/src/game/GameView.ts
View file @
b5a29cf9
...
@@ -21,14 +21,14 @@ export default class GameView extends engine.Container {
...
@@ -21,14 +21,14 @@ export default class GameView extends engine.Container {
private
_timer
;
private
_timer
;
private
_timeCounter
=
0
;
private
_timeCounter
=
0
;
// 倒计时时间
// private countTime = 20;
start
()
{
start
()
{
if
(
this
.
pictures
)
{
for
(
const
pic
of
this
.
pictures
)
{
for
(
const
pic
of
this
.
pictures
)
{
if
(
pic
&&
pic
.
parent
)
if
(
pic
&&
pic
.
parent
)
pic
.
parent
.
removeChild
(
pic
);
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
(),
...
@@ -57,11 +57,12 @@ export default class GameView extends engine.Container {
...
@@ -57,11 +57,12 @@ export default class GameView extends engine.Container {
const
[
x
,
y
]
=
posList
[
i
];
const
[
x
,
y
]
=
posList
[
i
];
this
.
dragPic
.
x
=
x
;
this
.
dragPic
.
x
=
x
;
this
.
dragPic
.
y
=
y
;
this
.
dragPic
.
y
=
y
;
}
}
this
.
_timer
=
setInterval
(()
=>
{
//
this._timer = setInterval(() => {
this
.
onTimer
();
//
this.onTimer();
},
10
)
//
}, 10)
}
}
...
@@ -112,20 +113,21 @@ export default class GameView extends engine.Container {
...
@@ -112,20 +113,21 @@ export default class GameView extends engine.Container {
//当前图片对象
//当前图片对象
dragPic
;
dragPic
;
// 鼠标在当前图片上的位置
localPicX
;
localPicX
;
localPicY
;
localPicY
;
// 拖动的图片最开始的位置(左上角为准)
distanceX
;
distanceX
;
distanceY
;
distanceY
;
// 图片中心的位置
centerX
:
number
;
centerX
:
number
;
centerY
:
number
;
centerY
:
number
;
pictures
:
engine
.
Sprite
[];
pictures
:
engine
.
Sprite
[];
// 点击图片时的索引
// 点击图片时的
一维数组
索引
index
;
index
;
// 计算目标图片行和列的位置
indexI
:
number
;
indexI
:
number
;
indexJ
:
number
;
indexJ
:
number
;
rightList
:
engine
.
Sprite
[];
rightList
:
engine
.
Sprite
[];
...
@@ -156,6 +158,18 @@ export default class GameView extends engine.Container {
...
@@ -156,6 +158,18 @@ export default class GameView extends engine.Container {
const
parent
=
new
engine
.
Sprite
();
const
parent
=
new
engine
.
Sprite
();
this
.
picturesWrapper
=
parent
;
this
.
picturesWrapper
=
parent
;
this
.
addChild
(
parent
);
this
.
addChild
(
parent
);
// 添加按钮
// 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
)
{
...
@@ -174,13 +188,25 @@ export default class GameView extends engine.Container {
...
@@ -174,13 +188,25 @@ export default class GameView extends engine.Container {
this
.
distanceY
=
this
.
dragPic
.
y
;
this
.
distanceY
=
this
.
dragPic
.
y
;
// 最开始点击的图片的索引值
// 最开始点击的图片的索引值
this
.
indexI
=
this
.
distanceX
/
(
w
+
GAP
);
// this.indexI = this.distanceX / (w + GAP);
this
.
indexJ
=
this
.
distanceY
/
(
h
+
GAP
);
// this.indexJ = this.distanceY / (h + GAP);
this
.
index
=
(
this
.
indexI
-
1
)
*
MAX_COL
+
this
.
indexJ
;
// this.index = (this.indexI - 1) * MAX_COL + this.indexJ;
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
=
e
.
clientX
+
w
/
2
;
// this.centerX = e.clientX + w / 2;
this
.
centerY
=
e
.
clientY
+
h
/
2
;
// this.centerY = e.clientY + h / 2;
this
.
centerX
=
Math
.
floor
(
e
.
clientX
/
w
)
*
w
+
w
/
2
;
this
.
centerY
=
Math
.
floor
(
e
.
clientY
/
h
)
*
h
+
w
/
2
this
.
stage
.
addEventListener
(
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
engine
.
MouseEvent
.
MOUSE_MOVE
,
...
@@ -202,17 +228,23 @@ export default class GameView extends engine.Container {
...
@@ -202,17 +228,23 @@ export default class GameView extends engine.Container {
this
this
);
);
// 拖动的图片的中心位置在图片之外,回到原来的位置
if
(
this
.
centerY
<
0
||
this
.
centerX
<
0
)
{
this
.
dragPic
.
x
=
this
.
distanceX
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
));
// 点击图片的位置
// 点击图片的位置
if
(
curJ
<
MAX_COL
&&
curI
<
MAX_ROW
)
{
if
(
curJ
<
(
MAX_COL
)
&&
curI
<
(
MAX_ROW
)
)
{
// 获取交互图片的索引值
// 获取交互图片的索引值
let
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
let
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
...
@@ -238,7 +270,7 @@ export default class GameView extends engine.Container {
...
@@ -238,7 +270,7 @@ export default class GameView extends engine.Container {
this
.
pictures
[
dropPicIndex
]
=
this
.
dragPic
;
this
.
pictures
[
dropPicIndex
]
=
this
.
dragPic
;
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
...
@@ -278,6 +310,7 @@ export default class GameView extends engine.Container {
...
@@ -278,6 +310,7 @@ export default class GameView extends engine.Container {
// 当前图片的位置
// 当前图片的位置
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
;
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
;
console
.
log
(
this
.
dragPic
.
x
,
this
.
dragPic
.
y
)
// 当前图片的中心位置
// 当前图片的中心位置
this
.
centerX
=
this
.
dragPic
.
x
+
w
/
2
;
this
.
centerX
=
this
.
dragPic
.
x
+
w
/
2
;
...
@@ -285,4 +318,13 @@ export default class GameView extends engine.Container {
...
@@ -285,4 +318,13 @@ export default class GameView extends engine.Container {
}
}
// onClk(e){
// // 重置时间
// this._timeCounter = 0;
// //重置图片顺序
// }
}
}
src/custom/pictures/src/game/utils.ts
View file @
b5a29cf9
...
@@ -20,7 +20,8 @@ export function createSvga(name, anchorName?) {
...
@@ -20,7 +20,8 @@ export function createSvga(name, anchorName?) {
}
}
export
function
getIndexFromRC
(
row
,
col
,
maxCol
){
export
function
getIndexFromRC
(
row
,
col
,
maxCol
){
let
index
=
row
*
maxCol
+
col
let
index
;
index
=
row
*
maxCol
+
col
;
return
index
return
index
}
}
...
...
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