Ejemplo n.º 1
0
def render_toolbar_icons():
    img_names = ["PREV FRM", "UNDO", "DEL FRM", "LOAD SCN"]
    index = 0
    for img_name in img_names:
        try:
            background_texture = arcadeplus.load_texture("res/icons/" +
                                                         img_name + ".png")
            arcadeplus.draw_texture_rectangle(center_x=925,
                                              center_y=625 - (index * 50),
                                              width=40,
                                              height=40,
                                              texture=background_texture)
        except:
            pass
        index += 1
    img_names = ["NEXT FRM", "CLR FRM", "NEW FRM", "NEW SCN"]
    index = 0
    for img_name in img_names:
        try:
            background_texture = arcadeplus.load_texture("res/icons/" +
                                                         img_name + ".png")
            arcadeplus.draw_texture_rectangle(center_x=975,
                                              center_y=625 - (index * 50),
                                              width=40,
                                              height=40,
                                              texture=background_texture)
        except:
            pass
        index += 1
Ejemplo n.º 2
0
    def setup_level_one(self):
        # Load the textures for the enemies, one facing left, one right
        self.enemy_textures = []
        texture = arcadeplus.load_texture(
            ":resources:images/enemies/slimeBlue.png", mirrored=True)
        self.enemy_textures.append(texture)
        texture = arcadeplus.load_texture(
            ":resources:images/enemies/slimeBlue.png")
        self.enemy_textures.append(texture)

        # Create rows and columns of enemies
        x_count = 7
        x_start = 380
        x_spacing = 60
        y_count = 5
        y_start = 420
        y_spacing = 40
        for x in range(x_start, x_spacing * x_count + x_start, x_spacing):
            for y in range(y_start, y_spacing * y_count + y_start, y_spacing):

                # Create the enemy instance
                # enemy image from kenney.nl
                enemy = arcadeplus.Sprite()
                enemy.scale = SPRITE_SCALING_enemy
                enemy.texture = self.enemy_textures[1]

                # Position the enemy
                enemy.center_x = x
                enemy.center_y = y

                # Add the enemy to the lists
                self.enemy_list.append(enemy)
Ejemplo n.º 3
0
def test_calculate_points():
    texture = arcadeplus.load_texture(":resources:images/items/coinGold.png")
    result = arcadeplus.calculate_points(texture.image)
    print(result)

    texture = arcadeplus.load_texture(":resources:images/animated_characters/female_person/femalePerson_idle.png")
    result = arcadeplus.calculate_points(texture.image)
    print(result)
Ejemplo n.º 4
0
def load_texture_pair(filename):
    """
    Load a texture pair, with the second being a mirror image.
    """
    return [
        arcadeplus.load_texture(filename),
        arcadeplus.load_texture(filename, mirrored=True)
    ]
Ejemplo n.º 5
0
    def __init__(self):

        # Set up parent class
        super().__init__()

        # Default to face-right
        self.character_face_direction = RIGHT_FACING

        # Used for flipping between image sequences
        self.cur_texture = 0
        self.scale = CHARACTER_SCALING

        # Track our state
        self.jumping = False
        self.climbing = False
        self.is_on_ladder = False

        # --- Load Textures ---

        # Images from Kenney.nl's Asset Pack 3
        # main_path = ":resources:images/animated_characters/female_adventurer/femaleAdventurer"
        # main_path = ":resources:images/animated_characters/female_person/femalePerson"
        main_path = ":resources:images/animated_characters/male_person/malePerson"
        # main_path = ":resources:images/animated_characters/male_adventurer/maleAdventurer"
        # main_path = ":resources:images/animated_characters/zombie/zombie"
        # main_path = ":resources:images/animated_characters/robot/robot"

        # Load textures for idle standing
        self.idle_texture_pair = load_texture_pair(f"{main_path}_idle.png")
        self.jump_texture_pair = load_texture_pair(f"{main_path}_jump.png")
        self.fall_texture_pair = load_texture_pair(f"{main_path}_fall.png")

        # Load textures for walking
        self.walk_textures = []
        for i in range(8):
            texture = load_texture_pair(f"{main_path}_walk{i}.png")
            self.walk_textures.append(texture)

        # Load textures for climbing
        self.climbing_textures = []
        texture = arcadeplus.load_texture(f"{main_path}_climb0.png")
        self.climbing_textures.append(texture)
        texture = arcadeplus.load_texture(f"{main_path}_climb1.png")
        self.climbing_textures.append(texture)

        # Set the initial texture
        self.texture = self.idle_texture_pair[0]

        # Hit box will be set based on the first image used. If you want to specify
        # a different hit box, you can do it like the code below.
        # self.set_hit_box([[-22, -64], [22, -64], [22, 28], [-22, 28]])
        self.set_hit_box(self.texture.hit_box_points)
