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
Expand all
Show 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
This diff is collapsed.
Click to expand it.
src/scenes/IndexScene.ts
View file @
6847581b
...
@@ -86,6 +86,12 @@ export class IndexScene extends Scene {
...
@@ -86,6 +86,12 @@ export class IndexScene extends Scene {
_initEvents
()
{
_initEvents
()
{
this
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
_enterFrame
,
this
)
this
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
_enterFrame
,
this
)
this
.
addEventListener
(
FYGE
.
MouseEvent
.
CLICK
,
this
.
birdJump
,
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;
...
@@ -16,7 +16,9 @@ import FrameAni = FYGE.FrameAni;
/** 初始坠落步长 */
/** 初始坠落步长 */
const
FIAL_STEP
=
4
const
FIAL_STEP
=
4
/** 初始跳跃步长 */
/** 初始跳跃步长 */
const
JUMP_STEP
=
18
const
JUMP_STEP
=
19
/** 最大跳跃步长 */
const
JUMP_MAX_STEP
=
JUMP_STEP
-
8
/** 坠落速率 */
/** 坠落速率 */
const
FIAL_MUI
=
0.4
const
FIAL_MUI
=
0.4
...
@@ -46,6 +48,8 @@ export class Bird extends Container {
...
@@ -46,6 +48,8 @@ export class Bird extends Container {
]
]
this
.
player
=
new
FrameAni
(
birdAni
)
this
.
player
=
new
FrameAni
(
birdAni
)
this
.
player
.
play
(
0
)
this
.
player
.
play
(
0
)
this
.
anchorX
=
this
.
width
/
2
this
.
anchorY
=
this
.
height
/
2
// this.player.scale.x = 3
// this.player.scale.x = 3
// this.player.scale.y = 3
// this.player.scale.y = 3
this
.
addChild
(
this
.
player
)
this
.
addChild
(
this
.
player
)
...
@@ -83,7 +87,7 @@ export class Bird extends Container {
...
@@ -83,7 +87,7 @@ export class Bird extends Container {
if
(
this
.
isGameOver
)
return
if
(
this
.
isGameOver
)
return
if
(
this
.
y
<=
0
)
return
if
(
this
.
y
<=
0
)
return
// console.log('jump')
// 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 {
...
@@ -97,7 +101,7 @@ export class Bird extends Container {
this
.
reset
()
this
.
reset
()
this
.
isGameOver
=
true
this
.
isGameOver
=
true
this
.
rotation
=
0
this
.
rotation
=
0
this
.
player
.
reset
()
this
.
player
.
reset
(
this
.
player
.
getCurrentFrame
()
)
}
}
destroy
()
{
destroy
()
{
...
...
src/scenes/pipe.ts
View file @
6847581b
...
@@ -26,6 +26,35 @@ function randomNum(min, max) {
...
@@ -26,6 +26,35 @@ function randomNum(min, max) {
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
))
+
min
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
{
export
class
Pipe
extends
Container
{
/** 水管类型 */
/** 水管类型 */
...
@@ -94,7 +123,6 @@ export class PipeMannager {
...
@@ -94,7 +123,6 @@ export class PipeMannager {
/** 创建一组水管 */
/** 创建一组水管 */
createGroupPipe
()
{
createGroupPipe
()
{
console
.
log
(
this
.
deep
)
const
upD
=
this
.
downPipes
.
length
?
this
.
downPipes
.
pop
()
:
new
Pipe
(
'down'
)
const
upD
=
this
.
downPipes
.
length
?
this
.
downPipes
.
pop
()
:
new
Pipe
(
'down'
)
const
upP
=
this
.
upPipes
.
length
?
this
.
upPipes
.
pop
()
:
new
Pipe
(
'up'
)
const
upP
=
this
.
upPipes
.
length
?
this
.
upPipes
.
pop
()
:
new
Pipe
(
'up'
)
upD
.
x
=
750
upD
.
x
=
750
...
@@ -130,13 +158,17 @@ export class PipeMannager {
...
@@ -130,13 +158,17 @@ export class PipeMannager {
const
player
=
this
.
player
const
player
=
this
.
player
const
posx
=
player
.
x
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
()
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
()
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