Commit 7315e8f7 by BellCodeEditor

save project

parent 6100e1a7
Showing with 22 additions and 8 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
fps = pygame.time.Clock().tick()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
......@@ -12,26 +14,37 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
my_font = pygame.font.Font('neuropol.ttf',18)
x,y = 240,120
long = [(210, 120),(180, 120),(180, 90),(x,y)]
longs = [(210, 120),(180, 120),(180, 90),(x,y)]
apple_x = 360
apple_y = 300
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
x+=30
long.append(x,y)
long.pop(0)
longs.append(x,y)
if apple_x == x and apple_y == y:
apple_x = random.randrange(0,660,30)
apple_y = random.randrange(0,480,30)
else:
longs.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
screen.blit(background,(0, 0))
# 将贪吃蛇画上去
screen.blit(right, (240,long[-1])
screen.blit(right, (240,longs[-1])
# 将贪吃蛇的身体画上去
for i in range(len(long)-1)
screen.blit(body,long[i])
for i in range(len(longs)-1):
screen.blit(body,longs[i])
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apple_x,apple_y))
text = "score"+str(score)
Myscore = my_font.render(text,Ture,(0,0,0))
screen.blit(Myscore,(540,10))
# 刷新画面
fps = tick(3)
pygame.display.update()
\ 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