コード例 #1
0
def create_floor(space, sprite_list):
    """ Create a bunch of blocks for the floor. """
    for x in range(-1000, 2000, SPRITE_SIZE):
        y = SPRITE_SIZE / 2
        sprite = PymunkSprite(":resources:images/tiles/grassMid.png", x, y, scale=0.5, body_type=pymunk.Body.STATIC)
        sprite_list.append(sprite)
        space.add(sprite.body, sprite.shape)
コード例 #2
0
def create_platform(space, sprite_list, start_x, y, count):
    """ Create a platform """
    for x in range(start_x, start_x + count * SPRITE_SIZE + 1, SPRITE_SIZE):
        sprite = PymunkSprite("../images/grassMid.png",
                              x,
                              y,
                              scale=0.5,
                              body_type=pymunk.Body.STATIC)
        sprite_list.append(sprite)
        space.add(sprite.body, sprite.shape)
    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        # Set the working directory (where we expect to find files) to the same
        # directory this .py file is in. You can leave this out of your own
        # code, but it is needed to easily run the examples using "python -m"
        # as mentioned at the top of this program.
        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)

        arcade.set_background_color(arcade.color.DARK_SLATE_GRAY)

        # -- Pymunk
        self.space = pymunk.Space()
        self.space.gravity = GRAVITY

        # Physics joint used for grabbing items
        self.grab_joint = None

        # Lists of sprites
        self.dynamic_sprite_list = arcade.SpriteList[PymunkSprite]()
        self.static_sprite_list = arcade.SpriteList()

        # Used for dragging shapes around with the mouse
        self.shape_being_dragged = None
        self.last_mouse_position = 0, 0

        # Draw and processing timings
        self.draw_time = 0
        self.processing_time = 0

        # Current force applied to the player for movement by keyboard
        self.force = (0, 0)

        # Set the viewport boundaries
        # These numbers set where we have 'scrolled' to.
        self.view_left = 0
        self.view_bottom = 0

        create_level_1(self.space, self.static_sprite_list,
                       self.dynamic_sprite_list)

        # Create player
        x = 50
        y = (SPRITE_SIZE + SPRITE_SIZE / 2)
        self.player = PymunkSprite(
            ":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png",
            x,
            y,
            scale=0.5,
            moment=pymunk.inf,
            mass=1)
        self.dynamic_sprite_list.append(self.player)
        self.space.add(self.player.body, self.player.shape)
コード例 #4
0
def create_level_1(space, static_sprite_list, dynamic_sprite_list):
    """ Create level one. """
    create_floor(space, static_sprite_list)
    create_platform(space, static_sprite_list, 200, SPRITE_SIZE * 3, 3)
    create_platform(space, static_sprite_list, 500, SPRITE_SIZE * 6, 3)
    create_platform(space, static_sprite_list, 200, SPRITE_SIZE * 9, 3)

    # Create the stacks of boxes
    for column in range(6):
        for row in range(column):
            x = 600 + column * SPRITE_SIZE
            y = (3 * SPRITE_SIZE / 2) + row * SPRITE_SIZE
            sprite = PymunkSprite(":resources:images/tiles/boxCrate_double.png", x, y, scale=0.5, friction=0.4)
            dynamic_sprite_list.append(sprite)
            space.add(sprite.body, sprite.shape)