Commit 653cd4d2 by BellCodeEditor

save project

parent fba0ad29
Showing with 15 additions and 9 deletions
mf = pygame.font.Font('neuropol.ttf')
\ No newline at end of file
...@@ -4,7 +4,6 @@ fkfs = pygame.time.Clock() ...@@ -4,7 +4,6 @@ fkfs = pygame.time.Clock()
import random import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
# 背景 # 背景
...@@ -15,11 +14,13 @@ up = pygame.image.load('up.png') ...@@ -15,11 +14,13 @@ up = pygame.image.load('up.png')
down = pygame.image.load('down.png') down = pygame.image.load('down.png')
food = pygame.image.load('apple.png') food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
mf = pygame.font.Font('neuropol.ttf',18)
x,y = 240, 120 x,y = 240, 120
a_x,a_y = 12, 10 a_x,a_y = 12, 10
snake = [(180,90),(180,120),(210,120),(x,y)] snake = [(180,90),(180,120),(210,120),(x,y)]
setheading = "right" setheading = "right"
st = right st = right
score = 0
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:
...@@ -48,22 +49,25 @@ while True: ...@@ -48,22 +49,25 @@ while True:
x-=30 x-=30
if setheading == "right": if setheading == "right":
x+=30 x+=30
a=(x,y) snake.append((x,y))
snake.append(a)
if x == a_x*30 and y == a_y*30: if x == a_x*30 and y == a_y*30:
a_x = random.randint(0,22) a_x = random.randint(0,21)
a_y = random.randint(0,16) a_y = random.randint(0,15)
snake.pop(0) score +=10
else:
snake.pop(0)
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(st, (x,y)) screen.blit(st, (x,y))
screen.blit(body, snake[-4]) for i in range(len(snake)-1):
screen.blit(body, snake[-3]) screen.blit(body,(snake[i]))
screen.blit(body, snake[-2])
# 将果实画上去 # 将果实画上去
screen.blit(food, (a_x*30,a_y*30)) screen.blit(food, (a_x*30,a_y*30))
# 刷新画面 # 刷新画面
info = 'Score'+str(score)
text = mf.render(info,True,(0,0,0))
screen.blit(text,(540,10))
pygame.display.update() pygame.display.update()
fkfs.tick(3) fkfs.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