Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson04_diy
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
1bf99165
authored
May 14, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
fa67a887
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
79 deletions
.py
12.py
.py
View file @
1bf99165
...
@@ -72,3 +72,4 @@ while True:
...
@@ -72,3 +72,4 @@ while True:
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
12.py
View file @
1bf99165
import
pygame
import
pygame
from
pygame
import
locals
from
pygame
import
locals
import
os
pygame
.
init
()
# 初始化
pygame
.
init
()
# 初始化
# 创建窗口
# 创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
640
,
480
))
screen
=
pygame
.
display
.
set_mode
((
1000
,
600
))
# 载入图片、资源
FPS
=
pygame
.
time
.
Clock
()
# pygame时钟,控制游戏速度(帧数)
bg_img
=
pygame
.
image
.
load
(
'background.png'
)
# 背景图
pygame
.
display
.
set_caption
(
"悟空跑酷"
)
play_img
=
pygame
.
image
.
load
(
'play.png'
)
# 播放按钮
# 载入图片
stop_img
=
pygame
.
image
.
load
(
'stop.png'
)
# 暂停按钮
background
=
pygame
.
image
.
load
(
'bg.png'
)
# 背景
last_img
=
pygame
.
image
.
load
(
'last.png'
)
# 上一曲按钮
road
=
pygame
.
image
.
load
(
'road.png'
)
# 路
next_img
=
pygame
.
image
.
load
(
'next.png'
)
# 下一曲按钮
stone
=
pygame
.
image
.
load
(
'stone.png'
)
# 石头
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 下一曲按钮
cacti
=
pygame
.
image
.
load
(
'cacti.png'
)
# 仙人掌
apple
=
pygame
.
image
.
load
(
'bush.png'
)
# 灌木丛
# 音乐
hero
=
[
pygame
.
image
.
load
(
'hero1.png'
),
music_list
=
[]
pygame
.
image
.
load
(
'hero2.png'
),
path
=
"C:
\\
Users
\\
HP
\\
Desktop
\\
test"
pygame
.
image
.
load
(
'hero3.png'
),
filelist
=
os
.
listdir
(
path
)
pygame
.
image
.
load
(
'hero4.png'
),
for
i
in
filelist
:
pygame
.
image
.
load
(
'hero5.png'
)]
if
i
[
-
4
:]
==
".ogg"
or
i
[
-
4
:]
==
".mp3"
or
i
[
-
4
:]
==
".wav"
:
index
=
0
music_list
.
append
(
i
)
y
=
400
jumState
=
"runing"
num
=
-
1
t
=
30
volume
=
0.2
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
click
=
0
play_button
=
stop_img
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
:
# 接收到退出事件后退出程序
exit
()
exit
()
# 按键,控制声音大小
if
jumState
==
"runing"
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_UP
:
if
event
.
key
==
locals
.
K_SPACE
:
volume
+=
0.1
jumState
=
"up"
if
volume
>
1
:
if
jumState
==
"up"
:
volume
=
1
if
t
>
0
:
pygame
.
mixer
.
music
.
set_volume
(
volume
)
y
-=
t
if
event
.
key
==
locals
.
K_DOWN
:
t
-=
2
volume
-=
0.1
else
:
if
volume
<
0
:
jumState
=
"down"
volume
=
0
pygame
.
mixer
.
music
.
set_volume
(
volume
)
if
jumState
==
"down"
:
if
t
<=
30
:
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
y
+=
t
if
event
.
button
==
1
:
# 左击
t
+=
2
x
,
y
=
event
.
pos
else
:
if
x
>
270
and
x
<
370
and
y
>
350
and
y
<
450
:
jumState
=
"runing"
click
+=
1
t
=
30
if
click
%
2
==
0
:
play_button
=
stop_img
wukong
=
hero
[
index
]
pygame
.
mixer
.
music
.
unpause
()
if
jumState
==
"runing"
:
else
:
index
+=
1
play_button
=
play_img
if
index
==
5
:
pygame
.
mixer
.
music
.
pause
()
index
=
0
if
x
>
120
and
x
<
220
and
y
>
350
and
y
<
400
:
# 将背景图画上去
num
+-
1
screen
.
blit
(
background
,
(
0
,
0
))
if
num
>
len
(
music_list
)
-
1
:
screen
.
blit
(
road
,
(
0
,
500
))
num
-=
0
screen
.
blit
(
wukong
,
(
150
,
y
))
pygame
.
mixer
.
music
.
load
(
path
+
"
\\
"
+
music_list
[
num
])
pygame
.
mixer
.
music
.
play
()
play_button
=
stop_img
click
=
0
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
num
+=
1
if
num
>
len
(
filelist
)
-
1
:
num
=
0
print
(
num
)
pygame
.
mixer
.
music
.
load
(
path
+
"
\\
"
+
music_list
[
num
])
pygame
.
mixer
.
music
.
play
()
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
play_button
,
(
270
,
330
))
# 暂停按钮
screen
.
blit
(
logo_img
,
(
170
,
60
))
# 中间logo图
screen
.
blit
(
last_img
,
(
120
,
350
))
# 上一曲
screen
.
blit
(
next_img
,
(
420
,
350
))
# 下一曲
# 刷新画面
# 刷新画面
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPS
.
tick
(
60
)
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