Commit 1154b685 by BellCodeEditor

save project

parent 6acd052a
Showing with 21 additions and 4 deletions
......@@ -18,8 +18,12 @@ body = pygame.image.load('body.png')
left=pygame.image.load('left.png')
up=pygame.image.load('up.png')
down=pygame.image.load('down.png')
my_font=pygame.font.Font("neuropol.ttf",18)
x,y=240,120
a=[(180,90),(180,120),(210,120),(x,y)]
a_x=360
a_y=300
setheading="right"
setheading='right'
snake_head=raight
while True:
......@@ -30,13 +34,22 @@ while True:
elif event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading !="left":
setheading = "right"
snake_head = right
if event.key == locals.K_
a.append((x,y))
a.pop(0)
import random
if a_x==x and a_y==y:
a_x=random.randint(0,22)
a_y=random.randint(0,16)
a_x=random.randint(0,21)
a_y=random.randint(0,15)
a_x=a_x*30
a_y=a_y*30
score+=10
else:
a.pop(0)
if x<0 or x>630 or y<0 or y>450:
exit()
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
......@@ -45,7 +58,10 @@ while True:
for i in range(len(a)-1):
screen.blit(body,a[i])
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (a_x, a_y))
info="Score:"+str(score)
text=my_font.render(info,Ture,(0,0,0))
screen.blit(text,(540,10))
# 刷新画面
pygame.display.update()
wb.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