我试图在pygame中每经过5秒创建一个类的实例,但是它创建了大量的实例,而不是1

import pygame as pg
import random
from player import Player

pg.init()
pg.font.init()


#screen settings
(width, height) = (800, 600)
bg = (128, 128, 128)
screen = pg.display.set_mode((width, height))
pg.display.set_caption("2D game")


#speed of the game and color rgb values
speed = 1

red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
yellow = (255,255,0)
cyan = (0,255,255)
colors = [red, green, blue, yellow, cyan]


#player
player = Player((255, 0, 127), 50, 50, 1)
player.rect.x = 380
player.rect.y = 500

#enemy
enemy1 = Player(random.choice(colors), 30, 30, random.randint(50, 100))
enemy1.rect.x = 50
enemy1.rect.y = -50


#adds the player and enemies to their respective lists
all_sprites_list = pg.sprite.Group()
all_sprites_list.add(player)
all_sprites_list.add(enemy1)

all_enemies = pg.sprite.Group()
all_enemies.add(enemy1)

#clock
clock = pg.time.Clock()
passed_time = 0

def make_enemy(name, color, width, height, speed):
    name = Player(color, width, height, speed)
    name.add(all_sprites_list)
    name.add(all_enemies)

def textboard(font ,text, color, x, y):
    font = pg.font.SysFont(font, 50)
    textsurf = font.render(text, False, color)
    screen.blit(textsurf, (x,y))


#game loop
running = True
while running:

    passed_time = round(pg.time.get_ticks()/1000)
    if passed_time%5 == 0:
        variable_name = 0
        variable_name += 1
        speed += 0.01
        make_enemy('enemy' + str(variable_name), random.choice(colors), 30, 30, random.randint(50, 100))

    for event in pg.event.get():
        if event.type == pg.QUIT:
            running = False
        elif event.type == pg.KEYDOWN:
            if event.key == pg.K_x:
                running = False

    keys = pg.key.get_pressed()
    if keys[pg.K_RIGHT]:
        player.moveRight(5)
    if keys[pg.K_LEFT]:
        player.moveLeft(5)

    for enemy in all_enemies:
        enemy.enemyFall(speed)
        if enemy.rect.y > height:
            enemy.changeSpeed(random.randint(50, 100))
            enemy.rect.y = random.randint(50, 100) * -1
            enemy.changePosition()
            enemy.randColor(random.choice(colors))

    collisions = pg.sprite.spritecollide(player, all_enemies, False)
    for enemy in collisions:
        running = False

    all_sprites_list.update()

    screen.fill(bg)

    textboard('ComicSans', 'timer: ' + str(passed_time), cyan, 100, 400)

    all_sprites_list.draw(screen)

    pg.display.flip()
    clock.tick(60)

pg.quit()
pg.font.quit()

这是游戏本身。我在make_enemy()函数中遇到了麻烦,使数十个实例而不是我想要的一个实例。我认为这与壁虱有关,但我无法弄清楚。

基本上,当我运行此命令时,在5秒钟后它会产生10-30个敌人,这些敌人会在屏幕上过大,我希望它每5秒钟仅创建一个。