'道奇'型游戏

时间:2010-04-20 10:03:47

标签: python pygame livewires

我正在尝试用livewires和pygame写一个游戏,我有一个厨师(只有我有的图像,哈哈),避免从天上掉下来的岩石。岩石应该落在随机的地方。我想让它成为一块岩石开始落下,然后每当你成功躲避岩石时,又会有2块岩石落下,直到你输了。到目前为止我所拥有的是厨师和一块岩石。然而,出于某种原因,如果精灵碰撞,或者岩石触及屏幕的底部,游戏结束,而不是像我告诉它那样给游戏留下消息。我很困惑,看不到我做了什么。我知道我没有为2个岩石部分正确编码,但我甚至无法让它略微运行。救命!这就是我现在所拥有的:

from livewires import games, color
import random

games.init(screen_width = 640, screen_height = 480, fps = 50)


class Chef(games.Sprite):

    image = games.load_image("chef.bmp")

    def __init__(self):
        super(Chef, self).__init__(image = Chef.image,
                                  x = games.mouse.x,
                                  bottom = games.screen.height)

    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_catch()

    def check_catch(self):
        for pizza in self.overlapping_sprites:
            if not self.bottom>games.screen.height:
                self.end_game()


class Rock(games.Sprite):

    def update(self):
        if self.bottom > games.screen.height:
                new_rock=Rock(x=random.randrange(games.screen.width),
                              y=10,
                              dy=1)
                games.screen.add(new_rock)

    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 = 5 * games.screen.fps,
                                    after_death = games.screen.quit)
        games.screen.add(end_message)


def main():

    wall_image = games.load_image("wall.jpg", transparent = False)
    games.screen.background = wall_image

    the_chef = Chef()
    games.screen.add(the_chef)

    rock_image=games.load_image("rock.bmp")
    the_rock=Rock(image=rock_image,
                  x=random.randrange(games.screen.width),
                  y=10,
                  dy=1)
    games.screen.add(the_rock)

    games.mouse.is_visible = False

    games.screen.event_grab = True
    games.screen.mainloop()

main()

1 个答案:

答案 0 :(得分:0)

您已在end_game中声明了Rock class方法,但您是通过check_catch的{​​{1}}方法调用它。