The Tile Occupier
A tile occupier has a unique name, a type value (BLOCK, PICKUP, or SPRITE), a tile coordinate (xTile, yTile), and a coordinate relative to the top-left corner of the floor image (xDraw, yDraw), where the occupier's image should be drawn. The relationship between these coordinates is shown in Figure 13-11.

Figure 13-11. Positioning a tile occupier in a tile
xDraw and yDraw are relative to the floor image, so floor offsets must be added to them before the image is drawn into the JPanel. The constructor initializes the coordinate details and calls calcPosition() to calculate xDraw and yDraw:
// globals
private String name;
private int type; // BLOCK, PICKUP, or SPRITE
private BufferedImage image;
private int xTile, yTile; // tile coordinate
private int xDraw, yDraw;
// coordinate relative to the floor image where the tile
// occupier should be drawn
private TiledSprite sprite = null;
// used when the TileOccupier is a sprite
public TileOccupier(String nm, int ty, int x, int y,
BufferedImage im, int xRowStart, int yRowStart,
int xTileWidth, int yTileHeight)
{ name = nm;
type = ty;
xTile = x; yTile = y;
image = im;
calcPosition(xRowStart, yRowStart, xTileWidth, yTileHeight);
}If this object is in an even row, then xRowStart and yRowStart will hold the pixel location of the first even row; otherwise, the location of the first odd row is used. The (x, y) arguments give the ...