Commit 9af1f7b8 by BellCodeEditor

save project

parent 710dabd6
Showing with 35 additions and 3 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
score = 0 score = 0
...@@ -16,7 +17,36 @@ clock = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) ...@@ -16,7 +17,36 @@ 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) # 字体
main_pos=[2,8] main_pos=[2,8]
b_t=[(0,-2),(0,-1),(0,0),(0,1)]
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),(0,0),(1,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=[O,I,Z,S,T,J,L]
cube_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)]
random_cube=random.choice(shape_list)
random_color=random.choice(cube_colors)
random_facing=random.choice(random_cube)
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:
...@@ -31,16 +61,18 @@ while True: ...@@ -31,16 +61,18 @@ while True:
if event.key==locals.K_DOWN: if event.key==locals.K_DOWN:
if main_pos[0]<25: if main_pos[0]<25:
main_pos[0]=main_pos[0]+1 main_pos[0]=main_pos[0]+1
pos=[] pos=[]
# 将背景图画上去 # 将背景图画上去
screen.blit(background,(0,0)) screen.blit(background,(0,0))
# 得分 # 得分
for cube in b_t:
for cube in random_facing:
apos=(cube[0]+main_pos[0],cube[1]+main_pos[1]) apos=(cube[0]+main_pos[0],cube[1]+main_pos[1])
pos.append(apos) pos.append(apos)
for cube in pos: for cube in pos:
pygame.draw.rect(screen,(255,0,0),(cube[1]*20-20,cube[0]*20-20,20,20),0) pygame.draw.rect(screen,random_color,(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) pygame.draw.rect(screen,(255,255,255),(cube[1]*20-20,cube[0]*20-20,20,20),1)
blit_score=font.render(str(score),True,(0,0,0)) blit_score=font.render(str(score),True,(0,0,0))
......
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