Commit d3d5adb5 by BellCodeEditor

save project

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