Sprite

org.homebrew.engine

## Class Sprite

- java.lang.Object
- - org.homebrew.engine.Sprite

-     public class Sprite
      extends java.lang.Object

  This class contains all the methods necessary to work with a single sprite such as moving, displaying and collision detection.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `currentState` the sprites current state
    `private ImageEntity` | `entity` the sprites image
    `protected Point2D` | `pos` sprites position
    `protected Point2D` | `vel` sprites velocity

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Sprite(org.havi.ui.HScene hscene)` class constructor initializes the sprites properties and adds it to the scene

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `alive()` returns if the sprite should be displayed
    `Point2D` | `center()` returns the center position of the image as a tuple
    `boolean` | `collidesWith(Point2D point)` returns if the sprite collides with another point
    `boolean` | `collidesWith(java.awt.Rectangle rect)` returns if the sprite collides with another object
    `boolean` | `collidesWith(Sprite sprite)` returns if the sprite collides with another sprite
    `void` | `draw(java.awt.Graphics g)` draws the sprite on the screen
    `java.awt.Rectangle` | `getBounds()` returns the bounding rectangle of the sprite
    `int` | `getState()` gets the sprites current state (alive, dead, etc.)
    `int` | `imageHeight()` returns the sprite images height
    `int` | `imageWidth()` returns the sprite images width
    `void` | `load(java.lang.String filename)` loads an image to use as the sprite
    `Point2D` | `Position()` Reurns the sprites position as a single tuple
    `void` | `setAlive(boolean alive)` sets whether to display the sprite or not
    `void` | `setPosition(Point2D pos)` sets the sprites position
    `void` | `setState(int state)` sets the sprites new state
    `void` | `setVelocity(Point2D vel)` sets the sprites velocity
    `void` | `updatePosition()` updates the sprites position based on it's velocity
    `Point2D` | `Velocity()` returns the sprites velocity as a single tuple

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### entity

          private ImageEntity entity

      the sprites image

    - #### pos

          protected Point2D pos

      sprites position

    - #### vel

          protected Point2D vel

      sprites velocity

    - #### currentState

          protected int currentState

      the sprites current state

  - ### Constructor Detail

    - #### Sprite

          public Sprite(org.havi.ui.HScene hscene)

      class constructor initializes the sprites properties and adds it to the scene
      Parameters:
        `hscene` - scene to add to for drawing purposes

  - ### Method Detail

    - #### load

          public final void load(java.lang.String filename)

      loads an image to use as the sprite
      Parameters:
        `filename` - filename of image to load and use as the sprite image

    - #### draw

          public final void draw(java.awt.Graphics g)

      draws the sprite on the screen
      Parameters:
        `g` - graphics context to use for drawing

    - #### updatePosition

          public final void updatePosition()

      updates the sprites position based on it's velocity

    - #### getState

          public final int getState()

      gets the sprites current state (alive, dead, etc.)
      Returns:
        int sprites current state

    - #### setState

          public final void setState(int state)

      sets the sprites new state
      Parameters:
        `state` - sprites new state

    - #### getBounds

          public final java.awt.Rectangle getBounds()

      returns the bounding rectangle of the sprite
      Returns:
        Rectangle sprites bounding rectangle

    - #### Position

          public final Point2D Position()

      Reurns the sprites position as a single tuple
      Returns:
        Point2D sprites position

    - #### setPosition

          public final void setPosition(Point2D pos)

      sets the sprites position
      Parameters:
        `pos` - sprites new position as a tuple

    - #### Velocity

          public final Point2D Velocity()

      returns the sprites velocity as a single tuple
      Returns:
        Point2D sprites new velocity

    - #### setVelocity

          public final void setVelocity(Point2D vel)

      sets the sprites velocity
      Parameters:
        `vel` - sprites new velocity as a tuple

    - #### center

          public final Point2D center()

      returns the center position of the image as a tuple
      Returns:
        Point2D center of image as a tuple of x and y position

    - #### alive

          public final boolean alive()

      returns if the sprite should be displayed
      Returns:
        boolean true if to display the sprite, otherwise false

    - #### setAlive

          public final void setAlive(boolean alive)

      sets whether to display the sprite or not
      Parameters:
        `alive` - true to display the object, otherwise false

    - #### imageWidth

          public final int imageWidth()

      returns the sprite images width
      Returns:
        int sprite images width

    - #### imageHeight

          public final int imageHeight()

      returns the sprite images height
      Returns:
        int sprite images height

    - #### collidesWith

          public final boolean collidesWith(java.awt.Rectangle rect)

      returns if the sprite collides with another object
      Parameters:
        `rect` - bounds of object to check against
      Returns:
        true if sprite has collided with object, otherwise false

    - #### collidesWith

          public final boolean collidesWith(Sprite sprite)

      returns if the sprite collides with another sprite
      Parameters:
        `sprite` - sprite to check against
      Returns:
        true if sprite has collided with sprite, otherwise false

    - #### collidesWith

          public final boolean collidesWith(Point2D point)

      returns if the sprite collides with another point
      Parameters:
        `point` - point to check against
      Returns:
        true if sprite has collided with point, otherwise false