CSE115.BouncyShapes
Class Triangle
java.lang.Object
NGP.Graphics.Shape
NGP.Graphics.RectangularShape
NGP.Graphics.FilledRectangularShape
CSE115.Graphics.FilledTriangle
CSE115.BouncyShapes.Triangle
- All Implemented Interfaces:
- Colorable, EventListener, Graphic, Locatable, MouseListener, MouseMotionListener, Reactor, Rotatable, Shape, Sizeable
- public class Triangle
- extends FilledTriangle
- implements Shape
A triangle that moves when told to.
Must be used with either cs015.SP.Frame or cs015.SP.Applet (or
their subclasses).
Created: Tuesday Oct 12 2004
- Author:
- Carl Alphonce
|
Constructor Summary |
Triangle()
Creates a new Triangle 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 triangle 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 triangle. |
void |
update()
Update the position of the triangle based on the velocity,
if the triangle 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 |
Triangle
public Triangle()
- Creates a new
Triangle instance.
update
public void update()
- Update the position of the triangle based on the velocity,
if the triangle 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 triangle 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 triangle.
- 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.