Commit 5310ae1e by BellCodeEditor

auto save

parent 88f759b7
Showing with 71 additions and 0 deletions
import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock()
x,y=210,240
setheading ="right"
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
position=[(180,240),(180,120),(x,y)]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT:
setheading='right'
elif event.key==locals.K_LEFT:
setheading='left'
elif event.key==locals.K_UP:
setheading='up'
elif event.key==locals.K_DOWN:
setheading='down'
if setheading=="right":
x+=30
elif setheading=="left":
x-=30
elif setheading=="up":
y-=30
elif setheading=="down":
y+=30
position.append((x,y))
position.pop(0)
screen.blit(background, (0,0)) #背景
screen.blit(right,position[-1])
for i in range(len(position)-1):
screen.blit(body,position[i])
screen.blit(right, (x,y)) #蛇头
#身体
screen.blit(body, (180, 240))
screen.blit(body, (150, 240))
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (360, 270))
screen.blit(food, (360, 240))
screen.blit(food, (360, 210))
screen.blit(food, (360, 180))
screen.blit(food, (360, 150))
screen.blit(food, (360, 120))
screen.blit(food, (360, 90))
screen.blit(food, (360, 60))
screen.blit(food, (360, 30))
# 刷新画面
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