<commit_before>"""
Sprite class for encapsulating all visible objects in ggame applications.
"""
import math
from ggame.sysdeps import GFX_Sprite
from ggame.asset import (
    RectangleAsset,
    CircleAsset,
    ImageAsset,
    PolygonAsset,
    EllipseAsset,
    TextAsset,
    LineAsset,
)
from ggame.app import App

# pylint: disable=useless-object-inheritance
class Sprite(object):  # pylint: disable=too-many-public-methods
    """
    The Sprite class combines the idea of a visual/graphical asset, a
    position on the screen, and *behavior*. Although the Sprite can be
    used as-is, it is generally subclassed to give it some desired behavior.

    When subclassing the Sprite class, you may customize the initialization
    code to use a specific asset. A 'step' or 'poll' method may be added
    for handling per-frame actions (e.g. checking for collisions). Step or poll
    functions are not automatically called by the :class:`~ggame.app.App` class,
    but you may subclass the :class:`~ggame.app.App` class in order to do this.

    Furthermore, you may wish to define event callback methods in your customized
    sprite class. With customized creation, event handling, and periodic processing
    you can achieve fully autonomous behavior for your sprite objects.

    :param asset asset: An existing graphical asset

    :param tuple(int,int) pos:  The sprite position may be provided, which
        specifies the starting (x,y) coordinates of the sprite on the screen.
        By default, the position of a sprite defines the location of its upper-left
        hand corner. This behavior can be modified by customizing its
        :data:`center`.

    :param asset edgedef: An edge definition asset may be provided, which
        specifies an asset that will be used to define the boundaries of
        the sprite for the purpose of collision detection. If no `edgedef`
        asset is given, the required asset is used, which will be a rectangular
        asset in the case of an image texture. This option is typically used
        to define a visible image outline for a texture-based sprite that has
        a transparent texture image background.

    :returns: Nothing. If the position is on screen the sprite will be displayed
        in the browser.

    Example::

        from ggame.sprite import Sprite
        from ggame.asset import ImageAsset, CircleAsset
        from ggame.app import App

        player = Sprite(
            ImageAsset("bunny.png",
            (100,100),
            CircleAsset(50))

        App().run()

    This creates a sprite using the 'player.png' image, positioned with its
    upper-left corner at coordinates (100,100) and with a 50 pixel radius
    circular collision border.

    """

    def __init__(self, asset, pos=(0, 0), edgedef=None):
        self._index = 0
        if isinstance(asset, ImageAsset):
            self.asset = asset
            try:
                self.gfx = GFX_Sprite(asset.gfx)  # gfx is PIXI Sprite
            except:  # pylint: disable=bare-except
                self.gfx = None
                raise
        elif isinstance(
            asset, (RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset, LineAsset)
        ):
            self.asset = asset<commit_msg>update sprite example<commit_after>"""
Sprite class for encapsulating all visible objects in ggame applications.
"""
import math
from ggame.sysdeps import GFX_Sprite
from ggame.asset import (
    RectangleAsset,
    CircleAsset,
    ImageAsset,
    PolygonAsset,
    EllipseAsset,
    TextAsset,
    LineAsset,
)
from ggame.app import App

# pylint: disable=useless-object-inheritance
class Sprite(object):  # pylint: disable=too-many-public-methods
    """
    The Sprite class combines the idea of a visual/graphical asset, a
    position on the screen, and *behavior*. Although the Sprite can be
    used as-is, it is generally subclassed to give it some desired behavior.

    When subclassing the Sprite class, you may customize the initialization
    code to use a specific asset. A 'step' or 'poll' method may be added
    for handling per-frame actions (e.g. checking for collisions). Step or poll
    functions are not automatically called by the :class:`~ggame.app.App` class,
    but you may subclass the :class:`~ggame.app.App` class in order to do this.

    Furthermore, you may wish to define event callback methods in your customized
    sprite class. With customized creation, event handling, and periodic processing
    you can achieve fully autonomous behavior for your sprite objects.

    :param asset asset: An existing graphical asset

    :param tuple(int,int) pos:  The sprite position may be provided, which
        specifies the starting (x,y) coordinates of the sprite on the screen.
        By default, the position of a sprite defines the location of its upper-left
        hand corner. This behavior can be modified by customizing its
        :data:`center`.

    :param asset edgedef: An edge definition asset may be provided, which
        specifies an asset that will be used to define the boundaries of
        the sprite for the purpose of collision detection. If no `edgedef`
        asset is given, the required asset is used, which will be a rectangular
        asset in the case of an image texture. This option is typically used
        to define a visible image outline for a texture-based sprite that has
        a transparent texture image background.

    :returns: Nothing. If the position is on screen the sprite will be displayed
        in the browser.

    Example of use:

    .. literalinclude:: ../examples/spritesprite.py

    This creates a sprite using the 'player.png' image, positioned with its
    upper-left corner at coordinates (100,100) and with a 50 pixel radius
    circular collision border.

    """

    def __init__(self, asset, pos=(0, 0), edgedef=None):
        self._index = 0
        if isinstance(asset, ImageAsset):
            self.asset = asset
            try:
                self.gfx = GFX_Sprite(asset.gfx)  # gfx is PIXI Sprite
            except:  # pylint: disable=bare-except
                self.gfx = None
                raise
        elif isinstance(
            asset, (RectangleAsset, CircleAsset, EllipseAsset, PolygonAsset, LineAsset)
        ):
            self.asset = asset
{'fraction_non_alphanumeric': 0.06012308663405397, 'fraction_numerical': 0.004734101309768029, 'mean_word_length': 2.7458628841607564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294154', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1602, 'n_words': 756}