Commit 1f58ddd2 by BellCodeEditor

save project

parent ed97a254
Showing with 11 additions and 13 deletions
......@@ -2,9 +2,6 @@ import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -29,6 +26,8 @@ down =pygame.image.load('down.png')
setheading='right'
snake_head=right
my_font=pygame.font.Font("neuropol.ttf",18)
score=0
while True:
for event in pygame.event.get():
......@@ -62,30 +61,29 @@ while True:
if x == apple_x and y==apple_y:
num1=random.randint(1,16)
num2=random.randint(1,22)
apple_x=30*nun1-30
apple_y=30*nun2-30
apple_x=30*num1-30
apple_y=30*num2-30
else:
position.pop(0)
# 将背景图画上去
screen.blit(background, ( 0,0))
screen.blit(background, (0,0))
# 将贪吃蛇画上去
screen.blit(right,position[-1])
screen.blit(snake_head,position[-1])
# screen.blit(right, (x, y))
#将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body,position[i])
#将果实画上去
screen.blit(food, (apple_x , apple_y))
info='Score:'+str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 刷新画面
pygame.display.update()
FPS.tick(3)
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