Commit 648bea75 by BellCodeEditor

save project

parent 2ffb9ec5
Showing with 65 additions and 4 deletions
import pygame
import os
from pygame import locals
pygame.init() # 初始化
pygame.mixer.init()
# 创建窗口
screen = pygame.display.set_mode((640, 480))
# 载入图片、资源
......@@ -11,16 +14,74 @@ stop_img = pygame.image.load('stop.png') # 暂停按钮
last_img = pygame.image.load('last.png') # 上一曲按钮
next_img = pygame.image.load('next.png') # 下一曲按钮
logo_img = pygame.image.load('logo.png') # 中间logo
volume = 0.2
flag = True
index = 0
button = stop_img
music_list = []
#music_list = ["歌曲1.wav","歌曲2.wav","歌曲3.wav","歌曲4.ogg"]
path = os.getcwd()
resource = os.listdir(path)
for element in resource:
suffix = element[-4:]
if suffix == ".wav" or suffix == ".ogg":
music_list.append(element)
music_len = len(music_list)
while True:
for event in pygame.event.get():
????
if event.type == pygame.QUIT:
exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
volume += 0.1
if volume > 1:
volume = 1
if event.key == pygame.K_DOWN:
volume -= 0.1
if volume < 0:
volume = 0
pygame.mixer.music.set_volume(volume)
if event.type == pygame.MOUSEBUTTONDOWN:
#鼠标左键按下
if event.button == 1:
click_x,click_y = event.pos # click_x = event.pos[0] click_y = event.pos[1]
if click_x > 270 and click_x < 370 and click_y > 330 and click_y < 430:
flag = not flag
if click_x > 120 and click_x < 220 and click_y > 350 and click_y < 400:
pygame.mixer.music.stop()
index -= 1
flag = True
#因为播放歌曲之后此时指向的序号已经是下一首歌曲,所以要先调整回当前歌曲
index -= 1
if click_x > 420 and click_x < 520 and click_y > 350 and click_y < 400:
pygame.mixer.music.stop()
index +=1
flag = True
#因为播放歌曲之后此时指向的序号已经是下一首歌曲,所以要先调整回当前歌曲
index -= 1
if flag == True:
button = stop_img
pygame.mixer.music.unpause()
else:
button = play_img
pygame.mixer.music.pause()
if pygame.mixer.music.get_busy() == False:
pygame.mixer.music.load(music_list[(index%music_len)])
pygame.mixer.music.play()
index += 1
# 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(stop_img, (270, 330)) # 暂停按钮
screen.blit(button, (270, 330)) # 暂停按钮
screen.blit(logo_img, (170, 60)) # 中间logo图
screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面
???
pygame.display.flip()
File deleted
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