Exemple #1
0
    def _create_boundaries(self, thickness):
        """Create boundary walls of given 'thickness'"""
        width, height = self._pixel_size

        walls = [
            ('top', (0 - thickness, 0 - thickness), (width + thickness, 0 - thickness)),
            ('bottom', (0 - thickness, height + thickness), (width + thickness, height + thickness)),
            ('left', (0 - thickness, 0 - thickness), (0 - thickness, height + thickness)),
            ('right', (width + thickness, 0 - thickness), (width + thickness, height + thickness)),
        ]

        for wall_id, top_left, bottom_right in walls:
            wall = BoundaryWall(wall_id, self._space.static_body,
                                top_left, bottom_right, thickness)

            self._space.add(wall.get_shape())
Exemple #2
0
    def scroll(self):
        """Scroll the view along if the player is within SCROLL_RADIUS
        from the edge of the screen.
        """
        # calculate the x distance from the right edge
        x_position = self._player.get_position()[0]
        x_offset = self._view.get_offset()[0]
        screen_size = self._master.winfo_width()
        edge_distance = screen_size - (x_position + x_offset)

        if edge_distance < SCROLL_RADIUS:
            x_position -= 5

            # place a backstop boundary wall on the left side of the screen
            # to prevent the player from going backwards in the game
            world_space = self._world.get_space()
            wall = BoundaryWall("backstop", world_space.static_body,
                                (x_position, 0),
                                (x_position, self._world.get_pixel_size()[1]), 5)
            world_space.add(wall.get_shape())

            # shift the view offset by the screen size
            self._view.shift((-(screen_size - SCROLL_RADIUS), 0))