Commit 5a88a109 by BellCodeEditor

auto save

parent dd301239
Showing with 6 additions and 16 deletions
import pygame import pygame
from pygame import locals from pygame import locals
# 初始化py game,为使用硬件做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
...@@ -17,22 +16,13 @@ body = pygame.image.load('body.png') ...@@ -17,22 +16,13 @@ body = pygame.image.load('body.png')
x,y = 240,120 x,y = 240,120
pos = [(180,90),(182,120),(210,120),(x,y)] pos = [(180,90),(182,120),(210,120),(x,y)]
setheading="right"
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()
x+=30 if event.type == locals.KEYDOWN:
pos.append((x,y)) if eventkey==locals.K_UP and setheading!="down":
pos.pop(0) setheading
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, (x,y))
for i in range(len(pos)-1):
screen.blit(body,pos[i])
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
FPS.tick(1.5)
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