Ejemplo n.º 6
0
    def setup(self):
        """ Setup """
        self.ship = arcadeplus.Sprite(
            ":resources:images/space_shooter/playerShip1_orange.png", 0.5)
        self.ship.center_x = SCREEN_WIDTH / 2
        self.ship.center_y = SCREEN_HEIGHT / 2
        self.ship.angle = 270
        self.stars = arcadeplus.load_texture(
            ":resources:images/backgrounds/stars.png")
        self.xy_square = arcadeplus.load_texture(
            ":resources:images/test_textures/xy_square.png")

        # Set the background color
        arcadeplus.set_background_color(arcadeplus.color.BLACK)
Ejemplo n.º 7
0
def on_draw():
    global toolbar, frames, current_frame, linked_scenes

    # Render entire toolbar, all user-drawn shapes
    arcadeplus.start_render()

    if (current_frame - 1) in linked_scenes.keys():
        background_texture = arcadeplus.load_texture(
            "data/scenes/" + linked_scenes[current_frame - 1] + ".png")
        arcadeplus.draw_texture_rectangle(center_x=500,
                                          center_y=400,
                                          width=800,
                                          height=800,
                                          texture=background_texture)
    try:
        frames[current_frame - 1].draw()
    except Exception as e:
        pass
    try:
        toolbar.draw()
    except Exception as e:
        pass

    render_toolbar_icons()
    render_toolbar_text()
Ejemplo n.º 8
0
    def __init__(self):
        super().__init__()

        self.textures = []
        # Load a left facing texture and a right facing texture.
        # mirrored=True will mirror the image we load.
        texture = arcadeplus.load_texture(":resources:images/enemies/bee.png")
        self.textures.append(texture)
        texture = arcadeplus.load_texture(":resources:images/enemies/bee.png",
                                          mirrored=True)
        self.textures.append(texture)

        self.scale = SPRITE_SCALING

        # By default, face right.
        self.set_texture(TEXTURE_RIGHT)
Ejemplo n.º 9
0
    def setup(self):
        """ Set up the game and initialize the variables. """

        # Load the background image. Do this in the setup so we don't keep reloading it all the time.
        # Image from:
        # http://wallpaper-gallery.net/single/free-background-images/free-background-images-22.html
        self.background = arcadeplus.load_texture(
            ":resources:images/backgrounds/abstract_1.jpg")

        # Sprite lists
        self.player_list = arcadeplus.SpriteList()
        self.coin_list = arcadeplus.SpriteList()

        # Set up the player
        self.score = 0
        self.player_sprite = arcadeplus.Sprite(
            ":resources:images/animated_characters/female_person/femalePerson_idle.png",
            PLAYER_SCALING)
        self.player_sprite.center_x = 50
        self.player_sprite.center_y = 50
        self.player_list.append(self.player_sprite)

        for i in range(50):

            # Create the coin instance
            coin = arcadeplus.Sprite(":resources:images/items/coinGold.png",
                                     COIN_SCALING)

            # Position the coin
            coin.center_x = random.randrange(SCREEN_WIDTH)
            coin.center_y = random.randrange(SCREEN_HEIGHT)

            # Add the coin to the lists
            self.coin_list.append(coin)
Ejemplo n.º 10
0
    def on_update(self, delta_time):
        """ Movement and game logic """

        # Call update on all sprites (The sprites don't do much in this
        # example though.)
        self.player_list.update()
        self.coin_list.update()

        # Generate a list of all sprites that collided with the player.
        hit_list = arcadeplus.check_for_collision_with_list(
            self.player_sprite, self.coin_list)

        # Loop through each colliding sprite, change it, and add to the score.
        for coin in hit_list:
            # Have we collected this?
            if not coin.changed:
                # No? Then do so
                coin.append_texture(
                    arcadeplus.load_texture(
                        ":resources:images/pinball/bumper.png"))
                coin.set_texture(1)
                coin.changed = True
                coin.width = 30
                coin.height = 30
                self.score += 1
Ejemplo n.º 11
0
    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        arcadeplus.set_background_color(arcadeplus.color.AMAZON)

        self.texture = arcadeplus.load_texture(
            ":resources:images/items/coinGold.png")
