Commit 79cb8128 by BellCodeEditor

save project

parent 669b4ad8
Showing with 48 additions and 3 deletions
import pygame import pygame
import random
from pygame import locals from pygame import locals
xy = [2,8] xy = [2,8]
...@@ -13,6 +14,28 @@ grid_num_width = 15 # 横向格子数量 ...@@ -13,6 +14,28 @@ grid_num_width = 15 # 横向格子数量
grid_num_height = 25 # 纵向格子数量 grid_num_height = 25 # 纵向格子数量
FPS = 30 FPS = 30
O = [[(0,0),(0,1),(1,0),(1,1)]]
I = [[(0,-1),(0,0),(0,1),(0,2)],
[(-1,0),(0,0),(1,0),(2,0)]]
Z = [[(0,-1),(0,0),(1,0),(1,1)],
[(-1,0),(0,0),(0,-1),(1,-1)]]
S = [[(-1,0),(0,0),(0,1),(1,1)],
[(1,-1),(1,0),(0,0),(0,1)]]
T = [[(0,1),(0,0),(0,-1),(-1,0)],
[(-1,0),(0,0),(1,0),(0,1)],
[(0,-1),(0,0),(0,1),(1,0)],
[(-1,0),(0,0),(1,0),(0,-1)]]
J = [[(-1,0),(0,0),(1,0),(1,-1)],
[(0,-1),(0,0),(0,1),(-1,-1)],
[(-1,0),(0,0),(1,0),(-1,1)],
[(0,-1),(0,0),(0,1),(1,1)]]
L = [[(-1,0),(0,0),(1,0),(1,1)],
[(0,-1),(0,0),(0,1),(1,-1)],
[(-1,0),(0,0),(1,0),(-1,-1)],
[(0,-1),(0,0),(0,1),(-1,1)]]
shape_list = [I,J,L,O,S,T,Z]
# 创建窗口 # 创建窗口
screen = pygame.display.set_mode((460, 500)) screen = pygame.display.set_mode((460, 500))
pygame.display.set_caption("俄罗斯方块") pygame.display.set_caption("俄罗斯方块")
...@@ -21,6 +44,23 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) ...@@ -21,6 +44,23 @@ 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) # 字体
app = font.render(str(score),True,(0,0,0)) app = font.render(str(score),True,(0,0,0))
shape_colors = [(204,153,153),
(102,102,153),
(153,0,102),
(255,204,0),
(204,0,51),
(255,0,51),
(0,102,153),
(153,0,51),
(204,255,102),
(255,153,0)]
shape = random.choice(shape_list)
index = random.randint(0,len(shape)-1)
current_shape = shape[index]
color = random.choice(shape_colors)
while True: while True:
...@@ -38,15 +78,20 @@ while True: ...@@ -38,15 +78,20 @@ while True:
if xy[1] > 1: if xy[1] > 1:
xy[1] += -1 xy[1] += -1
elif event.key == locals.K_DOWN: elif event.key == locals.K_DOWN:
if xy[0] < 25:+ if xy[0] < 25:
xy[0] += 1 xy[0] += 1
# 将背景图画上去 # 将背景图画上去
screen.blit(background,(0,0)) screen.blit(background,(0,0))
pygame.draw.rect(screen,(255,0,0),(xy[1]*20-20,(xy[0]-1)*20,20,20),0) shape_pos = []
pygame.draw.rect(screen,(255,255,255),(xy[1]*20-20,(xy[0]-1)*20,20,20),1) for cube in current_shape:
pos = (cube[0]+xy[0],cube[1]+xy[1])
shape_pos.append(pos)
for cube in shape_pos:
pygame.draw.rect(screen,color,(cube[1]*20-20,(cube[0]-1)*20,20,20),0)
pygame.draw.rect(screen,(255,255,255),(cube[1]*20-20,(cube[0]-1)*20,20,20),1)
# 得分 # 得分
screen.blit(app,(340,80)) screen.blit(app,(340,80))
# 刷新画面 # 刷新画面
......
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