Commit 92c434b0 by BellCodeEditor

save project

parent 88994ed0
Showing with 40 additions and 5 deletions
...@@ -5,13 +5,48 @@ pygame.init() ...@@ -5,13 +5,48 @@ 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')
food=pygame.image.load('apple.png')
body=pygame.image.load('body.png')
left=pygame.image.load('left.png')
up=pygame.image.load('up.png')
down=pygame.image.load('down.png')
x,y=240,120
post=[(180,90),(180,120),(210,120),(x,y)]
set='right'
snake_head=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()
if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and set!='left':
set='right'
snake_head=right
if event.key==locals.K_LEFT and set!='right':
set='left'
snake_head=left
if event.key==locals.K_DOWN and set!='up':
set='down'
snake_head=down
if event.key==locals.K_UP and set!='down':
set='up'
snake_head=up
if set=='right':
x+=30
if set=='left':
x-=30
if set=='up':
y-=30
if set=='down':
y+=30
post.append((x,y))
post.pop(0)
screen.blit(background,(0,0)) screen.blit(background,(0,0))
pygame.display.update() screen.blit(snake_head,post[-1])
\ No newline at end of file for i in range(len(post)-1):
screen.blit(body,post[i])
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