Ejemplo n.º 12
0
    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        arcadeplus.set_background_color(arcadeplus.color.AMAZON)

        self.texture = arcadeplus.load_texture(
            ":resources:images/space_shooter/playerShip1_orange.png")
        assert self.texture.width == 99
        assert self.texture.height == 75

        self.circle_texture = arcadeplus.make_circle_texture(
            10, arcadeplus.color.RED)
        self.soft_circle_texture = arcadeplus.make_soft_circle_texture(
            10, arcadeplus.color.RED, 255, 0)
        self.soft_square_texture = arcadeplus.make_soft_square_texture(
            10, arcadeplus.color.RED, 255, 0)

        columns = 16
        count = 60
        sprite_width = 256
        sprite_height = 256
        file_name = ":resources:images/spritesheets/explosion.png"

        # Load the explosions from a sprite sheet
        self.explosion_texture_list = arcadeplus.load_spritesheet(
            file_name, sprite_width, sprite_height, columns, count)
Ejemplo n.º 13
0
    def __init__(self):
        """
        Initializer
        """
        # Open a window in full screen mode. Remove fullscreen=True if
        # you don't want to start this way.
        super().__init__(SCREEN_WIDTH,
                         SCREEN_HEIGHT,
                         SCREEN_TITLE,
                         fullscreen=True)

        # 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)

        # This will get the size of the window, and set the viewport to match.
        # So if the window is 1000x1000, then so will our viewport. If
        # you want something different, then use those coordinates instead.
        width, height = self.get_size()
        self.set_viewport(0, width, 0, height)
        arcadeplus.set_background_color(arcadeplus.color.AMAZON)
        self.example_image = arcadeplus.load_texture(
            ":resources:images/tiles/boxCrate_double.png")
Ejemplo n.º 14
0
    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)

        arcadeplus.set_background_color(arcadeplus.color.AMAZON)

        self.texture = arcadeplus.load_texture(
            ":resources:images/space_shooter/playerShip1_orange.png")
Ejemplo n.º 15
0
def main():
    arcadeplus.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, TITLE)
    arcadeplus.set_background_color(BACKGROUND_COLOR)
    arcadeplus.start_render()
    arcadeplus.draw_circle_filled(400, 250, 100, arcadeplus.color.BLACK)
    # load image
    image = arcadeplus.load_texture(resource_path('character.png'))
    arcadeplus.draw_texture_rectangle(200, 250, image.width, image.height,
                                      image)
    # load sound
    sound = arcadeplus.sound.load_sound(resource_path('cat-meow.wav'))
    arcadeplus.sound.play_sound(sound)
    arcadeplus.finish_render()
    arcadeplus.run()
    return
Ejemplo n.º 16
0
def setup_room_1():
    """
    Create and return room 1.
    If your program gets large, you may want to separate this into different
    files.
    """
    room = Room()

    """ Set up the game and initialize the variables. """
    # Sprite lists
    room.wall_list = arcadeplus.SpriteList()

    # -- Set up the walls
    # Create bottom and top row of boxes
    # This y loops a list of two, the coordinate 0, and just under the top of window
    for y in (0, SCREEN_HEIGHT - SPRITE_SIZE):
        # Loop for each box going across
        for x in range(0, SCREEN_WIDTH, SPRITE_SIZE):
            wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING)
            wall.left = x
            wall.bottom = y
            room.wall_list.append(wall)

    # Create left and right column of boxes
    for x in (0, SCREEN_WIDTH - SPRITE_SIZE):
        # Loop for each box going across
        for y in range(SPRITE_SIZE, SCREEN_HEIGHT - SPRITE_SIZE, SPRITE_SIZE):
            # Skip making a block 4 and 5 blocks up on the right side
            if (y != SPRITE_SIZE * 4 and y != SPRITE_SIZE * 5) or x == 0:
                wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING)
                wall.left = x
                wall.bottom = y
                room.wall_list.append(wall)

    wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING)
    wall.left = 7 * SPRITE_SIZE
    wall.bottom = 5 * SPRITE_SIZE
    room.wall_list.append(wall)

    # If you want coins or monsters in a level, then add that code here.

    # Load the background image for this level.
    room.background = arcadeplus.load_texture(":resources:images/backgrounds/abstract_1.jpg")

    return room
