Commit 30a945c3 by BellCodeEditor

save project

parent 3aa39713
Showing with 24 additions and 45 deletions
import pygame import pygame
from pygame import locals from pygame import locals
pygame.init() # 初始化 # 初始化pygame,为使用硬件做准备
# 创建窗口 pygame.init()
screen = pygame.display.set_mode((640, 480))
# 载入图片 # 创建一个窗口
bg_img = pygame.image.load('background.png') # 背景图 screen = pygame.display.set_mode((660, 480))
play_img = pygame.image.load('play.png') # 播放按钮
stop_img = pygame.image.load('stop.png') # 暂停按钮 # 背景
last_img = pygame.image.load('last.png') # 上一曲按钮 background = pygame.image.load('bg.png')
next_img = pygame.image.load('next.png') # 下一曲按钮 right = pygame.image.load('right.png')
logo_img = pygame.image.load('logo.png') # 中间logo food = pygame.image.load('apple.png')
pygame.mixer.music.load("歌曲4.ogg") body = pygame.image.load('body.png')
volume=0.2
pygame.mixer.music.set_volume(volume)
click=0
play_button=stop_img
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit() exit()
if event.type==locals.KEYDOWN: # 将背景图画上去
if event.key==locals.K_w: screen.blit(background, (0, 0))
volume+=0.1 # 将贪吃蛇画上去
if volume>1: screen.blit(right, (240, 120))
volume=1 # 将贪吃蛇的身体画上去
pygame.mixer.music.set_volume(volume) screen.blit(body, (210, 120))
if event.key == locals.K_s: screen.blit(body, (180, 120))
volume-= 0.1 screen.blit(body, (180, 90))
if volume < 0: # 将果实画上去
volume = 0 screen.blit(food, (360, 300))
pygame.mixer.music.set_volume(volume)
if event.type==locals.MOUSEBUTTONDOWN:
click+=1
if click % 2 == 0:
play_button=stop_img
pygame.mixer.music.unpause()
else:
play_button=play_img
pygame.muixer.music.pause()
if pygame.mixer.music.get_busy()==False:
pygame.mixer.music.play()
# 绘制画面
screen.blit(bg_img, (0, 0)) # 填充背景
screen.blit(play_button, (270, 330)) # 暂停按钮
screen.blit(logo_img, (170, 60)) # 中间logo图
screen.blit(last_img, (120, 350)) # 上一曲
screen.blit(next_img, (420, 350)) # 下一曲
# 刷新画面 # 刷新画面
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