Package controller
Class EgoController
java.lang.Object
controller.ObjectController
controller.EgoController
- Direct Known Subclasses:
CollisionAwareEgoController
Controller using key events for up, down, left, right and space (shooting) to control the ego
object behavior.
-
Constructor Summary
ConstructorDescriptionEgoController
(double egoRad) constructor that gives the ego controller a radius to stop the ego object when it reaches the level boundaries.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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
onDown
(KeyEvent kc, GameObject ego) void
onLeft
(KeyEvent kc, GameObject ego) void
onRight
(KeyEvent kc, GameObject ego) void
onSpace
(KeyEvent e, GameObject ego) behavior for shooting on key spacevoid
onStop
(KeyEvent kc, GameObject ego) void
onUp
(KeyEvent kc, GameObject ego) boolean
checks the position and respects level boundaries and own radius or width/height set on constructor.void
updates position based on key events (mouse currently ignored)Methods inherited from class controller.ObjectController
applySpeedVector, getPlayground, getTimestep, getVX, getVY, getX, getY, setDummy, setObject, setPlayground, setVX, setVY, setX, setY
-
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
-
onDown
-
onLeft
-
onRight
-
onStop
-
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
behavior for shooting on key space- Parameters:
e
- KeyEvent of the space keyego
- 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 classObjectController
-