Package view

Class EntityView

java.lang.Object
view.EntityView
All Implemented Interfaces:
Configuration
Direct Known Subclasses:
SceneryView, SpriteView, TextView

public abstract class EntityView extends Object implements Configuration
The EntityView represents the un-scaled appearance of the entity on screen. The view is resized by the scaling factor before it is drawn. Collision bounds will track the rectangle that bounds the view. The default collision bounds is the same that of the dimensions of the view. Collision bounds can be changed to suit the dynamics of the game without affecting the size of the view. The view contains the transformational and representational state of the entity. The draw method when invoked by the ModelEntity, will render the current representation of the entity on the supplied graphics context at the coordinates specified. This class, like all of the Java 2D API, uses a default coordinate system called user space in which the y-axis values increase downward and x-axis values increase to the right.
Author:
Krish Pillai
See Also:
  • Constructor Details

    • EntityView

      public EntityView()
      EntityView contains scale information and provides a mechanism for adding screen location information to the image to be rendered It takes the image form the concrete class and the location information from the model to draw the view on screen.
  • Method Details

    • draw

      public void draw(Graphics2D gc, int x, int y)
      Renders the concrete view for this entity. If an affine transform is defined for this view, it is applied. Rendering is done for the graphics context supplied. View that are unbounded will wrap around the drawing canvas if the entity is set as unbounded.
      Parameters:
      gc - Graphics context (2D)
      x - Entity body-center x coordinate
      y - Entity body-center y coordinate
      See Also:
    • getScaleX

      public float getScaleX()
      Getter for horizontal scaling
      Returns:
      scale The scale factor along the x axis
    • getScaleY

      public float getScaleY()
      Returns the scale factor along the y axis
      Returns:
      scale The vertical scale factor
    • setScaleFactor

      public void setScaleFactor(float scaleX, float scaleY)
      Sets the x and y scale factors
      Parameters:
      scaleX - Scale factor along x axis
      scaleY - Scale factor along y axis
    • setAnimation

      public void setAnimation(boolean active)
      Enables/disables the rolling of frames for the sprite or scenery. Iterator does not advance frames if made inactive.
      Parameters:
      active - True is the iterator returns a new image for each frame
    • getAnimation

      public boolean getAnimation()
      Returns the state of the view iterator
      Returns:
      true or false
    • isWrappedView

      public boolean isWrappedView()
      Returns the state of the wrapped view setting. In wrapped mode, the entity will wrap around screen edges. Wrapped entities leaving the North edge will enter through the South and vice versa. Similarly, the East and West boundaries are also conjoined.
      Returns:
      state True if entity is in wrapped mode
    • setWrappedView

      public void setWrappedView(boolean wrap)
      Sets the entity to wrapped mode when argument is true.
      Parameters:
      wrap - True if entity is in wrapped mode
    • getDimension

      public Dimension getDimension()
      Returns the dimensions of of the rendered text.
      Returns:
      dim Contains the width and height of the current rendering
    • drawBounds

      public void drawBounds(Rectangle r, Color c, Graphics2D gc)
      Renders a hit-box around the text view. The rectangle is specified by 'r' using the color 'c'
      Parameters:
      r - The hit-box
      c - The color
      gc - The graphics context to use
    • getWidth

      public abstract int getWidth()
      The width of the scaled visual representation for this entity.
      Returns:
      width
    • getHeight

      public abstract int getHeight()
      The height of the scaled visual representation for this entity.
      Returns:
      height