Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Cocos-GoldenMiner
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-GoldenMiner
Commits
52de0a2b
Commit
52de0a2b
authored
Apr 14, 2023
by
Friends233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
随机生成游戏舞台
parent
03f5a902
Changes
13
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
838 additions
and
667 deletions
+838
-667
Game.fire
assets/Scenes/Game.fire
+587
-646
GameConfig.ts
assets/Script/Config/GameConfig.ts
+21
-1
GameScene.ts
assets/Script/GameScene.ts
+79
-3
utils.ts
assets/Script/utils.ts
+44
-2
clipRation.anim
assets/resources/ani/clipRation.anim
+2
-2
computer.prefab
assets/resources/props/computer.prefab
+3
-3
propWrp.prefab
assets/resources/props/propWrp.prefab
+83
-0
propWrp.prefab.meta
assets/resources/props/propWrp.prefab.meta
+9
-0
safetyHat.prefab
assets/resources/props/safetyHat.prefab
+2
-2
star.prefab
assets/resources/props/star.prefab
+2
-2
tool.prefab
assets/resources/props/tool.prefab
+2
-2
vehicle.prefab
assets/resources/props/vehicle.prefab
+2
-2
wheatEar.prefab
assets/resources/props/wheatEar.prefab
+2
-2
No files found.
assets/Scenes/Game.fire
View file @
52de0a2b
This diff is collapsed.
Click to expand it.
assets/Script/Config/GameConfig.ts
View file @
52de0a2b
...
...
@@ -14,7 +14,7 @@ export const CUSTOM_EVENT = {
export
const
Config
=
{
/** 爪子能伸出去的长度 */
maxLong
:
5
44
,
maxLong
:
6
44
,
/** 摇晃速度 */
rotationSpeed
:
1
,
...
...
@@ -24,4 +24,24 @@ export const Config = {
/** 高级道具移动速度 */
bestPropSpeed
:
500
,
/** 每轮生成加分道具数量 */
bestPropsNum
:
3
,
/** 普通道具每种最多生成数量 */
propsNum
:
2
,
/** 道具分布图 4*3 */
propsMap
:
[
[
1
,
0
,
0
,
1
,
1
,
1
,
1
,
0
,
1
,
1
,
1
,
1
],
[
1
,
0
,
0
,
1
,
1
,
1
,
1
,
1
,
1
,
0
,
1
,
1
]
]
}
\ No newline at end of file
assets/Script/GameScene.ts
View file @
52de0a2b
...
...
@@ -6,7 +6,7 @@
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
import
{
CUSTOM_EVENT
,
Config
,
LevelInfo
}
from
"./Config/GameConfig"
;
import
{
loadGameResources
,
numToChinese
,
set16ToRgb
}
from
"./utils"
;
import
{
getProbability
,
getRandomArrayElements
,
loadGameResources
,
numToChinese
,
randomNum
,
set16ToRgb
}
from
"./utils"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
// 爪子状态
...
...
@@ -25,6 +25,14 @@ export default class GameScene extends cc.Component {
@
property
(
cc
.
Prefab
)
procItem
:
cc
.
Prefab
=
null
/** 舞台道具 */
@
property
([
cc
.
Prefab
])
propItem
:
cc
.
Prefab
[]
=
[]
/** 加分道具 */
@
property
(
cc
.
Prefab
)
bsetPropItem
:
cc
.
Prefab
=
null
/** 当前关卡 0、1、2... */
actLevel
=
0
,
...
...
@@ -57,8 +65,11 @@ export default class GameScene extends cc.Component {
/** 抓取的目标 */
clipTarget
:
cc
.
Node
=
null
/** 场面上剩余加分道具数量 */
surplusStar
=
Config
.
bestPropsNum
protected
onLoad
():
void
{
loadGameResources
()
//
loadGameResources()
/** 开启碰撞检测 */
const
cm
=
cc
.
director
.
getCollisionManager
()
cm
.
enabled
=
true
...
...
@@ -70,12 +81,14 @@ export default class GameScene extends cc.Component {
this
.
resetConfig
()
this
.
refreshLevelInfo
()
this
.
refreshStageProps
()
this
.
addNodeEvent
()
}
/** 重置游戏设置 */
resetConfig
()
{
this
.
clipSpeed
=
Config
.
normalPropSpeed
this
.
surplusStar
=
Config
.
bestPropsNum
this
.
clip
.
getChildByName
(
'line'
).
height
=
Config
.
maxLong
const
rotationAni
=
cc
.
find
(
'clipMask/clipWrp'
,
this
.
node
)
.
getComponent
(
cc
.
Animation
)
...
...
@@ -115,7 +128,7 @@ export default class GameScene extends cc.Component {
this
.
clipState
=
state
switch
(
state
)
{
case
CLIP_STATE
.
DEFAULT
:
//
回
复旋转
//
恢
复旋转
ani
.
resume
()
// 显示默认动效
def
.
active
=
true
...
...
@@ -127,6 +140,10 @@ export default class GameScene extends cc.Component {
this
.
clipTarget
=
null
})
}
// 场面上没有剩余加分道具,刷新道具舞台
if
(
this
.
surplusStar
==
0
)
{
this
.
refreshStageProps
()
}
break
;
case
CLIP_STATE
.
PLAY
:
case
CLIP_STATE
.
STOP
:
...
...
@@ -199,6 +216,7 @@ export default class GameScene extends cc.Component {
setStarProc
()
{
const
proc
=
cc
.
find
(
'procBg/proc'
,
this
.
node
)
const
key
=
this
.
starNum
this
.
surplusStar
--
if
(
key
>=
this
.
levelObjectives
)
return
const
node
=
cc
.
instantiate
(
this
.
procItem
)
...
...
@@ -235,7 +253,65 @@ export default class GameScene extends cc.Component {
procBg
.
x
=
-
(
procBg
.
width
/
2
)
}
/** 刷新舞台道具 */
refreshStageProps
()
{
this
.
surplusStar
=
Config
.
bestPropsNum
const
gameStage
=
cc
.
find
(
'gameStage'
,
this
.
node
)
const
stageProps
:
cc
.
Node
[]
=
gameStage
.
children
const
mapIdx
=
Math
.
floor
(
randomNum
(
0
,
Config
.
propsMap
.
length
))
const
stageMap
:
number
[]
=
[...
Config
.
propsMap
[
mapIdx
]]
// 生成加分道具
for
(
let
i
=
0
;
i
<
Config
.
bestPropsNum
;
i
++
)
{
// 随机取
let
idx
=
Math
.
floor
(
randomNum
(
0
,
stageMap
.
length
))
// 找到第一个非空的位置
while
(
stageMap
[
idx
%
stageMap
.
length
]
!==
1
)
idx
++
// 放入加分道具
stageMap
[
idx
%
stageMap
.
length
]
=
2
}
// 随机道具池
let
propsRandom
=
[]
for
(
let
i
=
0
;
i
<
Config
.
propsNum
;
i
++
)
{
propsRandom
.
push
(...
this
.
propItem
)
}
// 剩余格子数量
const
emptyNum
=
stageMap
.
filter
(
_
=>
_
==
1
).
length
propsRandom
=
getRandomArrayElements
(
propsRandom
,
emptyNum
)
for
(
let
i
=
0
;
i
<
stageProps
.
length
;
i
++
)
{
const
node
=
stageProps
[
i
]
const
k
=
stageMap
[
i
]
// 随机旋转角度
const
angle
=
randomNum
(
0
,
90
).
toFixed
(
2
)
let
propNode
:
cc
.
Node
=
null
node
.
removeAllChildren
()
if
(
k
==
1
)
{
const
pre
=
cc
.
instantiate
(
propsRandom
.
pop
())
propNode
=
cc
.
instantiate
(
pre
)
}
else
if
(
k
==
2
)
{
// 加分道具
propNode
=
cc
.
instantiate
(
this
.
bsetPropItem
)
}
else
{
continue
;
}
if
(
propNode
)
{
propNode
.
angle
=
angle
>
45
?
angle
-
90
:
angle
propNode
.
setParent
(
node
)
}
}
/** 随机翻转地图 */
const
layout
=
gameStage
.
getComponent
(
cc
.
Layout
)
layout
.
horizontalDirection
=
getProbability
(
50
)
?
cc
.
Layout
.
HorizontalDirection
.
LEFT_TO_RIGHT
:
cc
.
Layout
.
HorizontalDirection
.
RIGHT_TO_LEFT
}
update
(
dt
:
number
):
void
{
if
(
this
.
isGameOver
)
return
// 锚点跟爪子之间的大致距离
const
offset
=
41
const
maxLong
=
Config
.
maxLong
-
offset
...
...
assets/Script/utils.ts
View file @
52de0a2b
...
...
@@ -37,9 +37,51 @@ export const numToChinese = (num) => {
export
const
loadGameResources
=
async
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
resources
.
preloadDir
(
'images'
,
cc
.
SpriteFrame
,
(
err
,
res
)
=>
{
console
.
log
(
'111'
,
res
)
resolve
(
res
,
err
)
console
.
log
(
'111'
,
res
)
resolve
(
res
,
err
)
})
})
}
/**
* 获取区间随机数 [min,max)
* @export
* @param {*} min
* @param {*} max
* @return {*}
*/
export
function
randomNum
(
min
,
max
):
number
{
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
))
+
min
}
/**
* 从数组里随机取元素
* @param arr
* @param count
*/
export
function
getRandomArrayElements
(
arr
,
count
)
{
if
(
arr
.
length
<=
count
)
return
arr
;
let
shuffled
=
arr
.
slice
(
0
),
i
=
arr
.
length
,
min
=
i
-
count
,
temp
,
index
;
while
(
i
--
>
min
)
{
index
=
(
i
+
1
)
*
Math
.
random
()
>>
0
;
temp
=
shuffled
[
index
];
shuffled
[
index
]
=
shuffled
[
i
];
shuffled
[
i
]
=
temp
;
}
return
shuffled
.
slice
(
min
);
}
/**
* 获取概率
* @param pro 1-100
*/
export
function
getProbability
(
pro
)
{
const
randomAry
=
[
...
Array
(
100
-
pro
).
fill
(
false
),
...
Array
(
pro
).
fill
(
true
)
]
const
num
=
Math
.
floor
(
randomNum
(
0
,
99
))
return
randomAry
[
num
]
}
assets/resources/ani/clipRation.anim
View file @
52de0a2b
...
...
@@ -16,11 +16,11 @@
},
{
"frame": 1,
"value":
4
0
"value":
5
0
},
{
"frame": 3,
"value": -
4
0
"value": -
5
0
},
{
"frame": 3.966666666666667,
...
...
assets/resources/props/computer.prefab
View file @
52de0a2b
...
...
@@ -54,8 +54,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-254.344
,
-121.5
,
0
,
0
,
0,
0,
0,
...
...
@@ -63,7 +63,7 @@
1,
1,
1,
1
1
.2125
]
},
"_eulerAngles": {
...
...
assets/resources/props/propWrp.prefab
0 → 100644
View file @
52de0a2b
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false,
"readonly": false
},
{
"__type__": "cc.Node",
"_name": "propWrp",
"_objFlags": 0,
"_parent": null,
"_children": [],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 2
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 194,
"height": 173
},
"_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": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "",
"sync": false
}
]
\ No newline at end of file
assets/resources/props/propWrp.prefab.meta
0 → 100644
View file @
52de0a2b
{
"ver": "1.3.2",
"uuid": "5ac08756-721e-492f-893d-0bfa92750f89",
"importer": "prefab",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
assets/resources/props/safetyHat.prefab
View file @
52de0a2b
...
...
@@ -54,8 +54,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
219.967
,
119.302
,
0
,
0
,
0,
0,
0,
...
...
assets/resources/props/star.prefab
View file @
52de0a2b
...
...
@@ -57,8 +57,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-243.227
,
138.001
,
0
,
0
,
0,
0,
0,
...
...
assets/resources/props/tool.prefab
View file @
52de0a2b
...
...
@@ -54,8 +54,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-10.36
,
134.681
,
0
,
0
,
0,
0,
0,
...
...
assets/resources/props/vehicle.prefab
View file @
52de0a2b
...
...
@@ -54,8 +54,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
248.696
,
-138.446
,
0
,
0
,
0,
0,
0,
...
...
assets/resources/props/wheatEar.prefab
View file @
52de0a2b
...
...
@@ -54,8 +54,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-19.134
,
-92.25
,
0
,
0
,
0,
0,
0,
...
...
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