core

## Class VGDLSprite

- java.lang.Object
- - core.VGDLSprite

- Direct Known Subclasses:
    Conveyor, Flicker, Immovable, Missile, MovingAvatar, Passive, RandomNPC, SpriteProducer

      public abstract class VGDLSprite
      extends java.lang.Object

  Created with IntelliJ IDEA. User: Diego Date: 17/10/13 Time: 10:59 This is a Java port from Tom Schaul's VGDL - https://github.com/schaul/py-vgdl

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `int` | `bucket` Bucket
    `boolean` | `bucketSharp` Bucket remainder.
    `java.awt.Color` | `color` Color of this sprite.
    `int` | `cooldown` States the pause ticks in-between two moves
    `boolean` | `draw_arrow` Tells if an arrow must be drawn to indicate the orientation of the sprite.
    `java.awt.Image` | `image` Image of this sprite.
    `java.lang.String` | `img` String that represents the image in VGDL.
    `boolean` | `invisible` Indicates if the sprite is invisible.
    `boolean` | `is_avatar` Indicates if this sprite is the avatar (player) of the game.
    `boolean` | `is_from_avatar` Indicates if this sprite was created by the avatar.
    `boolean` | `is_npc` Indicates if this sprite is an NPC.
    `boolean` | `is_oriented` Indicates if this sprite has an oriented behaviour.
    `boolean` | `is_resource` Indicates if this sprite is a resource.
    `boolean` | `is_static` Indicates if this sprite is static or not.
    `boolean` | `is_stochastic` Indicates if the sprite has a stochastic behaviour.
    `java.util.ArrayList<java.lang.Integer>` | `itypes` List of types this sprite belongs to.
    `int` | `lastmove` Tells how many timesteps ago was the last move
    `java.awt.Rectangle` | `lastrect` Rectangle occupied for this sprite in the previous game step.
    `double` | `mass` Mass of this sprite (for Continuous physics).
    `java.lang.String` | `name` Name of this sprite.
    `boolean` | `only_active` Indicates if passive movement is denied for this sprite.
    `Vector2d` | `orientation` Orientation of the sprite.
    `Physics` | `physics` Reference to the physics object this sprite belongs to.
    `java.lang.String` | `physicstype` String that represents the physics type of this sprite.
    `int` | `physicstype_id` Id of the type if physics this sprite responds to.
    `boolean` | `portal` Indicates if this sprite is a portal.
    `java.awt.Rectangle` | `rect` Rectangle that this sprite occupies on the screen.
    `java.util.TreeMap<java.lang.Integer,java.lang.Integer>` | `resources` Indicates the amount of resources this sprite has, for each type defined as its int identifier.
    `double` | `shrinkfactor` Scale factor to draw this sprite.
    `boolean` | `singleton` Indicates if this sprite is a singleton.
    `double` | `speed` Scalar speed of this sprite.
    `int` | `spriteID` ID of this sprite.
    `double` | `strength` Strength measure of this sprite.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `VGDLSprite()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `_draw(java.awt.Graphics2D gphx, Game game)` Draws the not-oriented part of the sprite
    `void` | `_drawImage(java.awt.Graphics2D gphx, Game game)` Draws the not-oriented part of the sprite, as an image.
    `void` | `_drawOriented(java.awt.Graphics2D g)` In case this sprite is oriented and has an arrow to draw, it draws it.
    `protected void` | `_drawResources(java.awt.Graphics2D gphx, Game game)` Draws the resources hold by this sprite, as an horizontal bar on top of the sprite.
    `void` | `_updatePos(Vector2d orientation, int speed)` Updates the position of the sprite, giving its orientation and speed.
    `Vector2d` | `_velocity()` Returns the velocity of the sprite, in a Vector2d object.
    `void` | `applyMovement(boolean[] actionMask)` Applies both the passive and active movement for the avatar in the forward model.
    `abstract VGDLSprite` | `copy()` Creates a copy of this sprite.
    `void` | `copyTo(VGDLSprite toSprite)` Copies the attributes of this object to the one passed as parameter.
    `void` | `draw(java.awt.Graphics2D gphx, Game game)` Draws this sprite (both the not oriented and, if appropriate, the oriented part)
    `int` | `getAmountResource(int resourceId)` Returns the amount of resource of a given type this sprite has.
    `Vector2d` | `getPosition()` Gets the position of this sprite.
    `int` | `getType()` Gets the unique and precise type of this sprite
    `protected void` | `init(Vector2d position, java.awt.Dimension size)` Initializes the sprite, giving its position and dimensions.
    `Vector2d` | `lastDirection()` Returns the last direction this sprite is following.
    `protected void` | `loadDefaults()` Loads the default values for this sprite.
    `void` | `loadImage(java.lang.String str)` Loads the image that represents this sprite, using its string name as reference.
    `void` | `modifyResource(int resourceId, int amount_delta)` Modifies the amount of resource by a given quantity.
    `void` | `parseParameters(SpriteContent content)` Parses parameters for the sprite, received as a SpriteContent object.
    `void` | `postProcess()` Method to perform post processing when the sprite has received its parameters.
    `void` | `setFromAvatar(boolean fromAvatar)` Used to indicate if this sprite was created by the avatar.
    `void` | `setRect(java.awt.Rectangle rectangle)`
    `void` | `setRect(Vector2d position, java.awt.Dimension size)`
    `java.lang.String` | `toString()` Returns a string representation of this string, including its name and position.
    `void` | `update(Game game)` Updates this sprite, performing the movements and actions for the next step.
    `void` | `updatePassive()` Updates this sprite applying the passive movement.

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

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

- - ### Field Detail

    - #### name

          public java.lang.String name

      Name of this sprite.

    - #### is_static

          public boolean is_static

      Indicates if this sprite is static or not.

    - #### only_active

          public boolean only_active

      Indicates if passive movement is denied for this sprite.

    - #### is_avatar

          public boolean is_avatar

      Indicates if this sprite is the avatar (player) of the game.

    - #### is_stochastic

          public boolean is_stochastic

      Indicates if the sprite has a stochastic behaviour.

    - #### color

          public java.awt.Color color

      Color of this sprite.

    - #### cooldown

          public int cooldown

      States the pause ticks in-between two moves

    - #### speed

          public double speed

      Scalar speed of this sprite.

    - #### mass

          public double mass

      Mass of this sprite (for Continuous physics).

    - #### physicstype_id

          public int physicstype_id

      Id of the type if physics this sprite responds to.

    - #### physicstype

          public java.lang.String physicstype

      String that represents the physics type of this sprite.

    - #### physics

          public Physics physics

      Reference to the physics object this sprite belongs to.

    - #### shrinkfactor

          public double shrinkfactor

      Scale factor to draw this sprite.

    - #### is_oriented

          public boolean is_oriented

      Indicates if this sprite has an oriented behaviour.

    - #### draw_arrow

          public boolean draw_arrow

      Tells if an arrow must be drawn to indicate the orientation of the sprite.

    - #### orientation

          public Vector2d orientation

      Orientation of the sprite.

    - #### rect

          public java.awt.Rectangle rect

      Rectangle that this sprite occupies on the screen.

    - #### lastrect

          public java.awt.Rectangle lastrect

      Rectangle occupied for this sprite in the previous game step.

    - #### lastmove

          public int lastmove

      Tells how many timesteps ago was the last move

    - #### strength

          public double strength

      Strength measure of this sprite.

    - #### singleton

          public boolean singleton

      Indicates if this sprite is a singleton.

    - #### is_resource

          public boolean is_resource

      Indicates if this sprite is a resource.

    - #### portal

          public boolean portal

      Indicates if this sprite is a portal.

    - #### invisible

          public boolean invisible

      Indicates if the sprite is invisible. If it is, the effect is that it is not drawn.

    - #### itypes

          public java.util.ArrayList<java.lang.Integer> itypes

      List of types this sprite belongs to. It contains the ids, including itself's, from this sprite up in the hierarchy of sprites defined in SpriteSet in the game definition.

    - #### resources

          public java.util.TreeMap<java.lang.Integer,java.lang.Integer> resources

      Indicates the amount of resources this sprite has, for each type defined as its int identifier.

    - #### image

          public java.awt.Image image

      Image of this sprite.

    - #### img

          public java.lang.String img

      String that represents the image in VGDL.

    - #### is_npc

          public boolean is_npc

      Indicates if this sprite is an NPC.

    - #### spriteID

          public int spriteID

      ID of this sprite.

    - #### is_from_avatar

          public boolean is_from_avatar

      Indicates if this sprite was created by the avatar.

    - #### bucket

          public int bucket

      Bucket

    - #### bucketSharp

          public boolean bucketSharp

      Bucket remainder.

  - ### Constructor Detail

    - #### VGDLSprite

          public VGDLSprite()

  - ### Method Detail

    - #### init

          protected void init(Vector2d position,
                  java.awt.Dimension size)

      Initializes the sprite, giving its position and dimensions.
      Parameters:
        `position` - position of the sprite
        `size` - dimensions of the sprite on the screen.

    - #### setRect

          public void setRect(Vector2d position,
                     java.awt.Dimension size)

    - #### setRect

          public void setRect(java.awt.Rectangle rectangle)

    - #### loadDefaults

          protected void loadDefaults()

      Loads the default values for this sprite.

    - #### parseParameters

          public void parseParameters(SpriteContent content)

      Parses parameters for the sprite, received as a SpriteContent object.
      Parameters:
        `content` -

    - #### update

          public void update(Game game)

      Updates this sprite, performing the movements and actions for the next step.
      Parameters:
        `game` - the current game that is being played.

    - #### applyMovement

          public void applyMovement(boolean[] actionMask)

      Applies both the passive and active movement for the avatar in the forward model.

    - #### updatePassive

          public void updatePassive()

      Updates this sprite applying the passive movement.

    - #### _updatePos

          public void _updatePos(Vector2d orientation,
                        int speed)

      Updates the position of the sprite, giving its orientation and speed.
      Parameters:
        `orientation` - the orientation of the sprite.
        `speed` - the speed of the sprite.

    - #### _velocity

          public Vector2d _velocity()

      Returns the velocity of the sprite, in a Vector2d object.
      Returns:
        the velocity of the sprite

    - #### lastDirection

          public Vector2d lastDirection()

      Returns the last direction this sprite is following.
      Returns:
        the direction.

    - #### getPosition

          public Vector2d getPosition()

      Gets the position of this sprite.
      Returns:
        the position as a Vector2d.

    - #### modifyResource

          public void modifyResource(int resourceId,
                            int amount_delta)

      Modifies the amount of resource by a given quantity.
      Parameters:
        `resourceId` - id of the resource whose quantity must be changed.
        `amount_delta` - amount of units the resource has to be modified by.

    - #### getAmountResource

          public int getAmountResource(int resourceId)

      Returns the amount of resource of a given type this sprite has.
      Parameters:
        `resourceId` - id of the resource to check.
      Returns:
        how much of this resource this sprite has.

    - #### draw

          public void draw(java.awt.Graphics2D gphx,
                  Game game)

      Draws this sprite (both the not oriented and, if appropriate, the oriented part)
      Parameters:
        `gphx` - graphics object to draw in.
        `game` - reference to the game that is being played now.

    - #### _drawOriented

          public void _drawOriented(java.awt.Graphics2D g)

      In case this sprite is oriented and has an arrow to draw, it draws it.
      Parameters:
        `g` - graphics device to draw in.

    - #### _draw

          public void _draw(java.awt.Graphics2D gphx,
                   Game game)

      Draws the not-oriented part of the sprite
      Parameters:
        `gphx` - graphics object to draw in.
        `game` - reference to the game that is being played now.

    - #### _drawImage

          public void _drawImage(java.awt.Graphics2D gphx,
                        Game game)

      Draws the not-oriented part of the sprite, as an image. this.image must be not null.
      Parameters:
        `gphx` - graphics object to draw in.
        `game` - reference to the game that is being played now.

    - #### _drawResources

          protected void _drawResources(java.awt.Graphics2D gphx,
                            Game game)

      Draws the resources hold by this sprite, as an horizontal bar on top of the sprite.
      Parameters:
        `gphx` - graphics to draw in.
        `game` - game being played at the moment.

    - #### getType

          public int getType()

      Gets the unique and precise type of this sprite
      Returns:
        the type

    - #### postProcess

          public void postProcess()

      Method to perform post processing when the sprite has received its parameters.

    - #### loadImage

          public void loadImage(java.lang.String str)

      Loads the image that represents this sprite, using its string name as reference.
      Parameters:
        `str` - name of the image to load.

    - #### setFromAvatar

          public void setFromAvatar(boolean fromAvatar)

      Used to indicate if this sprite was created by the avatar.
      Parameters:
        `fromAvatar` - true if the avatar created this sprite.

    - #### toString

          public java.lang.String toString()

      Returns a string representation of this string, including its name and position.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the string representation of this sprite.

    - #### copy

          public abstract VGDLSprite copy()

      Creates a copy of this sprite. To be overwritten in each subclass.
      Returns:
        a copy of this sprite.

    - #### copyTo

          public void copyTo(VGDLSprite toSprite)

      Copies the attributes of this object to the one passed as parameter.
      Parameters:
        `toSprite` - the sprite to copy to.