Commit 2aadbf28 by BellCodeEditor

save project

parent 19f22638
Showing with 35 additions and 2 deletions
import pygame
import os
from pygame import locals
pygame.init() # 初始化
......@@ -12,14 +13,23 @@ last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 下一曲按钮
# 将文件内的音乐添加到列表
music_list=[]
path="C:\\Users\\LTT\\Documents\\pygame_lesson5_diy1\\"
file=os.listdir(path)
for i in file:
if i[-4:]==".wav" or i[-4:]==".ogg":
music_list.append(i)
# 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
#pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量
click = 0
click_xy=(0,0)
play_button = stop_img
num=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -37,7 +47,15 @@ while True:
volume = 0
pygame.mixer.music.set_volume(volume)
# 按下鼠标
if event.type == locals.MOUSEBUTTONDOWN:
# 获取点击处的坐标
click_xy=event.pos
click_x=click_xy[0]
click_y=click_xy[1]
# 按下音乐暂停/开始按钮处
if click_x>270 and click_x<370 and click_y>350 and click_y<450:
# 次数增加
click += 1
if click % 2 == 0:
play_button = stop_img
......@@ -45,8 +63,23 @@ while True:
else:
play_button = play_img
pygame.mixer.music.pause()
# 按下上一曲
if click_x>120 and click_x<220 and click_y>350 and click_y<400:
num-=1
if num < 0:
num=len(music_list)-1
pygame.mixer.music.load(path+"\\"+music_list[num])
pygame.mixer.music.play()
click=0
play_button=stop_img
if pygame.mixer.music.get_busy() == False:
num += 1
if num > len(music_list)-1:
num=0
pygame.mixer.music.load(path+"\\"+music_list[num])
pygame.mixer.music.play()
# 绘制画面
......
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