如何通过OOP增加游戏的难度?

时间:2016-11-07 18:05:44

标签: python pygame

我正在制作一款名为Pizza Panic的游戏,它基本上是一个投掷比萨饼的家伙,你必须抓住它们。现在我想在玩家达到一定分数后增加难度级别。但是当我试图提高比萨饼的速度时,整个游戏似乎都在放慢速度。以下是我的代码:

class Pan(games.Sprite):
    image = games.load_image("pan.bmp", transparent=True)

    def __init__(self):
        super(Pan, self).__init__(image=Pan.image,
                                  bottom=games.screen.height,
                                  x=games.mouse.x)
        self.score = games.Text(value=0, size=25, color=color.black, right=games.screen.width-10, top=10)
        games.screen.add(self.score)
        self.level = 0

    def update(self):
        self.x = games.mouse.x
        if self.left < 0:
            self.left = 0
        if self.right > games.screen.width:
            self.right = games.screen.width
        self.check_collide()
        if self.score.value > 200:
            text = games.Message(value='Increased difficulty',
                                 color=color.red,
                                 size=60,
                                 x=games.screen.width/2,
                                 y=games.screen.height/2,
                                 lifetime=100,
                                 after_death=Pizza.increased_speed)
            games.screen.add(text)

    def check_collide(self):
        for pizza in self.overlapping_sprites:
            self.score.value += 10
            self.score.right = games.screen.width-10
            pizza.handle_caught()


class Pizza(games.Sprite):
    image = games.load_image('pizza.bmp')
    speed = 1

    def __init__(self, x=90, y=90):
        super(Pizza, self).__init__(image=Pizza.image,
                                    y=y,
                                    x=x,
                                    dy=Pizza.speed)

    def handle_caught(self):
        self.destroy()

    def update(self):
        if self.bottom > games.screen.height:
            self.end_game()
            self.destroy()

    def end_game(self):
        end_message = games.Message(value='GAME OVER',
                                    size=90,
                                    color=color.red,
                                    x=games.screen.width / 2,
                                    y=games.screen.height / 2,
                                    lifetime=4 * games.screen.fps,
                                    after_death=games.screen.quit)
        games.screen.add(end_message)

    @staticmethod
    def increased_speed():
        Pizza.speed = 2

0 个答案:

没有答案