|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.trinity.cs.gamecore.Location<B,E>
public final class Location<B extends Block<B,E>,E extends GameEntity<B,E>>
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.
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 |
---|
public Location(Screen<B,E> s, int x, int y)
s
- The screen for this location.x
- The value to be stored in locX.y
- The value to be stored in locY.public Location(Screen<B,E> s, int x, int y, int px, int py)
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.public Location(Screen<B,E> s, double x, double y)
s
- The screen for this location.x
- The value to be stored in locX.y
- The value to be stored in locY.Method Detail |
---|
public Screen<B,E> getScreen()
public int getLocX()
public int getLocY()
public int getPartialX()
public int getPartialY()
public Location<B,E> partialMove(int dx, int dy)
dx
- The partial block offset in x.dy
- The partial block offset in y.
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object to check for equality against.
public int getPartialLocX()
public int getPartialLocY()
public double getDoubleLocX()
public double getDoubleLocY()
public static int getPartialsInWhole()
public static void setPartialsInWhole(int num)
num
- The numberof partials you want in a whole block.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |