Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-demo
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
等吃饭
game-demo
Commits
6847581b
Commit
6847581b
authored
Feb 16, 2023
by
Friends233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
跳跃优化
parent
5f60989d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
560 deletions
+58
-560
ResJson.ts
src/ResJson.ts
+9
-553
IndexScene.ts
src/scenes/IndexScene.ts
+6
-0
bird.ts
src/scenes/bird.ts
+7
-3
pipe.ts
src/scenes/pipe.ts
+36
-4
No files found.
src/ResJson.ts
View file @
6847581b
...
...
@@ -2,580 +2,36 @@ export const ResJson = {
"groups"
:
[
{
"keys"
:
"5cab5037-81fc-4246-96e5-b1353f339275.png,7458bc9a-d07d-4a7c-972b-4de7ed7c040d.png,7e4500a1-83be-4686-a46b-67147ed44ddd.png,845ae874-998e-4f68-8e79-641eb77466f3.png,a122de8a-beed-4442-9252-8c047986f371.png,ad9681a6-9eb2-40ad-8c2c-0b3ad121a00d.png,b48ee079-b3d7-4371-b294-944200eccba9.png,cd1a775d-36c9-4c8e-9c67-8191070068e9.png"
,
"name"
:
"LoadingEffect"
,
"atlas"
:
{
"5cab5037-81fc-4246-96e5-b1353f339275.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
516
,
"h"
:
108
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
516
,
"sh"
:
108
,
"ro"
:
false
},
"b48ee079-b3d7-4371-b294-944200eccba9.png"
:
{
"x"
:
2
,
"y"
:
112
,
"w"
:
137
,
"h"
:
74
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
137
,
"sh"
:
74
,
"ro"
:
false
},
"a122de8a-beed-4442-9252-8c047986f371.png"
:
{
"x"
:
141
,
"y"
:
112
,
"w"
:
134
,
"h"
:
24
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
134
,
"sh"
:
24
,
"ro"
:
false
},
"cd1a775d-36c9-4c8e-9c67-8191070068e9.png"
:
{
"x"
:
2
,
"y"
:
188
,
"w"
:
123
,
"h"
:
104
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
123
,
"sh"
:
104
,
"ro"
:
false
},
"7458bc9a-d07d-4a7c-972b-4de7ed7c040d.png"
:
{
"x"
:
127
,
"y"
:
188
,
"w"
:
48
,
"h"
:
30
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
48
,
"sh"
:
30
,
"ro"
:
true
},
"ad9681a6-9eb2-40ad-8c2c-0b3ad121a00d.png"
:
{
"x"
:
141
,
"y"
:
138
,
"w"
:
23
,
"h"
:
36
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
23
,
"sh"
:
36
,
"ro"
:
false
},
"845ae874-998e-4f68-8e79-641eb77466f3.png"
:
{
"x"
:
127
,
"y"
:
238
,
"w"
:
24
,
"h"
:
25
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
24
,
"sh"
:
25
,
"ro"
:
false
},
"7e4500a1-83be-4686-a46b-67147ed44ddd.png"
:
{
"x"
:
141
,
"y"
:
176
,
"w"
:
5
,
"h"
:
6
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
5
,
"sh"
:
6
,
"ro"
:
false
}
}
"name"
:
"LoadingEffect"
},
{
"keys"
:
"overBtn.png,overPrizeBg.png"
,
"name"
:
"OverPanel"
,
"atlas"
:
{
"overPrizeBg.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
581
,
"h"
:
843
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
581
,
"sh"
:
843
,
"ro"
:
false
},
"overBtn.png"
:
{
"x"
:
585
,
"y"
:
2
,
"w"
:
418
,
"h"
:
102
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
418
,
"sh"
:
102
,
"ro"
:
true
}
}
"name"
:
"OverPanel"
},
{
"keys"
:
"reviveBg.png,reviveCancel.png,reviveOk.png"
,
"name"
:
"RevivePanel"
,
"atlas"
:
{
"reviveBg.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
581
,
"h"
:
508
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
581
,
"sh"
:
508
,
"ro"
:
false
},
"reviveOk.png"
:
{
"x"
:
2
,
"y"
:
512
,
"w"
:
233
,
"h"
:
89
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
233
,
"sh"
:
89
,
"ro"
:
false
},
"reviveCancel.png"
:
{
"x"
:
237
,
"y"
:
512
,
"w"
:
224
,
"h"
:
85
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
224
,
"sh"
:
85
,
"ro"
:
false
}
}
"name"
:
"RevivePanel"
},
{
"keys"
:
"base.png,pipe_green.png,pipe_green_down.png,redbird_downflap.png,redbird_midflap.png,redbird_upflap.png"
,
"name"
:
"bird"
,
"atlas"
:
{
"pipe_green.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
141
,
"h"
:
1462
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
141
,
"sh"
:
1462
,
"ro"
:
false
},
"pipe_green_down.png"
:
{
"x"
:
145
,
"y"
:
2
,
"w"
:
141
,
"h"
:
1462
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
141
,
"sh"
:
1462
,
"ro"
:
false
},
"base.png"
:
{
"x"
:
288
,
"y"
:
2
,
"w"
:
750
,
"h"
:
377
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
750
,
"sh"
:
377
,
"ro"
:
true
},
"redbird_downflap.png"
:
{
"x"
:
288
,
"y"
:
754
,
"w"
:
89
,
"h"
:
63
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
89
,
"sh"
:
63
,
"ro"
:
false
},
"redbird_midflap.png"
:
{
"x"
:
379
,
"y"
:
754
,
"w"
:
89
,
"h"
:
63
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
89
,
"sh"
:
63
,
"ro"
:
false
},
"redbird_upflap.png"
:
{
"x"
:
470
,
"y"
:
754
,
"w"
:
89
,
"h"
:
63
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
89
,
"sh"
:
63
,
"ro"
:
false
}
}
"name"
:
"bird"
},
{
"keys"
:
"comCloseBtn.png,com_bg.jpg,toastBg.png,waitingBg.png,waitingRot.png"
,
"name"
:
"common"
,
"atlas"
:
{
"toastBg.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
460
,
"h"
:
130
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
460
,
"sh"
:
130
,
"ro"
:
false
},
"waitingBg.png"
:
{
"x"
:
2
,
"y"
:
134
,
"w"
:
160
,
"h"
:
180
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
160
,
"sh"
:
180
,
"ro"
:
true
},
"comCloseBtn.png"
:
{
"x"
:
184
,
"y"
:
134
,
"w"
:
58
,
"h"
:
58
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
58
,
"sh"
:
58
,
"ro"
:
false
},
"waitingRot.png"
:
{
"x"
:
184
,
"y"
:
194
,
"w"
:
56
,
"h"
:
56
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
56
,
"sh"
:
56
,
"ro"
:
false
}
}
"name"
:
"common"
},
{
"keys"
:
"gameMusicOff.png,gameMusicOn.png,gameScore+.png,gameScore0.png,gameScore1.png,gameScore2.png,gameScore3.png,gameScore4.png,gameScore5.png,gameScore6.png,gameScore7.png,gameScore8.png,gameScore9.png,guide.png"
,
"name"
:
"game"
,
"atlas"
:
{
"guide.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
320
,
"h"
:
416
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
320
,
"sh"
:
416
,
"ro"
:
false
},
"gameMusicOff.png"
:
{
"x"
:
324
,
"y"
:
2
,
"w"
:
82
,
"h"
:
82
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
82
,
"sh"
:
82
,
"ro"
:
false
},
"gameMusicOn.png"
:
{
"x"
:
324
,
"y"
:
86
,
"w"
:
82
,
"h"
:
82
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
82
,
"sh"
:
82
,
"ro"
:
false
},
"gameScore0.png"
:
{
"x"
:
324
,
"y"
:
170
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
true
},
"gameScore1.png"
:
{
"x"
:
324
,
"y"
:
216
,
"w"
:
28
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
32
,
"sh"
:
56
,
"ro"
:
true
},
"gameScore2.png"
:
{
"x"
:
324
,
"y"
:
246
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
true
},
"gameScore3.png"
:
{
"x"
:
324
,
"y"
:
292
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
true
},
"gameScore4.png"
:
{
"x"
:
324
,
"y"
:
338
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
48
,
"sh"
:
56
,
"ro"
:
false
},
"gameScore5.png"
:
{
"x"
:
408
,
"y"
:
2
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
false
},
"gameScore6.png"
:
{
"x"
:
408
,
"y"
:
60
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
false
},
"gameScore7.png"
:
{
"x"
:
408
,
"y"
:
118
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
false
},
"gameScore8.png"
:
{
"x"
:
382
,
"y"
:
176
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
true
},
"gameScore9.png"
:
{
"x"
:
382
,
"y"
:
222
,
"w"
:
44
,
"h"
:
56
,
"ox"
:
2
,
"oy"
:
0
,
"sw"
:
47
,
"sh"
:
56
,
"ro"
:
true
},
"gameScore+.png"
:
{
"x"
:
382
,
"y"
:
268
,
"w"
:
42
,
"h"
:
40
,
"ox"
:
2
,
"oy"
:
8
,
"sw"
:
46
,
"sh"
:
56
,
"ro"
:
false
}
}
"name"
:
"game"
},
{
"keys"
:
"btnTipBg.png,prizeBtn.png,progressBg.png,progressFill.png,progressLabel.png,rankBtn.png,ruleBtn.png,startBtn.png,taskBtn.png"
,
"name"
:
"index"
,
"atlas"
:
{
"progressBg.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
750
,
"h"
:
188
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
750
,
"sh"
:
188
,
"ro"
:
false
},
"progressFill.png"
:
{
"x"
:
2
,
"y"
:
192
,
"w"
:
615
,
"h"
:
20
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
615
,
"sh"
:
20
,
"ro"
:
false
},
"startBtn.png"
:
{
"x"
:
2
,
"y"
:
214
,
"w"
:
490
,
"h"
:
111
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
490
,
"sh"
:
111
,
"ro"
:
false
},
"prizeBtn.png"
:
{
"x"
:
494
,
"y"
:
214
,
"w"
:
153
,
"h"
:
51
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
153
,
"sh"
:
51
,
"ro"
:
false
},
"taskBtn.png"
:
{
"x"
:
494
,
"y"
:
267
,
"w"
:
151
,
"h"
:
51
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
151
,
"sh"
:
51
,
"ro"
:
false
},
"btnTipBg.png"
:
{
"x"
:
2
,
"y"
:
327
,
"w"
:
147
,
"h"
:
36
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
147
,
"sh"
:
36
,
"ro"
:
false
},
"ruleBtn.png"
:
{
"x"
:
649
,
"y"
:
192
,
"w"
:
102
,
"h"
:
42
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
102
,
"sh"
:
42
,
"ro"
:
false
},
"rankBtn.png"
:
{
"x"
:
494
,
"y"
:
320
,
"w"
:
98
,
"h"
:
43
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
98
,
"sh"
:
43
,
"ro"
:
false
},
"progressLabel.png"
:
{
"x"
:
151
,
"y"
:
327
,
"w"
:
87
,
"h"
:
31
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
87
,
"sh"
:
31
,
"ro"
:
false
}
}
"name"
:
"index"
},
{
"keys"
:
"loading_effect.png,loading_title.png"
,
"name"
:
"loading"
,
"atlas"
:
{
"loading_effect.png"
:
{
"x"
:
2
,
"y"
:
2
,
"w"
:
665
,
"h"
:
121
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
665
,
"sh"
:
121
,
"ro"
:
false
},
"loading_title.png"
:
{
"x"
:
2
,
"y"
:
125
,
"w"
:
531
,
"h"
:
146
,
"ox"
:
0
,
"oy"
:
0
,
"sw"
:
531
,
"sh"
:
146
,
"ro"
:
false
}
}
"name"
:
"loading"
}
],
"path"
:
"https://yun.duiba.com.cn/db_games/activity/template/1676519680
/resource/"
"path"
:
location
.
origin
+
"
/resource/"
}
\ No newline at end of file
src/scenes/IndexScene.ts
View file @
6847581b
...
...
@@ -86,6 +86,12 @@ export class IndexScene extends Scene {
_initEvents
()
{
this
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
_enterFrame
,
this
)
this
.
addEventListener
(
FYGE
.
MouseEvent
.
CLICK
,
this
.
birdJump
,
this
)
// this.addEventListener(FYGE.MouseEvent.MOUSE_MOVE,this.testBird,this)
}
testBird
(
e
)
{
this
.
bird
.
x
=
e
.
stageX
this
.
bird
.
y
=
e
.
stageY
}
/** 检查小鸟掉落位置 */
...
...
src/scenes/bird.ts
View file @
6847581b
...
...
@@ -16,7 +16,9 @@ import FrameAni = FYGE.FrameAni;
/** 初始坠落步长 */
const
FIAL_STEP
=
4
/** 初始跳跃步长 */
const
JUMP_STEP
=
18
const
JUMP_STEP
=
19
/** 最大跳跃步长 */
const
JUMP_MAX_STEP
=
JUMP_STEP
-
8
/** 坠落速率 */
const
FIAL_MUI
=
0.4
...
...
@@ -46,6 +48,8 @@ export class Bird extends Container {
]
this
.
player
=
new
FrameAni
(
birdAni
)
this
.
player
.
play
(
0
)
this
.
anchorX
=
this
.
width
/
2
this
.
anchorY
=
this
.
height
/
2
// this.player.scale.x = 3
// this.player.scale.y = 3
this
.
addChild
(
this
.
player
)
...
...
@@ -83,7 +87,7 @@ export class Bird extends Container {
if
(
this
.
isGameOver
)
return
if
(
this
.
y
<=
0
)
return
// console.log('jump')
this
.
failStep
-=
this
.
jumpStep
this
.
failStep
=
Math
.
max
(
this
.
failStep
-
this
.
jumpStep
,
-
JUMP_MAX_STEP
)
}
/** 重置 */
...
...
@@ -97,7 +101,7 @@ export class Bird extends Container {
this
.
reset
()
this
.
isGameOver
=
true
this
.
rotation
=
0
this
.
player
.
reset
()
this
.
player
.
reset
(
this
.
player
.
getCurrentFrame
()
)
}
destroy
()
{
...
...
src/scenes/pipe.ts
View file @
6847581b
...
...
@@ -26,6 +26,35 @@ function randomNum(min, max) {
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
))
+
min
}
/**
* 碰撞检测
* @param {FYGE.Container} coA
* @param {FYGE.Container} coB
* @returns 是否碰撞
*/
export
const
isCollision
=
(
coA
,
coB
)
=>
{
const
aGlobalPos
=
coA
.
localToGlobal
(
new
FYGE
.
Point
(
0
,
0
),
new
FYGE
.
Point
())
const
bGlobalPos
=
coB
.
localToGlobal
(
new
FYGE
.
Point
(
0
,
0
),
new
FYGE
.
Point
())
const
disX
=
(
coA
.
width
+
coB
.
width
)
*
0.5
const
disY
=
(
coB
.
height
+
coB
.
height
)
*
0.5
const
centerA
=
{
x
:
aGlobalPos
.
x
+
coA
.
width
*
0.5
,
y
:
aGlobalPos
.
y
+
coA
.
height
*
0.5
}
const
centerB
=
{
x
:
bGlobalPos
.
x
+
coB
.
width
*
0.5
,
y
:
bGlobalPos
.
y
+
coB
.
height
*
0.5
}
const
diffNumX
=
Math
.
abs
(
centerA
.
x
-
centerB
.
x
)
const
diffNumY
=
Math
.
abs
(
centerA
.
y
-
centerB
.
y
)
return
diffNumX
<
disX
&&
diffNumY
<
disY
}
export
class
Pipe
extends
Container
{
/** 水管类型 */
...
...
@@ -94,7 +123,6 @@ export class PipeMannager {
/** 创建一组水管 */
createGroupPipe
()
{
console
.
log
(
this
.
deep
)
const
upD
=
this
.
downPipes
.
length
?
this
.
downPipes
.
pop
()
:
new
Pipe
(
'down'
)
const
upP
=
this
.
upPipes
.
length
?
this
.
upPipes
.
pop
()
:
new
Pipe
(
'up'
)
upD
.
x
=
750
...
...
@@ -130,13 +158,17 @@ export class PipeMannager {
const
player
=
this
.
player
const
posx
=
player
.
x
// 重叠水管
if
((
posx
+
player
.
width
/
2
)
>=
up
.
x
&&
(
posx
-
player
.
width
/
2
)
<=
(
up
.
x
+
up
.
width
))
{
if
(((
posx
+
player
.
width
/
2
)
>=
up
.
x
)
&&
((
posx
-
player
.
width
/
2
)
<=
(
up
.
x
+
up
.
width
)))
{
// console.log('水管中')
const
half
=
Number
((
player
.
height
/
2
).
toFixed
(
3
))
// 碰撞头朝上的水管
if
(
up
.
y
<=
player
.
y
)
{
if
(
up
.
y
<=
(
player
.
y
+
half
))
{
// console.log('触碰下',up.y,player.y, half)
this
.
stage
.
gameOver
()
}
// 碰撞头朝下的水管
if
((
down
.
y
+
down
.
height
+
player
.
height
/
2
)
>=
player
.
y
)
{
if
((
down
.
y
+
down
.
height
)
>=
(
player
.
y
-
half
))
{
// console.log('触碰上',(down.y + down.height),(player.y - half))
this
.
stage
.
gameOver
()
}
}
...
...
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