CSE115.BouncyShapes
Class Square
java.lang.Object
NGP.Graphics.Shape
NGP.Graphics.RectangularShape
NGP.Graphics.FilledRectangularShape
NGP.Graphics.FilledRectangle
CSE115.BouncyShapes.Square
- All Implemented Interfaces:
- Colorable, EventListener, Graphic, Locatable, MouseListener, MouseMotionListener, Reactor, Rotatable, Shape, Sizeable
- public class Square
- extends FilledRectangle
- implements Shape
A square that moves when told to.
Must be used with either cs015.SP.Frame or cs015.SP.Applet (or
their subclasses).
Created: Sun Feb 10 15:00:55 2002
- Author:
- Phil Ventura, Carl Alphonce
Modified to from FilledEllipse to FilledSquare.
Constructor Summary |
Square()
Creates a new Square instance. |
Method Summary |
int |
getDx()
Get the change in x. |
int |
getDy()
Get the change in y. |
void |
setAcceleration(Vector dV)
Sets the acceleration (change in velocity) of the square using a vector. |
void |
setFrameDelay(int milliseconds)
Sets the delay in milliseconds between calls to move(). |
void |
setSize(int newDiameter)
Set the diameter. |
void |
setVelocity(int dx,
int dy)
Sets the velocity, in the x and y directions of the square. |
void |
update()
Update the position of the square based on the velocity,
if the square hits a wall, reverses velocity in the appropriate
direction. |
Methods inherited from class NGP.Graphics.Shape |
contains, drag, getBounds, getCenterLocation, getColor, getDrawingPanel, getRotation, hide, intersects, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, paint, react, setColor, setDrawingPanel, setRotation, show |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Square
public Square()
- Creates a new
Square
instance.
update
public void update()
- Update the position of the square based on the velocity,
if the square hits a wall, reverses velocity in the appropriate
direction.
- Specified by:
update
in interface Shape
setAcceleration
public void setAcceleration(Vector dV)
- Sets the acceleration (change in velocity) of the square using a vector.
- Specified by:
setAcceleration
in interface Shape
- Parameters:
dV
- the acceleration (change in velocity) vector
setVelocity
public void setVelocity(int dx,
int dy)
- Sets the velocity, in the x and y directions of the square.
- Parameters:
dx
- the new change in x value.dy
- the new change in y value.
getDx
public int getDx()
- Get the change in x.
- Returns:
- the change in x.
getDy
public int getDy()
- Get the change in y.
- Returns:
- the change in y.
setSize
public void setSize(int newDiameter)
- Set the diameter.
- Parameters:
newDiameter
- the new diameter.
setFrameDelay
public void setFrameDelay(int milliseconds)
- Sets the delay in milliseconds between calls to move().
- Parameters:
milliseconds
- the delay in milliseconds.