Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6483ae7d
authored
May 01, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
080ee70a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
my_game.py
my_game.py
View file @
6483ae7d
...
@@ -22,10 +22,8 @@ index = 0
...
@@ -22,10 +22,8 @@ index = 0
y
=
400
y
=
400
jumpState
=
"runing"
jumpState
=
"runing"
t
=
30
t
=
30
obstacle
=
random
.
choice
([
bush
,
stone
,
cacti
])
rect_x
=
0
# 设置道路x坐标为0并赋值给变量road_x
rect
=
obstacle
.
get_rect
()
bg_x
=
0
# 设置远景坐标为0并赋值给变量bg_x
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
...
@@ -58,8 +56,14 @@ while True:
...
@@ -58,8 +56,14 @@ while True:
if
index
>=
5
:
if
index
>=
5
:
index
=
0
index
=
0
# 将背景图画上去
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
# 远处背景
bg_x
-=
1
# 将远景x坐标每次循环都-1
screen
.
blit
(
road
,
(
0
,
500
))
# 路
if
bg_x
<=
-
1000
:
# if判断当远景x坐标小于-1000
bg_x
=
0
# 远景x坐标回到0
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远处背景中x坐标改为bg_x
road_x
-=
8
# 将道路x坐标每次循环都-8,使道路和障碍物依相同速度向左移动
if
road_x
<=
-
1000
:
# if判断当道路x坐标小于-1000
road_x
=
0
# 道路x坐标回到0
screen
.
blit
(
road
,
(
road_x
,
500
))
# 道路背景代码中x坐标改为变量road_x
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
if
rect
.
x
<=
0
-
rect
.
width
:
# 障碍物消失
if
rect
.
x
<=
0
-
rect
.
width
:
# 障碍物消失
...
...
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