当我的玩家在pygame中相撞时,该如何使其穿过敌人?

时间:2019-08-04 20:19:38

标签: python python-3.x pygame

我正在测试一款平台游戏。我有一个球员和一个敌人。但是,当我击中它时,即使我没有告诉程序,敌人也就像是玩家无法穿过的一堵墙。我还告诉程序在发生冲突时打印(“命中”),但是什么也没有发生。有谁知道如何解决这一问题?注意:我导入了文件,所以此代码不是全部在同一个文件中。

SLIME_WALK = (52, 125, 50, 28)


class Mob(pygame.sprite.Sprite):
    def __init__(self, sprite_sheet_data):
    """ Mob constructor. Assumes constructed with user passing in
        an array of 5 numbers like what's defined at the top of this
        code. """

        # Call the parent's constructor
        super().__init__()

        sprite_sheet = SpriteSheet('enemies_spritesheet.png')
        # Grab the image for this platform
        self.image = sprite_sheet.get_image(sprite_sheet_data[0],
                                        sprite_sheet_data[1],
                                        sprite_sheet_data[2],
                                        sprite_sheet_data[3])

        self.rect = self.image.get_rect()


class Level01(Level):
     def __init__(self, player):

        # Call the parent constructor
        Level.__init__(self, player)
        # Array with type of mob, and x, y location of the mob
        level_enemies = [[mobs.SLIME_WALK, 500, 300]]

        # Go through the array above and add mobs
        for mob in level_enemies:
            enemy = mobs.Mob(mob[0])
            enemy.rect.x = mob[1]
            enemy.rect.y = mob[2]
            enemy.player = self.player
            self.platform_list.add(enemy)


class Player(pygame.sprite.Sprite):


    # -- Methods
    def __init__(self):
        """ Constructor function """

        # Call the parent's constructor
        super().__init__()

    def update(self):
        # See if we hit anything
        mob_hit_list = pygame.sprite.spritecollide(self, 
        self.level.enemy_list, False)
        if mob_hit_list:
            print("Hit")

1 个答案:

答案 0 :(得分:3)

我想您可以使用 webbrowser

for (PurchaseDetails purchase in response.pastPurchases) {

    if(purchase.billingClientPurchase.sku == "your_subscriptionID"){
      hasSubscription = true;
    }

    if (Platform.isIOS) {
      InAppPurchaseConnection.instance.completePurchase(purchase);
    }
  }