Package controller

Class ObjectController

java.lang.Object
controller.ObjectController
Direct Known Subclasses:
EgoController, EnemyController, FallingStarController, LimitedTimeController, MineController, SimpleShotController

public abstract class ObjectController extends Object
Class that controls the LOGICAL behavior of an object independently of how it is displayed or drawn. The most important method here is updateObject(): this method is, by various indirections, called exactly once per game time step for every object that is on the playground. It has, by virtue of the member variables gameObject full access to
  • the object it is controlling
  • the playground this object belongs to
Typically, updateObject would check whether an object leaves the screen to react appropriately. In that case the object can be marked for deletion (by adding it to the flag "deleted" that is always defined for any playground), but of course other reactions are possible like rebounding, emerging on the other side, ...
  • Constructor Details

    • ObjectController

      public ObjectController()
  • Method Details

    • setObject

      public void setObject(GameObject gameObject)
    • setDummy

      public void setDummy(String x)
    • updateObject

      public abstract void updateObject()
      Is called once every game time step by the game itself. NEVER call this directly, not necessary!
      The method can do whatever it likes, including nothing. The attribute gameObject contains a reference to the controlled object, which allows access to the Playground the object belongs to (useful for getting the pixel size in x and y of the playing field.
      Recommended: when implementing this method, call at the end applySpeedVector() method. This is a helper method that sets the new x,y coordinates for the gameObject correctly.
    • applySpeedVector

      public void applySpeedVector()
      Convenience method: simply moves the object forward one step from its present position, using its present speed.
    • getTimestep

      public double getTimestep()
    • getX

      public double getX()
    • getY

      public double getY()
    • getVX

      public double getVX()
    • getVY

      public double getVY()
    • setX

      public void setX(double x)
    • setY

      public void setY(double y)
    • setVX

      public void setVX(double vx)
    • setVY

      public void setVY(double vy)
    • getPlayground

      public Playground getPlayground()
    • setPlayground

      public void setPlayground(Playground playground)