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
4fc3d9b8
Commit
4fc3d9b8
authored
Feb 14, 2023
by
Friends233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
小鸟下坠、跳跃
parent
482fc052
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
1 deletion
+128
-1
IndexScene.ts
src/scenes/IndexScene.ts
+63
-1
bird.ts
src/scenes/bird.ts
+65
-0
No files found.
src/scenes/IndexScene.ts
View file @
4fc3d9b8
...
...
@@ -2,6 +2,7 @@ import { changeScene } from "../../module/ctrls";
import
{
Scene
}
from
"../../module/views/Scene"
;
import
{
Tools
}
from
"../tools/Tools"
;
import
UI
from
"../tools/UI"
;
import
{
Bird
}
from
"./bird"
;
import
{
LoadingScene
}
from
"./LoadingScene"
;
import
Button
=
FYGE
.
Button
;
import
Container
=
FYGE
.
Container
;
...
...
@@ -20,8 +21,69 @@ export class IndexScene extends Scene {
]
}
/** 玩家(鸟) */
private
bird
:
Bird
=
null
/** 游戏是否结束 */
private
isGameOver
:
boolean
=
false
/** 游戏是否开始 */
private
isGameStart
:
boolean
=
false
async
initUi
()
{
UI
.
Sp
(
this
,
Texture
.
from
(
'com_bg.jpg'
))
// UI.Sp(this, Texture.from('com_bg.jpg'))
this
.
addChild
(
new
Sprite
(
Texture
.
from
(
'com_bg.jpg'
)))
const
bird
=
this
.
bird
=
new
Bird
()
bird
.
x
=
(
this
.
width
-
bird
.
width
)
*
0.5
bird
.
y
=
800
this
.
addChild
(
bird
)
this
.
_initEvents
()
}
_initEvents
()
{
this
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
_enterFrame
,
this
)
this
.
addEventListener
(
FYGE
.
MouseEvent
.
CLICK
,
this
.
birdJump
,
this
)
}
/** 检查小鸟掉落位置 */
_checkRmove
()
{
if
(
this
.
bird
.
y
>=
(
this
.
bird
.
height
+
this
.
height
))
{
// this.removeChild(this.bird)
this
.
gameOver
()
}
}
/** 帧动画 */
_enterFrame
()
{
if
(
this
.
isGameOver
||
!
this
.
isGameStart
)
return
console
.
log
(
this
.
bird
.
y
)
this
.
bird
.
fail
(
1
)
this
.
_checkRmove
()
}
/** 游戏结束 */
gameOver
()
{
this
.
isGameOver
=
true
this
.
isGameStart
=
false
}
/** 小鸟跳跃 */
birdJump
()
{
if
(
!
this
.
isGameStart
)
{
this
.
startGame
()
return
}
this
.
bird
.
jump
()
}
/** 开始游戏 */
startGame
()
{
if
(
this
.
bird
.
y
>
this
.
height
)
{
this
.
bird
.
y
=
0
this
.
bird
.
reset
()
}
this
.
isGameStart
=
true
this
.
isGameOver
=
false
}
destroy
()
{
...
...
src/scenes/bird.ts
0 → 100644
View file @
4fc3d9b8
import
{
changeScene
}
from
"../../module/ctrls"
;
import
{
Scene
}
from
"../../module/views/Scene"
;
import
{
Tools
}
from
"../tools/Tools"
;
import
UI
from
"../tools/UI"
;
import
{
LoadingScene
}
from
"./LoadingScene"
;
import
Button
=
FYGE
.
Button
;
import
Container
=
FYGE
.
Container
;
import
Shape
=
FYGE
.
Shape
;
import
Sprite
=
FYGE
.
Sprite
;
import
TEXT_ALIGN
=
FYGE
.
TEXT_ALIGN
;
import
TextField
=
FYGE
.
TextField
;
import
VERTICAL_ALIGN
=
FYGE
.
VERTICAL_ALIGN
;
import
Texture
=
FYGE
.
Texture
;
/** 初始坠落步长 */
const
FIAL_STEP
=
5
/** 初始跳跃步长 */
const
JUMP_STEP
=
30
export
class
Bird
extends
Container
{
/** 坠落步长 */
failStep
=
FIAL_STEP
/** 跳跃步长 */
jumpStep
=
JUMP_STEP
constructor
()
{
super
()
this
.
initUi
()
}
async
initUi
()
{
this
.
addChild
(
new
Sprite
(
Texture
.
fromUrl
(
'//yun.duiba.com.cn/aurora/assets/0bcb2c26a85addb1714b4c63f2a873aafe210749.png'
)))
}
/**
* 小鸟坠落
* @param acceleration 加速比
*/
fail
(
acceleration
=
0
)
{
this
.
failStep
+=
acceleration
// console.log(this.step.toFixed(2))
this
.
y
=
Math
.
max
(
this
.
y
+
this
.
failStep
,
0
)
if
(
this
.
y
==
0
){
this
.
reset
()
}
}
/** 小鸟跳跃 */
jump
()
{
if
(
this
.
y
<=
0
)
return
this
.
failStep
-=
this
.
jumpStep
}
/** 重置 */
reset
(){
this
.
failStep
=
FIAL_STEP
this
.
jumpStep
=
JUMP_STEP
}
destroy
()
{
super
.
destroy
();
}
}
\ No newline at end of file
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