Commit b52e5e80 by BellCodeEditor

save project

parent b8e2fa4a
Showing with 35 additions and 2 deletions
...@@ -6,7 +6,7 @@ pygame.init() ...@@ -6,7 +6,7 @@ pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
FPSCLOCK=pygame.time.Clock()
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
...@@ -38,7 +38,39 @@ while True: ...@@ -38,7 +38,39 @@ while True:
if event.type==locals.QUIT: if event.type==locals.QUIT:
exit() exit()
elif event.type==locals.KEYDOWN: elif event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and setheding!="left" if event.key==locals.K_d and setheading!="left":
setheading='right'
snake_head=right
if event.key==locals.K_a and setheading!="right"
setheading='left'
snake_head=left
if event.key==locals.K_w and setheading!="down":
setheading='up'
snake_head=up
if event.key==locals.K_s and setheading!="up":
setheading='down'
snake_head=down
if setheading=="right":
x + = 30
elif setheading=="left":
x - = 30
elif setheading=="up":
y - = 30
else:
y + = 30
position.append((x,y))
position.pop(0)
screen.blit(background,(0,0))
screen.blit(snake_head,position[-1])
for i in range(len(position)-1):
screen.blit(body,position[i])
screen.blit(food,(360,300))
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