Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson8_diy4
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
b14a780d
authored
a year ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
3c84f352
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
27 deletions
my_game.py
my_game.py
View file @
b14a780d
...
@@ -32,6 +32,7 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -32,6 +32,7 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
pygame
.
image
.
load
(
'hero5.png'
)]
lose
=
pygame
.
image
.
load
(
'gameover.png'
)
lu_x
=
0
lu_x
=
0
shan_x
=
0
shan_x
=
0
index
=
0
index
=
0
...
@@ -40,6 +41,7 @@ jumpState = "runing"
...
@@ -40,6 +41,7 @@ jumpState = "runing"
t
=
30
t
=
30
time
=
0
time
=
0
s_list
=
pygame
.
sprite
.
Group
()
s_list
=
pygame
.
sprite
.
Group
()
game_state
=
True
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -54,7 +56,7 @@ while True:
...
@@ -54,7 +56,7 @@ while True:
index
+=
1
index
+=
1
if
index
>=
5
:
if
index
>=
5
:
index
=
0
index
=
0
screen
.
blit
(
wukong
.
image
,
(
150
,
wukong
.
rect
.
y
))
if
jumpState
==
"up"
:
# 起跳状态
if
jumpState
==
"up"
:
# 起跳状态
if
t
>
0
:
if
t
>
0
:
...
@@ -75,29 +77,33 @@ while True:
...
@@ -75,29 +77,33 @@ while True:
# 悟空造型
# 悟空造型
# 将背景图画上去
# 将背景图画上去
shan_x
-=
2
if
game_state
:
if
shan_x
<-
1000
:
shan_x
-=
2
shan_x
=
0
if
shan_x
<-
1000
:
screen
.
blit
(
background
,
(
shan_x
,
0
))
# 远处背景
shan_x
=
0
lu_x
-=
8
screen
.
blit
(
background
,
(
shan_x
,
0
))
# 远处背景
if
lu_x
<-
1000
:
lu_x
-=
8
lu_x
=
0
if
lu_x
<-
1000
:
screen
.
blit
(
road
,
(
lu_x
,
500
))
# 路
lu_x
=
0
# 悟空
screen
.
blit
(
road
,
(
lu_x
,
500
))
# 路
# 悟空
screen
.
blit
(
wukong
.
image
,
(
150
,
wukong
.
rect
.
y
))
time
+=
1
time
+=
1
if
time
>
60
:
if
time
>
60
:
time
=
0
time
=
0
num
=
random
.
randint
(
0
,
50
)
num
=
random
.
randint
(
0
,
50
)
if
num
>
15
:
if
num
>
15
:
aa
=
Block
(
bush
,
cacti
,
stone
)
aa
=
Block
(
bush
,
cacti
,
stone
)
s_list
.
add
(
aa
)
s_list
.
add
(
aa
)
for
i
in
s_list
:
for
i
in
s_list
:
if
i
.
rect
.
x
<=
0
-
i
.
rect
.
width
:
# 障碍物消失
if
i
.
rect
.
x
<=
0
-
i
.
rect
.
width
:
# 障碍物消失
i
.
kill
()
i
.
kill
()
i
.
rect
.
x
-=
8
i
.
rect
.
x
-=
8
screen
.
blit
(
i
.
image
,
(
i
.
rect
.
x
,
i
.
rect
.
y
))
screen
.
blit
(
i
.
image
,
(
i
.
rect
.
x
,
i
.
rect
.
y
))
# 刷新画面
if
pygame
.
sprite
.
collide_rect
(
wukong
,
i
):
pygame
.
display
.
update
()
screen
.
blit
(
lose
,
(
400
,
300
))
FPS
.
tick
(
60
)
game_state
=
False
\ No newline at end of file
# 刷新画面
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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