Commit 9dbfe3f0 by BellCodeEditor

save project

parent 77525f60
Showing with 16 additions and 9 deletions
...@@ -6,16 +6,19 @@ score = 0 ...@@ -6,16 +6,19 @@ score = 0
grid_size = 20 # 格子大小 grid_size = 20 # 格子大小
grid_num_width = 15 # 横向格子数量 grid_num_width = 15 # 横向格子数量
grid_num_height = 25 # 纵向格子数量 grid_num_height = 25 # 纵向格子数量
rect = [8,1] rect = [2,8]
FPS = 30 FPS = 30
# 创建窗口 # 创建窗口
screen = pygame.display.set_mode((460, 500)) screen = pygame.display.set_mode((460, 500))
pygame.display.set_caption("俄罗斯方块") pygame.display.set_caption("俄罗斯方块")
clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入素材 # 载入素材
pos = []
new_pos1 = [(0,-1),(0,0),(0,1),(-1,0)]
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))
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:
...@@ -23,16 +26,20 @@ while True: ...@@ -23,16 +26,20 @@ while True:
screen.blit(background,(0,0)) # 将背景图画上去 screen.blit(background,(0,0)) # 将背景图画上去
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if event.key == locals.K_LEFT: if event.key == locals.K_LEFT:
if rect[0]>1: if rect[1]>2:
rect[0]-=1 rect[1]-=1
elif event.key == locals.K_RIGHT: elif event.key == locals.K_RIGHT:
if rect[0]<15: if rect[1]<14:
rect[0]+=1
elif event.key == locals.K_DOWN:
if rect[1]<20:
rect[1]+=1 rect[1]+=1
pygame.draw.rect(screen,(0,150,255),(rect[0]*20-20,rect[1]*20-20,20,20),0) elif event.key == locals.K_DOWN:
pygame.draw.rect(screen,(255,255,255),(rect[0]*20-20,rect[1]*20-20,20,20),1) if rect[0]<25:
rect[0]+=1
for cube in new_pos1:
new_pos2=(cube[0]+rect[0],cube[1]+rect[1])
pos.append(new_pos2)
for cube in pos:
pygame.draw.rect(screen,(0,150,255),(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