Commit cb890d90 by BellCodeEditor

auto save

parent 19f22638
Showing with 33 additions and 3 deletions
import pygame
from pygame import locals
import os
pygame.init() # 初始化
# 创建窗口
screen = pygame.display.set_mode((640, 480))
......@@ -14,6 +14,14 @@ logo_img = pygame.image.load('logo.png') # 下一曲按钮
# 载入音乐
pygame.mixer.music.load('歌曲4.ogg') # 载入音乐
music=[]
path="C:\\Users\\hp\\Desktop\\音乐"
file=os.listdir(path)
for i in file:
if i[-4:]==".mp3" or i[-4:]==".ogg":
music.append(i)
num=-1
volume = 0.2
pygame.mixer.music.set_volume(volume) # 初始播放音量
......@@ -38,6 +46,10 @@ while True:
pygame.mixer.music.set_volume(volume)
if event.type == locals.MOUSEBUTTONDOWN:
x,y=event.pos
if event.button==1:
if x>270 and x<350 and y>350 and y<450:
click += 1
if click % 2 == 0:
play_button = stop_img
......@@ -45,10 +57,28 @@ while True:
else:
play_button = play_img
pygame.mixer.music.pause()
if x>120 and x<220 and y>350 and y<400:
num-=1
if num>len(music)-1:
num=0
pygame.mixer.music.load(path+"\\"+music[num])
pygame.mixer.music.play()
click=0
play_button=stop_img
if x>420 and x<520 and y>350 and y<400:
num+=1
if num>len(music)-1:
num=0
pygame.mixer.music.load(path+"\\"+music[num])
pygame.mixer.music.play()
click=0
play_button=stop_img
if pygame.mixer.music.get_busy() == False:
num+=1
if num>len(music)-1:
num=0
pygame.mixer.music.load(path+"\\"+music[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