0

そこで、ゲームにランダムドロップを追加して、プレイヤーが拾うことができるミサイルパックを生成し、プレイヤーのインベントリにミサイルを 1 つ追加しようとしましたが、MissilePackオブジェクトを作成し、Spawner クラスを更新してミサイルパックをランダムに生成した後、 Pygame ウィンドウが完全にフリーズし、エラー メッセージが表示されないため、どうすればよいかわかりません。助けていただければ幸いです。

inventory=[]

class MissilePack(games.Sprite):
    speed = 1.7
    image = games.load_image('MissilePack.bmp')
    global inventory

    def __init__(self, x,y = 10):
        """ Initialize a missilepack object. """
        super(MissilePack, self).__init__(image = MissilePack.image,
                                    x = x, y = y,
                                    dy = MissilePack.speed)


    def update(self):
        """ Check if bottom edge has reached screen bottom. """
        if self.bottom>games.screen.height:
            self.destroy()

    def handle_caughtpack(self):
        inventory.append('missile')

これは Spawner クラスの一部で、プレイヤーが拾うミサイル パックをランダムに生成します。

def update(self):
    """ Determine if direction needs to be reversed. """
    if self.left < 0 or self.right > games.screen.width:
        self.dx = -self.dx
    elif random.randrange(self.odds_change) == 0:
       self.dx = -self.dx

    self.check_drop()
    self.drop_missile()

 def drop_missile(self):
    """Randomely drops a missile pack for the player to use"""
    while True:
        dropmissile = random.randrange(0, 10)
        if dropmissile == 5:
            missilepack = MissilePack(x = self.x)
            games.screen.add(missilepack)
4

1 に答える 1