vooga.gameEngine.controller
Class CameraController

java.lang.Object
  extended by vooga.gameEngine.game.GameRelatedObject
      extended by vooga.gameEngine.controller.GameRelatedController
          extended by vooga.gameEngine.controller.CameraController
All Implemented Interfaces:
java.io.Serializable, Tangible
Direct Known Subclasses:
KeyMovingCameraController, UnicornCamera, WormsCameraController

public class CameraController
extends GameRelatedController
implements Tangible

This class represents the connection between the game and the camera. This class can be extended to implement listener methods for all relevant events. This class also fires a PositionChangedEvent when the camera is moved and a SizeChangedEvent when the camera is resized and a RotationChangedEvent when the camera is rotated; any object who wants to listen for these events should implement CameraListener.

For example to make the camera follow mario you would make your own CameraController class say myCameraController and add mario to it
CameraController myCamera = new myCameraController();
GameItem mario = new MarioCharacter();
mario.add(myCamera);

If mario fires a MoveRight event and the CameraController implements a MarioListener with the method:
public void moveCameraRight(MoveRight event); then this method will be called whenever a MoveRight event is fired.

Author:
Jacob Harer, Geoffrey Lawler
See Also:
Serialized Form

Constructor Summary
CameraController(Position p, Dimension size)
          Creates a new CameraController with the top left corner at a Position p and with a Dimension, viewableArea, representing the viewable area in terms of the game coordinate system.
CameraController(Position p, Dimension size, Rotation2D rotation)
          Creates a new CameraController with the top left corner at a Position p and with a Dimension, viewableArea, representing the viewable area in terms of the game coordinate system.
 
Method Summary
 java.awt.geom.Rectangle2D getBounds()
          Deprecated. 
 Position getPosition()
          Getter method for the current position of this item in the coordinate system used by the game.
 Rotation2D getRotation()
          Getter method for the current rotation of this item in the coordinate system used by the game.
 java.awt.Shape getShape()
          Method for getting a Shape representing the area that can be rendered on screen.
 Dimension getSize()
          Getter method for the current dimension of this item in the coordinate system used by the game.
 Dimension getViewableArea()
          Deprecated. 
 void move(double dx, double dy)
          Moves this object dx to the right and dy up, which is relative to the in game coordinate system.
 void move(Position pointToMoveTo)
          Deprecated. 
 void resize(double dx, double dy)
          Change's the size of this object dx in width and dy in height, which is relative to the in game coordinate system.
 void rotate(double dtheta)
          Rotates this object dtheta clockwise, which is relative to the Position defined the existing Rotation2D associated with this object.
 void setPosition(Position p)
          Moves this object to a specified Position.
 void setRotation(Rotation2D r)
          Changes this object's rotation to the specified Rotation2D.
 void setSize(Dimension d)
          Changes this object's size to a specified Dimension.
 void setViewableArea(Dimension viewableArea)
          Deprecated. 
 
Methods inherited from class vooga.gameEngine.game.GameRelatedObject
addEventListener, clearListeners, equals, fire, fire, fire, getEventListeners, getID, getListenerCount, removeEventListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CameraController

public CameraController(Position p,
                        Dimension size,
                        Rotation2D rotation)
Creates a new CameraController with the top left corner at a Position p and with a Dimension, viewableArea, representing the viewable area in terms of the game coordinate system.

Parameters:
p - is starting position
viewableArea - the area the camera can see
orientation - the initial orientation of the camera

CameraController

public CameraController(Position p,
                        Dimension size)
Creates a new CameraController with the top left corner at a Position p and with a Dimension, viewableArea, representing the viewable area in terms of the game coordinate system. A default Rotation2D is used to represent the rotation of this object.

Parameters:
p - is starting position
viewableArea - the area the camera can see
Method Detail

move

@Deprecated
public void move(Position pointToMoveTo)
Deprecated. 

Method used to cause the camera to move and with the Position of the top left corner. Fires PositionChangedEvent.

Parameters:
pointToMoveTo - place to move the camera to

move

public void move(double dx,
                 double dy)
Description copied from interface: Tangible
Moves this object dx to the right and dy up, which is relative to the in game coordinate system. A negative dx corresponds to moving left, and a negative dy corresponds to moving down. Fires a PositionChangedEvent when called.

Specified by:
move in interface Tangible
Parameters:
dx - the change in the x-axis
dy - the change in the y-axis

getPosition

public Position getPosition()
Description copied from interface: Tangible
Getter method for the current position of this item in the coordinate system used by the game.

Specified by:
getPosition in interface Tangible
Returns:
a copy of the Position representing current position

getViewableArea

@Deprecated
public Dimension getViewableArea()
Deprecated. 

Method used for determining the portion of the game that should be visible.

Returns:
the the dimensions of the area visible by the camera

setViewableArea

@Deprecated
public void setViewableArea(Dimension viewableArea)
Deprecated. 

Method used to change the viewable area on the screen. Useful for zooming the camera in and out, particularly in boss battles. Fires SizedChangedEvent.

Parameters:
viewableArea - seen by the camera in terms of the game's coordinate system

getBounds

@Deprecated
public java.awt.geom.Rectangle2D getBounds()
Deprecated. 

Method for getting a Rectangle2D representing the area that can be rendered on screen.

Returns:
the boundaries of the camera

getRotation

public Rotation2D getRotation()
Description copied from interface: Tangible
Getter method for the current rotation of this item in the coordinate system used by the game.

Specified by:
getRotation in interface Tangible
Returns:
a copy of the Rotation2D representing current rotation

getSize

public Dimension getSize()
Description copied from interface: Tangible
Getter method for the current dimension of this item in the coordinate system used by the game.

Specified by:
getSize in interface Tangible
Returns:
a copy of the Dimension representing current size

resize

public void resize(double dx,
                   double dy)
Description copied from interface: Tangible
Change's the size of this object dx in width and dy in height, which is relative to the in game coordinate system. Fires a SizeChangedEvent when called.

Specified by:
resize in interface Tangible
Parameters:
dx - the change in the width
dy - the change in the height

rotate

public void rotate(double dtheta)
Description copied from interface: Tangible
Rotates this object dtheta clockwise, which is relative to the Position defined the existing Rotation2D associated with this object. Fires a RotationChangedEvent when called.

Specified by:
rotate in interface Tangible
Parameters:
dtheta - is the angle to rotate the object in radians

setPosition

public void setPosition(Position p)
Description copied from interface: Tangible
Moves this object to a specified Position. Fires a PositionChangedEvent when called.

Specified by:
setPosition in interface Tangible
Parameters:
p - new position of the object (top left corner)

setRotation

public void setRotation(Rotation2D r)
Description copied from interface: Tangible
Changes this object's rotation to the specified Rotation2D. Fires a RotationChangedEvent when called.

Specified by:
setRotation in interface Tangible
Parameters:
r - is new rotation of the object

setSize

public void setSize(Dimension d)
Description copied from interface: Tangible
Changes this object's size to a specified Dimension. Fires a SizeChangedEvent when called.

Specified by:
setSize in interface Tangible
Parameters:
d - is new dimension of the object in the game's coordinate system

getShape

public java.awt.Shape getShape()
Description copied from interface: Tangible
Method for getting a Shape representing the area that can be rendered on screen.

Specified by:
getShape in interface Tangible
Returns:
the shape of the object