Commit c783085a by BellCodeEditor

save project

parent 0848f8bb
Showing with 16 additions and 4 deletions
import pygame
import random
from pygame import locals
pygame.init() # 初始化
......@@ -15,10 +16,13 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入素材
new_pos1 = [(0,-1),(0,0),(0,1),(-1,0)]
new_pos2 = [(2,-1),(2,0),(2,1),(2,2)]
background = pygame.image.load('bg.png')
font = pygame.font.Font('STKAITI.TTF', 60) # 字体
text = font.render(str(score),True,(0,150,0))
color1 = random.randint(0,255)
color2 = random.randint(0,255)
color3 = random.randint(0,255)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -36,11 +40,19 @@ while True:
rect[0]+=1
pos = []
for cube in new_pos1:
new_pos2=(cube[0]+rect[0],cube[1]+rect[1])
pos.append(new_pos2)
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_pos2:
new_pos=(cube[0]+rect[0],cube[1]+rect[1])
pos.append(new_pos)
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,(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)) # 得分
pygame.display.update() # 刷新画面
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