Ejemplo n.º 17
0
def setup_room_2():
    """
    Create and return room 2.
    """
    room = Room()

    """ Set up the game and initialize the variables. """
    # Sprite lists
    room.wall_list = arcadeplus.SpriteList()

    # -- Set up the walls
    # Create bottom and top row of boxes
    # This y loops a list of two, the coordinate 0, and just under the top of window
    for y in (0, SCREEN_HEIGHT - SPRITE_SIZE):
        # Loop for each box going across
        for x in range(0, SCREEN_WIDTH, SPRITE_SIZE):
            wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING)
            wall.left = x
            wall.bottom = y
            room.wall_list.append(wall)

    # Create left and right column of boxes
    for x in (0, SCREEN_WIDTH - SPRITE_SIZE):
        # Loop for each box going across
        for y in range(SPRITE_SIZE, SCREEN_HEIGHT - SPRITE_SIZE, SPRITE_SIZE):
            # Skip making a block 4 and 5 blocks up
            if (y != SPRITE_SIZE * 4 and y != SPRITE_SIZE * 5) or x != 0:
                wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING)
                wall.left = x
                wall.bottom = y
                room.wall_list.append(wall)

    wall = arcadeplus.Sprite(":resources:images/tiles/boxCrate_double.png", SPRITE_SCALING)
    wall.left = 5 * SPRITE_SIZE
    wall.bottom = 6 * SPRITE_SIZE
    room.wall_list.append(wall)
    room.background = arcadeplus.load_texture(":resources:images/backgrounds/abstract_2.jpg")

    return room
Ejemplo n.º 18
0
    def setup(self):
        self.player_list = arcadeplus.SpriteList()
        self.coin_list = arcadeplus.SpriteList()

        # Set up the player
        self.score = 0
        self.player = PlayerCharacter()

        self.player.center_x = SCREEN_WIDTH // 2
        self.player.center_y = SCREEN_HEIGHT // 2
        self.player.scale = 0.8

        self.player_list.append(self.player)

        for i in range(COIN_COUNT):
            coin = arcadeplus.AnimatedTimeSprite(scale=0.5)
            coin.center_x = random.randrange(SCREEN_WIDTH)
            coin.center_y = random.randrange(SCREEN_HEIGHT)

            coin.textures = []
            coin.textures.append(
                arcadeplus.load_texture(":resources:images/items/gold_1.png"))
            coin.textures.append(
                arcadeplus.load_texture(":resources:images/items/gold_2.png"))
            coin.textures.append(
                arcadeplus.load_texture(":resources:images/items/gold_3.png"))
            coin.textures.append(
                arcadeplus.load_texture(":resources:images/items/gold_4.png"))
            coin.textures.append(
                arcadeplus.load_texture(":resources:images/items/gold_3.png"))
            coin.textures.append(
                arcadeplus.load_texture(":resources:images/items/gold_2.png"))
            coin.scale = COIN_SCALE
            coin.cur_texture_index = random.randrange(len(coin.textures))

            self.coin_list.append(coin)

        # Set the background color
        arcadeplus.set_background_color(arcadeplus.color.AMAZON)
Ejemplo n.º 19
0
    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)

        self.frame_count = 0
        arcadeplus.set_background_color(arcadeplus.color.AMAZON)

        self.character_list = arcadeplus.SpriteList()

        self.player = arcadeplus.AnimatedWalkingSprite()

        self.player.stand_right_textures = [
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_idle.png")
        ]

        self.player.stand_left_textures = [
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_idle.png",
                mirrored=True)
        ]

        self.player.walk_right_textures = [
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk0.png"),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk1.png"),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk2.png"),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk3.png"),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk4.png"),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk5.png"),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk6.png"),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk7.png")
        ]

        self.player.walk_left_textures = [
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk0.png",
                mirrored=True),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk1.png",
                mirrored=True),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk2.png",
                mirrored=True),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk3.png",
                mirrored=True),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk4.png",
                mirrored=True),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk5.png",
                mirrored=True),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk6.png",
                mirrored=True),
            arcadeplus.load_texture(
                ":resources:images/animated_characters/robot/robot_walk7.png",
                mirrored=True)
        ]

        self.player.texture_change_distance = 20

        self.player.center_x = SCREEN_WIDTH // 2
        self.player.center_y = SCREEN_HEIGHT // 2
        self.player.scale = 0.8
        self.player.change_x = 2
        self.player.texture = self.player.stand_left_textures[0]

        self.character_list.append(self.player)

        self.coin_list = arcadeplus.SpriteList()

        coin = arcadeplus.AnimatedTimeSprite(scale=0.5)
        coin.center_x = 500
        coin.center_y = 500

        coin.textures = []
        coin.textures.append(
            arcadeplus.load_texture(":resources:images/items/gold_1.png"))
        coin.textures.append(
            arcadeplus.load_texture(":resources:images/items/gold_2.png"))
        coin.textures.append(
            arcadeplus.load_texture(":resources:images/items/gold_3.png"))
        coin.textures.append(
            arcadeplus.load_texture(":resources:images/items/gold_4.png"))
        coin.textures.append(
            arcadeplus.load_texture(":resources:images/items/gold_3.png"))
        coin.textures.append(
            arcadeplus.load_texture(":resources:images/items/gold_2.png"))
        coin.scale = COIN_SCALE
        coin.set_texture(0)
        self.coin_list.append(coin)
