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
024e8b3b
authored
Jun 04, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
9a0ec4ce
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
4 deletions
my_music.py
my_music.py
View file @
024e8b3b
...
...
@@ -11,15 +11,43 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img
=
pygame
.
image
.
load
(
'last.png'
)
# 上一曲按钮
next_img
=
pygame
.
image
.
load
(
'next.png'
)
# 下一曲按钮
logo_img
=
pygame
.
image
.
load
(
'logo.png'
)
# 中间logo
pygame
.
mixer
.
music
.
load
(
'歌曲4.ogg'
)
# 载入音乐
while
True
:
# 循环
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
volume
=
0.8
# 新建变量volume初始值设置为0.8
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
click
=
0
# 新建变量click初始值设为0
play_button
=
stop_img
# 创建变量play_button表示播放按钮造型并初始值设为stop_img暂停造型
while
True
:
# while循环
for
event
in
pygame
.
event
.
get
():
# 遍历列表中的事件
if
event
.
type
==
locals
.
QUIT
:
# if判断事件类型编号与lcals模块的QUIT事件编号是否相等
exit
()
# 接收到退出事件后退出程序
# 按键,控制声音大小
if
event
.
type
==
locals
.
KEYDOWN
:
# if判断键盘是否按下
if
event
.
key
==
locals
.
K_w
:
# if判断w键是否按下
volume
+=
0.1
# 音量增加0.1
if
volume
>
1
:
# if判断音量大于1
volume
=
1
# 音量设为1
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
if
event
.
key
==
locals
.
K_s
:
# if判断s键是否按下
volume
-=
0.1
# 音量减少0.1
if
volume
<
0
:
# if判断音量小于0
volume
=
0
# 音量设为0
pygame
.
mixer
.
music
.
set_volume
(
volume
)
# 初始播放音量
if
event
.
type
==
locals
.
MOUSEBUTTONDOWN
:
# 判断是否是鼠标点击事件
click
+=
1
# 变量click值增加1
if
click
%
2
==
0
:
# if判断click除2的余数是否相等于0
play_button
=
stop_img
# 播放造型设为暂停造型
pygame
.
mixer
.
music
.
unpause
()
# 渲染出对应造型
else
:
# 否则
play_button
=
play_img
# 播放造型设为播放造型
pygame
.
mixer
.
music
.
pause
()
# 渲染出对应造型
if
pygame
.
mixer
.
music
.
get_busy
()
==
False
:
# 音乐是否正在播放
pygame
.
mixer
.
music
.
play
()
# 播放音乐
# 绘制画面
screen
.
blit
(
bg_img
,
(
0
,
0
))
# 填充背景
screen
.
blit
(
stop_img
,
(
270
,
330
))
# 暂停按钮
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
))
# 下一曲
...
...
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