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
b2dd49ef
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
e630520a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
23 deletions
my_game.py
my_game.py
View file @
b2dd49ef
import
pygame
import
pygame
import
time
import
time
import
random
from
pygame
import
locals
from
pygame
import
locals
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建一个窗口
# 创建一个窗口
i
=-
1
y
=
400
tiao
=
0
g
=
30
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
pygame
.
display
.
set_caption
(
'wukongkupao'
)
pygame
.
display
.
set_caption
(
'wukongkupao'
)
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
#变量 #不要动
i
=
1
#造型 #不要动
y
=
400
#y值 #不要动
Status
=
"running"
#状态 #不要动
g
=
30
#重力
#不要动
# 载入图片
# 载入图片
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
cacti
=
pygame
.
image
.
load
(
'cacti.png'
)
# 仙人掌
cacti
=
pygame
.
image
.
load
(
'cacti.png'
)
# 仙人掌
apple
=
pygame
.
image
.
load
(
'bush.png'
)
# 灌木丛
bush
=
pygame
.
image
.
load
(
'bush.png'
)
# 灌木丛
hero
=
[
pygame
.
image
.
load
(
'hero1.png'
),
pygame
.
image
.
load
(
'hero2.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
hero
=
[
pygame
.
image
.
load
(
'hero1.png'
),
pygame
.
image
.
load
(
'hero2.png'
),
pygame
.
image
.
load
(
'hero3.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
zhang_ai
=
random
.
choice
([
stone
,
cacti
,
bush
])
rect
=
zhang_ai
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
index
=
0
index
=
0
while
True
:
while
True
:
#不要动
i
=
i
+
1
wukong
=
hero
[
i
]
#不要动 #不要动 #不要动#不要动#不要动#不要动#不要动#不要动#不要动
if
i
>
4
:
if
Status
==
"running"
:
#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
i
=
0
i
=
i
+
1
#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动#不要动
wukong
=
hero
[
i
]
if
i
>
4
:
i
=
0
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
# 接收到退出事件后退出程序
exit
()
# 接收到退出事件后退出程序
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_SPACE
:
if
Status
==
"running"
:
tiao
=
1
if
event
.
key
==
locals
.
K_SPACE
:
if
tiao
==
1
:
Status
=
"up"
if
Status
==
"up"
:
if
g
>=
0
:
if
g
>=
0
:
y
-=
g
y
-=
g
g
-=
2
g
-=
2
else
:
else
:
#不要动#不要动#不要动#不要动#不要动#不要动
tiao
=
0
Status
=
"down"
#不要动#不要动#不要动#不要动#不要动
if
tiao
==
0
:
if
Status
==
"down"
:
if
g
<
=
30
:
if
g
<
30
:
y
+=
g
+
2
y
+=
g
+
2
g
+=
2
g
+=
2
else
:
else
:
tiao
=
3
Status
=
"running"
screen
.
blit
(
background
,
(
0
,
0
))
# 将背景图画上去
screen
.
blit
(
background
,
(
0
,
0
))
# 将背景图画上去
screen
.
blit
(
road
,
(
0
,
500
))
# 将背景图画上去
screen
.
blit
(
road
,
(
0
,
500
))
# 将背景图画上去
#不要动#不要动#不要动#不要动#不要动
screen
.
blit
(
wukong
,(
150
,
y
))
#悟空的动作
screen
.
blit
(
wukong
,(
150
,
y
))
#悟空的动作
if
rect
.
x
<=
0
-
rect
.
width
:
zhang_ai
=
random
.
choice
([
stone
,
cacti
,
bush
])
rect
=
zhang_ai
.
get_rect
()
rect
.
x
=
1000
rect
.
y
=
500
-
rect
.
height
rect
.
x
-=
8
screen
.
blit
(
zhang_ai
,(
rect
.
x
,
rect
.
y
))
pygame
.
display
.
update
()
#保存
pygame
.
display
.
update
()
#保存
FPS
.
tick
(
60
)
# 刷新画面
FPS
.
tick
(
40
)
# 刷新画面
\ No newline at end of file
\ 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