我正在做一个破砖游戏,现在球击中了一块砖(一个矩形),并且在第一次击中时破了。我希望它使球第一次击中砖块时,它变为浅红色,第二次变为红色,然后在第三次击中时就断裂。
#brick list
rectInfo = [rX, rY]
allRectInfo = [rectInfo[:] for i in range(numRects)]
allRectInfo[0] = [45, 20, True]
allRectInfo[1] = [45, 60, True]
allRectInfo[2] = [45, 100, True]
allRectInfo[3] = [45, 140, True]
allRectInfo[4] = [195, 20, True]
allRectInfo[5] = [195, 60, True]
allRectInfo[6] = [195, 100, True]
allRectInfo[7] = [195, 140, True]
allRectInfo[8] = [345, 20, True]
allRectInfo[9] = [345, 100, True]
allRectInfo[10] = [345, 60, True]
allRectInfo[11] = [345, 140, True]
allRectInfo[12] = [495, 140, True]
allRectInfo[13] = [495, 100, True]
allRectInfo[14] = [495, 60, True]
allRectInfo[15] = [495, 20, True]
allRectInfo[16] = [645, 20, True]
allRectInfo[17] = [645, 60, True]
allRectInfo[18] = [645, 100, True]
allRectInfo[19] = [645, 140, True]
#when the ball hits the bricks
for i in range (numRects):
if allRectInfo[i][2] == True:
rect (allRectInfo[i][0], allRectInfo[i][1], rectW, rectH)
if allRectInfo[i][1]-25 <= y <= allRectInfo[i][1]+74 and
allRectInfo[i][0]-5.5 <= x <= allRectInfo[i][0]+150:
incry = incry * (-1)
allRectInfo[i][2] = allRectInfo[i][2] - 1
score = score + 1
hits = hits + 1
答案 0 :(得分:0)
allRectInfo[i]
元组的第3个元素必须是命中次数,而不是布尔属性,它必须由0初始化:
allRectInfo[0] = [45, 20, 0]
allRectInfo[1] = [45, 60, 0]
allRectInfo[2] = [45, 100, 0]
# [...]
在识别出匹配后增加匹配计数器:
for i in range (numRects):
if # [...]
# [...]
allRectInfo[i][2] += 1
定义颜色数组并使用取决于砖的颜色:
brickcolor1 = # [...]
brickcolor2 = (255, 128, 128)
brickcolor3 = (255, 0, 0)
brickcolors = [brickcolor1, brickcolor2, brickcolor3]
currentcolor = brickcolors[allRectInfo[i][2]]
如果砖达到命中极限,则砖会破裂。在这种情况下,跳过砖头:
for i in range (numRects):
if allRectInfo[i][2] < 3:
# [...]
所有看起来可能如下:
for i in range (numRects):
if allRectInfo[i][2] < 3:
currentcolor = brickcolors[allRectInfo[i][2]]
fill(*currentcolor)
rect(allRectInfo[i][0], allRectInfo[i][1], rectW, rectH)
if allRectInfo[i][1]-25 <= y <= allRectInfo[i][1]+74 and allRectInfo[i][0]-5.5 <= x <= allRectInfo[i][0]+150:
incry = incry * (-1)
score = score + 1
allRectInfo[i][2] += 1