Commit 5395b1d1 by BellCodeEditor

save project

parent c783085a
Showing with 22 additions and 1 deletions
...@@ -17,6 +17,9 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) ...@@ -17,6 +17,9 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
new_pos1 = [(0,-1),(0,0),(0,1),(-1,0)] new_pos1 = [(0,-1),(0,0),(0,1),(-1,0)]
new_pos2 = [(2,-1),(2,0),(2,1),(2,2)] new_pos2 = [(2,-1),(2,0),(2,1),(2,2)]
new_pos3 = [(4,-1),(4,0),(5,-1),(5,0)]
new_pos4 = [(4,2),(5,2),(3,3),(4,3)]
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) # 字体
text = font.render(str(score),True,(0,150,0)) text = font.render(str(score),True,(0,150,0))
...@@ -33,11 +36,14 @@ while True: ...@@ -33,11 +36,14 @@ while True:
if rect[1]>2: if rect[1]>2:
rect[1]-=1 rect[1]-=1
elif event.key == locals.K_RIGHT: elif event.key == locals.K_RIGHT:
if rect[1]<14: if rect[1]<13:
rect[1]+=1 rect[1]+=1
elif event.key == locals.K_DOWN: elif event.key == locals.K_DOWN:
if rect[0]<25: if rect[0]<25:
rect[0]+=1 rect[0]+=1
elif event.key == locals.K_UP:
rect[0]-=1
rect[1]+=1
pos = [] pos = []
for cube in new_pos1: for cube in new_pos1:
new_pos=(cube[0]+rect[0],cube[1]+rect[1]) new_pos=(cube[0]+rect[0],cube[1]+rect[1])
...@@ -52,7 +58,22 @@ while True: ...@@ -52,7 +58,22 @@ while True:
for cube in pos: for cube in pos:
pygame.draw.rect(screen,(color1,color2,color3),(cube[1]*20-20,cube[0]*20-20,20,20),0) pygame.draw.rect(screen,(color1,color2,color3),(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) pygame.draw.rect(screen,(255,255,255),(cube[1]*20-20,cube[0]*20-20,20,20),1)
for cube in new_pos3:
new_pos=(cube[0]+rect[0],cube[1]+rect[1])
pos.append(new_pos)
for cube in pos:
pygame.draw.rect(screen,(color1,color2,color3),(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)
for cube in new_pos4:
new_pos=(cube[0]+rect[0],cube[1]+rect[1])
pos.append(new_pos)
for cube in pos:
pygame.draw.rect(screen,(color1,color2,color3),(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)
screen.blit(text,(350,70)) # 得分 screen.blit(text,(350,70)) # 得分
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