Commit 1f58ddd2 by BellCodeEditor

save project

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