Commit cb5d9174 by BellCodeEditor

save project

parent 03b91d97
Showing with 18 additions and 18 deletions
...@@ -4,7 +4,6 @@ import os ...@@ -4,7 +4,6 @@ import os
pygame.init() # 初始化 pygame.init() # 初始化
# 创建窗口 # 创建窗口
screen = pygame.display.set_mode((640, 480)) screen = pygame.display.set_mode((640, 480))
# 载入图片、资源 # 载入图片、资源
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') # 播放按钮
...@@ -16,8 +15,6 @@ volume=0.1 ...@@ -16,8 +15,6 @@ volume=0.1
font=pygame.font.Font('neuropol.ttf',15) font=pygame.font.Font('neuropol.ttf',15)
music_list=[] music_list=[]
path="C:\\Users\\Jason\\Music\\Music1" path="C:\\Users\\Jason\\Music\\Music1"
filelist=os.listdir(path) filelist=os.listdir(path)
num=-1 num=-1
angle=0 angle=0
...@@ -49,8 +46,8 @@ while True: ...@@ -49,8 +46,8 @@ 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()
music1=pygame.mixer.Sound(path+'\\'+music_list[num])
music_length=int(music1.get_length())
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
...@@ -63,10 +60,6 @@ while True: ...@@ -63,10 +60,6 @@ while True:
pygame.mixer.music.pause() pygame.mixer.music.pause()
play_button=play_img play_button=play_img
if x>120 and x<220 and y>350 and y<400: if x>120 and x<220 and y>350 and y<400:
num-=1 num-=1
if num<0: if num<0:
...@@ -75,11 +68,8 @@ while True: ...@@ -75,11 +68,8 @@ while True:
pygame.mixer.music.play() pygame.mixer.music.play()
click=0 click=0
play_button=stop_img play_button=stop_img
music1=pygame.mixer.Sound(path+'\\'+music_list[num])
music_length=int(music1.get_length())
if x>420 and x<520 and y>350 and y<400: if x>420 and x<520 and y>350 and y<400:
num+=1 num+=1
if num>len(music_list)-1: if num>len(music_list)-1:
...@@ -88,14 +78,13 @@ while True: ...@@ -88,14 +78,13 @@ while True:
pygame.mixer.music.play() pygame.mixer.music.play()
click=0 click=0
play_button=stop_img play_button=stop_img
music1=pygame.mixer.Sound(path+'\\'+music_list[num])
music_length=int(music1.get_length())
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: if play_button==stop_img:
angle+=1 angle+=1
play_time=pygame.mixer.music.get_pos() play_time=pygame.mixer.music.get_pos()
play_time=int(play_time/1000) play_time=int(play_time/1000)
play_m=play_time//60 play_m=play_time//60
...@@ -105,6 +94,14 @@ while True: ...@@ -105,6 +94,14 @@ while True:
if play_m<10: if play_m<10:
play_m='0'+str(play_m) play_m='0'+str(play_m)
info=str(play_m)+':'+str(play_s) info=str(play_m)+':'+str(play_s)
music_m=music_length//60
music_s=music_length%60
if music_s<10:
music_s='0'+str(music_s)
if music_m<10:
music_m='0'+str(music_m)
info2='/'+str(music_m)+':'+str(music_s)
# 绘制画面 # 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景 screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮 screen.blit(play_button, (270, 330)) # 暂停按钮
...@@ -114,5 +111,7 @@ while True: ...@@ -114,5 +111,7 @@ while True:
# 刷新画面 # 刷新画面
play_time=font.render(info,True,(255,255,255)) play_time=font.render(info,True,(255,255,255))
screen.blit(play_time,(120,440)) screen.blit(play_time,(120,440))
play_time=font.render(info2,True,(0,0,0))
screen.blit(play_time,(200,440))
pygame.display.update() pygame.display.update()
fps.tick(60) fps.tick(60)
\ No newline at end of file
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