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 {
*/
public
static
takeOut
<
T
>
(
name
:
string
):
T
{
if
(
this
.
pool
[
name
]
&&
this
.
pool
[
name
].
length
)
{
// console.log('从对象池中qu');
return
this
.
pool
[
name
].
shift
();
}
return
null
;
...
...
src/scenes/LevonoGameScene/ConveyorBelt.ts
View file @
f95898a6
...
...
@@ -62,17 +62,23 @@ export class ConveyorBelt extends FYGE.Container {
spl
:
number
// 下一个 出现的 距离 后面就去取 随机值
tanValue
:
number
totalDisY
:
number
// 全部距离
ty
:
number
=
0
// y 经历的距离
ty
:
number
=
0
// y 经历的距离
用来判断是否出下一个
isMove
:
boolean
=
false
// 是否已经开始
clock
:
Clock
conveyorItems
:
Array
<
ConveyorBeltItemConstruct
>
=
[]
scaleEndProportion
:
number
=
0.3
_config
:
ConveyorItemConfig
totalTy
:
number
=
0
// 一共走了多少距离 计算分数
_
totalTy
:
number
=
0
// 一共走了多少距离 计算分数
updateScore
:
Function
acc
:
number
=
0
// 加速度
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
)
{
...
...
@@ -87,9 +93,18 @@ export class ConveyorBelt extends FYGE.Container {
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
.
totalDisY
=
Math
.
abs
(
props
.
start
.
y
-
props
.
end
.
y
)
this
.
initEvents
()
}
/**
* 计算加速度
*/
initAcc
()
{
let
t
=
this
.
totalDisY
/
this
.
speed
this
.
acc
=
2
*
this
.
totalDisY
/
Math
.
pow
(
t
,
2
)
}
reStart
()
{
this
.
conveyorItems
.
forEach
(
i
=>
{
this
.
popConveyor
(
i
)
...
...
@@ -132,8 +147,7 @@ export class ConveyorBelt extends FYGE.Container {
// item = GPool.takeOut<GameEleOfWater>(e.resName) || new GameEleOfWater(e.resName)
// }
item
.
setPostion
(
this
.
startPos
.
x
,
this
.
startPos
.
y
)
item
.
scale
.
set
(
0
)
item
.
visible
=
true
item
.
reset
()
this
.
conveyorItems
.
push
(
item
)
return
item
}
...
...
@@ -150,7 +164,7 @@ export class ConveyorBelt extends FYGE.Container {
return
this
.
_config
.
conveyorItemsList
[
0
]
}
const
p
=
Math
.
random
()
const
currDiff
=
GameDiffConfig
.
getCurrGameDiff
(
this
.
getScore
())
.
proportion
const
currDiff
=
this
.
currConfig
.
proportion
// this._config.conveyorItemsList
const
r
=
currDiff
.
findIndex
((
n
:
number
)
=>
{
return
p
<
n
...
...
@@ -174,40 +188,66 @@ export class ConveyorBelt extends FYGE.Container {
this
.
addChild
(
con
)
}
/**
* 获取分数
*/
getScore
()
{
return
Math
.
floor
(
this
.
totalTy
/
10
)
get
totalTy
()
{
return
this
.
_totalTy
}
_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
)
{
this
.
ty
+=
changeY
this
.
totalTy
+=
changeY
this
.
updateScore
&&
this
.
updateScore
(
this
.
getScore
()
)
this
.
updateScore
&&
this
.
updateScore
(
this
.
_score
)
if
(
this
.
ty
>=
this
.
spl
)
{
// console.log('渲染一个:', this.ty)
this
.
ty
=
0
this
.
onRenderConveyorItem
()
this
.
obstacleJudge
&&
this
.
obstacleJudge
(
null
,
this
)
}
this
.
conveyorItems
.
forEach
(
target
=>
{
if
(
!
this
.
tanValue
)
{
}
else
{
target
.
x
+=
changeY
/
this
.
tanValue
}
target
.
y
+=
changeY
const
yp
=
changeY
/
(
this
.
totalDisY
*
this
.
scaleEndProportion
)
// target.alpha += yp
target
.
scaleX
<
1
&&
(
target
.
scaleX
+=
yp
);
target
.
scaleX
<
1
&&
(
target
.
scaleY
+=
yp
);
if
(
target
.
y
>=
this
.
endPos
.
y
)
{
this
.
popConveyor
(
target
)
}
this
.
obstacleJudge
&&
this
.
obstacleJudge
(
target
,
this
)
})
// if (target.y >= RabbitPos.y + 200) {
// this.ConveyorBeltConfigData.onBehindFromRabbit(target)
// this.conveyorItems.forEach(target => {
// if (!this.tanValue) {
// } else {
// target.x += changeY / this.tanValue
// }
// target.y += changeY
// const yp = changeY / (this.totalDisY * this.scaleEndProportion)
// // target.alpha += yp
// target.scaleX < 1 && (target.scaleX += yp);
// target.scaleX < 1 && (target.scaleY += yp);
// if (target.y >= this.endPos.y) {
// this.popConveyor(target)
// this.obstacleJudge && this.obstacleJudge(target, this)
// }
// })
}
// 因为碰撞或者移动出去的 销毁
...
...
@@ -228,6 +268,7 @@ export class ConveyorBelt extends FYGE.Container {
const
currSpeed
=
this
.
speed
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 = {
export
const
GameDiffConfig
:
GameDiffConfigType
=
(
function
()
{
let
proportionList
:
ProportionList
=
[]
let
_i
=
null
// 暂作比较
let
_lcurr
=
null
return
{
initGameDiff
(
pl
:
ProportionList
)
{
proportionList
=
pl
||
[
...
...
@@ -29,10 +31,10 @@ export const GameDiffConfig: GameDiffConfigType = (function() {
{
mileage
:
120
,
proportion
:
[
0.5
,
0.7
,
1
],
speed
:
3
30
,
speed
:
5
30
,
},
{
mileage
:
2200
,
mileage
:
2200
,
proportion
:
[
0.1
,
0.7
,
1
],
speed
:
500
,
}
...
...
@@ -42,8 +44,16 @@ export const GameDiffConfig: GameDiffConfigType = (function() {
* 获取当前 概率
* @param m
*/
getCurrGameDiff
(
m
:
number
):
CurrProportion
{
getCurrGameDiff
(
m
:
number
,
cb
?:
Function
):
CurrProportion
{
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))
const
curr
=
currIndex
==
-
1
?
proportionList
.
slice
(
-
1
)[
0
]
:
proportionList
[
currIndex
]
return
curr
...
...
@@ -59,6 +69,7 @@ export type GameEleType = 'obstacle' | 'unObstacle'
interface
GameEleInfer
{
_type
:
GameEleType
,
_res
:
string
,
speed
:
number
,
// 当前速度
getMaterialCollisionObj
:
()
=>
CollisionData
,
// 获取碰撞
setPostion
:
(
x
:
number
,
y
:
number
)
=>
void
// 配置坐标
onCollision
:
()
=>
void
...
...
@@ -69,6 +80,7 @@ interface GameEleOfGamerPropsInfer {
}
export
class
GameEleOfGamer
extends
FYGE
.
Container
implements
GameEleInfer
{
speed
:
number
_type
:
GameEleType
=
'obstacle'
_res
:
string
;
_isSpeedUp
:
boolean
=
false
...
...
@@ -154,7 +166,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
reset
()
{
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 {
this
.
reset
()
}
setPostion
(
x
:
number
,
y
:
number
=
1
1
30
)
{
setPostion
(
x
:
number
,
y
:
number
=
1
0
30
)
{
this
.
fx
=
x
this
.
fy
=
y
// this.position.set(x - this.offsetX, y - this.offsetY)
...
...
@@ -207,6 +219,7 @@ export class GameEleOfGamer extends FYGE.Container implements GameEleInfer {
}
export
class
GameEleOfPowerBall
extends
FYGE
.
Container
implements
GameEleInfer
{
speed
:
number
=
0
_type
:
GameEleType
=
'unObstacle'
_res
:
string
offsetX
:
number
=
130
...
...
@@ -227,6 +240,7 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
this
.
addChild
(
new
FYGE
.
MovieClip
(
RES
.
getRes
(
mv
)))
this
.
_res
=
mv
this
.
anchor
.
set
(
this
.
offsetX
,
this
.
offsetY
)
this
.
reset
()
const
t
=
this
.
getMaterialCollisionObj
()
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 {
this
.
position
.
set
(
x
-
this
.
offsetX
,
y
-
this
.
offsetY
)
}
reset
()
{
this
.
speed
=
0
this
.
scale
.
set
(
0
)
this
.
visible
=
true
}
onCollision
()
{
}
...
...
@@ -250,6 +270,7 @@ export class GameEleOfPowerBall extends FYGE.Container implements GameEleInfer {
}
export
class
GameEleOfWater
extends
FYGE
.
Sprite
implements
GameEleInfer
{
speed
:
number
=
0
_type
:
GameEleType
=
'obstacle'
_res
:
string
collisionProportionOfY
:
number
=
0.5
...
...
@@ -259,6 +280,7 @@ export class GameEleOfWater extends FYGE.Sprite implements GameEleInfer {
this
.
_res
=
res
this
.
anchorTexture
.
set
(
0.5
,
0.5
)
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
)
}
...
...
@@ -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
{
speed
:
number
;
_type
:
GameEleType
=
'obstacle'
_res
:
string
collisionProportionOfY
:
number
=
0.4
...
...
@@ -295,10 +320,17 @@ export class GameEleOfBucket extends FYGE.Sprite implements GameEleInfer {
this
.
_res
=
res
this
.
anchorTexture
.
set
(
0.5
,
0.5
)
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
)
}
reset
()
{
this
.
speed
=
0
this
.
scale
.
set
(
0
)
this
.
visible
=
true
}
setPostion
(
x
:
number
,
y
:
number
=
0
)
{
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