Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
DuibaGameTemplate
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
钱根
DuibaGameTemplate
Commits
c49c78ce
Commit
c49c78ce
authored
Jun 16, 2022
by
Master Q
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加防止必死情况的出现
parent
2added8b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
33 deletions
+95
-33
ParkourGameConfig.ts
src/scenes/ParkourGameConfig.ts
+20
-18
ParkourGameScene.ts
src/scenes/ParkourGameScene.ts
+33
-5
ConveyorBelt.ts
src/scenes/comp/ConveyorBelt.ts
+42
-10
No files found.
src/scenes/ParkourGameConfig.ts
View file @
c49c78ce
import
UI
from
"../tools/UI"
;
type
UniqueKeyType
=
'uniqueKey1'
|
'uniqueKey2'
|
'uniqueKey3'
/**
* 传送带 item 的 类型申明
*/
...
...
@@ -14,7 +16,7 @@ export type ConveyorItemConstrutType = {
w
:
number
,
h
:
number
},
uniqueKey
?:
string
,
// 唯一标志
uniqueKey
?:
UniqueKeyType
,
// 唯一标志
}
type
ParkourGamerType
=
ConveyorItemConstrutType
...
...
@@ -118,7 +120,7 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
y
:
510
,
},
endPos
:
{
x
:
3
55
,
y
:
1624
x
:
3
80
,
y
:
1624
},
startTyl
:
400
,
scaleEndProportion
:
0.8
...
...
@@ -139,7 +141,7 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
{
uniqueKey
:
'uniqueKey1'
,
Container
:
'bucket_GE.png'
,
ProbabilityPort
:
10
,
ProbabilityPort
:
10
00
,
collisionConfig
:
{
type
:
'rect'
,
x
:
-
100
,
...
...
@@ -162,22 +164,22 @@ export const ParkourGameConfig: ParkourGameConfigInfer = {
h
:
60
}
},
{
uniqueKey
:
'uniqueKey3'
,
Container
:
class
extends
FYGE
.
Container
{
constructor
()
{
super
();
this
.
onInitUi
()
}
//
{
//
uniqueKey: 'uniqueKey3',
//
Container: class extends FYGE.Container {
//
constructor() {
//
super();
//
this.onInitUi()
//
}
onInitUi
()
{
UI
.
Rect
(
this
,
200
,
200
,
0x000000
,
20
)
}
},
ProbabilityPort
:
8
,
anchorX
:
100
,
anchorY
:
100
}
//
onInitUi() {
//
UI.Rect(this, 200, 200, 0x000000, 20)
//
}
//
},
//
ProbabilityPort: 8,
//
anchorX: 100,
//
anchorY: 100
//
}
],
CommonConfig
:
{
speed
:
300
,
...
...
src/scenes/ParkourGameScene.ts
View file @
c49c78ce
import
{
ParkourGameConfig
,
ParkourGameEvents
}
from
'./ParkourGameConfig'
;
import
{
ParkourGameConfig
,
ParkourGameE
leType
,
ParkourGameE
vents
}
from
'./ParkourGameConfig'
;
import
{
Scene
}
from
"../../module/views/Scene"
;
import
UI
from
"../tools/UI"
;
import
{
ConveyorBelt
,
ConveyorBeltItem
}
from
"./comp/ConveyorBelt"
;
import
{
GDispatcher
}
from
'../Game'
;
import
{
CollisionDetection
,
RectPhysicsCont
,
WithCollisionDetection
}
from
'./CollisionComposite'
;
/**
* 解个一元一次方程式咯
* @param x1
* @param y1
* @param x2
* @param y2
* @returns
*/
function
SolveUnivariateEquation
(
x1
:
number
,
y1
:
number
,
x2
:
number
,
y2
:
number
)
{
const
k
=
(
y2
-
y1
)
/
(
x2
-
x1
)
const
b
=
y1
-
k
*
x1
...
...
@@ -31,7 +39,7 @@ export class ParkourScene extends Scene {
this
.
_GamerIndex
=
v
const
y
=
ParkourGameConfig
.
CommonConfig
.
GamerAxisY
const
x
=
(
y
-
b
)
/
k
const
x
=
!
Number
.
isFinite
(
k
)
?
data
.
startPos
.
x
:
(
y
-
b
)
/
k
this
.
NewContIns
.
fy
=
y
// 简单的做一个 tween 动画吧
...
...
@@ -54,7 +62,7 @@ export class ParkourScene extends Scene {
this
.
conBeltList
.
push
(
this
.
addChild
(
new
ConveyorBelt
({
ParkourGameEleList
:
ParkourGameConfig
.
ParkourGameEleList
,
...
item
,
})))
}
,
this
.
onJudgeNextObstacle
)))
})
window
[
'conBeltList'
]
=
this
.
conBeltList
...
...
@@ -67,6 +75,27 @@ export class ParkourScene extends Scene {
GDispatcher
.
dispatchEvent
(
ParkourGameEvents
.
GAME_RESTART
)
}
/**
* 判断下一个障碍物 是否可以出,防止必死的情况
* @param data
* @returns
*/
onJudgeNextObstacle
=
(
data
:
ParkourGameEleType
)
=>
{
// TODO: 判断下一个障碍物 是否可以出,防止必死的情况
// 就比如下面就比较简单 下一个 item.uniqueKey 为 uniqueKey1 就回去
// 判断全部的传送带是否有 uniqueKey1 并且距离刷新点小于一定距离
// 这样就能 防止必死的情况
if
(
data
.
uniqueKey
===
'uniqueKey1'
)
{
return
this
.
conBeltList
.
filter
(
item
=>
{
return
item
.
children
.
some
((
child
:
ConveyorBeltItem
)
=>
{
return
child
.
y
<
800
&&
child
.
uniqueKey
===
"uniqueKey1"
})
}).
length
<
2
}
return
true
}
initEvents
():
void
{
this
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
)
...
...
@@ -91,7 +120,7 @@ export class ParkourScene extends Scene {
* @param e
*/
onGameEleCollision
(
e
:
FYGE
.
Event
)
{
console
.
log
(
e
.
data
)
//
console.log(e.data)
}
/**
...
...
@@ -121,7 +150,6 @@ export class ParkourScene extends Scene {
const
item
:
ConveyorBeltItem
=
it
.
conveyorItemList
[
i
]
as
ConveyorBeltItem
// @ts-expect-error
if
(
CollisionDetection
.
onCollsionJudge
(
item
.
PythicCont
,
this
.
NewContIns
.
PythicCont
))
{
console
.
log
(
'penzhuangle:'
,
item
.
constructType
)
it
.
onTakeIntoPool
(
item
,
false
)
}
...
...
src/scenes/comp/ConveyorBelt.ts
View file @
c49c78ce
...
...
@@ -100,6 +100,11 @@ export class ConveyorBeltItem extends FYGE.Container {
}
}
type
ProbabilityItemType
=
{
value
:
number
index
:
number
}
/**
* 传送带
*/
...
...
@@ -115,7 +120,7 @@ export class ConveyorBelt extends FYGE.Container {
private
tyl
:
number
// _ty 大于 tyl 就会出新的障碍物
private
props
:
ConveyorBeltType
private
ProbabilityList
:
number
[]
// 障碍物的 概率数组 是经过 前置相加处理过的
private
ProbabilityList
:
ProbabilityItemType
[]
// 障碍物的 概率数组 是经过 前置相加处理过的
isMoving
:
boolean
=
false
private
_tSpeed
:
number
...
...
@@ -126,6 +131,8 @@ export class ConveyorBelt extends FYGE.Container {
conveyorItemList
:
ConveyorBeltItem
[]
=
[]
private
onJudgeNextObstacle
:
(
item
:
ParkourGameEleType
)
=>
boolean
get
tSpeed
()
{
return
this
.
_tSpeed
}
...
...
@@ -137,11 +144,13 @@ export class ConveyorBelt extends FYGE.Container {
this
.
acc
=
2
*
this
.
totalDisY
/
Math
.
pow
(
t
,
2
);
}
constructor
(
props
:
ConveyorBeltType
)
{
constructor
(
props
:
ConveyorBeltType
,
onJudgeNextObstacle
?:
(
item
:
ParkourGameEleType
)
=>
boolean
)
{
super
()
this
.
props
=
props
this
.
onJudgeNextObstacle
=
onJudgeNextObstacle
this
.
startPos
=
props
.
startPos
this
.
endPos
=
props
.
endPos
this
.
tanValue
=
Math
.
abs
(
props
.
startPos
.
x
-
props
.
endPos
.
x
)
?
(
props
.
startPos
.
y
-
props
.
endPos
.
y
)
/
(
props
.
startPos
.
x
-
props
.
endPos
.
x
)
:
0
...
...
@@ -170,9 +179,12 @@ export class ConveyorBelt extends FYGE.Container {
const
_ParkourGameEleList
=
this
.
ParkourGameEleList
const
sumProbability
=
_ParkourGameEleList
.
reduce
((
prev
,
cur
)
=>
prev
+
cur
.
ProbabilityPort
,
0
)
const
_ProbabilityList
=
[]
_ParkourGameEleList
.
reduce
((
pre
,
curr
)
=>
{
_ProbabilityList
.
push
(
pre
+
curr
.
ProbabilityPort
/
sumProbability
)
const
_ProbabilityList
:
ProbabilityItemType
[]
=
[]
_ParkourGameEleList
.
reduce
((
pre
,
curr
,
index
)
=>
{
_ProbabilityList
.
push
({
value
:
pre
+
curr
.
ProbabilityPort
/
sumProbability
,
index
})
return
pre
+
curr
.
ProbabilityPort
/
sumProbability
},
0
)
this
.
ProbabilityList
=
_ProbabilityList
...
...
@@ -310,15 +322,35 @@ export class ConveyorBelt extends FYGE.Container {
})
}
onGetFinalObstacle
(
portList
:
ProbabilityItemType
[])
{
if
(
portList
.
length
===
0
)
return
const
maxProbability
=
portList
[
portList
.
length
-
1
].
value
const
random
=
Math
.
random
()
*
maxProbability
const
randomItem
=
portList
.
find
((
item
)
=>
{
return
random
<=
item
.
value
})
const
index
=
randomItem
.
index
const
ParkourGameEle
=
this
.
ParkourGameEleList
[
index
]
if
(
this
.
onJudgeNextObstacle
)
{
const
b
=
this
.
onJudgeNextObstacle
(
ParkourGameEle
)
if
(
!
b
)
{
const
skipPortList
=
portList
.
filter
((
item
)
=>
{
return
item
.
index
!==
index
})
return
this
.
onGetFinalObstacle
(
skipPortList
)
}
}
return
ParkourGameEle
}
/**
* 初始化障碍物
*/
onInitObstack
()
{
const
random
=
Math
.
random
()
const
index
=
this
.
ProbabilityList
.
findIndex
((
item
)
=>
{
return
random
<=
item
})
const
ParkourGameEle
=
this
.
ParkourGameEleList
[
index
]
const
ParkourGameEle
=
this
.
onGetFinalObstacle
(
this
.
ProbabilityList
)
if
(
!
ParkourGameEle
)
return
this
.
onTakeoutFromPool
(
ParkourGameEle
)
...
...
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