Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_diy3
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
9539b4bb
authored
Apr 15, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
454b113d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
17 deletions
my_game.py
my_game.py
View file @
9539b4bb
import
pygame
from
pygame
import
locals
import
random
y
=
400
t
=
30
zhuangtai
=
'running'
...
...
@@ -20,8 +19,6 @@ hero3 = pygame.image.load('hero3.png')
hero4
=
pygame
.
image
.
load
(
'hero4.png'
)
hero5
=
pygame
.
image
.
load
(
'hero5.png'
)
run
=
[
hero1
,
hero2
,
hero3
,
hero4
,
hero5
]
zhangai
=
[
cacti
,
bush
]
zhangaiwu
=
index
=
0
while
True
:
...
...
@@ -30,32 +27,31 @@ while True:
# 接收到退出事件后退出程序
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_SPACE
and
zhuangtai
==
'running'
:
if
event
.
key
==
locals
.
K_SPACE
:
zhuangtai
=
'up'
if
y
<=
150
:
zhuangtai
=
'down'
if
zhuangtai
==
'down'
and
y
>=
400
:
zhuangtai
=
'running'
if
zhuangtai
==
'up'
:
if
t
>
=
0
:
if
t
>
0
:
y
-=
t
t
-=
2
else
:
zhuangtai
=
'down'
elif
zhuangtai
==
'down'
:
if
t
<=
3
0
:
if
t
<=
15
0
:
y
+=
t
t
+=
2
else
:
t
=
30
y
=
400
zhuangtai
=
'running'
else
:
y
=
400
t
=
30
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
road
,
(
0
,
500
))
screen
.
blit
(
run
[
index
],
(
150
,
y
))
if
zhuangtai
==
'running'
:
index
+=
1
if
index
>=
5
:
index
=
0
index
+=
1
if
index
>=
5
:
index
=
0
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
28
)
\ 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