Class Drawable

java.lang.Object
fr.paris.saclay.sidescroller.drawables.Drawable
Direct Known Subclasses:
Background, Entity, Terrain

public abstract class Drawable extends Object
Basic template for each object drawn on the screen excluding player UI.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Drawable's facing direction
    protected final GamePanel
    GamePanel reference.
    int
    Drawable's movement speed
    int
    Drawable's position on the X axis (relative to window)
    int
    Drawable's position on the Y axis (relative to window)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Drawable(GamePanel gamePanel)
    Creates a Drawable instance and saves GamePanel reference.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    draw(Graphics2D graphics2D)
    Each Drawable object must implement a method to be rendered inside the JFrame.
    int
    Gets x position.
    abstract void
    This method is called by the GamePanel every time a new frame has to be generated.
    void
    Updates camera position by setting it equal to the distance travelled by the player.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • gamePanel

      protected final GamePanel gamePanel
      GamePanel reference.
    • xPosition

      public int xPosition
      Drawable's position on the X axis (relative to window)
    • yPosition

      public int yPosition
      Drawable's position on the Y axis (relative to window)
    • speed

      public int speed
      Drawable's movement speed
    • direction

      public Direction direction
      Drawable's facing direction
  • Constructor Details

    • Drawable

      public Drawable(GamePanel gamePanel)
      Creates a Drawable instance and saves GamePanel reference.
      Parameters:
      gamePanel - reference.
  • Method Details

    • updatePositionToCamera

      public void updatePositionToCamera(int deltaX)
      Updates camera position by setting it equal to the distance travelled by the player.
      Parameters:
      deltaX - distance travelled.
    • update

      public abstract void update()
      This method is called by the GamePanel every time a new frame has to be generated. Each Drawable object is responsible for calculating its position, state and aspect (such as sprite animations) for every new frame.
    • draw

      public abstract void draw(Graphics2D graphics2D)
      Each Drawable object must implement a method to be rendered inside the JFrame.
      Parameters:
      graphics2D - the rendering environment.
    • getXPosition

      public int getXPosition()
      Gets x position.
      Returns:
      the x position