我需要帮助修复 new_hail 函数,使一个像素一直下降到 y 7 并重新生成回到顶部,即零。我尝试制作一个 new_hail 函数来制作新的冰雹,但它没有用,因为我认为它可能与冰雹变量是一个列表有关,也许是因为我没有列出它们。我也不知道 new_hail 是否有效,因为我不知道它是否包含在冰雹列表中。
代码:
hail_x_list = [random.randrange(0,4),random.randrange(4,7)]
hail_y_list = [0,0]
hail_x = 0
hail_y = random.randrange(0,7)
hail_x2 = 0
hail_y2 = random.randrange(0,7)
hail_x3 = 0
hail_y3 = random.randrange(0,7)
def update():
global hail_x, hail_y, game_over, hail_y2,hail_x2,hail_x3,hail_y3,hail_y_list,hail_x_list
sense.clear()
sense.set_pixel(avoider_x, 7, purp)
while min(hail_y_list) < 7 :
for i in range(len(hail_y_list)):
if hail_y_list[i] < 7 :
hail_y_list[i] += 1
sense.set_pixel(hail_x_list[i],hail_y_list[i], yelo)
time.sleep(0.04)
if hail_y_list[i] > 0 :
sense.set_pixel(hail_x_list[i], hail_y_list[i]-1, O )
def new_hail():
global hail_y, hail_x, score, hail_y2, hail_x2, hail_y3, hail_x3, hail_y_list, hail_x_list
score = score + 1
sense.show_message(str(score), text_colour=g, scroll_speed=0.05)
hail_y = 0
hail_x = random.randrange(0,7)
score = score + 1
sense.show_message(str(score), text_colour=g, scroll_speed=0.05)
time.sleep(0.03)
hail_y2 = 0
hail_x2 = random.randrange(0,7)
sense.show_message(str(score), text_colour=g, scroll_speed=0.05)