Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-stydy
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-stydy
Commits
ffdce49d
Commit
ffdce49d
authored
Mar 10, 2021
by
邱旭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
08.FlppyBird-模拟重力
parent
b30ed884
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
27 deletions
+16
-27
08.FlppyBird-模拟重力.html
08.FlppyBird-模拟重力/08.FlppyBird-模拟重力.html
+11
-17
08.FlppyBird-模拟重力.md
08.FlppyBird-模拟重力/08.FlppyBird-模拟重力.md
+5
-10
No files found.
08.FlppyBird-模拟重力/08.FlppyBird-模拟重力.html
View file @
ffdce49d
...
@@ -52,24 +52,19 @@
...
@@ -52,24 +52,19 @@
this
.
gravity
=
gravity
;
// 保存gravity
this
.
gravity
=
gravity
;
// 保存gravity
// 放到合适的位置
// 放到合适的位置
const
{
width
,
height
}
=
this
.
getSize
();
const
{
width
,
height
}
=
this
.
size
;
this
.
setPosition
(
this
.
top
=
(
winSize
.
height
-
height
)
/
2
-
100
;
(
winSize
.
height
-
height
)
/
2
-
100
,
this
.
left
=
(
winSize
.
width
-
width
)
/
2
;
(
winSize
.
width
-
width
)
/
2
,
);
}
}
update
()
{
update
()
{
super
.
update
();
super
.
update
();
let
top
=
this
.
getPosition
().
top
// v = v0 + a * t²
// v = v0 + a * t²
this
.
speed
+=
this
.
gravity
;
// 速度 = 速度 + 加速度 * 时间²
this
.
speed
+=
this
.
gravity
;
// 速度 = 速度 + 加速度 * 时间²
top
+=
this
.
speed
;
// 更新位置
t
his
.
t
op
+=
this
.
speed
;
// 更新位置
this
.
setPosition
(
top
);
}
}
}
}
...
@@ -88,21 +83,20 @@
...
@@ -88,21 +83,20 @@
this
.
bg2
=
bg2
;
this
.
bg2
=
bg2
;
this
.
speed
=
speed
;
this
.
speed
=
speed
;
bg1
.
setPosition
(
winSize
.
height
-
bg1
.
getSize
().
height
)
;
// 放在底部
bg1
.
top
=
winSize
.
height
-
bg1
.
size
.
height
;
// 放在底部
bg2
.
setPosition
(
winSize
.
height
-
bg2
.
getSize
().
height
)
;
// 放在底部
bg2
.
top
=
winSize
.
height
-
bg2
.
size
.
height
;
// 放在底部
}
}
update
()
{
update
()
{
super
.
update
();
super
.
update
();
// 获取一些参数
// 获取一些参数
let
{
top
:
bg1Top
,
left
:
bg1Left
}
=
this
.
bg1
.
getPosition
();
let
bg1Left
=
this
.
bg1
.
left
;
const
bg1Width
=
this
.
bg1
.
getSize
().
width
;
const
bg1Width
=
this
.
bg1
.
size
.
width
;
const
bg2Top
=
this
.
bg2
.
getPosition
().
top
;
// 计算位置
// 计算位置
bg1Left
-=
this
.
speed
;
// 计算位置
bg1Left
-=
this
.
speed
;
// 计算位置
this
.
bg1
.
setPosition
(
bg1Top
,
bg1Left
);
// 设置bg1的位置
this
.
bg1
.
left
=
bg1Left
;
// 设置bg1的位置
this
.
bg2
.
setPosition
(
bg2Top
,
bg1Left
+
this
.
bg1
.
getSize
().
width
);
// bg2跟在bg1后面
this
.
bg2
.
left
=
bg1Left
+
this
.
bg1
.
size
.
width
;
// bg2跟在bg1后面
// 如果超出屏幕则交换bg1和bg2,为了做到循环滚动
// 如果超出屏幕则交换bg1和bg2,为了做到循环滚动
if
(
bg1Left
<=
-
bg1Width
)
{
if
(
bg1Left
<=
-
bg1Width
)
{
...
@@ -129,7 +123,7 @@
...
@@ -129,7 +123,7 @@
const
landMgr
=
new
ScrollMgr
(
"land"
,
land1
,
land2
,
5
);
const
landMgr
=
new
ScrollMgr
(
"land"
,
land1
,
land2
,
5
);
// 将背景放在地面的上面,因为默认top是0,子节点在内部定位在底部,所以只需要把背景定位在负的land的高度就可以了
// 将背景放在地面的上面,因为默认top是0,子节点在内部定位在底部,所以只需要把背景定位在负的land的高度就可以了
bgMgr
.
setPosition
(
-
land1
.
getSize
().
height
)
;
bgMgr
.
top
=
-
land1
.
size
.
height
;
</script>
</script>
<script>
<script>
...
...
08.FlppyBird-模拟重力/08.FlppyBird-模拟重力.md
View file @
ffdce49d
...
@@ -26,11 +26,9 @@ class Bird extends GameObject {
...
@@ -26,11 +26,9 @@ class Bird extends GameObject {
this
.
gravity
=
gravity
;
// 保存gravity
this
.
gravity
=
gravity
;
// 保存gravity
// 放到合适的位置
// 放到合适的位置
const
{
width
,
height
}
=
this
.
getSize
();
const
{
width
,
height
}
=
this
.
size
;
this
.
setPosition
(
this
.
top
=
(
winSize
.
height
-
height
)
/
2
-
100
;
(
winSize
.
height
-
height
)
/
2
-
100
,
this
.
left
=
(
winSize
.
width
-
width
)
/
2
;
(
winSize
.
width
-
width
)
/
2
,
);
}
}
/* ... */
/* ... */
...
@@ -52,14 +50,11 @@ class Bird extends GameObject {
...
@@ -52,14 +50,11 @@ class Bird extends GameObject {
update
()
{
update
()
{
super
.
update
();
super
.
update
();
let
top
=
this
.
getPosition
().
top
// v = v0 + a * t²
// v = v0 + a * t²
this
.
speed
+=
this
.
gravity
;
// 速度 = 速度 + 加速度 * 时间²
this
.
speed
+=
this
.
gravity
;
// 速度 = 速度 + 加速度 * 时间²
top
+=
this
.
speed
;
// 更新位置
this
.
top
+=
this
.
speed
;
// 更新位置
this
.
setPosition
(
top
);
}
}
}
}
```
```
...
...
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