Package controller

Class CollisionAwareEgoController


public class CollisionAwareEgoController extends EgoController
An EgoController which cannot move through obstacle objects (is collission aware). Only respects GameObjects that have the String 'obstacle' in their name.
  • Constructor Details

    • CollisionAwareEgoController

      public CollisionAwareEgoController(double egoRad)
      Parameters:
      egoRad - radius of ego object to be used.
    • CollisionAwareEgoController

      public CollisionAwareEgoController(double egoRad, File soundOnShot)
      Parameters:
      egoRad - radius of ego object to be used.
      soundOnShot - WAV file to be played on shot
  • Method Details

    • saveDynamicState

      public void saveDynamicState()
      Copies current values of x,y position and speed vx,vy into attributes. These can be restored by call to restoreDynamicState().
    • restoreDynamicState

      public void restoreDynamicState()
      Restores formally saved values of x,y position and speed vx,vy from attributes back to the ego object. These values should have been stored before by a call to saveDynamicState(), otherwise all values will be 0.00.
    • stopObject

      public boolean stopObject()
      extends parent class implementation by a check whether or not the ego object collides with any other "obstacle" object. If yes, the position stays fixed (by using saveDynamicState() and restoreDynamicState().
      Overrides:
      stopObject in class EgoController
      Returns:
      true if the object reached the boundaries of the level, false otherwise.
    • onSpace

      public void onSpace(KeyEvent e, GameObject ego)
      calls superclass EgoController.onSpace(KeyEvent, GameObject) only, if the time elapsed since last pressing of space is above 0.1 ms.
      Overrides:
      onSpace in class EgoController
      Parameters:
      e - KeyEvent of the space key
      ego - EgoObject instance (used to determine position of shot object's start)