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
83f46908
authored
May 21, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
575f31c3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
lesson7-diy4.py
lesson7-diy4.py
View file @
83f46908
...
@@ -22,16 +22,17 @@ screen = pygame.display.set_mode((1000, 600))
...
@@ -22,16 +22,17 @@ screen = pygame.display.set_mode((1000, 600))
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
pygame
.
display
.
set_caption
(
"悟空酷跑"
)
pygame
.
display
.
set_caption
(
"悟空酷跑"
)
# 载入图片
# 载入图片
background
=
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\bg.png'
)
# 背景
background
=
pygame
.
image
.
load
(
r'bg.png'
)
# 背景
road
=
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\road.png'
)
# 路
road
=
pygame
.
image
.
load
(
r'road.png'
)
# 路
stone
=
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\stone.png'
)
# 石头
stone
=
pygame
.
image
.
load
(
r'stone.png'
)
# 石头
cacti
=
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\cacti.png'
)
# 仙人掌
cacti
=
pygame
.
image
.
load
(
r'cacti.png'
)
# 仙人掌
bush
=
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\bush.png'
)
# 灌木丛
bush
=
pygame
.
image
.
load
(
r'bush.png'
)
# 灌木丛
hero
=
[
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\hero1.png'
),
hero
=
[
pygame
.
image
.
load
(
r'hero1.png'
),
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\hero2.png'
),
pygame
.
image
.
load
(
r'hero2.png'
),
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\hero3.png'
),
pygame
.
image
.
load
(
r'hero3.png'
),
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\hero4.png'
),
pygame
.
image
.
load
(
r'hero4.png'
),
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\hero5.png'
)]
pygame
.
image
.
load
(
r'hero5.png'
)]
font
=
pygame
.
font
.
Font
(
'STKAITI.TTF'
,
32
)
index
=
0
index
=
0
y
=
400
y
=
400
jumpState
=
"runing"
jumpState
=
"runing"
...
@@ -76,11 +77,11 @@ while True:
...
@@ -76,11 +77,11 @@ while True:
# 悟空造型
# 悟空造型
# 将背景图画上去
# 将背景图画上去
bg_x
-=
1
0
bg_x
-=
1
if
bg_x
<-
1000
:
if
bg_x
<-
1000
:
bg_x
=
0
bg_x
=
0
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远处背景
screen
.
blit
(
background
,
(
bg_x
,
0
))
# 远处背景
road_x
-=
15
road_x
-=
8
if
road_x
<-
1000
:
if
road_x
<-
1000
:
road_x
=
0
road_x
=
0
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
screen
.
blit
(
road
,
(
road_x
,
500
))
# 路
...
@@ -95,17 +96,18 @@ while True:
...
@@ -95,17 +96,18 @@ while True:
time
=
0
time
=
0
num
=
random
.
randint
(
0
,
50
)
num
=
random
.
randint
(
0
,
50
)
if
num
>
20
:
if
num
>
20
:
obstacle
=
jinglin
(
stone
,
cacti
,
bush
)
obstacle
=
jinglin
(
stone
,
cacti
,
bush
)
obstacle_list
.
add
(
obstacle
)
obstacle_list
.
add
(
obstacle
)
for
temp_sprit
in
obstacle_list
:
for
temp_sprit
in
obstacle_list
:
temp_sprit
.
rect
.
x
-=
8
temp_sprit
.
rect
.
x
-=
8
screen
.
blit
(
temp_sprit
.
image
,
(
temp_sprit
.
rect
.
x
,
temp_sprit
.
rect
.
y
))
screen
.
blit
(
temp_sprit
.
image
,
(
temp_sprit
.
rect
.
x
,
temp_sprit
.
rect
.
y
))
if
temp_sprit
.
rect
.
x
<=
0
-
temp_sprit
.
rect
.
x
:
if
temp_sprit
.
rect
.
x
<=
0
-
temp_sprit
.
rect
.
x
:
temp_sprit
.
kill
()
temp_sprit
.
kill
()
if
pygame
.
sprite
.
collide_rect
(
wukong
,
temp_sprit
):
if
pygame
.
sprite
.
collide_rect
(
wukong
,
temp_sprit
):
gameover
=
pygame
.
image
.
load
(
r'D:\PycharmProjects\pythonProject\jxeducation\悟空快跑\
gameover.png'
)
gameover
=
pygame
.
image
.
load
(
r'
gameover.png'
)
screen
.
blit
(
gameover
,(
400
,
200
))
screen
.
blit
(
gameover
,(
400
,
200
))
gamestate
=
False
gamestate
=
Falses
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
50
)
FPS
.
tick
(
50
)
\ 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