pygame使用iphone打字键盘震动事件移动方块但是方块只是拉长

玩蛇系列之Pygame教程(十二)-- Tetromino俄罗斯方块 - 简书
玩蛇系列之Pygame教程(十二)-- Tetromino俄罗斯方块
失踪人口回归了!
失踪人口回归了!
失踪人口回归了!
实在是抱歉,这么久没更新这个系列的文章了,(●'?'●),都是因为接了个坑爹的外包,改去干老本行撸android代码了,感觉外包还是有点坑,钱没赚到多少,人都累死了。
搞外包期间,一时勾起了我自己撸app的兴趣,就没时间写文章了,顺便给自己撸的应用打个广告
有兴趣可以下载下来玩玩,很好用的哦 (●'?'●)
好了,废话不多说了,这次带来的是俄罗斯方块的实现。
先上个图:
游戏主要是对各种形状piece(S,Z,I,O,J,L,T)的处理,代码注释我写得也比较清楚了,模块都和上一篇
大同小异,甚至感觉比贪吃蛇还要好理解,主要还是python对数组的操作实在是太简洁方便了,可能会有点不好理解,不过认真多看一下,还是看的懂的。
友情提醒:
我已经把代码托管到github了,这样对游戏用到的资源(图片,字体,音效等)管理会方便些,你们也可以直接到github下载到所有的代码和资源。
但是,对于代码的学习,我还是觉得不要简单的复制粘贴,不然感觉还是领悟不到的
# -*- coding: UTF-8 -*-
Created on 日
@author: 小峰峰
import random, time, pygame, sys
from pygame.locals import *
FPS = 25 #设置屏幕刷新率
WINDOWWIDTH = 640 # 设置窗口宽度
WINDOWHEIGHT = 480 # 设置窗口高度
BOXSIZE = 20 # 方格大小
# 放置俄罗斯方块窗口的大小
BOARDWIDTH = 10
BOARDHEIGHT = 20
BLANK = '.' # 代表空的形状
MOVESIDEWAYSFREQ = 0.15 # ?
MOVEDOWNFREQ = 0.1 # 向下的频率
# x方向的边距
XMARGIN = int((WINDOWWIDTH - BOARDWIDTH * BOXSIZE) / 2)
# 距离窗口顶部的边距
TOPMARGIN = WINDOWHEIGHT - (BOARDHEIGHT * BOXSIZE) - 5
# 定义几个颜色
= (255, 255, 255)
= (185, 185, 185)
LIGHTGREEN
= ( 20, 175,
= (155, 155,
LIGHTYELLOW = (175, 175,
BORDERCOLOR = BLUE
BGCOLOR = BLACK
TEXTCOLOR = WHITE
TEXTSHADOWCOLOR = GRAY
LIGHTCOLORS = (LIGHTBLUE, LIGHTGREEN, LIGHTRED, LIGHTYELLOW)
# 断言 每一个颜色都应该对应有亮色
assert len(COLORS) == len(LIGHTCOLORS) # each color must have light color
# 模板的宽高
TEMPLATEWIDTH = 5
TEMPLATEHEIGHT = 5
# 形状_S(S旋转有2种)
S_SHAPE_TEMPLATE = [['.....',
# 形状_Z(Z旋转有2种)
Z_SHAPE_TEMPLATE = [['.....',
# 形状_I(I旋转有2种)
I_SHAPE_TEMPLATE = [['..O..',
# 形状_O(O旋转只有一个)
O_SHAPE_TEMPLATE = [['.....',
# 形状_J(J旋转有4种)
J_SHAPE_TEMPLATE = [['.....',
# 形状_L(L旋转有4种)
L_SHAPE_TEMPLATE = [['.....',
# 形状_T(T旋转有4种)
T_SHAPE_TEMPLATE = [['.....',
# 定义一个数据结构存储,对应的形状
PIECES = {'S': S_SHAPE_TEMPLATE,
'Z': Z_SHAPE_TEMPLATE,
'J': J_SHAPE_TEMPLATE,
'L': L_SHAPE_TEMPLATE,
'I': I_SHAPE_TEMPLATE,
'O': O_SHAPE_TEMPLATE,
'T': T_SHAPE_TEMPLATE}
def main():
global FPSCLOCK, DISPLAYSURF, BASICFONT, BIGFONT # 定义全局变量
pygame.init() # 初始化pygame
FPSCLOCK = pygame.time.Clock() # 获得pygame时钟
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) # 设置窗口
BASICFONT = pygame.font.Font('resource/PAPYRUS.ttf', 18) # 设置基础的字体
BIGFONT = pygame.font.Font('resource/PAPYRUS.ttf', 100) # 设置大字体
pygame.display.set_caption('Tetromino') # 窗口标题
showTextScreen('Tetromino') # 显示开始画面
while True: # 游戏主循环
# 二选一随机播放背景音乐
if random.randint(0, 1) == 0:
pygame.mixer.music.load('resource/tetrisb.mid')
pygame.mixer.music.load('resource/tetrisc.mid')
pygame.mixer.music.play(-1, 0.0)
# 运行游戏
# 退出游戏后,结束播放音乐
pygame.mixer.music.stop()
# 显示结束画面
showTextScreen('Game Over')
# 运行游戏
def runGame():
# 在游戏开始前初始化变量
board = getBlankBoard() # 获得一个空的board
lastMoveDownTime = time.time() # 最后向下移动的时刻
lastMoveSidewaysTime = time.time() # 最后侧向移动的时刻
lastFallTime = time.time() # 最后的下降时间
# 是否可以
向下,向左,向右
# 注意:这里没有向上可用
movingDown = False
movingLeft = False
movingRight = False
# 根据分数计算等级和下降的频率
level, fallFreq = calculateLevelAndFallFreq(score)
# 获得新的形状(当前的形状)
fallingPiece = getNewPiece()
# 获得下一个形状
nextPiece = getNewPiece()
while True: # 游戏循环体
if fallingPiece == None: # 当前没有下降的形状
# 重新获得新的形状和下一个形状
fallingPiece = nextPiece
nextPiece = getNewPiece()
# 重置最后下降的时间
lastFallTime = time.time()
# 判断界面上是否还有空位(方块是否到顶),没有则结束游戏
if not isValidPosition(board, fallingPiece):
return # can't fit a new piece on the board, so game over
# 检查是否有退出事件
checkForQuit()
for event in pygame.event.get(): # 事件处理loop
if event.type == KEYUP: # KEYUP事件处理
if (event.key == K_p): # 用户按P键暂停
# Pausing the game
DISPLAYSURF.fill(BGCOLOR)
pygame.mixer.music.stop() #停止音乐
showTextScreen('Paused') # 显示暂停界面,until a key press
pygame.mixer.music.play(-1, 0.0) # 继续循环音乐
# 重置各种时间
lastFallTime = time.time()
lastMoveDownTime = time.time()
lastMoveSidewaysTime = time.time()
elif (event.key == K_LEFT or event.key == K_a):
movingLeft = False
elif (event.key == K_RIGHT or event.key == K_d):
movingRight = False
elif (event.key == K_DOWN or event.key == K_s):
movingDown = False
elif event.type == KEYDOWN: # KEYDOWN事件处理
# 左右移动piece
if (event.key == K_LEFT or event.key == K_a) and isValidPosition(board, fallingPiece, adjX=-1):
fallingPiece['x'] -= 1
movingLeft = True
movingRight = False
lastMoveSidewaysTime = time.time()
elif (event.key == K_RIGHT or event.key == K_d) and isValidPosition(board, fallingPiece, adjX=1):
fallingPiece['x'] += 1
movingRight = True
movingLeft = False
lastMoveSidewaysTime = time.time()
# UP或W键 旋转piece (在有空间旋转的前提下)
elif (event.key == K_UP or event.key == K_w): # 正向旋转
fallingPiece['rotation'] = (fallingPiece['rotation'] + 1) % len(PIECES[fallingPiece['shape']])
if not isValidPosition(board, fallingPiece):
fallingPiece['rotation'] = (fallingPiece['rotation'] - 1) % len(PIECES[fallingPiece['shape']])
elif (event.key == K_q): # Q键,反向旋转
fallingPiece['rotation'] = (fallingPiece['rotation'] - 1) % len(PIECES[fallingPiece['shape']])
if not isValidPosition(board, fallingPiece):
fallingPiece['rotation'] = (fallingPiece['rotation'] + 1) % len(PIECES[fallingPiece['shape']])
# DOWN或S键 使piece下降得更快
elif (event.key == K_DOWN or event.key == K_s):
movingDown = True
if isValidPosition(board, fallingPiece, adjY=1):
fallingPiece['y'] += 1
lastMoveDownTime = time.time()
# 空格键,直接下降到最下面且可用的地方
elif event.key == K_SPACE:
movingDown = False
movingLeft = False
movingRight = False
for i in range(1, BOARDHEIGHT):
if not isValidPosition(board, fallingPiece, adjY=i):
fallingPiece['y'] += i - 1
# 根据记录的用户输入方向的变量来移动piece
if (movingLeft or movingRight) and time.time() - lastMoveSidewaysTime & MOVESIDEWAYSFREQ:
if movingLeft and isValidPosition(board, fallingPiece, adjX=-1):
fallingPiece['x'] -= 1
elif movingRight and isValidPosition(board, fallingPiece, adjX=1):
fallingPiece['x'] += 1
lastMoveSidewaysTime = time.time()
if movingDown and time.time() - lastMoveDownTime & MOVEDOWNFREQ and isValidPosition(board, fallingPiece, adjY=1):
fallingPiece['y'] += 1
lastMoveDownTime = time.time()
# 自动下降piece
if time.time() - lastFallTime & fallFreq:
# see if the piece has landed
if not isValidPosition(board, fallingPiece, adjY=1):
# falling piece has landed, set it on the board
addToBoard(board, fallingPiece)
score += removeCompleteLines(board)
level, fallFreq = calculateLevelAndFallFreq(score)
fallingPiece = None
# piece did not land, just move the piece down
fallingPiece['y'] += 1
lastFallTime = time.time()
# 绘制屏幕上的所有东西
DISPLAYSURF.fill(BGCOLOR)
drawBoard(board)
drawStatus(score, level)
drawNextPiece(nextPiece)
if fallingPiece != None:
drawPiece(fallingPiece)
pygame.display.update()
FPSCLOCK.tick(FPS)
# 创建文本绘制对象
def makeTextObjs(text, font, color):
surf = font.render(text, True, color)
return surf, surf.get_rect()
def terminate():
pygame.quit()
sys.exit()
# 检查是否有按键被按下
def checkForKeyPress():
# 通过事件队列寻找KEYUP事件
# 从事件队列删除KEYDOWN事件
checkForQuit()
for event in pygame.event.get([KEYDOWN, KEYUP]):
if event.type == KEYDOWN:
return event.key
return None
# 显示开始、暂停、结束画面
def showTextScreen(text):
# This function displays large text in the
# center of the screen until a key is pressed.
# Draw the text drop shadow
titleSurf, titleRect = makeTextObjs(text, BIGFONT, TEXTSHADOWCOLOR)
titleRect.center = (int(WINDOWWIDTH / 2), int(WINDOWHEIGHT / 2))
DISPLAYSURF.blit(titleSurf, titleRect)
# Draw the text
titleSurf, titleRect = makeTextObjs(text, BIGFONT, TEXTCOLOR)
titleRect.center = (int(WINDOWWIDTH / 2) - 3, int(WINDOWHEIGHT / 2) - 3)
DISPLAYSURF.blit(titleSurf, titleRect)
# Draw the additional "Press a key to play." text.
pressKeySurf, pressKeyRect = makeTextObjs('Press a key to play.', BASICFONT, TEXTCOLOR)
pressKeyRect.center = (int(WINDOWWIDTH / 2), int(WINDOWHEIGHT / 2) + 100)
DISPLAYSURF.blit(pressKeySurf, pressKeyRect)
while checkForKeyPress() == None:
pygame.display.update()
FPSCLOCK.tick()
# 检查是否有退出事件
def checkForQuit():
for event in pygame.event.get(QUIT): # get all the QUIT events
terminate() # terminate if any QUIT events are present
for event in pygame.event.get(KEYUP): # get all the KEYUP events
if event.key == K_ESCAPE:
terminate() # terminate if the KEYUP event was for the Esc key
pygame.event.post(event) # put the other KEYUP event objects back
# 根据分数来计算等级和下落的频率
def calculateLevelAndFallFreq(score):
level = int(score / 10) + 1
fallFreq = 0.27 - (level * 0.02)
return level, fallFreq
# 随机获得一个新的形状(形状,方向,颜色)
def getNewPiece():
# return a random new piece in a random rotation and color
shape = random.choice(list(PIECES.keys()))
newPiece = {'shape': shape,
'rotation': random.randint(0, len(PIECES[shape]) - 1),
'x': int(BOARDWIDTH / 2) - int(TEMPLATEWIDTH / 2), # x居中
'y': -2, # y在屏幕的上方,小于0
'color': random.randint(0, len(COLORS)-1)}
return newPiece
# 将一个piece添加到board中
def addToBoard(board, piece):
# fill in the board based on piece's location, shape, and rotation
for x in range(TEMPLATEWIDTH):
for y in range(TEMPLATEHEIGHT):
if PIECES[piece['shape']][piece['rotation']][y][x] != BLANK:
board[x + piece['x']][y + piece['y']] = piece['color']
# 清空board
def getBlankBoard():
# create and return a new blank board data structure
board = []
for i in range(BOARDWIDTH):
board.append([BLANK] * BOARDHEIGHT)
return board
# board边界
def isOnBoard(x, y):
return x &= 0 and x & BOARDWIDTH and y & BOARDHEIGHT
# piece在当前的board里是否是一个合法可用的位置
def isValidPosition(board, piece, adjX=0, adjY=0):
# Return True if the piece is within the board and not colliding
for x in range(TEMPLATEWIDTH):
for y in range(TEMPLATEHEIGHT):
isAboveBoard = y + piece['y'] + adjY & 0
if isAboveBoard or PIECES[piece['shape']][piece['rotation']][y][x] == BLANK:
if not isOnBoard(x + piece['x'] + adjX, y + piece['y'] + adjY):
return False
if board[x + piece['x'] + adjX][y + piece['y'] + adjY] != BLANK:
return False
return True
# 判断当前的这行是否被全部填满
def isCompleteLine(board, y):
# Return True if the line filled with boxes with no gaps.
for x in range(BOARDWIDTH):
if board[x][y] == BLANK:
return False
return True
# 检查每一行,移除完成填满的一行,将这一行上面的所有的都下降一行,返回完成填满的总行数
def removeCompleteLines(board):
numLinesRemoved = 0
# 从-1开始从下往上检查每一行
y = BOARDHEIGHT - 1
while y &= 0:
if isCompleteLine(board, y):
# Remove the line and pull boxes down by one line.
for pullDownY in range(y, 0, -1):
for x in range(BOARDWIDTH):
board[x][pullDownY] = board[x][pullDownY-1]
# Set very top line to blank.
for x in range(BOARDWIDTH):
board[x][0] = BLANK
numLinesRemoved += 1
# Note on the next iteration of the loop, y is the same.
# This is so that if the line that was pulled down is also
# complete, it will be removed.
y -= 1 # move on to check next row up
return numLinesRemoved
# 根据box的坐标转化成像素坐标
def convertToPixelCoords(boxx, boxy):
# Convert the given xy coordinates of the board to xy
# coordinates of the location on the screen.
return (XMARGIN + (boxx * BOXSIZE)), (TOPMARGIN + (boxy * BOXSIZE))
def drawBox(boxx, boxy, color, pixelx=None, pixely=None):
# draw a single box (each tetromino piece has four boxes)
# at xy coordinates on the board. Or, if pixelx & pixely
# are specified, draw to the pixel coordinates stored in
# pixelx & pixely (this is used for the "Next" piece).
if color == BLANK:
if pixelx == None and pixely == None:
pixelx, pixely = convertToPixelCoords(boxx, boxy)
pygame.draw.rect(DISPLAYSURF, COLORS[color], (pixelx + 1, pixely + 1, BOXSIZE - 1, BOXSIZE - 1))
pygame.draw.rect(DISPLAYSURF, LIGHTCOLORS[color], (pixelx + 1, pixely + 1, BOXSIZE - 4, BOXSIZE - 4))
# 绘制board
def drawBoard(board):
# draw the border around the board
pygame.draw.rect(DISPLAYSURF, BORDERCOLOR, (XMARGIN - 3, TOPMARGIN - 7, (BOARDWIDTH * BOXSIZE) + 8, (BOARDHEIGHT * BOXSIZE) + 8), 5)
# fill the background of the board
pygame.draw.rect(DISPLAYSURF, BGCOLOR, (XMARGIN, TOPMARGIN, BOXSIZE * BOARDWIDTH, BOXSIZE * BOARDHEIGHT))
# draw the individual boxes on the board
for x in range(BOARDWIDTH):
for y in range(BOARDHEIGHT):
drawBox(x, y, board[x][y])
# 绘制游戏分数、等级信息
def drawStatus(score, level):
# draw the score text
scoreSurf = BASICFONT.render('Score: %s' % score, True, TEXTCOLOR)
scoreRect = scoreSurf.get_rect()
scoreRect.topleft = (WINDOWWIDTH - 150, 20)
DISPLAYSURF.blit(scoreSurf, scoreRect)
# draw the level text
levelSurf = BASICFONT.render('Level: %s' % level, True, TEXTCOLOR)
levelRect = levelSurf.get_rect()
levelRect.topleft = (WINDOWWIDTH - 150, 50)
DISPLAYSURF.blit(levelSurf, levelRect)
# 绘制各种形状piece(S,Z,I,O,J,L,T)
def drawPiece(piece, pixelx=None, pixely=None):
shapeToDraw = PIECES[piece['shape']][piece['rotation']]
if pixelx == None and pixely == None:
# if pixelx & pixely hasn't been specified, use the location stored in the piece data structure
pixelx, pixely = convertToPixelCoords(piece['x'], piece['y'])
# draw each of the boxes that make up the piece
for x in range(TEMPLATEWIDTH):
for y in range(TEMPLATEHEIGHT):
if shapeToDraw[y][x] != BLANK:
drawBox(None, None, piece['color'], pixelx + (x * BOXSIZE), pixely + (y * BOXSIZE))
# 绘制提示信息,下一个现状
def drawNextPiece(piece):
# draw the "next" text
nextSurf = BASICFONT.render('Next:', True, TEXTCOLOR)
nextRect = nextSurf.get_rect()
nextRect.topleft = (WINDOWWIDTH - 120, 80)
DISPLAYSURF.blit(nextSurf, nextRect)
# draw the "next" piece
drawPiece(piece, pixelx=WINDOWWIDTH-120, pixely=100)
if __name__ == '__main__':
用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金Cover 有什么料? 从这篇文章中你能获得这些料: 知道setContentView()之后发生了什么? ... Android 获取 View 宽高的常用正确方式,避免为零 - 掘金相信有很多朋友...
用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你能获得这些料: 知道setContentView()之后发生了什么? ... Android 获取 View 宽高的常用正确方式,避免为零 - 掘金 相信有很多...
请参考前面的教程篇 《玩蛇系列之Pygame教程(十一)-- Wormy贪吃蛇》 以前在网上看到过一个动图,很好玩,就是贪吃蛇自己吃苹果,然后把全屏都占满了,感觉确实很酷,我就想能不能把我们的这个版本也改成贪吃蛇自动寻找食物。 由于时间关系还是有bug,贪吃蛇容易把自己把自...
用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 友盟自动更新 环信即时IM系统 极光推送 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...
具体内容 ============================= 完整App@ GitHubRank - GitHub活跃用户排名(便于学习,请勿攀比). expo - Expo iOS/Android Client https://docs.expo.io/. PPR...
苏格拉底说: 哲学就是认识你自己 午夜行走在 南城区绿道 脑中闪现思绪一跳 这位古希腊思想家 今夜让我再次想起他 参天的凤凰木 影影疏疏摇曳注目 孤灯整齐列队明亮又无助 我就这样踩在盲道 脚踏实地一步接一步 尊皇夜总会 霓虹灯闪耀暗回 不夜城是它标志 豪车涌入无限制 延续东...
02328-胡朋会 你在炎热的天气出门的时候会记得涂防嗮霜,带防嗮帽或打遮阳伞吗?有时候我记得,有时候匆匆忙忙间我就什么也没做,有时候带孩子出去的时候也不记得这些,但今天我觉得自己上了一课,就是出门一定要防嗮,否则皮肤国的居民受不了。皮肤国居民?我今天要给大家分享的绘本就是...
边框属性3节搞定
今天早上,刚起床打开电视看到新闻上说储户存款消失,从几十万到几百万不等,我赶紧骑自行车到银行查看,卡里的2.98元钱还在,吓死我了。以后再也不看新闻了,心好累。走出银行,心更累了,钱还在,自行车不见了。 我的自行车陪伴了我三年,基本功能都有,两个轮子,一个铃铛。唯一闹心的是...
一、看到牌时的感受 平静 二、读牌 1、一个身穿蓝色上衣、红色裤子、黄色鞋子、腰扎紫色腰带、头发金黄的男人,双手背后倒挂在一个T形的木头上。 这个男人右腿伸直拴在木头上,左腿叠在右腿后面呈三角形,又与右腿呈十字。 2、男人的头后面有一个金黄色的光环,光环的边缘呈红色。 3、...用Python和Pygame写游戏-从入门到精通(实战二:恶搞俄罗斯方块1) – 目光博客
Theme | Powered bypython和pygame实现简单俄罗斯方块游戏
转载 &更新时间:日 09:15:32 & 作者:LY
这篇文章主要为大家详细介绍了python和pygame实现简单俄罗斯方块游戏,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文为大家分享了python实现俄罗斯方块游戏的具体代码,供大家参考,具体内容如下
# -*- coding:utf-8 -*-
import pygame, sys, random, copy
from pygame.locals import *
pygame.init()
CubeWidth = 40
CubeHeight = 40
Column = 10
ScreenWidth = CubeWidth * (Column + 5)
ScreenHeight = CubeHeight * Row
ScreenSize = (ScreenWidth, ScreenHeight)
Screen = pygame.display.set_mode(ScreenSize, 0, 32)
pygame.display.set_caption("Ly's Tetris")
pygame.mixer.music.load('BackgroundMusic.ogg')
pygame.mixer.music.play(-1, 0.0)
ClickMusic = pygame.mixer.Sound('ClickMusic.wav')
ExplodeMusic = pygame.mixer.Sound('Explode.wav')
BackgroundImg = pygame.image.load('BackgroundImg.png').convert()
PreImg = pygame.image.load('PreImg.png').convert()
PStartImg = pygame.image.load('PStartImg.png').convert()
ResultPreImg = pygame.image.load('GameResultPreBgImg.png').convert()
RestartImg = pygame.image.load('GameResultRestBgImg.png').convert()
ScoreHintFont = pygame.font.SysFont('arial', 50)
ScoreFont = pygame.font.SysFont('arial', 40)
ResultFont = pygame.font.SysFont('arial', 200)
Aquamarine = (127, 255, 212)
LightGoldenrod = (255, 236, 139)
IndianRed = (255, 106, 106)
DarkOrchid = (153, 50, 204)
RoyalBlue = (72, 118, 255)
DarkOrange = (255, 165, 0)
Turquoise = (0, 245, 255)
IsRect = []
FPSClock = pygame.time.Clock()
class I():
def __init__(self):
self.Statu = ''
self.Color = Aquamarine
self.Body = []
x = random.randint(1, 2)
if x == 1:
self.Statu = 'upright'
for i in range(4):
InitBody = pygame.Rect(160, i * 40, 40, 40)
self.Body.append(InitBody)
elif x == 2:
self.Statu = 'horizon'
for i in range(4):
InitBody = pygame.Rect(120 + i * 40, 0, 40, 40)
self.Body.append(InitBody)
def Fall(self):
for rect in self.Body:
rect.top += 40
def IsFalled(self):
for rect in self.Body:
if rect.top == 760:
return True
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
return True
def Move(self, Curkey):
CanMoveFlag = True
if Curkey == K_UP:
self.Rotate()
elif Curkey == K_LEFT:
for rect in self.Body:
if rect.left == 0:
CanMoveFlag = not CanMoveFlag
elif IsRect[int(rect.top / 40) + 1][int(rect.left / 40) - 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left -= 40
elif Curkey == K_RIGHT:
for rect in self.Body:
if rect.left == 360:
CanMoveFlag = not CanMoveFlag
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40) + 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left += 40
def Rotate(self):
if self.Statu == 'upright':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40
TempRotate[0].top += 40
TempRotate[2].left += 40
TempRotate[2].top -= 40
TempRotate[3].left += 40 * 2
TempRotate[3].top -= 40 * 2
IsRotate = True
if TempRotate[0].left & 0:
IsRotate = False
if TempRotate[3].left & 360:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'horizon'
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40
TempRotate[0].top -= 40
TempRotate[2].left -= 40
TempRotate[2].top += 40
TempRotate[3].left -= 40 * 2
TempRotate[3].top += 40 * 2
IsRotate = True
if TempRotate[0].top & 0:
IsRotate = False
if TempRotate[3].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'upright'
class O():
def __init__(self):
self.Color = LightGoldenrod
self.Body = []
for i in range(2):
InitBody = pygame.Rect(160, i * 40, 40, 40)
self.Body.append(InitBody)
for i in range(2):
InitBody = pygame.Rect(200, i * 40, 40, 40)
self.Body.append(InitBody)
def Fall(self):
for rect in self.Body:
rect.top += 40
def IsFalled(self):
for rect in self.Body:
if rect.top == 760:
return True
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
return True
def Move(self, Curkey):
CanMoveFlag = True
if Curkey == K_UP:
self.Rotate()
elif Curkey == K_LEFT:
for rect in self.Body:
if rect.left == 0:
CanMoveFlag = not CanMoveFlag
elif IsRect[int(rect.top / 40) + 1][int(rect.left / 40) - 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left -= 40
elif Curkey == K_RIGHT:
for rect in self.Body:
if rect.left == 360:
CanMoveFlag = not CanMoveFlag
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40) + 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left += 40
def Rotate(self):
class T():
def __init__(self):
self.Statu = ''
self.Color = IndianRed
self.Body = []
x = random.randint(1, 4)
if x == 1:
self.Statu = 'up'
self.Body.append(pygame.Rect(200, 0, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(160 + i * 40, 40, 40, 40))
elif x == 2:
self.Statu = 'left'
self.Body.append(pygame.Rect(160, 40, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(200, 80 - i * 40, 40, 40))
elif x == 3:
self.Statu = 'down'
self.Body.append(pygame.Rect(200, 80, 40, 40))
for i in range(2, -1, -1):
self.Body.append(pygame.Rect(160 + i * 40, 40, 40, 40))
elif x == 4:
self.Statu = 'right'
self.Body.append(pygame.Rect(240, 40, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(200, i * 40, 40, 40))
def Fall(self):
for rect in self.Body:
rect.top += 40
def IsFalled(self):
for rect in self.Body:
if rect.top == 760:
return True
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
return True
def Move(self, Curkey):
CanMoveFlag = True
if Curkey == K_UP:
self.Rotate()
elif Curkey == K_LEFT:
for rect in self.Body:
if rect.left == 0:
CanMoveFlag = not CanMoveFlag
elif IsRect[int(rect.top / 40) + 1][int(rect.left / 40) - 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left -= 40
elif Curkey == K_RIGHT:
for rect in self.Body:
if rect.left == 360:
CanMoveFlag = not CanMoveFlag
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40) + 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left += 40
def Rotate(self):
if self.Statu == 'up':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40
TempRotate[0].top += 40
TempRotate[1].left += 40
TempRotate[1].top += 40
TempRotate[3].left -= 40
TempRotate[3].top -= 40
IsRotate = True
if TempRotate[1].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'left'
elif self.Statu == 'left':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40
TempRotate[0].top += 40
TempRotate[1].left += 40
TempRotate[1].top -= 40
TempRotate[3].left -= 40
TempRotate[3].top += 40
IsRotate = True
if TempRotate[1].left & 360:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'down'
elif self.Statu == 'down':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40
TempRotate[0].top -= 40
TempRotate[1].left -= 40
TempRotate[1].top -= 40
TempRotate[3].left += 40
TempRotate[3].top += 40
IsRotate = True
if TempRotate[1].top & 0:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'right'
elif self.Statu == 'right':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40
TempRotate[0].top -= 40
TempRotate[1].left -= 40
TempRotate[1].top += 40
TempRotate[3].left += 40
TempRotate[3].top -= 40
IsRotate = True
if TempRotate[1].top & 0:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'up'
class Z():
def __init__(self):
self.Statu = ''
self.Color = DarkOrchid
self.Body = []
x = random.randint(1, 2)
if x == 1:
self.Statu = 'horizon'
for i in range(2):
self.Body.append(pygame.Rect(120 + i * 40, 0, 40, 40))
for i in range(2):
self.Body.append(pygame.Rect(160 + i * 40, 40, 40, 40))
elif x == 2:
self.Statu = 'upright'
for i in range(2):
self.Body.append(pygame.Rect(200, i * 40, 40, 40))
for i in range(2):
self.Body.append(pygame.Rect(160, 40 + i * 40, 40, 40))
def Fall(self):
for rect in self.Body:
rect.top += 40
def IsFalled(self):
for rect in self.Body:
if rect.top == 760:
return True
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
return True
def Move(self, Curkey):
CanMoveFlag = True
if Curkey == K_UP:
self.Rotate()
elif Curkey == K_LEFT:
for rect in self.Body:
if rect.left == 0:
CanMoveFlag = not CanMoveFlag
elif IsRect[int(rect.top / 40) + 1][int(rect.left / 40) - 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left -= 40
elif Curkey == K_RIGHT:
for rect in self.Body:
if rect.left == 360:
CanMoveFlag = not CanMoveFlag
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40) + 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left += 40
def Rotate(self):
if self.Statu == 'horizon':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40 * 2
TempRotate[1].left += 40
TempRotate[1].top += 40
TempRotate[3].left -= 40
TempRotate[3].top += 40
IsRotate = True
if TempRotate[3].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'upright'
elif self.Statu == 'upright':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40 * 2
TempRotate[1].left -= 40
TempRotate[1].top -= 40
TempRotate[3].left += 40
TempRotate[3].top -= 40
IsRotate = True
if TempRotate[0].left & 0:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'horizon'
class S():
def __init__(self):
self.Statu = ''
self.Color = DarkOrchid
self.Body = []
x = random.randint(1, 2)
if x == 1:
self.Statu = 'horizon'
for i in range(2):
self.Body.append(pygame.Rect(200 - i * 40, 0, 40, 40))
for i in range(2):
self.Body.append(pygame.Rect(160 - i * 40, 40, 40, 40))
elif x == 2:
self.Statu = 'upright'
for i in range(2):
self.Body.append(pygame.Rect(120, i * 40, 40, 40))
for i in range(2):
self.Body.append(pygame.Rect(160, 40 + i * 40, 40, 40))
def Fall(self):
for rect in self.Body:
rect.top += 40
def IsFalled(self):
for rect in self.Body:
if rect.top == 760:
return True
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
return True
def Move(self, Curkey):
CanMoveFlag = True
if Curkey == K_UP:
self.Rotate()
elif Curkey == K_LEFT:
for rect in self.Body:
if rect.left == 0:
CanMoveFlag = not CanMoveFlag
elif IsRect[int(rect.top / 40) + 1][int(rect.left / 40) - 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left -= 40
elif Curkey == K_RIGHT:
for rect in self.Body:
if rect.left == 360:
CanMoveFlag = not CanMoveFlag
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40) + 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left += 40
def Rotate(self):
if self.Statu == 'horizon':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40 * 2
TempRotate[1].left -= 40
TempRotate[1].top += 40
TempRotate[3].left += 40
TempRotate[3].top += 40
IsRotate = True
if TempRotate[3].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'upright'
elif self.Statu == 'upright':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40 * 2
TempRotate[1].left += 40
TempRotate[1].top -= 40
TempRotate[3].left -= 40
TempRotate[3].top -= 40
IsRotate = True
if TempRotate[0].left & 360:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'horizon'
class L():
def __init__(self):
self.Statu = ''
self.Color = DarkOrange
self.Body = []
x = random.randint(1, 4)
if x == 1:
self.Statu = 'horizonright'
self.Body.append(pygame.Rect(120, 0, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(120 + i * 40, 40, 40, 40))
elif x == 2:
self.Statu = 'uprightup'
self.Body.append(pygame.Rect(120, 80, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(160, 80 - i * 40, 40, 40))
elif x == 3:
self.Statu = 'horizonleft'
self.Body.append(pygame.Rect(200, 40, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(200 - i * 40, 0, 40, 40))
elif x == 4:
self.Statu = 'uprightdown'
self.Body.append(pygame.Rect(160, 0, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(120, i * 40, 40, 40))
def Fall(self):
for rect in self.Body:
rect.top += 40
def IsFalled(self):
for rect in self.Body:
if rect.top == 760:
return True
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
return True
def Move(self, Curkey):
CanMoveFlag = True
if Curkey == K_UP:
self.Rotate()
elif Curkey == K_LEFT:
for rect in self.Body:
if rect.left == 0:
CanMoveFlag = not CanMoveFlag
elif IsRect[int(rect.top / 40) + 1][int(rect.left / 40) - 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left -= 40
elif Curkey == K_RIGHT:
for rect in self.Body:
if rect.left == 360:
CanMoveFlag = not CanMoveFlag
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40) + 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left += 40
def Rotate(self):
if self.Statu == 'horizonright':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40
TempRotate[0].top += 40
TempRotate[2].left -= 40
TempRotate[2].top -= 40
TempRotate[3].left -= 40 * 2
TempRotate[3].top -= 40 * 2
IsRotate = True
if TempRotate[0].left & 0:
IsRotate = False
if TempRotate[3].top & 0:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'uprightup'
elif self.Statu == 'uprightup':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40
TempRotate[0].top += 40
TempRotate[2].left -= 40
TempRotate[2].top += 40
TempRotate[3].left -= 40 * 2
TempRotate[3].top += 40 * 2
IsRotate = True
if TempRotate[3].left & 0:
IsRotate = False
if TempRotate[0].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'horizonleft'
elif self.Statu == 'horizonleft':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40
TempRotate[0].top -= 40
TempRotate[2].left += 40
TempRotate[2].top += 40
TempRotate[3].left += 40 * 2
TempRotate[3].top += 40 * 2
IsRotate = True
if TempRotate[0].left & 360:
IsRotate = False
if TempRotate[3].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'uprightdown'
elif self.Statu == 'uprightdown':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40
TempRotate[0].top -= 40
TempRotate[2].left += 40
TempRotate[2].top -= 40
TempRotate[3].left += 40 * 2
TempRotate[3].top -= 40 * 2
IsRotate = True
if TempRotate[0].top & 0:
IsRotate = False
if TempRotate[3].left & 360:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'horizonright'
class J():
def __init__(self):
self.Statu = ''
self.Color = Turquoise
self.Body = []
x = random.randint(1, 4)
if x == 1:
self.Statu = 'horizonleft'
self.Body.append(pygame.Rect(200, 0, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(200 - i * 40, 40, 40, 40))
elif x == 2:
self.Statu = 'uprightup'
self.Body.append(pygame.Rect(240, 80, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(200, 80 - i * 40, 40, 40))
elif x == 3:
self.Statu = 'horizonright'
self.Body.append(pygame.Rect(120, 40, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(120 + i * 40, 0, 40, 40))
elif x == 4:
self.Statu = 'uprightdown'
self.Body.append(pygame.Rect(120, 0, 40, 40))
for i in range(3):
self.Body.append(pygame.Rect(160, i * 40, 40, 40))
def Fall(self):
for rect in self.Body:
rect.top += 40
def IsFalled(self):
for rect in self.Body:
if rect.top == 760:
return True
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
return True
def Move(self, Curkey):
CanMoveFlag = True
if Curkey == K_UP:
self.Rotate()
elif Curkey == K_LEFT:
for rect in self.Body:
if rect.left == 0:
CanMoveFlag = not CanMoveFlag
elif IsRect[int(rect.top / 40) + 1][int(rect.left / 40) - 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left -= 40
elif Curkey == K_RIGHT:
for rect in self.Body:
if rect.left == 360:
CanMoveFlag = not CanMoveFlag
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40) + 1]:
CanMoveFlag = not CanMoveFlag
if CanMoveFlag:
for rect in self.Body:
rect.left += 40
def Rotate(self):
if self.Statu == 'horizonleft':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40
TempRotate[0].top += 40
TempRotate[2].left += 40
TempRotate[2].top -= 40
TempRotate[3].left += 40 * 2
TempRotate[3].top -= 40 * 2
IsRotate = True
if TempRotate[0].left & 360:
IsRotate = False
if TempRotate[3].top & 0:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'uprightup'
elif self.Statu == 'uprightup':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40
TempRotate[0].top += 40
TempRotate[2].left += 40
TempRotate[2].top += 40
TempRotate[3].left += 40 * 2
TempRotate[3].top += 40 * 2
IsRotate = True
if TempRotate[3].left & 360:
IsRotate = False
if TempRotate[0].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'horizonright'
elif self.Statu == 'horizonright':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left -= 40
TempRotate[0].top -= 40
TempRotate[2].left -= 40
TempRotate[2].top += 40
TempRotate[3].left -= 40 * 2
TempRotate[3].top += 40 * 2
IsRotate = True
if TempRotate[0].left & 0:
IsRotate = False
if TempRotate[3].top & 760:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'uprightdown'
elif self.Statu == 'uprightdown':
TempRotate = copy.deepcopy(self.Body)
TempRotate[0].left += 40
TempRotate[0].top -= 40
TempRotate[2].left -= 40
TempRotate[2].top -= 40
TempRotate[3].left -= 40 * 2
TempRotate[3].top -= 40 * 2
IsRotate = True
if TempRotate[0].top & 0:
IsRotate = False
if TempRotate[3].left & 0:
IsRotate = False
if IsRotate:
for rect in TempRotate:
if IsRect[int(rect.top / 40) + 1][int(rect.left / 40)]:
IsRotate = False
if IsRotate:
self.Body = copy.deepcopy(TempRotate)
self.Statu = 'horizonleft'
def ShapeChoose():
ShapeChoose = random.randint(1, 7)
if ShapeChoose == 1:
return I()
elif ShapeChoose == 2:
return O()
elif ShapeChoose == 3:
return T()
elif ShapeChoose == 4:
return Z()
elif ShapeChoose == 5:
return S()
elif ShapeChoose == 6:
return L()
elif ShapeChoose == 7:
return J()
def GameMain():
global IsRect
for row in range(21):
TempRowIsRect = []
for column in range(11):
TempRowIsRect.append(False)
IsRect.append(TempRowIsRect)
PreBackgroundImg = PreImg
while True:
StarFalg = False
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
ClickMusic.play()
if event.key == K_SPACE:
PreBackgroundImg = PStartImg
if event.type == KEYUP:
ClickMusic.play()
if event.key == K_SPACE:
StarFalg = True
if StarFalg:
Screen.blit(PreBackgroundImg, (0, 0))
pygame.display.update()
falling = ShapeChoose()
GameOver = False
FallSpeed = 4
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_DOWN:
FallSpeed = 15
falling.Move(event.key)
if event.type == KEYUP:
if event.key == K_DOWN:
FallSpeed = 4
Screen.blit(BackgroundImg, (0, 0))
for row in range(20):
for column in range(10):
if IsRect[row][column]:
pygame.draw.rect(Screen, IsRect[row][column][1], IsRect[row][column][0], 0)
falling.Fall()
for rect in falling.Body:
pygame.draw.rect(Screen, falling.Color, rect, 0)
if falling.IsFalled():
for rect in falling.Body:
Info.append(rect)
Info.append(falling.Color)
IsRect[int(rect.top / 40)][int(rect.left / 40)] = Info
falling = ShapeChoose()
for IsOver in IsRect[1]:
if IsOver:
GameOver = True
if GameOver:
IsRect = []
return Score
for CheckRow in range(19, 0, -1):
CheckFlag = True
for CheckC in range(10):
if IsRect[CheckRow][CheckC]:
CheckFlag = False
if CheckFlag:
ExplodeMusic.play()
Score += 10
for ChangeRow in range(CheckRow, 0, -1):
for ChangeC in range(10):
if IsRect[ChangeRow - 1][ChangeC]:
IsRect[ChangeRow - 1][ChangeC][0].top += 40
IsRect[ChangeRow] = IsRect[ChangeRow - 1]
ScoreHintSurface = ScoreHintFont.render('Score:', True, (0, 0, 0))
Screen.blit(ScoreHintSurface, (420, 100))
ScoreSurface = ScoreFont.render(str(Score), True, (0, 0, 0))
Screen.blit(ScoreSurface, (480, 180))
pygame.display.update()
FPSClock.tick(FallSpeed)
def GameResult(Score):
ResultImg = ResultPreImg
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
ClickMusic.play()
if event.key == K_SPACE:
ResultImg = RestartImg
if event.type == KEYUP:
ClickMusic.play()
if event.key == K_SPACE:
return True
Screen.blit(ResultImg, (0, 0))
ScoreSurface = ResultFont.render(str(Score), True, (255, 127, 80))
if Score & 10:
Screen.blit(ScoreSurface, (250, 260))
elif Score & 100:
Screen.blit(ScoreSurface, (210, 260))
elif Score & 1000:
Screen.blit(ScoreSurface, (160, 260))
pygame.display.update()
if __name__ == '__main__':
Flag = True
while Flag:
Score = GameMain()
Flag = GameResult(Score)
运行结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具}

我要回帖

更多关于 iphone键盘设置大小 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信