Commit d7fabb8e by BellCodeEditor

auto save

parent 46ec1997
Showing with 8 additions and 34 deletions
import pygame import pygame
from pygame import locals from pygame import locals
xy = [(180,90),(210,90),(240,90),(270,90)] xy = [(0,90),(30,90),(60,90),(90,90)]
FPS = pygame.time.Clock() FPS = pygame.time.Clock()
fx = 'right' x = 90
x = 0 y = 90
y = 0
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -15,9 +14,6 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -15,9 +14,6 @@ screen = pygame.display.set_mode((660, 480))
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
food = pygame.image.load('apple.png') food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
...@@ -27,36 +23,14 @@ while True: ...@@ -27,36 +23,14 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: x += 30
if event.key == K_RIGHT and fx != 'left': for i in range(4):
fx = 'right' xy.del(i)
elif event.key == K_LEFT and fx != 'right': xy.insert(i,(x-4*30+i*30,y))
fx = 'left'
elif event.key == K_UP and fx != 'down':
fx = 'up'
else:
if fx != 'up':
fx = 'down'
xy.append((x,y))
xy.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
if fx == 'right': screen.blit(right, xy[3])
screen.blit(right, xy[3])
x += 30
else:
if fx == 'left':
screen.blit(left,xy[3])
x -= 30
else:
if fx == 'up':
screen.blit(up,xy[3])
y -= 30
else:
screen.blit(down,xy[3])
y += 30
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
screen.blit(body, xy[2]) screen.blit(body, xy[2])
screen.blit(body, xy[1]) screen.blit(body, xy[1])
......
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