edu.trinity.cs.gamecore
Class Location<B extends Block<B,E>,E extends GameEntity<B,E>>

java.lang.Object
  extended by edu.trinity.cs.gamecore.Location<B,E>
All Implemented Interfaces:
java.io.Serializable

public final class Location<B extends Block<B,E>,E extends GameEntity<B,E>>
extends java.lang.Object
implements java.io.Serializable

This class represents a location in the game. Each location is composed of three parts. The first is a reference to the Screen it is a location in. The second is the x,y coordinate specifying the block it is in. The third is a fine grained x,y giving a more accurate point in that block. It should be noted that this class is immutable. Once you create an instance of it, the values in it will not be changed. The partialMove method returns a new Location object that is offset from the current one by the specified number of "partial coordinate" units.

There are a number of helper functions provided in this class that convert to and from a double format instead of whole and partial values. In this format the block number is the whole part and the fractional part is the partials. There are also functions to convert to units of partials only. These can be helpful for doing collision detection because they put things into consistent units so that you can easily check if two object are overlapping.

This class is a generic that takes the general block type and the general entity type for each game.

See Also:
Serialized Form

Constructor Summary
Location(Screen<B,E> s, double x, double y)
          Constructor that sets the location from doubles.
Location(Screen<B,E> s, int x, int y)
          Constructor that sets the main location coordinates.
Location(Screen<B,E> s, int x, int y, int px, int py)
          Constructor that sets all the location coordinates.
 
Method Summary
 boolean equals(java.lang.Object o)
          This method overrides the same method from object.
 double getDoubleLocX()
          Provides the x-location in terms of a double.
 double getDoubleLocY()
          Provides the y-location in terms of a double.
 int getLocX()
          Returns the x block location.
 int getLocY()
          Returns the y block location.
 int getPartialLocX()
          This method returns the x-location as a single value in units of partials.
 int getPartialLocY()
          This method returns the y-location as a single value in units of partials.
static int getPartialsInWhole()
          Tells you how many partials are currently considered to be in a whole block.
 int getPartialX()
          Returns the x partial block location.
 int getPartialY()
          Returns the y partial block location.
 Screen<B,E> getScreen()
          Returns the Screen object that this location is in.
 Location<B,E> partialMove(int dx, int dy)
          Returns a Location object that has been offset from this one by the specified partial block distance.
static void setPartialsInWhole(int num)
          Allows you to set how many partials should be in a whole block.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Location

public Location(Screen<B,E> s,
                int x,
                int y)
Constructor that sets the main location coordinates. The partial coordinates are set to zero.

Parameters:
s - The screen for this location.
x - The value to be stored in locX.
y - The value to be stored in locY.

Location

public Location(Screen<B,E> s,
                int x,
                int y,
                int px,
                int py)
Constructor that sets all the location coordinates.

Parameters:
s - The screen for this location.
x - The value to be stored in locX.
y - The value to be stored in locY.
px - The value to be stored in partialX.
py - The value to be stored in partialY.

Location

public Location(Screen<B,E> s,
                double x,
                double y)
Constructor that sets the location from doubles. The fractional part of the double provides that partial values.

Parameters:
s - The screen for this location.
x - The value to be stored in locX.
y - The value to be stored in locY.
Method Detail

getScreen

public Screen<B,E> getScreen()
Returns the Screen object that this location is in.

Returns:
The screen object the location is in.

getLocX

public int getLocX()
Returns the x block location.

Returns:
The x block location.

getLocY

public int getLocY()
Returns the y block location.

Returns:
The y block location.

getPartialX

public int getPartialX()
Returns the x partial block location.

Returns:
The x partial block location.

getPartialY

public int getPartialY()
Returns the y partial block location.

Returns:
The y partial block location.

partialMove

public Location<B,E> partialMove(int dx,
                                 int dy)
Returns a Location object that has been offset from this one by the specified partial block distance. This function handles both when the partial motion moves it into another full block as well as problems with going beyond a screen bound.

Parameters:
dx - The partial block offset in x.
dy - The partial block offset in y.
Returns:
A location object offset from the current one.

equals

public boolean equals(java.lang.Object o)
This method overrides the same method from object. If the object passed in is not a Location it returns false. If it is, it checks to see if the screens are the same and if the four position variables are the same.

Overrides:
equals in class java.lang.Object
Parameters:
o - Object to check for equality against.
Returns:
Boolean telling if they are equal.

getPartialLocX

public int getPartialLocX()
This method returns the x-location as a single value in units of partials.

Returns:
The x coordinate in partials.

getPartialLocY

public int getPartialLocY()
This method returns the y-location as a single value in units of partials.

Returns:
The y coordinate in partials.

getDoubleLocX

public double getDoubleLocX()
Provides the x-location in terms of a double. The partials become the fractional part of the value.

Returns:
The x-location as a double.

getDoubleLocY

public double getDoubleLocY()
Provides the y-location in terms of a double. The partials become the fractional part of the value.

Returns:
The y-location as a double.

getPartialsInWhole

public static int getPartialsInWhole()
Tells you how many partials are currently considered to be in a whole block.

Returns:
The number of partials in a block.

setPartialsInWhole

public static void setPartialsInWhole(int num)
Allows you to set how many partials should be in a whole block.

Parameters:
num - The numberof partials you want in a whole block.