Ejemplo n.º 20
0
 def add_menu_texture(self, menu_texture):
     self.menu_texture = arcadeplus.load_texture(menu_texture)
Ejemplo n.º 21
0
 def add_button_textures(self, normal, hover="", clicked="", locked=""):
     self.button_textures['normal'] = arcadeplus.load_texture(normal)
     self.button_textures['hover'] = arcadeplus.load_texture(hover)
     self.button_textures['clicked'] = arcadeplus.load_texture(clicked)
     self.button_textures['locked'] = arcadeplus.load_texture(locked)
Ejemplo n.º 22
0
def _create_sprite_from_tile(map_object: pytiled_parser.objects.TileMap,
                             tile: pytiled_parser.objects.Tile,
                             scaling: float = 1.0,
                             base_directory: str = None):
    """
    Given a tile from the parser, see if we can create a sprite from it
    """

    # --- Step 1, find a reference to an image this is going to be based off of
    map_source = map_object.tmx_file
    map_directory = os.path.dirname(map_source)
    image_file = _get_image_source(tile, base_directory, map_directory)

    # print(f"Creating tile: {tmx_file}")
    if tile.animation:
        # my_sprite = AnimatedTimeSprite(tmx_file, scaling)
        my_sprite: Sprite = AnimatedTimeBasedSprite(image_file, scaling)
    else:
        image_x, image_y, width, height = _get_image_info_from_tileset(tile)

        my_sprite = Sprite(image_file, scaling, image_x, image_y, width,
                           height)

    if tile.properties is not None and len(tile.properties) > 0:
        for my_property in tile.properties:
            my_sprite.properties[my_property.name] = my_property.value

        # print(tile.image.source, my_sprite.center_x, my_sprite.center_y)
    if tile.objectgroup is not None:

        if len(tile.objectgroup) > 1:
            print(
                f"Warning, only one hit box supported for tile with image {tile.image.source}."
            )

        for hitbox in tile.objectgroup:
            points: List[Point] = []
            if isinstance(hitbox, pytiled_parser.objects.RectangleObject):
                if hitbox.size is None:
                    print(
                        f"Warning: Rectangle hitbox created for without a "
                        f"height or width for {tile.image.source}. Ignoring.")
                    continue

                # print(my_sprite.width, my_sprite.height)
                sx = hitbox.location[0] - (my_sprite.width / (scaling * 2))
                sy = -(hitbox.location[1] - (my_sprite.height / (scaling * 2)))
                ex = (hitbox.location[0] + hitbox.size[0]) - (my_sprite.width /
                                                              (scaling * 2))
                ey = -((hitbox.location[1] + hitbox.size[1]) -
                       (my_sprite.height / (scaling * 2)))

                # print(f"Size: {hitbox.size} Location: {hitbox.location}")
                p1 = [sx, sy]
                p2 = [ex, sy]
                p3 = [ex, ey]
                p4 = [sx, ey]
                # print(f"w:{my_sprite.width:.1f}, h:{my_sprite.height:.1f}", end=", ")
                points = [p1, p2, p3, p4]
                # for point in points:
                #     print(f"({point[0]:.1f}, {point[1]:.1f}) ")
                # print()

            elif isinstance(hitbox, pytiled_parser.objects.PolygonObject) \
                    or isinstance(hitbox, pytiled_parser.objects.PolylineObject):
                for point in hitbox.points:
                    adj_x = point[0] + hitbox.location[0] - my_sprite.width / (
                        scaling * 2)
                    adj_y = -(point[1] + hitbox.location[1] -
                              my_sprite.height / (scaling * 2))
                    adj_point = [adj_x, adj_y]
                    points.append(adj_point)

                # If we have a polyline, and it is closed, we need to
                # remove the duplicate end-point
                if points[0][0] == points[-1][0] and points[0][1] == points[
                        -1][1]:
                    points.pop()

            elif isinstance(hitbox, pytiled_parser.objects.ElipseObject):
                if hitbox.size is None:
                    print(
                        f"Warning: Ellipse hitbox created for without a height "
                        f"or width for {tile.image.source}. Ignoring.")
                    continue

                # print(f"Size: {hitbox.size} Location: {hitbox.location}")

                hw = hitbox.size[0] / 2
                hh = hitbox.size[1] / 2
                cx = hitbox.location[0] + hw
                cy = hitbox.location[1] + hh

                acx = cx - (my_sprite.width / (scaling * 2))
                acy = cy - (my_sprite.height / (scaling * 2))

                # print(f"acx: {acx} acy: {acy} cx: {cx} cy: {cy} hh: {hh} hw: {hw}")

                total_steps = 8
                angles = [
                    step / total_steps * 2 * math.pi
                    for step in range(total_steps)
                ]
                for angle in angles:
                    x = (hw * math.cos(angle) + acx)
                    y = (-(hh * math.sin(angle) + acy))
                    point = [x, y]
                    points.append(point)

                # for point in points:
                #     print(f"({point[0]:.1f}, {point[1]:.1f}) ")
                # print()

            else:
                print(f"Warning: Hitbox type {type(hitbox)} not supported.")

            my_sprite.points = points

    if tile.animation is not None:
        # Animated image
        key_frame_list = []
        # Loop through each frame
        for frame in tile.animation:
            # Get the tile for the frame
            frame_tile = _get_tile_by_id(map_object, tile.tileset,
                                         frame.tile_id)
            if frame_tile:

                image_file = _get_image_source(frame_tile, base_directory,
                                               map_directory)

                # Does the tile have an image?
                if frame_tile.image:
                    # Yes, use it
                    texture = load_texture(image_file)
                else:
                    # No image for tile? Pull from tilesheet
                    image_x, image_y, width, height = _get_image_info_from_tileset(
                        frame_tile)

                    texture = load_texture(image_file, image_x, image_y, width,
                                           height)

                key_frame = AnimationKeyframe(frame.tile_id, frame.duration,
                                              texture)
                key_frame_list.append(key_frame)
                # If this is the first texture in the animation, go ahead and
                # set it as the current texture.
                if len(key_frame_list) == 1:
                    my_sprite.texture = key_frame.texture
                # print(f"Add tile {frame.tile_id} for keyframe. Source: {frame_tile.image.source}")

        cast(AnimatedTimeBasedSprite, my_sprite).frames = key_frame_list

    return my_sprite
