Commit 4510688b by BellCodeEditor

save project

parent c4ba6e95
Showing with 81 additions and 41 deletions
...@@ -3,36 +3,40 @@ from pygame import locals ...@@ -3,36 +3,40 @@ from pygame import locals
import os import os
import random import random
pygame.init() # 初始化 #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') # 播放按钮 stop_img = pygame.image.load('stop.png')
stop_img = pygame.image.load('stop.png') # 暂停按钮 last_img = pygame.image.load('last.png')
last_img = pygame.image.load('last.png') # 上一曲按钮 next_img = pygame.image.load('next.png')
next_img = pygame.image.load('next.png') # 下一曲按钮 logo_img = pygame.image.load('logo.png')
logo_img = pygame.image.load('logo.png') # 下一曲按钮 f=pygame.font.Font("wula.ttc",50)
clock=pygame.time.Clock() clock=pygame.time.Clock()
music_list = []
#Search
path = "C:\\Users\\Administrator\\Desktop\\test" path = "C:\\Users\\Administrator\\Desktop\\test"
filelist = os.listdir(path) filelist = os.listdir(path)
num = -1 music_list = []
for i in filelist: for i in filelist:
if i[-4:] == ".wav" or i[-4:] == ".ogg" or i[-4:] == ".mp3": if i[-4:] == ".wav" or i[-4:] == ".ogg":
music_list.append(i) music_list.append(i)
volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量 #Special Define
num = -1
click = 0 click = 0
play_button = stop_img volume = 0.2
angle=0 angle=0
niyuchen=0 niyuchen=0
f2=pygame.font.Font("wula.ttc",50) play_button = stop_img
pygame.mixer.music.set_volume(volume)
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
#So you wanna go...
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
# 按键,控制声音大小 #Press?
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_w: if event.key == locals.K_w:
volume += 0.1 volume += 0.1
...@@ -44,11 +48,13 @@ while True: ...@@ -44,11 +48,13 @@ while True:
if volume < 0: if volume < 0:
volume = 0 volume = 0
pygame.mixer.music.set_volume(volume) pygame.mixer.music.set_volume(volume)
#Mouse!
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: # 播放按钮 #Pause?
if x > 270 and x < 370 and y > 350 and y < 450:
click += 1 click += 1
if click % 2 == 0: if click % 2 == 0:
pygame.mixer.music.unpause() pygame.mixer.music.unpause()
...@@ -58,12 +64,15 @@ while True: ...@@ -58,12 +64,15 @@ while True:
pygame.mixer.music.pause() pygame.mixer.music.pause()
play_button = play_img play_button = play_img
niyuchen=1 niyuchen=1
if x > 420 and x < 520 and y > 350 and y < 400: # 下一曲 #Next
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:
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()
sound=pygame.mixer.Sound(path+"\\"+music_list[num])
s_length=sound.get_length()
niyuchen=0 niyuchen=0
angle=-0.909 angle=-0.909
play_button = stop_img play_button = stop_img
...@@ -71,13 +80,15 @@ while True: ...@@ -71,13 +80,15 @@ while True:
click += 2 click += 2
else: else:
click += 1 click += 1
#Last
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:
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()
sound=pygame.mixer.Sound(path+"\\"+music_list[num])
s_length=sound.get_length()
niyuchen=0 niyuchen=0
angle=-0.909 angle=-0.909
play_button = stop_img play_button = stop_img
...@@ -85,43 +96,71 @@ while True: ...@@ -85,43 +96,71 @@ while True:
click += 2 click += 2
else: else:
click += 1 click += 1
#Yuchen Nee
if niyuchen==0: if niyuchen==0:
angle-=0.909 angle-=0.909 #Swinging~
font=pygame.font.Font("wula.ttc",50) font=pygame.font.Font("wula.ttc",50) #Present
else: else:
font=pygame.font.Font("wul.ttc",50) font=pygame.font.Font("wul.ttc",50) #Past
newlogo=pygame.transform.rotate(logo_img,angle)
newrect=newlogo.get_rect(center=(320,200)) #Run
pos=(newrect[0],newrect[1])
if pygame.mixer.music.get_busy() == False: if pygame.mixer.music.get_busy() == False:
num += 1 num += 1
if num > len(music_list)-1: if num > len(music_list)-1:
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()
s=int(pygame.mixer.music.get_pos()//1000) sound=pygame.mixer.Sound(path+"\\"+music_list[num])
info=str(s//60)+":"+str(s%60) s_length=sound.get_length()
print(info)
#T E N E T
now_seconds=int(pygame.mixer.music.get_pos()//1000)
if now_seconds % 60 < 10:
info=str(now_seconds // 60) + ":" + "0" + str(now_seconds % 60)
else:
info=str(now_seconds // 60) + ":" + str(now_seconds % 60)
whole_seconds=int(s_length)
if whole_seconds % 60 < 10:
info2="/" + str(whole_seconds // 60) + ":" + "0" + str(whole_seconds % 60)
else:
info2="/" + str(whole_seconds // 60) + ":" +str(whole_seconds % 60)
##Funny
#Colorful
ypa=random.randint(1,12) ypa=random.randint(1,12)
first=random.randint(0,20) first=random.randint(0,20)
second=random.randint(0,20) second=random.randint(0,20)
third=random.randint(0,20) third=random.randint(0,20)
#Change
if niyuchen==0: if niyuchen==0:
text = font.render(info,True,(first*ypa,second*ypa,third*ypa)) text = font.render(info,True,(first*ypa,second*ypa,third*ypa))
text2 = font.render(info2,True,(first*ypa,second*ypa,third*ypa))
else: else:
text = font.render(info,True,(255,255,255)) text = font.render(info,True,(255,255,255))
t2 = font.render(info,False,(third*ypa,first*ypa,second*ypa)) text2 = font.render(info2,True,(255,255,255))
# 绘制画面 #Blind
screen.blit(bg_img, (0, 0)) # 填充背景 chongying = font.render(info,False,(third*ypa,first*ypa,second*ypa))
screen.blit(play_button, (270, 330)) # 暂停按钮 chongying2 = font.render(info2,False,(third*ypa,first*ypa,second*ypa))
screen.blit(newlogo,pos) # 中间logo图
screen.blit(last_img, (120, 350)) # 上一曲 #Ready
screen.blit(next_img, (420, 350)) # 下一曲 newlogo=pygame.transform.rotate(logo_img,angle)
newrect=newlogo.get_rect(center=(320,200))
pos=(newrect[0],newrect[1])
#Painting
screen.blit(bg_img, (0, 0))
screen.blit(play_button, (270, 330))
screen.blit(newlogo,pos)
screen.blit(last_img, (120, 350))
screen.blit(next_img, (420, 350))
if niyuchen==0: if niyuchen==0:
screen.blit(text,(ypa+20,ypa+400)) screen.blit(text,(ypa+20,ypa+400))
screen.blit(t2,(ypa+20-first,ypa+400-first)) screen.blit(chongying,(ypa+20-first,ypa+400-first))
screen.blit(text2,(ypa+153,ypa+400))
screen.blit(chongying2,(ypa+153-first,ypa+400-first))
else: else:
screen.blit(text,(25,400)) screen.blit(text,(25,400))
# 刷新画面 screen.blit(text2,(153,400))
#Update
clock.tick(60) clock.tick(60)
pygame.display.update() pygame.display.update()
\ 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