Commit 7f22903f by BellCodeEditor

save project

parent f862ee32
Showing with 21 additions and 13 deletions
...@@ -5,6 +5,7 @@ import os ...@@ -5,6 +5,7 @@ import os
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
screen = pygame.display.set_mode((640, 480)) screen = pygame.display.set_mode((640, 480))
FPS = pygame.time.Clock()
# 载入图片、资源 # 载入图片、资源
bg_img = pygame.image.load('background.png') # 背景图 bg_img = pygame.image.load('background.png') # 背景图
play_img = pygame.image.load('play.png') # 播放按钮 play_img = pygame.image.load('play.png') # 播放按钮
...@@ -17,6 +18,7 @@ music_list=[] ...@@ -17,6 +18,7 @@ music_list=[]
volume = 0.2 volume = 0.2
path="C:\\Users\\dell\\Desktop\\test" path="C:\\Users\\dell\\Desktop\\test"
filelist=os.listdir(path) filelist=os.listdir(path)
music_list = []
for i in filelist: for i in filelist:
if i[-4:] ==".mp3" or i[-4:]==".ogg" or i[-4:]==".wav": if i[-4:] ==".mp3" or i[-4:]==".ogg" or i[-4:]==".wav":
music_list.append(i) music_list.append(i)
...@@ -48,7 +50,7 @@ while True: ...@@ -48,7 +50,7 @@ while True:
if event.type == locals.MOUSEBUTTONDOWN: if event.type == locals.MOUSEBUTTONDOWN:
if event.button == 1: if event.button == 1:
x,y = event.pos x,y = event.pos
if x > 270 and x <370 and y > 350 and y < 450: if x > 270 and x < 370 and y > 350 and y < 450:
# 次数增加 # 次数增加
click += 1 click += 1
if click % 2 == 0: if click % 2 == 0:
...@@ -57,22 +59,26 @@ while True: ...@@ -57,22 +59,26 @@ while True:
else: else:
play_button = play_img play_button = play_img
pygame.mixer.music.pause() pygame.mixer.music.pause()
if x > 120 and x < 220 and y > 350 and y < 400: if x > 420 and x < 520 and y > 350 and y < 450:
pygame.mixer.music.stop()
play_bytton = stop_img
if click % 2 == 0:
click += 2
else:
click += 1
if x > 120 and x < 220 and y > 350 and y < 450:
num -= 1 num -= 1
if num < 0: if num < 0:
num=len(music_list) -1 num = len(music_list) - 1
pygame.mixer.music.load(path+"\\"+music_list[num]) pygame.mixer.music.load(path+"\\"+music_list[num])
pygame.mixer.music.play() pygame.mixer.music.play()
play_button=stop_img play_button=stop_img
click=0
if x > 420 and x < 520 and y > 350 and y < 400: if click % 2 == 0:
num += 1 click += 2
if num > len(music_list)-1: else:
num=0 click += 1
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: if pygame.mixer.music.get_busy() == False:
...@@ -81,9 +87,10 @@ while True: ...@@ -81,9 +87,10 @@ while True:
num=0 num=0
pygame.mixer.music.load(path+"\\"+music_list[num]) pygame.mixer.music.load(path+"\\"+music_list[num])
pygame.mixer.music.play() pygame.mixer.music.play()
new_logo = pygame.transform.rotate(logo_img, angle) new_logo = pygame.transform.rotate(logo_img, -angle)
newRect = new_logo.get_rect(center=(320, 200)) newRect = new_logo.get_rect(center=(320, 200))
pos = (newRect[0], newRect[1]) pos = (newRect[0], newRect[1])
if play_button == stop_img:
angle += 1 angle += 1
# 绘制画面 # 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景 screen.blit(bg_img, (0, 0)) # 填充背景
...@@ -93,3 +100,4 @@ while True: ...@@ -93,3 +100,4 @@ while True:
screen.blit(next_img, (420, 350)) # 下一曲 screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60)
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