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
9cafdb09
authored
May 01, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
b7183b00
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
53 deletions
my_game.py
my_game.py
View file @
9cafdb09
...
@@ -60,55 +60,5 @@ while True:
...
@@ -60,55 +60,5 @@ while True:
if
jumpState
==
"runing"
:
if
jumpState
==
"runing"
:
if
event
.
key
==
locals
.
K_SPACE
:
if
event
.
key
==
locals
.
K_SPACE
:
jumpState
=
"up"
jumpState
=
"up"
if
gamestate
==
True
:
# if判断当gamestate的值为True时
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
\ No newline at end of file
y
-=
t
t
-=
2
else
:
jumpState
=
"down"
if
jumpState
==
"down"
:
# 降落状态
if
t
<=
30
:
y
+=
t
t
+=
2
else
:
jumpState
=
"runing"
t
=
30
# 悟空造型
wukong
=
Player
(
hero
[
index
])
# 将设置悟空造型的代码改成用类来实现
if
jumpState
==
"runing"
:
# 跑步状态下
index
+=
1
if
index
>=
5
:
index
=
0
# 将背景图画上去
bg_x
-=
1
# 将远景x坐标每次循环都-1
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
.
image
,
(
150
,
y
))
# 悟空代码里参数1改为.image
# 创建障碍物对象
time
+=
1
# 将time值+1
if
time
>=
60
:
# if判断time达到60
r
=
random
.
randint
(
0
,
100
)
# 随机数0,100并赋值给遍历r
if
r
>
40
:
# 判断r>40
obstacle
=
Block
(
bush
,
cacti
,
stone
)
# 创建障碍物精灵
block_list
.
add
(
obstacle
)
# 将精灵添加进精灵组
time
=
0
# 将变量time设为0
for
sprite
in
block_list
:
# for循环,遍历、展示障碍物
sprite
.
rect
.
x
-=
8
# 将精灵的x坐标-8
# 将程序渲染出来
screen
.
blit
(
sprite
.
image
,(
sprite
.
rect
.
x
,
sprite
.
rect
.
y
))
if
sprite
.
rect
.
x
<=
0
-
sprite
.
rect
.
width
:
# if判断精灵是否完全消失在窗口左边
sprite
.
kill
()
# 使用kill()方法将自己清除
if
pygame
.
sprite
.
collide_rect
(
wukong
,
sprite
):
# 精灵碰撞检测
gemeover
=
pygame
.
image
.
load
(
'gameover.png'
)
# 导入图片素材,游戏结束
screen
.
blit
(
gameover
,
(
400
,
200
))
# 将游戏结束展示在窗口上
gamestate
=
False
# 将变量gamestate的值设为False
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ 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