Class Character

  • All Implemented Interfaces:
    Drawable, com.badlogic.gdx.utils.Disposable

    public class Character
    extends com.badlogic.gdx.graphics.g2d.Sprite
    implements Drawable
    The Character class represents the avatar of the player in the game, extending the Sprite.
    Author:
    ENG1 Team 23 (Cohort 3)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private com.badlogic.gdx.physics.box2d.Body activeBody
      The Body reference belonging to the current Area context
      private java.util.Map<Area.Name,​com.badlogic.gdx.physics.box2d.Body> bodies
      The relationship between the Area and the Body, with standard area keys
      private static float HEIGHT
      The height of a Character, in in-game metres
      private static float MOVEMENT_VELOCITY
      The standard moving velocity, across both axes, of a mobile Character.
      private static float MOVEMENT_VELOCITY_CORRECTION
      The velocity correction factor by which movement should be slowed if the Character is traversing both axes simultaneously; i.e.
      private com.badlogic.gdx.graphics.Texture playerTexture
      The visual representation of the Character
      private static java.lang.String TEXTURE_PATH
      The file path of the Character
      private com.badlogic.gdx.math.Vector2 velocity
      The transient velocity of the Character
      private static float WIDTH
      The width of a Character, in in-game metres
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()
      Releases all resources used by the Character
      com.badlogic.gdx.math.Vector2 getPosition()
      Retrieves the Character position
      void move()
      Updates the position of the Character given its transient velocity
      void moveDown()
      Moves the Character downwards on the Y-axis
      void moveLeft()
      Moves the Character leftwards on the X-axis
      void moveRight()
      Moves the Character rightwards on the X-axis
      void moveUp()
      Moves the Character upwards on the Y-axis
      void render​(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      Registers the current Character onto the given game instance SpriteBatch
      void setPosition​(com.badlogic.gdx.math.Vector2 position)
      Sets the position of the Character
      void switchCharacterContext​(Area.Name areaName)
      Switch the Character context to Area identified by the given index
      • Methods inherited from class com.badlogic.gdx.graphics.g2d.Sprite

        draw, draw, flip, getBoundingRectangle, getColor, getHeight, getOriginX, getOriginY, getRotation, getScaleX, getScaleY, getVertices, getWidth, getX, getY, rotate, rotate90, scale, scroll, set, setAlpha, setBounds, setCenter, setCenterX, setCenterY, setColor, setColor, setFlip, setOrigin, setOriginBasedPosition, setOriginCenter, setPackedColor, setPosition, setRegion, setRotation, setScale, setScale, setSize, setU, setU2, setV, setV2, setX, setY, translate, translateX, translateY
      • Methods inherited from class com.badlogic.gdx.graphics.g2d.TextureRegion

        getRegionHeight, getRegionWidth, getRegionX, getRegionY, getTexture, getU, getU2, getV, getV2, isFlipX, isFlipY, setRegion, setRegion, setRegion, setRegion, setRegionHeight, setRegionWidth, setRegionX, setRegionY, setTexture, split, split
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Character

        public Character​(java.util.Map<Area.Name,​Area> areas,
                         Area.Name defaultArea)
        Initialises a new Character body as a player-movable Sprite
        Parameters:
        areas - All Areas in which the Character should exist
    • Method Detail

      • moveUp

        public void moveUp()
        Moves the Character upwards on the Y-axis
      • moveDown

        public void moveDown()
        Moves the Character downwards on the Y-axis
      • moveLeft

        public void moveLeft()
        Moves the Character leftwards on the X-axis
      • moveRight

        public void moveRight()
        Moves the Character rightwards on the X-axis
      • getPosition

        public com.badlogic.gdx.math.Vector2 getPosition()
        Retrieves the Character position
        Returns:
        The position
      • setPosition

        public void setPosition​(com.badlogic.gdx.math.Vector2 position)
        Sets the position of the Character
        Parameters:
        position - The new position
      • switchCharacterContext

        public void switchCharacterContext​(Area.Name areaName)
        Switch the Character context to Area identified by the given index
        Parameters:
        areaName - The Area.Name of the new Area
      • dispose

        public void dispose()
        Releases all resources used by the Character
        Specified by:
        dispose in interface com.badlogic.gdx.utils.Disposable
      • render

        public void render​(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
        Registers the current Character onto the given game instance SpriteBatch
        Specified by:
        render in interface Drawable
        Parameters:
        batch - The SpriteBatch to which the Character should be polled