Ejemplo n.º 23
0
 def add_text_box_texture(self, text_box_texture):
     self.text_box_texture = arcadeplus.load_texture(text_box_texture)
Ejemplo n.º 24
0
 def add_dialogue_box_texture(self, dialogue_box_texture):
     self.dialogue_box_texture = arcadeplus.load_texture(
         dialogue_box_texture)
Ejemplo n.º 25
0
    def on_draw(self):
        """
        Render the screen.
        """

        # Start the render process. This must be done before any drawing commands.
        arcadeplus.start_render()

        # Draw a grid
        # Draw vertical lines every 120 pixels
        for x in range(0, 601, 120):
            arcadeplus.draw_line(x, 0, x, 600, arcadeplus.color.BLACK, 2)

        # Draw horizontal lines every 200 pixels
        for y in range(0, 601, 200):
            arcadeplus.draw_line(0, y, 800, y, arcadeplus.color.BLACK, 2)

        # Draw a point
        arcadeplus.draw_text("draw_point", 3, 405, arcadeplus.color.BLACK, 12)
        arcadeplus.draw_point(60, 495, arcadeplus.color.RED, 10)

        # Draw a set of points
        arcadeplus.draw_text("draw_points", 123, 405, arcadeplus.color.BLACK,
                             12)
        point_list = ((165, 495), (165, 480), (165, 465), (195, 495),
                      (195, 480), (195, 465))
        arcadeplus.draw_points(point_list, arcadeplus.color.ZAFFRE, 10)

        # Draw a line
        arcadeplus.draw_text("draw_line", 243, 405, arcadeplus.color.BLACK, 12)
        arcadeplus.draw_line(270, 495, 300, 450, arcadeplus.color.WOOD_BROWN,
                             3)

        # Draw a set of lines
        arcadeplus.draw_text("draw_lines", 363, 405, arcadeplus.color.BLACK,
                             12)
        point_list = ((390, 450), (450, 450), (390, 480), (450, 480),
                      (390, 510), (450, 510))
        arcadeplus.draw_lines(point_list, arcadeplus.color.BLUE, 3)

        # Draw a line strip
        arcadeplus.draw_text("draw_line_strip", 483, 405,
                             arcadeplus.color.BLACK, 12)
        point_list = ((510, 450), (570, 450), (510, 480), (570, 480),
                      (510, 510), (570, 510))
        arcadeplus.draw_line_strip(point_list,
                                   arcadeplus.color.TROPICAL_RAIN_FOREST, 3)
        arcadeplus.draw_line_strip(point_list, arcadeplus.color.BEIGE)

        # Draw a polygon
        arcadeplus.draw_text("draw_polygon_outline", 3, 207,
                             arcadeplus.color.BLACK, 9)
        point_list = ((30, 240), (45, 240), (60, 255), (60, 285), (45, 300),
                      (30, 300))
        arcadeplus.draw_polygon_outline(point_list,
                                        arcadeplus.color.SPANISH_VIOLET, 3)

        # Draw a filled in polygon
        arcadeplus.draw_text("draw_polygon_filled", 123, 207,
                             arcadeplus.color.BLACK, 9)
        point_list = ((150, 240), (165, 240), (180, 255), (180, 285),
                      (165, 300), (150, 300))
        arcadeplus.draw_polygon_filled(point_list,
                                       arcadeplus.color.SPANISH_VIOLET)

        # Draw an outline of a circle
        arcadeplus.draw_text("draw_circle_outline", 243, 207,
                             arcadeplus.color.BLACK, 10)
        arcadeplus.draw_circle_outline(300, 285, 18, arcadeplus.color.WISTERIA,
                                       3)
        arcadeplus.draw_circle_outline(350, 285, 18, arcadeplus.color.WISTERIA)

        # Draw a filled in circle
        arcadeplus.draw_text("draw_circle_filled", 363, 207,
                             arcadeplus.color.BLACK, 10)
        arcadeplus.draw_circle_filled(420, 285, 18, arcadeplus.color.GREEN)

        # Draw an ellipse outline, and another one rotated
        arcadeplus.draw_text("draw_ellipse_outline", 483, 207,
                             arcadeplus.color.BLACK, 10)
        arcadeplus.draw_ellipse_outline(540, 273, 15, 36,
                                        arcadeplus.color.AMBER, 3)
        arcadeplus.draw_ellipse_outline(540, 336, 15, 36,
                                        arcadeplus.color.BLACK_BEAN, 3, 45)

        # Draw a filled ellipse, and another one rotated
        arcadeplus.draw_text("draw_ellipse_filled", 3, 3,
                             arcadeplus.color.BLACK, 10)
        arcadeplus.draw_ellipse_filled(60, 81, 15, 36, arcadeplus.color.AMBER)
        arcadeplus.draw_ellipse_filled(60, 144, 15, 36,
                                       arcadeplus.color.BLACK_BEAN, 45)

        # Draw an arc, and another one rotated
        arcadeplus.draw_text("draw_arc/filled_arc", 123, 3,
                             arcadeplus.color.BLACK, 10)
        arcadeplus.draw_arc_outline(150, 81, 15, 36,
                                    arcadeplus.color.BRIGHT_MAROON, 90, 360)
        arcadeplus.draw_arc_filled(150, 144, 15, 36,
                                   arcadeplus.color.BOTTLE_GREEN, 90, 360, 45)

        # Draw an rectangle outline
        arcadeplus.draw_text("draw_rect", 243, 3, arcadeplus.color.BLACK, 10)
        arcadeplus.draw_rectangle_outline(
            295, 100, 45, 65, arcadeplus.color.BRITISH_RACING_GREEN)
        arcadeplus.draw_rectangle_outline(
            295, 160, 20, 45, arcadeplus.color.BRITISH_RACING_GREEN, 3, 45)

        # Draw a filled in rectangle
        arcadeplus.draw_text("draw_filled_rect", 363, 3,
                             arcadeplus.color.BLACK, 10)
        arcadeplus.draw_rectangle_filled(420, 100, 45, 65,
                                         arcadeplus.color.BLUSH)
        arcadeplus.draw_rectangle_filled(420, 160, 20, 40,
                                         arcadeplus.color.BLUSH, 45)

        # Load and draw an image to the screen
        # Image from kenney.nl asset pack #1
        arcadeplus.draw_text("draw_bitmap", 483, 3, arcadeplus.color.BLACK, 12)
        texture = arcadeplus.load_texture(
            ":resources:images/space_shooter/playerShip1_orange.png")
        scale = .6
        # arcadeplus.draw_texture_rectangle(540, 120, scale * texture.width,
        #                               scale * texture.height, texture, 0)
        # arcadeplus.draw_texture_rectangle(540, 60, scale * texture.width,
        #                               scale * texture.height, texture, 45)
        #
        # Overlapping, with transparency test
        # Draw
        arcadeplus.draw_rectangle_filled(650, 100, 50, 50, (255, 0, 0))
        arcadeplus.draw_rectangle_filled(670, 100, 50, 50, (0, 255, 0, 127))

        # Test colors
        color = arcadeplus.get_pixel(635, 100)
        assert color == (255, 0, 0)
        color = arcadeplus.get_pixel(670, 100)
        assert color == (128, 127, 0)
        color = arcadeplus.get_pixel(690, 100)
        assert color == (128, 255, 128)

        # Test this other thing
        color = arcadeplus.get_pixel(100, 100)
        assert color == (255, 255, 255)

        # Run the get image. Ideally we'd test the output
        arcadeplus.get_image()
