Пример #1
0
class MainGame(object):
    def __init__(self):
        pygame.mixer.pre_init(44100, -16, 2, 2048)  # sounds
        pygame.init()
        pygame.display.set_caption("IsoGame")  # Set app name
        pygame.key.set_repeat(1, 20)

        self.width, self.height = 800, 600
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.clock = pygame.time.Clock()
        self.player = Player("player", (100, 100))
        self.level = Level("level1")
        self.levelGroup = self.level.get_group()
        self.levelGroup.add(self.player)

    def draw(self, screen):
        self.levelGroup.center(self.player.rect.center)
        self.levelGroup.draw(screen)

    def update(self, dt):
        """ Tasks that occur over time should be handled here
        """
        self.levelGroup.update(dt)

    def main(self):
        """ main function """
        while True:
            dt = self.clock.tick(30)

            for event in pygame.event.get():
                if event.type == QUIT:
                    return
                elif event.type == pygame.KEYDOWN:
                    if event.key == K_ESCAPE:
                        return

                elif event.type == VIDEORESIZE:
                    self.screen = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)

                self.player.handle_event(event)

            self.player.update(dt)
            self.draw(self.screen)

            pygame.display.flip()