Commit 710dabd6 by BellCodeEditor

save project

parent 9c1cca8c
Showing with 18 additions and 9 deletions
...@@ -15,29 +15,38 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) ...@@ -15,29 +15,38 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入素材 # 载入素材
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
font = pygame.font.Font('STKAITI.TTF', 60) # 字体 font = pygame.font.Font('STKAITI.TTF', 60) # 字体
pos=[2,8] main_pos=[2,8]
b_t=[(0,-2),(0,-1),(0,0),(0,1)]
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key==locals.K_LEFT: if event.key==locals.K_LEFT:
if pos[1]>1: if main_pos[1]>1:
pos[1]=pos[1]-1 main_pos[1]=main_pos[1]-1
if event.key==locals.K_RIGHT: if event.key==locals.K_RIGHT:
if pos[1]<15: if main_pos[1]<15:
pos[1]=pos[1]+1 main_pos[1]=main_pos[1]+1
if event.key==locals.K_DOWN: if event.key==locals.K_DOWN:
if pos[0]<25: if main_pos[0]<25:
pos[0]=pos[0]+1 main_pos[0]=main_pos[0]+1
pos=[]
# 将背景图画上去 # 将背景图画上去
screen.blit(background,(0,0)) screen.blit(background,(0,0))
# 得分 # 得分
for cube in b_t:
apos=(cube[0]+main_pos[0],cube[1]+main_pos[1])
pos.append(apos)
for cube in pos:
pygame.draw.rect(screen,(255,0,0),(cube[1]*20-20,cube[0]*20-20,20,20),0)
pygame.draw.rect(screen,(255,255,255),(cube[1]*20-20,cube[0]*20-20,20,20),1)
blit_score=font.render(str(score),True,(0,0,0)) blit_score=font.render(str(score),True,(0,0,0))
screen.blit(blit_score,(360,80)) screen.blit(blit_score,(360,80))
# 刷新画面 # 刷新画面
pygame.draw.rect(screen,(255,0,0),(pos[1]*20-20,pos[0]*20-20,20,20),0)
pygame.draw.rect(screen,(255,255,255),(pos[1]*20-20,pos[0]*20-20,20,20),1)
pygame.display.update() pygame.display.update()
clock.tick(FPS) clock.tick(FPS)
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