Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Cocos-1010
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
等吃饭
Cocos-1010
Commits
9074f559
Commit
9074f559
authored
May 25, 2023
by
Friends233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
方块放置、刷新、校验
parent
bc669b04
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
559 additions
and
39 deletions
+559
-39
Game.fire
assets/Scenes/Game.fire
+386
-12
GameConfig.ts
assets/Script/Config/GameConfig.ts
+7
-1
GameScene.ts
assets/Script/GameScene.ts
+54
-19
block.ts
assets/Script/block.ts
+0
-1
blockManager.ts
assets/Script/blockManager.ts
+112
-6
No files found.
assets/Scenes/Game.fire
View file @
9074f559
...
...
@@ -120,13 +120,13 @@
"_active": true,
"_components": [
{
"__id__":
79
"__id__":
86
},
{
"__id__": 8
0
"__id__": 8
7
},
{
"__id__": 8
1
"__id__": 8
8
}
],
"_prefab": null,
...
...
@@ -424,7 +424,7 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
189.09
,
"width":
37.82
,
"height": 85.68
},
"_anchorPoint": {
...
...
@@ -476,8 +476,8 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "
99999
",
"_N$string": "
99999
",
"_string": "
0
",
"_N$string": "
0
",
"_fontSize": 68,
"_lineHeight": 68,
"_enableWrapText": true,
...
...
@@ -571,8 +571,8 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "历史最高分:2
50
",
"_N$string": "历史最高分:2
50
",
"_string": "历史最高分:2
22
",
"_N$string": "历史最高分:2
22
",
"_fontSize": 24,
"_lineHeight": 24,
"_enableWrapText": true,
...
...
@@ -1761,9 +1761,9 @@
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r":
88
,
"g": 2
17
,
"b": 1
79
,
"r":
160
,
"g": 2
05
,
"b": 1
92
,
"a": 255
},
"_contentSize": {
...
...
@@ -2160,12 +2160,15 @@
},
{
"__id__": 71
},
{
"__id__": 78
}
],
"_active": true,
"_components": [
{
"__id__":
78
"__id__":
85
}
],
"_prefab": null,
...
...
@@ -3700,6 +3703,377 @@
},
"_id": "5f4nSZrxRDD7xBbtkqLlxC"
},
{
"__type__": "cc.Node",
"_name": "radom",
"_objFlags": 0,
"_parent": {
"__id__": 49
},
"_children": [
{
"__id__": 79
}
],
"_active": true,
"_components": [
{
"__id__": 84
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
-30,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "f8KgqT7ZtKkKE8vDukuruG"
},
{
"__type__": "cc.Node",
"_name": "Background",
"_objFlags": 512,
"_parent": {
"__id__": 78
},
"_children": [
{
"__id__": 80
}
],
"_active": true,
"_components": [
{
"__id__": 82
},
{
"__id__": 83
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "50wxYx8QFF94HpnSK9C5NG"
},
{
"__type__": "cc.Node",
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 79
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 81
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "16wfANEO5BD7S+jZRB5m/f"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 80
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "随机生成",
"_N$string": "随机生成",
"_fontSize": 20,
"_lineHeight": 40,
"_enableWrapText": false,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 1,
"_N$cacheMode": 1,
"_id": "3eVVFIPAJEhpGEVrvXWl0N"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 79
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_type": 1,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "d8knnbi25K2KJoCnLWJ14V"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 79
},
"_enabled": true,
"alignMode": 0,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 100,
"_originalHeight": 40,
"_id": "08HUM0VaNKNpteb2NDflIr"
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 78
},
"_enabled": true,
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 2,
"transition": 2,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 230,
"g": 230,
"b": 230,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 120,
"g": 120,
"b": 120,
"a": 200
},
"_N$normalSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_N$pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$hoverSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"hoverSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_N$disabledSprite": {
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 79
},
"_id": "b7pxluBStIWKL2+u9pi2P+"
},
{
"__type__": "cc.Layout",
"_name": "",
...
...
assets/Script/Config/GameConfig.ts
View file @
9074f559
...
...
@@ -13,6 +13,10 @@ export const CUSTOM_EVENT = {
GAME_DESTROY
:
'GAME_DESTROY'
,
/** 加分 */
ADD_SCORE
:
'ADD_SCORE'
,
/** 放置方块 */
SET_BLOCK
:
'SET_BLOCK'
,
/** 检查方块能否放入 */
CHECK_IS_SET
:
'CHECK_IS_SET'
,
}
export
const
Config
=
{
...
...
@@ -22,6 +26,8 @@ export const Config = {
maxCol
:
10
,
/** 填入方块颜色,小方块颜色 */
miniBlockColor
:
'#58D9B3'
,
/** 小方块被禁用的颜色 */
miniBlockDisabledColor
:
'#A0CDC0'
,
/** 默认方块颜色,空白方块颜色 */
defaultColor
:
'#8FBABA'
,
/** 每一个方块动画播放延时 ms*/
...
...
@@ -63,11 +69,11 @@ export const Config = {
[
0
,
0
,
0
,
0
,
0
],
],
[
[
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
1
,
0
,
0
],
[
0
,
0
,
1
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
],
],
[
[
0
,
0
,
0
,
0
,
0
],
...
...
assets/Script/GameScene.ts
View file @
9074f559
...
...
@@ -2,7 +2,6 @@ import Svga from "./Components/Svga/Svga";
import
{
SvgaEvent
}
from
"./Components/Svga/SvgaEvent"
;
import
{
BLOCK_STATE
,
CUSTOM_EVENT
,
Config
,
GameColors
}
from
"./Config/GameConfig"
;
import
exportEvent
from
"./exportEvent"
;
import
propPool
from
"./propPool"
;
import
{
getProbability
,
getRandomArrayElements
,
loadGameResources
,
numToChinese
,
randomNum
,
getUrlParam
}
from
"./utils"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
...
@@ -22,13 +21,14 @@ export default class GameScene extends cc.Component {
/** 当前得分 */
score
=
0
/** 已放置方块集数量 */
setBlockNum
=
0
protected
onLoad
():
void
{
// loadGameResources()
/** 开启碰撞检测 */
const
cm
=
cc
.
director
.
getCollisionManager
()
cm
.
enabled
=
true
// const cm = cc.director.getCollisionManager()
// cm.enabled = true
// cm.enabledDebugDraw = true;
}
...
...
@@ -36,9 +36,9 @@ export default class GameScene extends cc.Component {
this
.
blockMatrix
=
cc
.
find
(
'blockMatrix'
,
this
.
node
)
const
{
maxRow
,
maxCol
}
=
this
.
gameConfig
const
testBlock
=
[]
//
for (let i = 0; i < maxCol - 2; i++) {
// testBlock.push(...Array(8
).fill('').map((_, j) => j + 1 + (i + 1) * maxRow))
//
}
for
(
let
i
=
0
;
i
<
maxCol
-
2
;
i
++
)
{
testBlock
.
push
(...
Array
(
6
).
fill
(
''
).
map
((
_
,
j
)
=>
j
+
1
+
(
i
+
1
)
*
maxRow
))
}
this
.
setDefaultBlock
(
testBlock
)
this
.
addNodeEvent
()
}
...
...
@@ -73,6 +73,8 @@ export default class GameScene extends cc.Component {
// this.dateNow = 0
// })
this
.
node
.
on
(
CUSTOM_EVENT
.
ADD_SCORE
,
this
.
addScore
,
this
)
this
.
node
.
on
(
CUSTOM_EVENT
.
SET_BLOCK
,
this
.
setBlockEventCb
,
this
)
this
.
node
.
on
(
CUSTOM_EVENT
.
CHECK_IS_SET
,
this
.
checkIsSetBlock
,
this
)
exportEvent
.
on
(
CUSTOM_EVENT
.
NEXT_LEVEL
,
this
.
nextLevel
,
this
)
exportEvent
.
on
(
CUSTOM_EVENT
.
GAME_START
,
this
.
startGame
,
this
)
exportEvent
.
on
(
CUSTOM_EVENT
.
GAME_INIT
,
({
detail
=
{}
})
=>
{
...
...
@@ -91,7 +93,8 @@ export default class GameScene extends cc.Component {
refreshProp
:
'refreshStageProps'
,
start
:
'testStartGame'
,
init
:
'testInit'
,
clear
:
'setDefaultBlock'
clear
:
'setDefaultBlock'
,
radom
:
'testRadom'
}
testNode
.
children
.
forEach
((
n
)
=>
{
const
event
=
this
?.[
testEventMap
[
n
.
name
]]
...
...
@@ -100,6 +103,15 @@ export default class GameScene extends cc.Component {
}
}
testRadom
()
{
const
{
maxCol
,
maxRow
}
=
this
.
gameConfig
const
testBlock
=
[]
for
(
let
i
=
0
;
i
<
maxCol
-
2
;
i
++
)
{
testBlock
.
push
(...
Array
(
6
).
fill
(
''
).
map
((
_
,
j
)
=>
j
+
1
+
(
i
+
1
)
*
maxRow
))
}
this
.
setDefaultBlock
(
testBlock
)
}
testStartGame
()
{
console
.
log
(
'测试'
)
exportEvent
.
fire
(
CUSTOM_EVENT
.
GAME_START
)
...
...
@@ -134,6 +146,7 @@ export default class GameScene extends cc.Component {
...
con
}
this
.
setLable
(
'score'
,
0
)
this
.
setLable
(
'bestScore'
,
'历史最高分:'
+
(
con
.
bestScore
||
0
))
this
.
setDefaultBlock
()
}
...
...
@@ -157,23 +170,45 @@ export default class GameScene extends cc.Component {
this
.
unschedule
(
this
.
startCd
)
}
/** 刷新关卡信息 */
refreshLevelInfo
(
level
=
0
)
{
/** 设置方块集事件回调 */
setBlockEventCb
()
{
this
.
checkIsSetBlock
()
this
.
setBlockNum
++
if
(
this
.
setBlockNum
>=
3
)
{
this
.
refreshStageProps
()
}
this
.
isCheckGameOver
()
}
/** 下一关 */
nextLevel
()
{
/** 检查游戏是否结束 */
isCheckGameOver
(){
const
allBlcokManagerKey
=
[
'miniBlockWrpLeft'
,
'miniBlockWrpMid'
,
'miniBlockWrpRight'
]
const
blockStates
=
allBlcokManagerKey
.
filter
((
key
)
=>
{
const
blockManager
=
cc
.
find
(
key
,
this
.
node
).
getComponent
(
'blockManager'
)
return
!
(
blockManager
.
isDisabled
||
blockManager
.
miniBlockKey
.
length
===
0
)
})
if
(
blockStates
.
length
===
0
){
this
.
gameOver
()
}
}
/** 检查矩阵能否放入 */
checkIsSetBlock
()
{
const
allBlcokManagerKey
=
[
'miniBlockWrpLeft'
,
'miniBlockWrpMid'
,
'miniBlockWrpRight'
]
allBlcokManagerKey
.
forEach
((
key
)
=>
{
const
blockManager
=
cc
.
find
(
key
,
this
.
node
).
getComponent
(
'blockManager'
)
blockManager
.
checkIsSetBlock
()
})
}
/** 刷新舞台道具 */
refreshStageProps
()
{
[
'miniBlockWrpLeft'
,
'miniBlockWrpMid'
,
'miniBlockWrpRight'
]
.
forEach
((
key
)
=>
{
const
blockManager
=
cc
.
find
(
key
,
this
.
node
).
getComponent
(
'blockManager'
)
blockManager
.
refreshMiniBlock
(
)
}
)
this
.
setBlockNum
=
0
const
allBlcokManagerKey
=
[
'miniBlockWrpLeft'
,
'miniBlockWrpMid'
,
'miniBlockWrpRight'
]
allBlcokManagerKey
.
forEach
((
key
)
=>
{
const
blockManager
=
cc
.
find
(
key
,
this
.
node
).
getComponent
(
'blockManager'
)
blockManager
.
refreshMiniBlock
(
true
)
})
}
update
(
dt
:
number
):
void
{
...
...
assets/Script/block.ts
View file @
9074f559
...
...
@@ -6,7 +6,6 @@
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
import
{
BLOCK_STATE
,
Config
}
from
"./Config/GameConfig"
;
import
propPool
from
"./propPool"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
...
assets/Script/blockManager.ts
View file @
9074f559
...
...
@@ -26,25 +26,46 @@ export default class BlockManager extends cc.Component {
defaultPos
:
cc
.
Vec2
=
null
/** 加分事件 */
addScoreEvents
:
cc
.
Event
.
EventCustom
=
null
addScoreEvent
:
cc
.
Event
.
EventCustom
=
null
/** 放置事件 */
setBlockEvent
:
cc
.
Event
.
EventCustom
=
null
/** 检查方块能否放入事件 */
checkIsSet
:
cc
.
Event
.
EventCustom
=
null
/** 当前矩阵 */
miniBlockKey
=
[]
/** 是否被禁用 */
isDisabled
=
false
/** 小方块 */
@
property
(
cc
.
Prefab
)
miniBlockPre
:
cc
.
Prefab
=
null
/** 消除动画是否执行中 */
isBlcokClearAni
=
false
start
()
{
this
.
viewHeight
=
cc
.
view
.
getVisibleSize
().
height
this
.
viewWidth
=
cc
.
view
.
getVisibleSize
().
width
this
.
defaultPos
=
this
.
node
.
getPosition
()
this
.
addScoreEvents
=
new
cc
.
Event
.
EventCustom
(
CUSTOM_EVENT
.
ADD_SCORE
,
true
)
this
.
addScoreEvent
=
new
cc
.
Event
.
EventCustom
(
CUSTOM_EVENT
.
ADD_SCORE
,
true
)
this
.
setBlockEvent
=
new
cc
.
Event
.
EventCustom
(
CUSTOM_EVENT
.
SET_BLOCK
,
true
)
this
.
checkIsSet
=
new
cc
.
Event
.
EventCustom
(
CUSTOM_EVENT
.
CHECK_IS_SET
,
true
)
this
.
blockMatrix
=
cc
.
find
(
'blockMatrix'
,
this
.
node
.
parent
)
this
.
refreshMiniBlock
()
this
.
addNodeEvent
()
}
/** 刷新小方块的生成 */
refreshMiniBlock
()
{
/**
* 刷新小方块的生成
* @param isPlayAni 是否需要播放刷新动画
*/
refreshMiniBlock
(
isPlayAni
)
{
const
miniBlockMatrix
=
getRandomArrayElements
(
Config
.
miniBlockMatrix
,
1
)[
0
]
this
.
miniBlockKey
=
JSON
.
parse
(
JSON
.
stringify
(
miniBlockMatrix
))
this
.
node
.
removeAllChildren
()
const
{
miniBlockOffset
,
miniBlockW
}
=
Config
const
len
=
miniBlockMatrix
.
length
,
maxRowNum
=
0
...
...
@@ -79,6 +100,12 @@ export default class BlockManager extends cc.Component {
n
.
y
+=
miniBlockW
/
2
})
}
if
(
isPlayAni
)
{
cc
.
tween
(
this
.
node
)
.
to
(
0.3
,
{
opacity
:
255
,
position
:
this
.
defaultPos
})
.
start
()
}
this
.
checkIsSetBlock
()
}
/** 设置所有的方块复原 */
...
...
@@ -90,9 +117,12 @@ export default class BlockManager extends cc.Component {
const
scripts
=
node
.
getComponent
(
'miniBlock'
)
scripts
.
setBlockMatrix
()
})
this
.
checkBlockMatrix
()
this
.
clearAllChildren
()
this
.
checkBlockMatrix
()
cc
.
find
(
'Canvas'
).
dispatchEvent
(
this
.
setBlockEvent
)
// this.refreshMiniBlock()
return
}
this
.
node
.
setPosition
(
this
.
defaultPos
)
this
.
node
.
scale
=
1
...
...
@@ -101,10 +131,16 @@ export default class BlockManager extends cc.Component {
/** 清除所有自己的子元素 */
clearAllChildren
()
{
this
.
miniBlockKey
=
[]
this
.
node
.
children
.
forEach
((
node
)
=>
{
propPool
.
push
(
node
)
})
this
.
node
.
removeAllChildren
()
this
.
node
.
opacity
=
0
this
.
node
.
setPosition
(
this
.
defaultPos
.
x
,
this
.
defaultPos
.
y
-
100
)
this
.
node
.
scale
=
1
this
.
setNodeState
(
1
)
}
/** 检查块矩阵是否能够消除 */
...
...
@@ -149,6 +185,7 @@ export default class BlockManager extends cc.Component {
}
this
.
clearMatrixBlock
(
eliminateBlocks
)
return
eliminateBlocks
.
length
>
0
// console.log('eliminateBlocks:', eliminateBlocks)
}
...
...
@@ -161,7 +198,10 @@ export default class BlockManager extends cc.Component {
if
(
els
.
length
===
0
)
return
const
{
script
}
=
els
.
pop
()
script
.
playClearAni
(()
=>
{
cc
.
find
(
'Canvas'
).
dispatchEvent
(
this
.
addScoreEvents
)
cc
.
find
(
'Canvas'
).
dispatchEvent
(
this
.
addScoreEvent
)
if
(
els
.
length
==
0
)
{
cc
.
find
(
'Canvas'
).
dispatchEvent
(
this
.
checkIsSet
)
}
})
await
waitTime
(
Config
.
blockAniDelay
)
recursionPlay
(
els
)
...
...
@@ -171,6 +211,71 @@ export default class BlockManager extends cc.Component {
})
}
/** 检查矩阵能否放入 */
checkIsSetBlock
()
{
// console.log('check====', this.node.name)
const
allEmptyBlock
=
this
.
blockMatrix
.
children
.
filter
((
block
)
=>
{
const
block
=
block
.
getComponent
(
'block'
)
return
block
.
blockState
===
BLOCK_STATE
.
EMPTY
})
const
allEmptyBlockIdx
=
allEmptyBlock
.
map
((
node
)
=>
node
.
getSiblingIndex
())
// console.log(allEmptyBlockIdx, 'allEmptyBlockIdx')
if
(
this
.
miniBlockKey
.
length
===
0
)
{
this
.
setNodeState
(
1
)
return
}
for
(
let
k
=
0
;
k
<
allEmptyBlockIdx
.
length
;
k
++
)
{
const
base
=
allEmptyBlockIdx
[
k
]
let
baseX
=
Math
.
trunc
(
base
/
10
),
baseY
=
base
%
10
let
mBaseX
=
-
1
,
mBaseY
=
-
1
,
isNext
=
false
// console.log('base', base, baseX, baseY)
for
(
let
i
=
0
;
i
<
this
.
miniBlockKey
.
length
;
i
++
)
{
if
(
isNext
)
break
const
keys
:
[]
=
this
.
miniBlockKey
[
i
]
for
(
let
j
=
0
;
j
<
keys
.
length
;
j
++
)
{
if
(
keys
[
j
]
===
BLOCK_STATE
.
NON_EMPTY
)
{
if
(
mBaseX
==
-
1
&&
mBaseY
==
-
1
)
{
mBaseX
=
i
mBaseY
=
j
}
else
{
const
diffX
=
i
-
mBaseX
,
diffY
=
j
-
mBaseY
const
tempX
=
baseX
+
diffX
,
tempY
=
baseY
+
diffY
// console.log(baseX, baseY, mBaseX, mBaseY, i, j,tempX,tempY)
// console.log(this.miniBlockKey)
const
tempBase
=
tempY
+
tempX
*
10
// console.log('newBase', tempBase, tempX, tempY)
if
(
tempX
<
0
||
tempY
<
0
||
tempBase
<
0
||
tempX
>=
10
||
tempY
>=
10
||
!
allEmptyBlockIdx
.
includes
(
tempBase
))
{
isNext
=
true
}
}
}
}
}
if
(
!
isNext
)
{
this
.
setNodeState
(
0
)
// console.log('可以放置', this.miniBlockKey)
return
}
}
this
.
setNodeState
(
1
)
}
/**
* 设置当前节点状态
* @param state 0 可用 1禁用
*/
setNodeState
(
state
)
{
const
isDisabled
=
this
.
isDisabled
=
state
!=
0
// console.log(this.miniBlockKey, !isDisabled ? '可用' : '禁用')
this
.
node
.
children
.
forEach
(
node
=>
{
node
.
color
=
cc
.
color
(
isDisabled
?
Config
.
miniBlockDisabledColor
:
Config
.
miniBlockColor
)
})
}
/**
* 判断是否能够放入
* @returns
...
...
@@ -201,6 +306,7 @@ export default class BlockManager extends cc.Component {
addNodeEvent
()
{
this
.
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
if
(
this
.
isDisabled
==
1
)
return
this
.
isMove
=
true
this
.
node
.
scale
=
1.7
},
this
)
...
...
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