Commit c0719193 by BellCodeEditor

auto save

parent 76968286
Showing with 19 additions and 37 deletions
import pygame
from pygame import locals
pygame.init() # 初始化
# 必要的声明
pygame.init() #初始化
score = 0
grid_size = 20 # 格子大小
grid_num_width = 15 # 横向格子数量
grid_num_height = 25 # 纵向格子数量
FPS = 30
grid_size = 20 #格子大小
grid_num_width = 15 #水平的格子数量
grid_num_height = 25 #竖直的格子数量 竖直 铅直
FPS = 30 #设置帧率
# 创建窗口
screen = pygame.display.set_mode((460, 500))
pygame.display.set_caption("俄罗斯方块")
clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入素材
background = pygame.image.load('bg.png')
font = pygame.font.Font('STKAITI.TTF', 60) # 字体\
center=[2,8]
screen = pygame.display.set_mode((460,500)) # 设置窗口大小
pygame.display.set_caption("俄罗斯方块") # 设置窗口标题
clock = pygame.time.Clock() # (时钟)控制游戏速度
background = pygame.image.load('bg.png') # 导入背景
font = pygame.font.Font('STKAITI.TTF',60) # 设置字体大小
# 只有接收到了关闭事件才会关闭
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT:
if center[1]<15:
center[1] += 1
elif event.key == locals.K_LEFT:
if center[1]>1:
center[1] -= 1
elif event.key == locals.K_DOWN:
if center[0]<25:
center[0] += 1
screen.blit(background,(0,0)) # 将背景图渲染(画)进去
pygame.draw.rect(screen,(255,0,0),(140,20,20,20),0)
pygame.draw.rect(screen,(255,255,255),(140,20,20,20),1)
# 将背景图画上去
screen.blit(background,(0,0))
pygame.draw.rect(screen,(255,0,0),
(center[1]*20-20,center[0]*20-20,20,20),0)
# 得分
pygame.draw.rect(screen,(255,255,255),
(center[1]*20-20,center[0]*20-20,20,20),1)
text_surface = font.render(str(score),True,(0,0,0))
screen.blit(text_surface,(350,70))
score_text = font.render(str(score), True, (0,0,0)) # 分数字体
screen.blit(score_text, (350, 70)) #分数字体位置
# 刷新画面
pygame.display.update()
clock.tick(FPS)
clock.tick(FPS)
\ No newline at end of file
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