public class HashTileGrid extends TileGrid
A HashTileGrid is a type of TileGrid that stores its tile data in HashMaps with grid locations as keys. A HashTileGrid's memory usage is proportional to the number of its grid locations that are occupied by tiles, plus the number of grid locations at which tiles are set to be flipped or rotated. The time needed to iterate through a HashTileGrid's set of tile locations is proportional only to the number of those locations.
Constructor and Description |
---|
HashTileGrid(int numColumns,
int numRows,
int tileWidth,
int tileHeight)
Constructs a HashTileGrid with all of its grid cells unoccupied by tiles,
and with none of its tiles set to be flipped or rotated.
|
HashTileGrid(int leftmostColumn,
int rightmostColumn,
int topmostRow,
int bottommostRow,
int tileWidth,
int tileHeight)
Constructs a HashTileGrid with all of its grid cells unoccupied by tiles,
and with none of its tiles set to be flipped or rotated.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<java.awt.Rectangle> |
cover()
Returns a list of non-overlapping rectangles that collectively overlap or
"cover" all and only the grid cells in this TileGrid that are occupied by
tiles.
|
int |
getBottommostRow()
Returns the index of this TileGrid's bottommost row.
|
int |
getLeftmostColumn()
Returns the index of this TileGrid's leftmost column.
|
int |
getRightmostColumn()
Returns the index of this TileGrid's rightmost column.
|
Drawable |
getTile(int column,
int row)
Returns the tile at the specified location in this TileGrid, or null if
there is none.
|
double |
getTileAngle(int column,
int row)
Returns the angle by which the tile at the specified location in this
TileGrid is rotated, or 0 if the location is outside the bounds of this
TileGrid.
|
java.util.Set<java.awt.Point> |
getTileLocations()
Returns an unmodifiable Set view of the locations in this TileGrid that
are occupied by tiles.
|
boolean |
getTileXFlip(int column,
int row)
Returns whether the tile at the specified location in this TileGrid is
flipped horizontally, or false if the location is outside the bounds of
this TileGrid.
|
boolean |
getTileYFlip(int column,
int row)
Returns whether the tile at the specified location in this TileGrid is
flipped vertically, or false if the location is outside the bounds of
this TileGrid.
|
int |
getTopmostRow()
Returns the index of this TileGrid's topmost row.
|
boolean |
setTile(int column,
int row,
Drawable tile)
Sets the tile at the specified location in this TileGrid to the specified
Drawable.
|
boolean |
setTileAngle(int column,
int row,
double angle)
Sets to the specified value the angle by which the tile at the specified
location in this TileGrid is rotated.
|
boolean |
setTileXFlip(int column,
int row,
boolean xFlip)
Sets whether the tile at the specified location in this TileGrid is
flipped horizontally.
|
boolean |
setTileYFlip(int column,
int row,
boolean yFlip)
Sets whether the tile at the specified location in this TileGrid is
flipped vertically.
|
coverObjects, coverPoints, draw, draw, draw, draw, draw, draw, getTileHeight, getTileWidth
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRenderableRegion
public HashTileGrid(int numColumns, int numRows, int tileWidth, int tileHeight)
numColumns
- The number of this HashTileGrid's columns. Column
indices will range from 0 to numColumns - 1.numRows
- The number of this HashTileGrid's rows. Row indices will
range from 0 to numRows - 1.tileWidth
- The width in pixels of each of this HashTileGrid's tilestileHeight
- The height in pixels of each of this HashTileGrid's
tilespublic HashTileGrid(int leftmostColumn, int rightmostColumn, int topmostRow, int bottommostRow, int tileWidth, int tileHeight)
leftmostColumn
- The index of this HashTileGrid's leftmost columnrightmostColumn
- The index of this HashTileGrid's rightmost columntopmostRow
- The index of this HashTileGrid's topmost rowbottommostRow
- The index of this HashTileGrid's bottommost rowtileWidth
- The width in pixels of each of this HashTileGrid's tilestileHeight
- The height in pixels of each of this HashTileGrid's
tilespublic final int getLeftmostColumn()
TileGrid
getLeftmostColumn
in class TileGrid
public final int getRightmostColumn()
TileGrid
getRightmostColumn
in class TileGrid
public final int getTopmostRow()
TileGrid
getTopmostRow
in class TileGrid
public final int getBottommostRow()
TileGrid
getBottommostRow
in class TileGrid
public final java.util.Set<java.awt.Point> getTileLocations()
TileGrid
getTileLocations
in class TileGrid
public final Drawable getTile(int column, int row)
TileGrid
public final boolean setTile(int column, int row, Drawable tile)
TileGrid
public final boolean getTileXFlip(int column, int row)
TileGrid
getTileXFlip
in class TileGrid
column
- The location's column indexrow
- The location's row indexpublic final boolean setTileXFlip(int column, int row, boolean xFlip)
TileGrid
setTileXFlip
in class TileGrid
column
- The location's column indexrow
- The location's row indexxFlip
- Whether the tile at the specified location should be flipped
horizontallypublic final boolean getTileYFlip(int column, int row)
TileGrid
getTileYFlip
in class TileGrid
column
- The location's column indexrow
- The location's row indexpublic final boolean setTileYFlip(int column, int row, boolean yFlip)
TileGrid
setTileYFlip
in class TileGrid
column
- The location's column indexrow
- The location's row indexyFlip
- Whether the tile at the specified location should be flipped
verticallypublic final double getTileAngle(int column, int row)
TileGrid
getTileAngle
in class TileGrid
column
- The location's column indexrow
- The location's row indexpublic final boolean setTileAngle(int column, int row, double angle)
TileGrid
setTileAngle
in class TileGrid
column
- The location's column indexrow
- The location's row indexangle
- The angle in degrees by which the tile at the specified
location should be rotatedpublic final java.util.List<java.awt.Rectangle> cover()
TileGrid