Esempio n. 1
0
 def __init__(self):
     super(Navigator, self).__init__()
     self._screen = pygame.display.get_surface()
     self._root = Layer(None, (0, 0), (
         self._screen.get_width(), self._screen.get_height()
     ))
     self.add(self._root)
     self._stack = []
Esempio n. 2
0
    def __init__(self):
        RESOLUTION = (800, 600)
        res_width, res_height = RESOLUTION
        super(SandBox, self).__init__(camera_config={
            'target': (5.0, 3.5),
            'width':
            15.0,
            'rect':
            Rect((10, 10), (res_width - 20, res_height - 20)),
            'limits': {
                'left': 0.0,
                'bottom': 0.0,
                'right': 70.0,
                'top': 10.0
            }
        },
                                      gravity=(0, 0))
        self.listen('quit')

        # Add background (filled with skyblue)
        self.add_layer(
            Layer(position=(0, 0), size=RESOLUTION).fill('005656'),
            self.BACKGROUND)

        self.loader().load_package('static')
        j1 = 1
        j2 = 5
        for i in range(50):
            self.add_chunk(
                Fence((i * 0.49, 2.0 + j1), (0.5, 0.5), 'static.brick'),
                self.PLATFORM)
            self.add_chunk(
                Fence((i * 0.49, 2.0 + j2), (0.5, 0.5), 'static.brick'),
                self.PLATFORM)

        # BulletML test
        target = bulletml.Bullet()
        path = os.path.join(os.path.dirname(__file__), 'python-bulletml-2',
                            'examples', 'normal', 'threefire.xml')
        self._bulletml = bulletml.BulletML.FromDocument(open(path, "rU"))
        source = bulletml.Bullet.FromDocument(self._bulletml,
                                              x=150,
                                              y=150,
                                              target=target,
                                              rank=0.5)
        self._bullets = [source]

        self.loader().load_package('ship')
        self.loader().load_package('bullet')

        self._ship = Ship(position=(1.5, 4.0), size=(1.0, 0.5), level=self)
        self.add_chunk(self._ship, self.SPRITES)

        self.world().camera().watch(self._ship)
Esempio n. 3
0
class Navigator(EventDispatcher):

    _current_view = None

    def __init__(self):
        super(Navigator, self).__init__()
        self._screen = pygame.display.get_surface()
        self._root = Layer(None, (0, 0), (
            self._screen.get_width(), self._screen.get_height()
        ))
        self.add(self._root)
        self._stack = []

    def current_view(self):
        return self._current_view

    def push(self, view):
        if self._current_view:
            self._stack.append(self._current_view)
        self.set_current_view(view)

    def pop(self):
        if len(self._stack):
            self.set_current_view(self._stack.pop())

    def set_current_view(self, view):
        if self._current_view:
            self._root.remove_layer(self._current_view)
        self._root.add_layer(view)
        self._current_view = view
        self._current_view.set_navigator(self)

    def on_frame(self, delta):
        super(Navigator, self).on_frame(delta)
        if self._current_view:
            self._current_view
        pygame.display.flip()