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
f95898a6
Commit
f95898a6
authored
Jan 28, 2022
by
Master Q
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
游戏 体验 加速度
parent
90bc30e8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
39 deletions
+113
-39
GPool.ts
module/tools/GPool.ts
+1
-0
ConveyorBelt.ts
src/scenes/LevonoGameScene/ConveyorBelt.ts
+71
-30
GameEle.ts
src/scenes/LevonoGameScene/GameEle.ts
+41
-9
No files found.
module/tools/GPool.ts
View file @
f95898a6
...
@@ -11,6 +11,7 @@ export class GPool {
...
@@ -11,6 +11,7 @@ export class GPool {
*/
*/
public
static
takeOut
<
T
>
(
name
:
string
):
T
{
public
static
takeOut
<
T
>
(
name
:
string
):
T
{
if
(
this
.
pool
[
name
]
&&
this
.
pool
[
name
].
length
)
{
if
(
this
.
pool
[
name
]
&&
this
.
pool
[
name
].
length
)
{
// console.log('从对象池中qu');
return
this
.
pool
[
name
].
shift
();
return
this
.
pool
[
name
].
shift
();
}
}
return
null
;
return
null
;
...
...
src/scenes/LevonoGameScene/ConveyorBelt.ts
View file @
f95898a6
...
@@ -62,17 +62,23 @@ export class ConveyorBelt extends FYGE.Container {
...
@@ -62,17 +62,23 @@ export class ConveyorBelt extends FYGE.Container {
spl
:
number
// 下一个 出现的 距离 后面就去取 随机值
spl
:
number
// 下一个 出现的 距离 后面就去取 随机值
tanValue
:
number
tanValue
:
number
totalDisY
:
number
// 全部距离
totalDisY
:
number
// 全部距离
ty
:
number
=
0
// y 经历的距离
ty
:
number
=
0
// y 经历的距离
用来判断是否出下一个
isMove
:
boolean
=
false
// 是否已经开始
isMove
:
boolean
=
false
// 是否已经开始
clock
:
Clock
clock
:
Clock
conveyorItems
:
Array
<
ConveyorBeltItemConstruct
>
=
[]
conveyorItems
:
Array
<
ConveyorBeltItemConstruct
>
=
[]
scaleEndProportion
:
number
=
0.3
scaleEndProportion
:
number
=
0.3
_config
:
ConveyorItemConfig
_config
:
ConveyorItemConfig
totalTy
:
number
=
0
// 一共走了多少距离 计算分数
_
totalTy
:
number
=
0
// 一共走了多少距离 计算分数
updateScore
:
Function
updateScore
:
Function
acc
:
number
=
0
// 加速度
get
speed
()
{
get
speed
()
{
return
GameDiffConfig
.
getCurrGameDiff
(
this
.
getScore
()).
speed
return
this
.
_speed
}
set
speed
(
n
)
{
this
.
initAcc
()
this
.
_speed
=
n
}
}
constructor
(
props
:
ConveyorBeltInfer
,
splt
?:
number
,
config
:
ConveyorItemConfig
=
defaultConveyorConfig
)
{
constructor
(
props
:
ConveyorBeltInfer
,
splt
?:
number
,
config
:
ConveyorItemConfig
=
defaultConveyorConfig
)
{
...
@@ -87,9 +93,18 @@ export class ConveyorBelt extends FYGE.Container {
...
@@ -87,9 +93,18 @@ export class ConveyorBelt extends FYGE.Container {
this
.
updateScore
=
props
.
updateScore
this
.
updateScore
=
props
.
updateScore
this
.
tanValue
=
Math
.
abs
(
props
.
start
.
x
-
props
.
end
.
x
)
?
(
props
.
start
.
y
-
props
.
end
.
y
)
/
(
props
.
start
.
x
-
props
.
end
.
x
)
:
0
this
.
tanValue
=
Math
.
abs
(
props
.
start
.
x
-
props
.
end
.
x
)
?
(
props
.
start
.
y
-
props
.
end
.
y
)
/
(
props
.
start
.
x
-
props
.
end
.
x
)
:
0
this
.
totalDisY
=
Math
.
abs
(
props
.
start
.
y
-
props
.
end
.
y
)
this
.
totalDisY
=
Math
.
abs
(
props
.
start
.
y
-
props
.
end
.
y
)
this
.
initEvents
()
this
.
initEvents
()
}
}
/**
* 计算加速度
*/
initAcc
()
{
let
t
=
this
.
totalDisY
/
this
.
speed
this
.
acc
=
2
*
this
.
totalDisY
/
Math
.
pow
(
t
,
2
)
}
reStart
()
{
reStart
()
{
this
.
conveyorItems
.
forEach
(
i
=>
{
this
.
conveyorItems
.
forEach
(
i
=>
{
this
.
popConveyor
(
i
)
this
.
popConveyor
(
i
)
...
@@ -132,8 +147,7 @@ export class ConveyorBelt extends FYGE.Container {
...
@@ -132,8 +147,7 @@ export class ConveyorBelt extends FYGE.Container {
// item = GPool.takeOut<GameEleOfWater>(e.resName) || new GameEleOfWater(e.resName)
// item = GPool.takeOut<GameEleOfWater>(e.resName) || new GameEleOfWater(e.resName)
// }
// }
item
.
setPostion
(
this
.
startPos
.
x
,
this
.
startPos
.
y
)
item
.
setPostion
(
this
.
startPos
.
x
,
this
.
startPos
.
y
)
item
.
scale
.
set
(
0
)
item
.
reset
()
item
.
visible
=
true
this
.
conveyorItems
.
push
(
item
)
this
.
conveyorItems
.
push
(
item
)
return
item
return
item
}
}
...
@@ -150,7 +164,7 @@ export class ConveyorBelt extends FYGE.Container {
...
@@ -150,7 +164,7 @@ export class ConveyorBelt extends FYGE.Container {
return
this
.
_config
.
conveyorItemsList
[
0
]
return
this
.
_config
.
conveyorItemsList
[
0
]
}
}
const
p
=
Math
.
random
()
const
p
=
Math
.
random
()
const
currDiff
=
GameDiffConfig
.
getCurrGameDiff
(
this
.
getScore
())
.
proportion
const
currDiff
=
this
.
currConfig
.
proportion
// this._config.conveyorItemsList
// this._config.conveyorItemsList
const
r
=
currDiff
.
findIndex
((
n
:
number
)
=>
{
const
r
=
currDiff
.
findIndex
((
n
:
number
)
=>
{
return
p
<
n
return
p
<
n
...
@@ -174,40 +188,66 @@ export class ConveyorBelt extends FYGE.Container {
...
@@ -174,40 +188,66 @@ export class ConveyorBelt extends FYGE.Container {
this
.
addChild
(
con
)
this
.
addChild
(
con
)
}
}
/**
get
totalTy
()
{
* 获取分数
return
this
.
_totalTy
*/
}
getScore
()
{
return
Math
.
floor
(
this
.
totalTy
/
10
)
_score
:
number
=
0
currConfig
:
any
set
totalTy
(
n
)
{
this
.
_score
=
Math
.
floor
(
n
/
10
)
this
.
currConfig
=
GameDiffConfig
.
getCurrGameDiff
(
this
.
_score
,
(
curr
)
=>
{
// this.speed = curr.speed
})
this
.
speed
=
this
.
currConfig
.
speed
this
.
_totalTy
=
n
}
onChangeTime
(
t
:
number
)
{
this
.
conveyorItems
.
forEach
(
item
=>
{
let
_y
=
item
.
speed
*
t
// vt + 1/2 *a t^2
let
_x
=
_y
/
this
.
tanValue
// item.setPostion()
item
.
position
.
set
(
item
.
x
+
_x
,
item
.
y
+
_y
)
const
yp
=
_y
/
(
this
.
totalDisY
*
this
.
scaleEndProportion
)
item
.
scaleX
<
1
&&
(
item
.
scaleX
+=
yp
);
item
.
scaleX
<
1
&&
(
item
.
scaleY
+=
yp
);
if
(
item
.
y
>=
this
.
endPos
.
y
)
{
this
.
popConveyor
(
item
)
}
item
.
speed
+=
this
.
acc
*
t
})
}
}
onChangePosByY
(
changeY
:
number
)
{
onChangePosByY
(
changeY
:
number
)
{
this
.
ty
+=
changeY
this
.
ty
+=
changeY
this
.
totalTy
+=
changeY
this
.
totalTy
+=
changeY
this
.
updateScore
&&
this
.
updateScore
(
this
.
getScore
()
)
this
.
updateScore
&&
this
.
updateScore
(
this
.
_score
)
if
(
this
.
ty
>=
this
.
spl
)
{
if
(
this
.
ty
>=
this
.
spl
)
{
// console.log('渲染一个:', this.ty)
this
.
ty
=
0
this
.
ty
=
0
this
.
onRenderConveyorItem
()
this
.
onRenderConveyorItem
()
this
.
obstacleJudge
&&
this
.
obstacleJudge
(
null
,
this
)
}
}
this
.
conveyorItems
.
forEach
(
target
=>
{
// this.conveyorItems.forEach(target => {
if
(
!
this
.
tanValue
)
{
// if (!this.tanValue) {
}
else
{
// } else {
target
.
x
+=
changeY
/
this
.
tanValue
// target.x += changeY / this.tanValue
}
// }
target
.
y
+=
changeY
// target.y += changeY
const
yp
=
changeY
/
(
this
.
totalDisY
*
this
.
scaleEndProportion
)
// const yp = changeY / (this.totalDisY * this.scaleEndProportion)
// target.alpha += yp
// // target.alpha += yp
target
.
scaleX
<
1
&&
(
target
.
scaleX
+=
yp
);
// target.scaleX < 1 && (target.scaleX += yp);
target
.
scaleX
<
1
&&
(
target
.
scaleY
+=
yp
);
// target.scaleX < 1 && (target.scaleY += yp);
if
(
target
.
y
>=
this
.
endPos
.
y
)
{
// if (target.y >= this.endPos.y) {
this
.
popConveyor
(
target
)
// this.popConveyor(target)
}
// this.obstacleJudge && this.obstacleJudge(target, this)
this
.
obstacleJudge
&&
this
.
obstacleJudge
(
target
,
this
)
})
// if (target.y >= RabbitPos.y + 200) {
// this.ConveyorBeltConfigData.onBehindFromRabbit(target)
// }
// }
// })
}
}
// 因为碰撞或者移动出去的 销毁
// 因为碰撞或者移动出去的 销毁
...
@@ -228,6 +268,7 @@ export class ConveyorBelt extends FYGE.Container {
...
@@ -228,6 +268,7 @@ export class ConveyorBelt extends FYGE.Container {
const
currSpeed
=
this
.
speed
const
currSpeed
=
this
.
speed
this
.
onChangePosByY
(
diff
*
currSpeed
)
this
.
onChangePosByY
(
diff
*
currSpeed
)
this
.
onChangeTime
(
diff
)
}
}
}
}
\ No newline at end of file
src/scenes/LevonoGameScene/GameEle.ts
View file @
f95898a6
...
@@ -18,6 +18,8 @@ type GameDiffConfigType = {
...
@@ -18,6 +18,8 @@ type GameDiffConfigType = {
export
const
GameDiffConfig
:
GameDiffConfigType
=
(
function
()
{
export
const
GameDiffConfig
:
GameDiffConfigType
=
(
function
()
{
let
proportionList
:
ProportionList
=
[]
let
proportionList
:
ProportionList
=
[]
let
_i
=
null
// 暂作比较
let
_lcurr
=
null
return
{
return
{
initGameDiff
(
pl
:
ProportionList
)
{
initGameDiff
(
pl
:
ProportionList
)
{
proportionList
=
pl
||
[
proportionList
=
pl
||
[
...
@@ -29,10 +31,10 @@ export const GameDiffConfig: GameDiffConfigType = (function() {
...
@@ -29,10 +31,10 @@ export const GameDiffConfig: GameDiffConfigType = (function() {
{
{
mileage
:
120
,
mileage
:
120
,
proportion
:
[
0.5
,
0.7
,
1
],
proportion
:
[
0.5
,
0.7
,
1
],
speed
:
3
30
,
speed
:
5
30
,
},
},
{
{
mileage
:
2200
,
mileage
:
2200
,
proportion
:
[
0.1
,
0.7
,
1
],
proportion
:
[
0.1
,
0.7
,
1
],
speed
:
500
,
speed
:
500
,
}
}
...
@@ -42,8 +44,16 @@ export const GameDiffConfig: GameDiffConfigType = (function() {
...
@@ -42,8 +44,16 @@ export const GameDiffConfig: GameDiffConfigType = (function() {
* 获取当前 概率
* 获取当前 概率
* @param m
* @param m
*/
*/
getCurrGameDiff
(
m
:
number
):
CurrProportion
{
getCurrGameDiff
(
m
:
number
,
cb
?:
Function
):
CurrProportion
{
const
currIndex
=
proportionList
.
findIndex
(
i
=>
m
<
i
.
mileage
)
const
currIndex
=
proportionList
.
findIndex
(
i
=>
m
<
i
.
mileage
)
if
(
currIndex
!=
_i
)
{
const
curr
=
_lcurr
=
currIndex
==
-
1
?
proportionList
.
slice
(
-
1
)[
0
]
:
proportionList
[
currIndex
]
_i
=
currIndex
cb
(
curr
)
return
curr
}
else
{
return
_lcurr
}
// console.log(currIndex, proportionList, proportionList.slice(currIndex, 1))
// console.log(currIndex, proportionList, proportionList.slice(currIndex, 1))
const
curr
=
currIndex
==
-
1
?
proportionList
.
slice
(
-
1
)[
0
]
:
proportionList
[
currIndex
]
const
curr
=
currIndex
==
-
1
?
proportionList
.
slice
(
-
1
)[
0
]
:
proportionList
[
currIndex
]
return
curr
return
curr
...
@@ -59,6 +69,7 @@ export type GameEleType = 'obstacle' | 'unObstacle'
...
@@ -59,6 +69,7 @@ export type GameEleType = 'obstacle' | 'unObstacle'
interface
GameEleInfer
{
interface
GameEleInfer
{
_type
:
GameEleType
,
_type
:
GameEleType
,
_res
:
string
,
_res
:
string
,
speed
:
number
,
// 当前速度
getMaterialCollisionObj
:
()
=>
CollisionData
,
// 获取碰撞
getMaterialCollisionObj
:
()
=>
CollisionData
,
// 获取碰撞
setPostion
:
(
x
:
number
,
y
:
number
)
=>
void
// 配置坐标
setPostion
:
(
x
:
number
,
y
:
number
)
=>
void
// 配置坐标
onCollision
:
()
=>
void
onCollision
:
()
=>
void
...
@@ -69,6 +80,7 @@ interface GameEleOfGamerPropsInfer {
...
@@ -69,6 +80,7 @@ interface GameEleOfGamerPropsInfer {
}
}
export
class
GameEleOfGamer
extends
FYGE
.
Container
implements
GameEleInfer
{
export
class
GameEleOfGamer
extends
FYGE
.
Container
implements
GameEleInfer
{
speed
:
number
_type
:
GameEleType
=
'obstacle'
_type
:
GameEleType
=
'obstacle'
_res
:
string
;
_res
:
string
;
_isSpeedUp
:
boolean
=
false
_isSpeedUp
:
boolean
=
false
...
@@ -154,7 +166,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
...
@@ -154,7 +166,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
reset
()
{
reset
()
{
this
.
pxlIndex
=
1
this
.
pxlIndex
=
1
this
.
fy
=
1
1
30
this
.
fy
=
1
0
30
}
}
/**
/**
...
@@ -172,7 +184,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
...
@@ -172,7 +184,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
this
.
reset
()
this
.
reset
()
}
}
setPostion
(
x
:
number
,
y
:
number
=
1
1
30
)
{
setPostion
(
x
:
number
,
y
:
number
=
1
0
30
)
{
this
.
fx
=
x
this
.
fx
=
x
this
.
fy
=
y
this
.
fy
=
y
// this.position.set(x - this.offsetX, y - this.offsetY)
// this.position.set(x - this.offsetX, y - this.offsetY)
...
@@ -207,6 +219,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
...
@@ -207,6 +219,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
}
}
export
class
GameEleOfPowerBall
extends
FYGE
.
Container
implements
GameEleInfer
{
export
class
GameEleOfPowerBall
extends
FYGE
.
Container
implements
GameEleInfer
{
speed
:
number
=
0
_type
:
GameEleType
=
'unObstacle'
_type
:
GameEleType
=
'unObstacle'
_res
:
string
_res
:
string
offsetX
:
number
=
130
offsetX
:
number
=
130
...
@@ -227,6 +240,7 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
...
@@ -227,6 +240,7 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
this
.
addChild
(
new
FYGE
.
MovieClip
(
RES
.
getRes
(
mv
)))
this
.
addChild
(
new
FYGE
.
MovieClip
(
RES
.
getRes
(
mv
)))
this
.
_res
=
mv
this
.
_res
=
mv
this
.
anchor
.
set
(
this
.
offsetX
,
this
.
offsetY
)
this
.
anchor
.
set
(
this
.
offsetX
,
this
.
offsetY
)
this
.
reset
()
const
t
=
this
.
getMaterialCollisionObj
()
const
t
=
this
.
getMaterialCollisionObj
()
Tools
.
PAGE
.
debug
&&
UI
.
Rect
(
this
,
t
.
w
,
t
.
h
,
0xcccccc
,
20
,
0
,
this
.
rHeight
*
(
1
-
this
.
collisionProportionOfY
),
0.7
)
Tools
.
PAGE
.
debug
&&
UI
.
Rect
(
this
,
t
.
w
,
t
.
h
,
0xcccccc
,
20
,
0
,
this
.
rHeight
*
(
1
-
this
.
collisionProportionOfY
),
0.7
)
}
}
...
@@ -235,6 +249,12 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
...
@@ -235,6 +249,12 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
this
.
position
.
set
(
x
-
this
.
offsetX
,
y
-
this
.
offsetY
)
this
.
position
.
set
(
x
-
this
.
offsetX
,
y
-
this
.
offsetY
)
}
}
reset
()
{
this
.
speed
=
0
this
.
scale
.
set
(
0
)
this
.
visible
=
true
}
onCollision
()
{
onCollision
()
{
}
}
...
@@ -250,6 +270,7 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
...
@@ -250,6 +270,7 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
}
}
export
class
GameEleOfWater
extends
FYGE
.
Sprite
implements
GameEleInfer
{
export
class
GameEleOfWater
extends
FYGE
.
Sprite
implements
GameEleInfer
{
speed
:
number
=
0
_type
:
GameEleType
=
'obstacle'
_type
:
GameEleType
=
'obstacle'
_res
:
string
_res
:
string
collisionProportionOfY
:
number
=
0.5
collisionProportionOfY
:
number
=
0.5
...
@@ -259,6 +280,7 @@ export class GameEleOfWater extends FYGE.Sprite implements GameEleInfer {
...
@@ -259,6 +280,7 @@ export class GameEleOfWater extends FYGE.Sprite implements GameEleInfer {
this
.
_res
=
res
this
.
_res
=
res
this
.
anchorTexture
.
set
(
0.5
,
0.5
)
this
.
anchorTexture
.
set
(
0.5
,
0.5
)
const
t
=
this
.
getMaterialCollisionObj
()
const
t
=
this
.
getMaterialCollisionObj
()
this
.
reset
()
Tools
.
PAGE
.
debug
&&
UI
.
Rect
(
this
,
t
.
w
,
t
.
h
,
0xcccccc
,
20
,
0
-
this
.
width
/
2
,
this
.
height
*
(
1
-
this
.
collisionProportionOfY
)
-
this
.
height
/
2
,
0.7
)
Tools
.
PAGE
.
debug
&&
UI
.
Rect
(
this
,
t
.
w
,
t
.
h
,
0xcccccc
,
20
,
0
-
this
.
width
/
2
,
this
.
height
*
(
1
-
this
.
collisionProportionOfY
)
-
this
.
height
/
2
,
0.7
)
}
}
...
@@ -275,17 +297,20 @@ export class GameEleOfWater extends FYGE.Sprite implements GameEleInfer {
...
@@ -275,17 +297,20 @@ export class GameEleOfWater extends FYGE.Sprite implements GameEleInfer {
}
}
}
}
onCollision
()
{
reset
()
{
this
.
speed
=
0
this
.
scale
.
set
(
0
)
this
.
visible
=
true
}
}
reset
()
{
onCollision
()
{
}
}
}
}
export
class
GameEleOfBucket
extends
FYGE
.
Sprite
implements
GameEleInfer
{
export
class
GameEleOfBucket
extends
FYGE
.
Sprite
implements
GameEleInfer
{
speed
:
number
;
_type
:
GameEleType
=
'obstacle'
_type
:
GameEleType
=
'obstacle'
_res
:
string
_res
:
string
collisionProportionOfY
:
number
=
0.4
collisionProportionOfY
:
number
=
0.4
...
@@ -295,10 +320,17 @@ export class GameEleOfBucket extends FYGE.Sprite implements GameEleInfer {
...
@@ -295,10 +320,17 @@ export class GameEleOfBucket extends FYGE.Sprite implements GameEleInfer {
this
.
_res
=
res
this
.
_res
=
res
this
.
anchorTexture
.
set
(
0.5
,
0.5
)
this
.
anchorTexture
.
set
(
0.5
,
0.5
)
const
t
=
this
.
getMaterialCollisionObj
()
const
t
=
this
.
getMaterialCollisionObj
()
this
.
reset
()
Tools
.
PAGE
.
debug
&&
UI
.
Rect
(
this
,
t
.
w
,
t
.
h
,
0xcccccc
,
20
,
0
-
this
.
width
/
2
,
this
.
height
*
(
1
-
this
.
collisionProportionOfY
)
-
this
.
height
/
2
,
0.7
)
Tools
.
PAGE
.
debug
&&
UI
.
Rect
(
this
,
t
.
w
,
t
.
h
,
0xcccccc
,
20
,
0
-
this
.
width
/
2
,
this
.
height
*
(
1
-
this
.
collisionProportionOfY
)
-
this
.
height
/
2
,
0.7
)
}
}
reset
()
{
this
.
speed
=
0
this
.
scale
.
set
(
0
)
this
.
visible
=
true
}
setPostion
(
x
:
number
,
y
:
number
=
0
)
{
setPostion
(
x
:
number
,
y
:
number
=
0
)
{
this
.
position
.
set
(
x
,
y
)
this
.
position
.
set
(
x
,
y
)
}
}
...
...
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