Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson7_diy2
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
3012a24e
authored
May 14, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
ea4945bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
20 deletions
my_game.py
my_game.py
View file @
3012a24e
...
@@ -5,7 +5,7 @@ pygame.init() # 初始化
...
@@ -5,7 +5,7 @@ pygame.init() # 初始化
# 创建一个窗口
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
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
(
'bg.png'
)
# 背景
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
...
@@ -18,8 +18,8 @@ hero = [pygame.image.load('hero1.png'),
...
@@ -18,8 +18,8 @@ hero = [pygame.image.load('hero1.png'),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero4.png'
),
pygame
.
image
.
load
(
'hero5.png'
)]
#悟空
pygame
.
image
.
load
(
'hero5.png'
)]
#悟空
index
=
0
index
=
0
y
=
400
y
=
400
#y坐标
t
=
30
t
=
30
#跳跃增减的值
Status
=
"running"
#悟空的初始状态
Status
=
"running"
#悟空的初始状态
while
True
:
while
True
:
...
@@ -28,33 +28,30 @@ while True:
...
@@ -28,33 +28,30 @@ while True:
# 接收到退出事件后退出程序
# 接收到退出事件后退出程序
exit
()
exit
()
if
event
.
type
==
locals
.
KEYDOWN
:
#当按键被按下
#当空格被按下
if
event
.
key
==
locals
.
K_SPACE
:
#当空格键被按下
if
event
.
type
==
locals
.
KEYDOWN
:
Status
=
"jump"
#悟空状态切换
if
event
.
key
==
locals
.
K_SPACE
:
if
Status
==
"jump"
:
#当状态为jump时
Status
=
"jump"
if
t
>
0
:
#向上跳
if
Status
==
"jump"
:
if
t
>
0
:
y
-=
t
y
-=
t
t
-=
2
t
-=
2
else
:
else
:
Status
=
"down"
Status
=
"down"
if
Status
==
"down"
:
if
Status
==
"down"
:
#当状态为down时
if
t
<=
30
:
if
t
<=
30
:
#向下降
y
+=
t
y
+=
t
t
+=
2
t
+=
2
else
:
else
:
Status
=
"running"
Status
=
"running"
#悟空状态切换
wukong
=
hero
[
index
]
wukong
=
hero
[
index
]
#悟空的跑步造型切换
index
+=
1
index
+=
1
#下一个造型
if
index
>
4
:
if
index
>
4
:
#造型变为第1个造型
index
=
0
index
=
0
# 将背景图画上去
# 将背景图画上去
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
))
#悟空
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
FPS
.
tick
(
60
)
\ 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