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) moves ego down bySpaceInvadersLevel.EGOSPEED
.void
onLeft
(KeyEvent kc, GameObject ego) moves ego left bySpaceInvadersLevel.EGOSPEED
.void
onRight
(KeyEvent kc, GameObject ego) moves ego right bySpaceInvadersLevel.EGOSPEED
.void
onSpace
(KeyEvent e, GameObject ego) behavior for shooting on key space.void
onStop
(KeyEvent kc, GameObject ego) sets speed to 0.0void
onUp
(KeyEvent kc, GameObject ego) moves ego up bySpaceInvadersLevel.EGOSPEED
.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
moves ego up bySpaceInvadersLevel.EGOSPEED
.- Parameters:
kc
- KeyEvent to process (ignored)ego
- the ego object
-
onDown
moves ego down bySpaceInvadersLevel.EGOSPEED
.- Parameters:
kc
- KeyEvent to process (ignored)ego
- the ego object
-
onLeft
moves ego left bySpaceInvadersLevel.EGOSPEED
.- Parameters:
kc
- KeyEvent to process (ignored)ego
- the ego object
-
onRight
moves ego right bySpaceInvadersLevel.EGOSPEED
.- Parameters:
kc
- KeyEvent to process (ignored)ego
- the ego object
-
onStop
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
behavior for shooting on key space. Creates a new shot using {#link SimpleShotController} with aRectObject
.- 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
-