Ejemplo n.º 26
0
 def add_window_texture(self, window_texture):
     self.window_texture = arcadeplus.load_texture(window_texture)
Ejemplo n.º 27
0
                           360, 45)

# Draw an rectangle outline
arcadeplus.draw_text("draw_rect", 243, 3, arcadeplus.color.BLACK, 10)
arcadeplus.draw_rectangle_outline(295, 100, 45, 65,
                                  arcadeplus.color.BRITISH_RACING_GREEN)
arcadeplus.draw_rectangle_outline(295, 160, 20, 45,
                                  arcadeplus.color.BRITISH_RACING_GREEN, 3, 45)

# Draw a filled in rectangle
arcadeplus.draw_text("draw_filled_rect", 363, 3, arcadeplus.color.BLACK, 10)
arcadeplus.draw_rectangle_filled(420, 100, 45, 65, arcadeplus.color.BLUSH)
arcadeplus.draw_rectangle_filled(420, 160, 20, 40, arcadeplus.color.BLUSH, 45)

# Load and draw an image to the screen
# Image from kenney.nl asset pack #1
arcadeplus.draw_text("draw_bitmap", 483, 3, arcadeplus.color.BLACK, 12)
texture = arcadeplus.load_texture(
    ":resources:images/space_shooter/playerShip1_orange.png")
