Commit 9a9a9730 by BellCodeEditor

auto save

parent da115b14
Showing with 13 additions and 3 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
my_font = pygame.font.Font("neuropol.ttf",18)
a_x=240
a_y=180
a1=0
a2=0
score=0
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -56,13 +58,17 @@ while True:
else:
y += 30
position.append((x, y))
position.pop(0)
# 将背景图画上去
if a_x ==x and a_y ==y:
a1=random.randint(0,21)
a2=random.randint(0,15)
a_x=a1*30
a_y=a2*30
score+=10
else:
position.pop(0)
if (x,y) in position[0:-1] :
break
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
......@@ -72,6 +78,9 @@ while True:
# 将果实画上去
screen.blit(food, (a_x, a_y))
# 刷新画面
# 刷新画面\
info="Score:"+str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,0))
pygame.display.update()
FPSCLOCK.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