Commit 511c42a1 by BellCodeEditor

save project

parent 59c76c3b
Showing with 23 additions and 3 deletions
......@@ -3,7 +3,7 @@ from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
s="right"
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
x=240
......@@ -20,8 +20,27 @@ while True:
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type==locals.KEYDOWN:
if event.key==locals.K_UP and s!="down":
s="up"
if event.key==locals.K_DOWN and s!="up":
s="down"
if event.key==locals.K_LEFT and s!="right":
s="left"
if event.key==locals.K_RIGHT and s!="left":
s="right"
x=x+30
if s=="right":
x=x+30
if s=="left":
x=x-30
if s=="up":
y=y-30
if s=="down":
y=y+30
zb.append((x,y))
zb.pop(0)
# 将背景图画上去
......@@ -34,5 +53,5 @@ while True:
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
G.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