scale = .6
arcadeplus.draw_scaled_texture_rectangle(540, 120, texture, scale, 0)
arcadeplus.draw_scaled_texture_rectangle(540, 60, texture, scale, 45)

# Finish the render.
# Nothing will be drawn without this.
# Must happen after all draw commands
arcadeplus.finish_render()

# Keep the window up until someone closes it.
arcadeplus.run()
Ejemplo n.º 28
0
    def __init__(self,
                 filename: str = None,
                 scale: float = 1,
                 image_x: float = 0,
                 image_y: float = 0,
                 image_width: float = 0,
                 image_height: float = 0,
                 center_x: float = 0,
                 center_y: float = 0,
                 repeat_count_x: int = 1,
                 repeat_count_y: int = 1):
        """
        Create a new sprite.

        Args:
            filename (str): Filename of an image that represents the sprite.
            scale (float): Scale the image up or down. Scale of 1.0 is none.
            image_x (float): X offset to sprite within sprite sheet.
            image_y (float): Y offset to sprite within sprite sheet.
            image_width (float): Width of the sprite
            image_height (float): Height of the sprite
            center_x (float): Location of the sprite
            center_y (float): Location of the sprite

        """

        if image_width < 0:
            raise ValueError("Width of image can't be less than zero.")

        if image_height < 0:
            raise ValueError(
                "Height entered is less than zero. Height must be a positive float."
            )

        if image_width == 0 and image_height != 0:
            raise ValueError("Width can't be zero.")

        if image_height == 0 and image_width != 0:
            raise ValueError("Height can't be zero.")

        self.sprite_lists: List[Any] = []

        self._texture: Optional[Texture]
        if filename is not None:
            try:
                self._texture = load_texture(filename, image_x, image_y,
                                             image_width, image_height)
            except Exception as e:
                print(f"Unable to load {filename} {e}")
                self._texture = None

            if self._texture:
                self.textures = [self._texture]
                # Ignore the texture's scale and use ours
                self._width = self._texture.width * scale
                self._height = self._texture.height * scale
            else:
                self.textures = []
                self._width = 0
                self._height = 0
        else:
            self.textures = []
            self._texture = None
            self._width = 0
            self._height = 0

        self.cur_texture_index = 0

        self._scale = scale
        self._position = (center_x, center_y)
        self._angle = 0.0

        self.velocity = [0.0, 0.0]
        self.change_angle = 0.0

        self.boundary_left = None
        self.boundary_right = None
        self.boundary_top = None
        self.boundary_bottom = None

        self.properties: Dict[str, Any] = {}

        self._alpha = 255
        self._collision_radius: Optional[float] = None
        self._color: RGB = (255, 255, 255)

        self._points: Optional[List[List[float]]] = None

        if self._texture:
            self._points = self._texture.hit_box_points

        self._point_list_cache: Optional[List[List[float]]] = None

        self.force = [0, 0]
        self.guid: Optional[str] = None

        self.repeat_count_x = repeat_count_x
        self.repeat_count_y = repeat_count_y
        self._texture_transform = Matrix3x3()

        # Used if someone insists on doing a sprite.draw()
        self._sprite_list = None