Breakout Problem Set Javadocs

breakout
Class BasicBall

java.lang.Object
  extended bybreakout.BasicBall
All Implemented Interfaces:
Ball, BreakoutComponent, Rebounding

public class BasicBall
extends java.lang.Object
implements Ball

Basic implementation of a Ball, with velocity arbitrarily picked at magnitude 3 and direction pi/3.


Field Summary
static int DEFAULT_DIAM
          The diameter of a BasicBall.
protected  boolean diedrebounding
          Whether or not we died during the last resolveBounces phase of the tick.
protected  java.awt.geom.Point2D.Double location
          The location of this BasicBall.
protected  java.awt.Dimension size
          The size of this BasicBall.
protected  java.awt.geom.Line2D.Float velvect
          The velocity vector of this BasicBall.
 
Constructor Summary
BasicBall()
          Creates a default ball with speed 3, direction pi/3, and diameter 10
 
Method Summary
 boolean diedWhileRebounding()
          Tells whether we hit the floor the last time we resolved bounces.
 java.awt.Point getLocation()
          Gets the current coordinates of the ball, cast to an integer grid.
 java.awt.Shape getShape()
          Gets the java.awt.Shape of this ball.
 java.awt.Dimension getSize()
          Gets the current size of the ball.
 boolean hit(BreakoutComponent bc)
          Called by an object implementing the Rebounding interface when it has detected an intersection with this ball.
 void paint(java.awt.Graphics g)
          Paints the ball.
 void resolveBounces(java.util.Iterator it)
          Checks all the BreakoutComponents in an iterator to see if it intersects them, hit()s them, and recalculates its velocity vector.
 void setLocation(java.awt.Point p)
          Sets the location of this ball to (p.x, p.y).
 void update()
          Called by World every tick; sets the new location of the ball, as affected by velocity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DIAM

public static final int DEFAULT_DIAM
The diameter of a BasicBall.

See Also:
Constant Field Values

location

protected java.awt.geom.Point2D.Double location
The location of this BasicBall. Uses Point2D.Double to increase the accuracy of velocity calculations.


size

protected java.awt.Dimension size
The size of this BasicBall.


velvect

protected java.awt.geom.Line2D.Float velvect
The velocity vector of this BasicBall.


diedrebounding

protected boolean diedrebounding
Whether or not we died during the last resolveBounces phase of the tick.

Constructor Detail

BasicBall

public BasicBall()
Creates a default ball with speed 3, direction pi/3, and diameter 10

Method Detail

setLocation

public void setLocation(java.awt.Point p)
Sets the location of this ball to (p.x, p.y).

Specified by:
setLocation in interface BreakoutComponent
Parameters:
p - A Point object representing the ball's intended location.

getLocation

public java.awt.Point getLocation()
Gets the current coordinates of the ball, cast to an integer grid.

Specified by:
getLocation in interface BreakoutComponent
Returns:
a new Point object representing the approximate location of the ball.

getSize

public java.awt.Dimension getSize()
Gets the current size of the ball.

Specified by:
getSize in interface BreakoutComponent
Returns:
a new Dimension object representing the size of the ball.

update

public void update()
Called by World every tick; sets the new location of the ball, as affected by velocity.

Specified by:
update in interface BreakoutComponent

hit

public boolean hit(BreakoutComponent bc)
Called by an object implementing the Rebounding interface when it has detected an intersection with this ball. If this method is overridden in a subclass, it should be sure to call super(bc) to maintain the mechanism that manages the death of balls when they hit the floor.

Specified by:
hit in interface BreakoutComponent
Parameters:
bc - The BreakoutComponent/Rebounding object that detected the hit.
Returns:
false. Invalid to return true, since Rebounding objects may not be removed during the phase of the tick where hits are calculated.
See Also:
BreakoutComponent, Rebounding

getShape

public java.awt.Shape getShape()
Gets the java.awt.Shape of this ball.

Specified by:
getShape in interface BreakoutComponent
Returns:
a new Shape label at the same location and of the same size/shape as this ball.

paint

public void paint(java.awt.Graphics g)
Paints the ball.

Specified by:
paint in interface BreakoutComponent
Parameters:
g - Graphics object for this ball's coordinate frame(ie, already located where we are).
See Also:
BoardPanel

resolveBounces

public void resolveBounces(java.util.Iterator it)
Checks all the BreakoutComponents in an iterator to see if it intersects them, hit()s them, and recalculates its velocity vector.

Specified by:
resolveBounces in interface Rebounding
Parameters:
it - Iterator handed to it by World of all the BreakoutComponents on the current Board.

diedWhileRebounding

public boolean diedWhileRebounding()
Tells whether we hit the floor the last time we resolved bounces. This provides a way to allow balls to die without the component iterators complaining about being modified in the middle of iterating.

Specified by:
diedWhileRebounding in interface Rebounding
Returns:
true if we died while rebounding; false otherwise.

Breakout Problem Set Javadocs