我想对其中的4个垃圾邮件进行垃圾邮件处理,但只对1个垃圾邮件进行垃圾邮件处理。
def create_lives(hearts, all_sprites):
corazon = Heart()
for heart_number in range(1,4):
corazon.x = (corazon.rect.width * heart_number)- corazon.rect.width
corazon.rect.x = corazon.x
corazon.rect.y = 40
hearts.add(corazon)
all_sprites.add(corazon)
这是我的主循环:
def run_game():
pygame.mixer.music.play(-1)
score = 0
gf.create_lives(hearts, all_sprites)
gf.add_mobs(ai_settings, all_sprites, mobs, meteor_imgs)
while True:
clock.tick(FPS)
gf.update_screen(ai_settings, screen, all_sprites, background, background_rect, hearts)
gf.check_events(player, all_sprites, bullets)
score = gf.collisions(score, screen, player, mobs, bullets, ai_settings, all_sprites, meteor_imgs)
gf.collisions(score, screen, player, mobs, bullets, ai_settings, all_sprites, meteor_imgs)
gf.draw_text(screen, "SCORE: " + str(score) , 20, 0,0, ai_settings)
gf.draw_text(screen, "LIFE: " + str(player.shield) , 20, 0,20, ai_settings)
all_sprites.update()
pygame.display.flip()
run_game()
我虽然在该范围内循环会导致4个图片被发送垃圾邮件。
答案 0 :(得分:2)
将corazon = Heart()
移动到for循环中。