Commit d3d5adb5 by BellCodeEditor

save project

parent 4aab993a
Showing with 9 additions and 0 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
time = pygame.time.Clock()
......@@ -10,6 +11,7 @@ apple_y=300
setheading = 'right'
screen = pygame.display.set_mode((660, 480))
shenti = [(180,90), (180,120), (210,120), (x,y)]
score = 0
# 背景
......@@ -20,6 +22,7 @@ body = pygame.image.load('body.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
ziti = pygame.font.Font('neuropol.ttf',18)
snake_head = right
while True:
for event in pygame.event.get():
......@@ -58,6 +61,7 @@ while True:
shenti.append((x,y))
if x==apple_x and y==apple_y:
score+=10
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=num1*30-30
......@@ -68,12 +72,17 @@ while True:
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(snake_head, shenti[-1])
info = 'score:'+str(score)
text = ziti.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 将贪吃蛇的身体画上去
for i in range(len(shenti)-1):
screen.blit(body,shenti[i])
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
# 刷新画面
pygame.display.update()
......
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