Commit c063ca6b by BellCodeEditor

auto save

parent 86aa613c
Showing with 2 additions and 32 deletions
import pygame import pygame
from pygame import locals from pygame import locals
xy = []
FPS = pygame.time.Clock() FPS = pygame.time.Clock()
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
...@@ -11,15 +12,8 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -11,15 +12,8 @@ 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')
down = pygame.image.load('down.png')
up = pygame.image.load('up.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')
xandy = 240,120
xy = [(180,90),(180,120),(210,120),(x,y)]
setheading = 'right'
snake_head = right
while True: while True:
FPS.tick(3) FPS.tick(3)
...@@ -27,34 +21,10 @@ while True: ...@@ -27,34 +21,10 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
elif event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and sethanding != 'left':
sethending = 'right'
snake_head = right
if event.key == locals.K_LEFT and sethanding != 'right':
setheanding = 'left'
snake_head = left
if event.key == locals.K_UP and sethanding != 'down':
sethending = 'up'
snake_head = up
if event.key == locals.K_DOWN and sethanding != 'up':
setheanding = 'down'
snake_head = down
if setheading == 'right':
x+=30
elif setheading == 'left':
x-=30
elif sethanding == 'up':
y-=30
else:
y+=30
xy.append(xandy)
xy.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
for i in range(len(xy)-1): screen.blit(right, xy[3])
screen.blit(body,xy[i])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
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