Package controller

Class EgoController

Direct Known Subclasses:
CollisionAwareEgoController

public class EgoController extends ObjectController
Controller using key events for up, down, left, right and space (shooting) to control the ego object behavior.
  • Constructor Details

    • EgoController

      public EgoController(double egoRad)
      constructor that gives the ego controller a radius to stop the ego object when it reaches the level boundaries.
      Parameters:
      egoRad - radius to use as a boundary stop for level borders (usually use the same dimensions as your ego object)
    • EgoController

      public EgoController(double width, double height)
      constructor that gives the ego controller a width and height to stop the ego object when it reaches the level boundaries.
      Parameters:
      width - width to use as a boundary stop for level borders (usually use the same dimensions as your ego object)
      height - height to use as a boundary stop for level borders (usually use the same dimensions as your ego object)
  • Method Details

    • onUp

      public void onUp(KeyEvent kc, GameObject ego)
    • onDown

      public void onDown(KeyEvent kc, GameObject ego)
    • onLeft

      public void onLeft(KeyEvent kc, GameObject ego)
    • onRight

      public void onRight(KeyEvent kc, GameObject ego)
    • onStop

      public void onStop(KeyEvent kc, GameObject ego)
    • stopObject

      public boolean stopObject()
      checks the position and respects level boundaries and own radius or width/height set on constructor.
      Returns:
      true if the object reached the boundaries of the level, false otherwise
    • onSpace

      public void onSpace(KeyEvent e, GameObject ego)
      behavior for shooting on key space
      Parameters:
      e - KeyEvent of the space key
      ego - EgoObject instance (used to determine position of shot object's start)
    • updateObject

      public void updateObject()
      updates position based on key events (mouse currently ignored)
      Specified by:
      updateObject in class ObjectController