Пример #1
0
    def __init__(self):
        super(PygameFramework, self).__init__()

        if fwSettings.onlyInit:  # testing mode doesn't initialize pygame
            return

        self.__reset()
        print('Initializing pygame framework...')
        # Pygame Initialization
        pygame.init()
        caption = "Python Box2D Testbed - " + self.name

        pygame.display.set_caption(caption)

        # Screen and debug draw
        #self.screen = pygame.display.set_mode( (640,480) )
        self.screen = pygame.display.set_mode((1000, 800))
        #       self.screen = pygame.display.set_mode( (1400,800) )

        #        ADDED TO TRY TO DO FULLSCREEN - WORKS, BUT ZOOM IS RESTRICTED TO AREA SPECIFIED ABOVE(?)
        #        screen = pygame.display.get_surface()
        #        w,h = screen.get_width(),screen.get_height()
        #        flags = screen.get_flags()
        #        bits = screen.get_bitsize()

        #        pygame.display.quit()
        #        pygame.display.init()

        #        self.screen = pygame.display.set_mode((w,h),flags^FULLSCREEN,bits)

        self.screenSize = b2Vec2(*self.screen.get_size())

        if self.settings.displayOn == True:
            self.renderer = PygameDraw(surface=self.screen, test=self)
        else:
            self.renderer = None

        self.world.renderer = self.renderer

        try:
            self.font = pygame.font.Font(None, 15)
        except IOError:
            try:
                self.font = pygame.font.Font("freesansbold.ttf", 15)
            except IOError:
                print("Unable to load default font or 'freesansbold.ttf'")
                print("Disabling text drawing.")
                self.Print = lambda *args: 0
                self.DrawStringAt = lambda *args: 0

        # GUI Initialization
        if GUIEnabled:
            self.gui_app = gui.App()
            self.gui_table = fwGUI(self.settings)
            container = gui.Container(align=1, valign=-1)
            container.add(self.gui_table, 0, 0)
            self.gui_app.init(container)

        self.viewCenter = (0, 20.0)
        self.groundbody = self.world.CreateBody()
Пример #2
0
    def __init__(self):
        super(PygameFramework, self).__init__()

        if fwSettings.onlyInit:  # testing mode doesn't initialize pygame
            return

        self.__reset()
        print('Initializing pygame framework...')
        # Pygame Initialization
        pygame.init()
        caption = "Python Box2D Testbed - " + self.name
        pygame.display.set_caption(caption)

        # Screen and debug draw
        self.screen = pygame.display.set_mode((640, 480))
        try:
            pygame.key.set_repeat(self.delay, self.interval)
        except:
            pass
        self.screenSize = b2Vec2(*self.screen.get_size())

        self.renderer = PygameDraw(surface=self.screen, test=self)
        self.world.renderer = self.renderer

        try:
            self.font = pygame.font.Font(None, 15)
        except IOError:
            try:
                self.font = pygame.font.Font("freesansbold.ttf", 15)
            except IOError:
                print("Unable to load default font or 'freesansbold.ttf'")
                print("Disabling text drawing.")
                self.Print = lambda *args: 0
                self.DrawStringAt = lambda *args: 0

        # GUI Initialization
        if GUIEnabled:
            self.gui_app = gui.App()
            self.gui_table = fwGUI(self.settings)
            container = gui.Container(align=1, valign=-1)
            container.add(self.gui_table, 0, 0)
            self.gui_app.init(container)

        self.viewCenter = (0, 20.0)
        self.groundbody = self.world.CreateBody()