Commit 0e1d69eb by BellCodeEditor

save project

parent d24acbc9
Showing with 54 additions and 69 deletions
import pygame import pygame
from pygame import locals from pygame import locals
# 初始化pygame,为使用硬件做准备 pygame.init() # 初始化
pygame.init() # 创建窗口
screen = pygame.display.set_mode((640, 480))
# 创建一个窗口 # 载入图片、资源
screen = pygame.display.set_mode((660, 480)) bg_img = pygame.image.load('background.png') # 背景图
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) 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('歌曲3.wav')
body = pygame.image.load('body.png') # 身体 volume=0.1
left = pygame.image.load('left.png') # 头 朝左 click=0
up = pygame.image.load('up.png') # 头 朝上 a=stop_img
down = pygame.image.load('down.png') # 头 朝下 pygame.mixer.music.set_volume(volume)
while True:
x, y = 240, 120 for event in pygame.event.get():
position = [(180, 90), (180, 120), (210, 120), (x, y)] if event.type == locals.QUIT:
# 接收到退出事件后退出程序
setheading = "right" exit()
snake_head = right if event.type==locals.KEYDOWN:
if event.key==locals.K_UP:
while True: volume+=0.1
for event in pygame.event.get(): if volume>1:
if event.type == locals.QUIT: volume=1
# 接收到退出事件后退出程序 pygame.mixer.music.set_volume(volume)
exit() if event.key==locals.K_DOWN:
if event.type == locals.KEYDOWN: volume-=0.1
if event.key == locals.K_RIGHT and setheading != "left": if volume<0:
setheading = 'right' volume=0
snake_head = right pygame.mixer.music.set_volume(volume)
if event.key == locals.K_LEFT and setheading != "right": if event.type==locals.MOUSEBUTTONDOWN:
setheading = 'left' click+=1
snake_head = left
if event.key == locals.K_UP and setheading != "down": if click%2==0:
setheading = 'up' pygame.mixer_music.unpause()
snake_head = up a=stop_img
if event.key == locals.K_DOWN and setheading != "up": else:
setheading = 'down' pygame.mixer_music.pause()
snake_head = down a=play_img
if pygame.mixer.music.get_busy()==False:
# 设置贪吃蛇的头部坐标 pygame.mixer.music.play()
if setheading == "right": # 绘制画面
x += 30 screen.blit(bg_img, (0, 0)) # 填充背景
elif setheading == "left": screen.blit(a, (270, 330)) # 暂停按钮
x -= 30 screen.blit(logo_img, (170, 60)) # 中间logo图
elif setheading == "up": screen.blit(last_img, (120, 350)) # 上一曲
y -= 30 screen.blit(next_img, (420, 350)) # 下一曲
else: # 刷新画面
y += 30 pygame.display.update()
position.append((x, y)) \ No newline at end of file
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ 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