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)
      Parameters:
      kc - KeyEvent to process (ignored)
      ego - the ego object
    • onDown

      public void onDown(KeyEvent kc, GameObject ego)
      moves ego down by SpaceInvadersLevel.EGOSPEED.
      Parameters:
      kc - KeyEvent to process (ignored)
      ego - the ego object
    • onLeft

      public void onLeft(KeyEvent kc, GameObject ego)
      moves ego left by SpaceInvadersLevel.EGOSPEED.
      Parameters:
      kc - KeyEvent to process (ignored)
      ego - the ego object
    • onRight

      public void onRight(KeyEvent kc, GameObject ego)
      moves ego right by SpaceInvadersLevel.EGOSPEED.
      Parameters:
      kc - KeyEvent to process (ignored)
      ego - the ego object
    • onStop

      public void onStop(KeyEvent kc, GameObject ego)
      sets speed to 0.0
      Parameters:
      kc - KeyEvent to process (ignored)
      ego - the ego object
    • 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. Creates a new shot using {#link SimpleShotController} with a RectObject.
      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