时间和敌人出现的问题(Python,Pygame)

我第二次发布此问题,但有更多信息。我的问题出在我的代码上,由于某些原因,几行不起作用。我正在使用pygame库在python中制作图块游戏。如果运行代码,您将在屏幕上看到1个红色方块将无休止地从顶部飞到底部。红场是敌人。我需要在10秒后飞行的不是1个正方形,而是2个。“ MobY()”类对此负责,它会生成敌人,并且在“ new()”方法中的“ Game()”类中是一个产生红色方块的循环:

     for i in range(self.mobY):
            m = MobY()
            self.all_sprites.add(m)
            self.mobs.add(m)

init中存储的变量“ self.mobY”等于1,即同时在屏幕上只能显示1个红色正方形。屏幕上还有一个计时器,其秒数存储在方法“ time()”中的变量“ self.seconds”中。 因此,在10秒后,有2个红色方块在屏幕上飞行,理论上,您需要将这些代码行放入“ new()”方法中:

        if self.seconds >= 10:
            self.mobY += 1

但是我收到一个错误“游戏对象没有属性“秒””,尽管没有。 通常,我需要在10秒钟后屏幕上再显示1个正方形。 这是代码:

import sys
import pygame as pg
import random

#         R    G    B
DARKGREY = (40, 40, 40)
LIGHTGREY = (43, 43, 43)
RED = (255, 0, 0)

WIDTH = 1008
HEIGHT = 768
FPS = 60
TITLE = "TITLE GAME"
BGCOLOR = DARKGREY
TILESIZE = 48


class MobY(pg.sprite.Sprite):
    def __init__(self):
        pg.sprite.Sprite.__init__(self)
        self.image = pg.Surface((TILESIZE, TILESIZE))
        self.image.fill(RED)
        self.rect = self.image.get_rect()
        self.rect.x = random.randrange(0, WIDTH, TILESIZE)
        self.rect.y = random.randrange(-100, -40)
        self.speedy = random.randrange(6, 9)

    def update(self):
        self.rect.y += self.speedy
        if self.rect.top > HEIGHT + TILESIZE:
            self.rect.x = random.randrange(0, WIDTH, TILESIZE)
            self.rect.y = random.randrange(-100, -40)
            self.speedy = random.randrange(6, 9)


class Game:
    def __init__(self):
        pg.init()
        self.screen = pg.display.set_mode((WIDTH, HEIGHT))
        pg.display.set_caption(TITLE)
        self.clock = pg.time.Clock()
        pg.key.set_repeat(1, 15)
        self.frame_count = 0
        self.mobY = 1

    def new(self):
        self.all_sprites = pg.sprite.Group()
        self.mobs = pg.sprite.Group()

        for i in range(self.mobY):
            m = MobY()
            self.all_sprites.add(m)
            self.mobs.add(m)

    def run(self):
        self.playing = True
        while self.playing:
            self.dt = self.clock.tick(FPS) / 1000
            self.events()
            self.update()
            self.draw()

    def quit(self):
        pg.quit()
        sys.exit()

    def update(self):
        self.all_sprites.update()

    def time(self):
        self.font = pg.font.Font(None, 50)
        self.font_color = pg.Color('springgreen')
        self.total_seconds = self.frame_count // FPS
        self.seconds = self.total_seconds % 6000
        self.output_string = "TIME: {0}".format(self.seconds)
        self.text = self.font.render(self.output_string, True, self.font_color)
        self.screen.blit(self.text, [10, 10])
        self.frame_count += 1

    def draw_grid(self):
        for x in range(0, WIDTH, TILESIZE):
            pg.draw.line(self.screen, LIGHTGREY, (x, 0), (x, HEIGHT))
        for y in range(0, HEIGHT, TILESIZE):
            pg.draw.line(self.screen, LIGHTGREY, (0, y), (WIDTH, y))

    def draw(self):
        self.screen.fill(BGCOLOR)
        self.draw_grid()
        self.all_sprites.draw(self.screen)
        self.time()
        pg.display.flip()

    def events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                self.quit()


g = Game()
while True:
    g.new()
    g.run()