Commit 2f992d82 by BellCodeEditor

save project

parent 16cf30b9
Showing with 25 additions and 6 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
score = 0 score = 0
grid_size = 20 # 格子大小 grid_size = 20 # 格子大小
...@@ -16,6 +16,18 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) ...@@ -16,6 +16,18 @@ 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) # 字体
center = [2,8] center = [2,8]
current_T = [(0,1),(0,0),(0,-1),(-1,0)]
current_O = [(0,0),(0,1),(-1,0),(-1,1)]
current_J = [(1,0),(2,0),(0,0),(2,-1)]
current_I = [(1,0),(2,0),(0,0),(3,0)]#[(0,-1),(-1,0),(0,1)],[(0,-2),(-2,0),(0,2)],[(0,-3),(-3,0),()]
current_L = [(1,0),(2,0),(0,0),(2,1)]
current_S = [(0,-1),(0,0),(-1,0),(-1,1)]
current_Z = [(-1,-1),(-1,0),(0,0),(0,1)]
current_all = [current_T,current_O,current_J,current_I,current_L,current_S,current_Z]
color_1 = random.randint(0,255)
color_2 = random.randint(0,255)
color_3 = random.randint(0,255)
k = random.choice(current_all)
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:
...@@ -30,12 +42,19 @@ while True: ...@@ -30,12 +42,19 @@ while True:
if event.key == locals.K_DOWN: if event.key == locals.K_DOWN:
if center[0]<25: if center[0]<25:
center[0] += 1#行数增加(向下) center[0] += 1#行数增加(向下)
#if event.key == locals.K_UP:
screen.blit(background,(0,0))# 将背景图画上去 screen.blit(background,(0,0))# 将背景图画上去
pygame.draw.rect(screen,(255,0,0),(center[1]*20-20,center[0]*20-20,20,20),0)#画出小方块 current_pos = []
pygame.draw.rect(screen,(255,255,255),(center[1]*20-20,center[0]*20-20,20,20),1)#画出小方块的边框 for cube in k:#图形
# ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ↖ pos = (cube[0] + center[0],cube[1] + center[1])
# 对象 / 颜色 / x坐标 / y坐标 / 方块高/ 宽 /是否填充(0填充,1不填充) current_pos.append(pos)
for cube in current_pos:
pygame.draw.rect(screen,(color_1,color_2,color_3),(cube[1]*20-20,cube[0]*20-20,20,20),0)#画出小方块
pygame.draw.rect(screen,(color_3+10,color_1+10,color_2+10),(cube[1]*20-20,cube[0]*20-20,20,20),1)#画出小方块的边框
# # ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
# # 对象 / 颜色 / x坐标 / y坐标 / 方块高/ 宽 /线宽(0没有线)
# 得分: # 得分:
MyFont=font.render(str(score),True,(0,0,0))#设置字体 MyFont=font.render(str(score),True,(0,0,0))#设置字体
screen.blit(MyFont,(350,70))#渲染字体 screen.blit(MyFont,(350,70))#渲染字体
......
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