com.bytefarmers.droids.models
Class DroidModel

java.lang.Object
  extended bycom.bytefarmers.droids.models.DroidModel
Direct Known Subclasses:
AbstractBallModel, AbstractPlayerModel

public class DroidModel
extends java.lang.Object

Class Droid is a simple robot implementation used for simulations and games.

Author:
Fini A. Alring collision detection for round objects (dx*dx + dy*dy) <= (r1*r1 + 2*r1*r2 + r2*r2)

Field Summary
 java.awt.Color arrowColor
           
 java.awt.Color borderColor
           
 DCosSin dcs
           
 java.awt.Point defaultLocation
           
 int direction
           
 java.awt.Color droidColor
           
 java.awt.Point location
           
 int radius
           
 java.awt.Point target
           
 Trajectory trajectory
           
 int velocity
           
 
Constructor Summary
DroidModel()
          Creates a new instance of Droid at default position
DroidModel(int x, int y)
          Creates a new instance of Droid at x,y
 
Method Summary
 int getAngleTo(java.awt.Point targetPoint)
          return angle to a specified location.
 java.awt.Point getBorderLocation(int d)
          get the outer Point (X,Y set) from the Circle shaped Droid.
 java.awt.Point getBorderLocation(int d, int r)
          get the outer Point (X,Y set) from the Circle shaped Droid.
 java.awt.Point getDefaultLocation()
          Returns Droid Default Location (x,y), generally the start position, but can be changed..
 int getDirection()
          Returns Droid direction (d)
 int getDistanceTo(java.awt.Point targetPoint)
          get distance to a specified point
 java.awt.Point getLocation()
          Returns Droid location (x,y)
 int getRadius()
          Returns Droid radius
 java.awt.Point getTarget()
          Returns Droid target (x,y)
 int getVelocity()
          Returns Droid Velocity (v)
 int getX()
          Returns Droid X location
 int getY()
          Returns Droid Y location
 java.awt.Point moveDirection(int degreeAngle, int distance)
          move a specified direction and length
 java.awt.Point moveTowards(java.awt.Point targetPoint, int moveDistance)
          move towards a point
 void render(java.awt.Graphics2D g2d)
          render object onto viewport
 void setDefaultLocation(java.awt.Point p)
          Set Droid Default Location (x,y)
 void setDirection(int d)
          Set new Droid direction (d)
 void setLocation(int x, int y)
          Set new Droid location (x,y)
 void setLocation(java.awt.Point p)
          Set Droid location (x,y)
 void setRadius(int r)
          Set new Droid radius
 void setTarget(java.awt.Point location)
          Set Droid target (x,y)
 void setVelocity(int v)
          Set Droid Velocity (v)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

location

public java.awt.Point location

defaultLocation

public java.awt.Point defaultLocation

borderColor

public java.awt.Color borderColor

droidColor

public java.awt.Color droidColor

arrowColor

public java.awt.Color arrowColor

radius

public int radius

direction

public int direction

velocity

public int velocity

target

public java.awt.Point target

dcs

public DCosSin dcs

trajectory

public Trajectory trajectory
Constructor Detail

DroidModel

public DroidModel()
Creates a new instance of Droid at default position


DroidModel

public DroidModel(int x,
                  int y)
Creates a new instance of Droid at x,y

Parameters:
x - x position
y - y position
Method Detail

getLocation

public java.awt.Point getLocation()
Returns Droid location (x,y)

Returns:
Point

setLocation

public void setLocation(java.awt.Point p)
Set Droid location (x,y)

Parameters:
p - source point

setLocation

public void setLocation(int x,
                        int y)
Set new Droid location (x,y)

Parameters:
x - X-coordinate
y - Y-coordinate

getX

public int getX()
Returns Droid X location

Returns:
Point

getY

public int getY()
Returns Droid Y location

Returns:
Point

getDefaultLocation

public java.awt.Point getDefaultLocation()
Returns Droid Default Location (x,y), generally the start position, but can be changed..

Returns:
Point

setDefaultLocation

public void setDefaultLocation(java.awt.Point p)
Set Droid Default Location (x,y)

Parameters:
p - source point

getTarget

public java.awt.Point getTarget()
Returns Droid target (x,y)

Returns:
Point

setTarget

public void setTarget(java.awt.Point location)
Set Droid target (x,y)

Parameters:
location - source point

getBorderLocation

public java.awt.Point getBorderLocation(int d)
get the outer Point (X,Y set) from the Circle shaped Droid. Specify a degree, it will get the radius from the DroidModel itself, the center will be the DroidModel center.

Parameters:
d - Degrees
Returns:
Point2D

getBorderLocation

public java.awt.Point getBorderLocation(int d,
                                        int r)
get the outer Point (X,Y set) from the Circle shaped Droid. Specify a degree, and a radius to get the point from, the center will be the DroidModel center.

Parameters:
d - Degrees
r - radius (optional)
Returns:
Point2D

getDirection

public int getDirection()
Returns Droid direction (d)

Returns:
(short) this.direction

setDirection

public void setDirection(int d)
Set new Droid direction (d)

Parameters:
d - degree (0-359)

getRadius

public int getRadius()
Returns Droid radius

Returns:
(short) this.radius

setRadius

public void setRadius(int r)
Set new Droid radius

Parameters:
r - radius

getVelocity

public int getVelocity()
Returns Droid Velocity (v)

Returns:
(long) this.velocity

setVelocity

public void setVelocity(int v)
Set Droid Velocity (v)

Parameters:
v - Velocity

render

public void render(java.awt.Graphics2D g2d)
render object onto viewport

Parameters:
g2d - Graphics2S viewport

moveDirection

public java.awt.Point moveDirection(int degreeAngle,
                                    int distance)
move a specified direction and length

Parameters:
degreeAngle - direction angle
distance - move distance
Returns:
Point of new position

moveTowards

public java.awt.Point moveTowards(java.awt.Point targetPoint,
                                  int moveDistance)
move towards a point

Parameters:
targetPoint - move towards this target point
moveDistance - move distance
Returns:
Point of new position

getAngleTo

public int getAngleTo(java.awt.Point targetPoint)
return angle to a specified location.

Parameters:
targetPoint - taret point
Returns:
angle to targetPoint

getDistanceTo

public int getDistanceTo(java.awt.Point targetPoint)
get distance to a specified point

Parameters:
targetPoint - target point
Returns:
distance to targetPoint