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
24d78c4c
Commit
24d78c4c
authored
Jun 03, 2020
by
汪欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
拼图0.3
parent
95b95b2b
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
33 deletions
+80
-33
main.js
src/custom/pictures/debug/main.js
+18
-11
main.js.map
src/custom/pictures/debug/main.js.map
+1
-1
GameView.ts
src/custom/pictures/src/game/GameView.ts
+59
-20
utils.ts
src/custom/pictures/src/game/utils.ts
+2
-1
No files found.
src/custom/pictures/debug/main.js
View file @
24d78c4c
...
@@ -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
);
...
@@ -67,7 +69,8 @@
...
@@ -67,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
)
{
...
@@ -75,6 +78,7 @@
...
@@ -75,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
;
...
@@ -93,7 +97,6 @@
...
@@ -93,7 +97,6 @@
return
_this
;
return
_this
;
}
}
GameView
.
prototype
.
start
=
function
()
{
GameView
.
prototype
.
start
=
function
()
{
var
_this
=
this
;
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
(),
...
@@ -114,9 +117,6 @@
...
@@ -114,9 +117,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
;
...
@@ -171,20 +171,24 @@
...
@@ -171,20 +171,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
;
...
@@ -226,6 +230,7 @@
...
@@ -226,6 +230,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
;
};
};
...
@@ -251,6 +256,7 @@
...
@@ -251,6 +256,7 @@
};
};
return
GameWrapper
;
return
GameWrapper
;
}(
engine
.
Container
));
}(
engine
.
Container
));
//# sourceMappingURL=GameWrapper.js.map
function
index
(
props
)
{
function
index
(
props
)
{
prepareProps
();
prepareProps
();
...
@@ -258,6 +264,7 @@
...
@@ -258,6 +264,7 @@
var
instance
=
new
GameWrapper
();
var
instance
=
new
GameWrapper
();
return
instance
;
return
instance
;
}
}
//# sourceMappingURL=index.js.map
return
index
;
return
index
;
...
...
src/custom/pictures/debug/main.js.map
View file @
24d78c4c
This diff is collapsed.
Click to expand it.
src/custom/pictures/src/game/GameView.ts
View file @
24d78c4c
...
@@ -21,9 +21,6 @@ export default class GameView extends engine.Container {
...
@@ -21,9 +21,6 @@ export default class GameView extends engine.Container {
private
_timer
;
private
_timer
;
private
_timeCounter
=
0
;
private
_timeCounter
=
0
;
// 倒计时时间
// private countTime = 20;
start
()
{
start
()
{
console
.
log
(
'on start'
)
console
.
log
(
'on start'
)
engine
.
globalEvent
.
dispatchEvent
(
'pictures-time-update'
,
{
engine
.
globalEvent
.
dispatchEvent
(
'pictures-time-update'
,
{
...
@@ -53,11 +50,12 @@ export default class GameView extends engine.Container {
...
@@ -53,11 +50,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)
}
}
...
@@ -108,20 +106,21 @@ export default class GameView extends engine.Container {
...
@@ -108,20 +106,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
;
pictures
;
// 点击图片时的索引
// 点击图片时的
一维数组
索引
index
;
index
;
// 计算目标图片行和列的位置
indexI
:
number
;
indexI
:
number
;
indexJ
:
number
;
indexJ
:
number
;
rightList
:
engine
.
Sprite
[];
rightList
:
engine
.
Sprite
[];
...
@@ -152,6 +151,18 @@ export default class GameView extends engine.Container {
...
@@ -152,6 +151,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
)
{
...
@@ -170,13 +181,25 @@ export default class GameView extends engine.Container {
...
@@ -170,13 +181,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
,
...
@@ -198,17 +221,23 @@ export default class GameView extends engine.Container {
...
@@ -198,17 +221,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
);
...
@@ -234,7 +263,7 @@ export default class GameView extends engine.Container {
...
@@ -234,7 +263,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
...
@@ -274,6 +303,7 @@ export default class GameView extends engine.Container {
...
@@ -274,6 +303,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
;
...
@@ -281,4 +311,13 @@ export default class GameView extends engine.Container {
...
@@ -281,4 +311,13 @@ export default class GameView extends engine.Container {
}
}
// onClk(e){
// // 重置时间
// this._timeCounter = 0;
// //重置图片顺序
// }
}
}
src/custom/pictures/src/game/utils.ts
View file @
24d78c4c
...
@@ -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