Commit 0e04a5b8 by BellCodeEditor

save project

parent a11d6bb6
Showing with 22 additions and 8 deletions
......@@ -13,12 +13,25 @@ next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 下一曲按钮
# 载入音乐
pygame.mixer.music.load('歌曲1.wav') # 载入音乐
music_list=[]
path="C:\\Users\\11111\\Documents\\pygame_lesson5_diy1"
filelist = os.listdir(path)
for i in filelist:
if i [-4:] == ".ogg" or i[-4:] == ".wav":
music_list.append(i)
num = 0
volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0
play_button = stop_img
is_playing = True
# 初始状态设置为播放中
if music_list:
pygame.mixer.music.load(os.path.join(path,music_list[num]))
pygame.mixer.music.play()
while True:
for event in pygame.event.get():
......@@ -37,12 +50,10 @@ while True:
volume = 0
pygame.mixer.music.set_volume(volume)
# 按下鼠标
if event.type == locals.MOUSEBUTTONDOWN:
if event.button == 1:
x,y = event.pos
if x > 270 and x <370 and y > 350 and y < 450:
# 次数增加
if event.button == 1: # 左击
x, y = event.pos
if x > 270 and x < 370 and y > 350 and y < 450:
click += 1
if click % 2 == 0:
play_button = stop_img
......@@ -50,10 +61,13 @@ while True:
else:
play_button = play_img
pygame.mixer.music.pause()
# 只在播放按钮状态为停止且音乐未播放时才自动播放
if pygame.mixer.music.get_busy() == False:
num += 1
if num > len(music_list)-1:
num = 0
pygame.mixer.music.load(music_list[num])
pygame.mixer.music.play()
# 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment