Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_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
5136ffbb
authored
May 21, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
b2dd49ef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
my_game.py
my_game.py
View file @
5136ffbb
...
@@ -14,7 +14,9 @@ i=1#造型 #不要动
...
@@ -14,7 +14,9 @@ i=1#造型 #不要动
y
=
400
#y值 #不要动
y
=
400
#y值 #不要动
Status
=
"running"
#状态 #不要动
Status
=
"running"
#状态 #不要动
g
=
30
#重力
g
=
30
#重力
#不要动
road_x
=
0
bg_x
=
0
#不要动
# 载入图片
# 载入图片
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
...
@@ -27,17 +29,22 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -27,17 +29,22 @@ 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'
)]
zhang_ai
=
random
.
choice
([
stone
,
cacti
,
bush
])
zhang_ai
=
random
.
choice
([
stone
,
cacti
,
bush
])
rect
=
zhang_ai
.
get_rect
()
rect
=
zhang_ai
.
get_rect
()
rect
.
x
=
1000
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
y
=
500
-
rect
.
height
index
=
0
index
=
0
while
True
:
#不要动
while
True
:
#不要动
wukong
=
hero
[
i
]
#不要动 #不要动 #不要动#不要动#不要动#不要动#不要动#不要动#不要动
wukong
=
hero
[
i
]
#不要动 #不要动 #不要动#不要动#不要动#不要动#不要动#不要动#不要动
if
Status
==
"running"
:
#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
if
Status
==
"running"
:
#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
i
=
i
+
1
#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
i
=
i
+
1
#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
if
i
>
4
:
if
i
>
4
:
i
=
0
i
=
0
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
...
@@ -47,12 +54,14 @@ while True:
...
@@ -47,12 +54,14 @@ while True:
if
Status
==
"running"
:
if
Status
==
"running"
:
if
event
.
key
==
locals
.
K_SPACE
:
if
event
.
key
==
locals
.
K_SPACE
:
Status
=
"up"
Status
=
"up"
if
Status
==
"up"
:
if
Status
==
"up"
:
if
g
>=
0
:
if
g
>=
0
:
y
-=
g
y
-=
g
g
-=
2
g
-=
2
else
:
#不要动#不要动#不要动#不要动#不要动#不要动
else
:
#不要动#不要动#不要动#不要动#不要动#不要动
Status
=
"down"
#不要动#不要动#不要动#不要动#不要动
Status
=
"down"
#不要动#不要动#不要动#不要动#不要动
if
Status
==
"down"
:
if
Status
==
"down"
:
if
g
<
30
:
if
g
<
30
:
y
+=
g
+
2
y
+=
g
+
2
...
@@ -61,10 +70,20 @@ while True:
...
@@ -61,10 +70,20 @@ while True:
Status
=
"running"
Status
=
"running"
screen
.
blit
(
background
,
(
0
,
0
))
# 将背景图画上去
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 将背景图画上去
screen
.
blit
(
road
,
(
0
,
500
))
# 将背景图画上去 #不要动#不要动#不要动#不要动#不要动
bg_x
-=
1
#背景的移动
if
bg_x
<-
1000
:
bg_x
=
0
screen
.
blit
(
road
,
(
road_x
,
500
))
# 将路画上去
road_x
-=
8
#路的移动
if
road_x
<-
1000
:
road_x
=
0
#不要动#不要动#不要动#不要动#不要动
screen
.
blit
(
wukong
,(
150
,
y
))
#悟空的动作
screen
.
blit
(
wukong
,(
150
,
y
))
#悟空的动作
#障碍:随机,移动
if
rect
.
x
<=
0
-
rect
.
width
:
if
rect
.
x
<=
0
-
rect
.
width
:
zhang_ai
=
random
.
choice
([
stone
,
cacti
,
bush
])
zhang_ai
=
random
.
choice
([
stone
,
cacti
,
bush
])
rect
=
zhang_ai
.
get_rect
()
rect
=
zhang_ai
.
get_rect
()
...
...
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