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
eb0982e9
authored
Jun 25, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
75a6126a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
7 deletions
my_game.py
my_game.py
View file @
eb0982e9
...
...
@@ -26,13 +26,16 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
lu_x
=
0
num
=
0
shan_x
=
0
index
=
0
y
=
400
jumpState
=
"runing"
t
=
30
aa
=
Block
(
bush
,
cacti
,
stone
)
time
=
0
gamestate
=
True
aa_list
=
pygame
.
sprite
.
Group
()
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
...
...
@@ -56,7 +59,12 @@ while True:
else
:
jumpState
=
"runing"
t
=
30
if
gamestate
==
True
:
if
jumpState
==
'up'
if
t
>
0
:
y
-=
t
wukong
.
rect
.
y
=
y
t
-=
2
# 悟空造型
wukong
=
hero
[
index
]
if
jumpState
==
"runing"
:
# 跑步状态下
...
...
@@ -74,12 +82,25 @@ while True:
screen
.
blit
(
road
,
(
lu_x
,
500
))
# 路
screen
.
blit
(
wukong
,
(
150
,
y
))
# 悟空
if
aa
.
rect
.
x
<=
0
-
aa
.
rect
.
width
:
# 障碍物消失
#
if aa.rect.x <= 0-aa.rect.width: # 障碍物消失
# 创建障碍物对象
aa
=
Block
(
bush
,
cacti
,
stone
)
aa
.
rect
.
x
-=
8
time
+=
1
if
time
>=
60
:
time
=
0
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
aa
=
Block
(
bush
,
cacti
,
stone
)
aa_list
.
add
(
aa
)
for
temp_sprit
in
aa_list
:
temp_sprit
.
rect
.
x
-=
8
screen
.
blit
(
temp_sprit
.
image
,(
temp_sprit
.
rect
.
x
,
temp_sprit
.
rect
.
y
))
if
temp_sprit
.
rect
.
x
<=
0
-
temp_sprit
.
rect
.
width
:
temp_sprit
.
kill
()
if
pygame
.
sprite
.
collide_rect
(
wukong
,
temp_sprit
):
gameover
=
pygame
.
image
.
load
()
screen
.
bilt
(
gameover
,(
400
,
200
))
gamestate
=
False
time
.
sleep
(
1
)
screen
.
blit
(
aa
.
image
,
(
aa
.
rect
.
x
,
aa
.
rect
.
y
))
# 刷新画面
pygame
.
display
.
update
()
...
...
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