edu.gatech.cs2335.lemmings.graphics
Class TileSet

java.lang.Object
  extended byedu.gatech.cs2335.lemmings.graphics.TileSet
Direct Known Subclasses:
ImprovedTileSet

public class TileSet
extends java.lang.Object

The tileset class simplifies loading bitmap files that contain several tiles. It is a fairly flexible class, but it does impose certain restrictions on the way the file is organized. First of all, there needs to be a set of control pixels in the upper-right corner of the image. The control pixels start at the coordinate (width-1, 0) and go down from there in the following order: transparency pixel, empty-region pixel, outside anchor pixel, used-region pixel, inside anchor pixel; five in all. The transparency pixel is used for color-keying, and all the pixels of that color in the image will be made transparent. The outside and inside anchor pixels do the same thing currently, and are used to denote the image anchor. When the tile is blitted using the putTile method, the anchor has the coordinates passed in to the method, and the rest of the image is drawn relatively to it. In other words, suppose we blit to rectangular tiles using the same target coordinates. One of the tiles has its anchor in the top-left corner, and the other - in the center. Then the center of the latter tile will coincide with the top-left corner of the former tile. The empty-region and used-region pixels are used to denote where the useful areas of the tile are, and which ones can be discarded. The reason for that is that the tiles in the tileset file have to be arranged in a table. In other words, all tiles in one column have to be the same width, and all the tiles in one row have to be the same height. That is not to say, however, that the width and the height have to be the equal, or that the tiles in different rows have to have the same height, and in different columns - the same width. Suppose a game has only two tiles. We can arrange them in a column. One of the tiles is square, and the other - a very thin rectangle. Then, we could mark the whole first tile as used, and for the second tile - only the space that is actually used up. Since we arranged the tiles in a column, the widths of the tiles have to be the same. However, we can mark the unused areas of the thin tile with the unused-area pixel color, and they will be discarded when blitting.

 Revision History:
     v1.0 (Mar. 11, 2004) - Created the TileSet class
 

Version:
Version 1.0, Mar. 11, 2004
Author:
Vladimir Urazov

Nested Class Summary
protected  class TileSet.FrameInformation
          Information structure for one tile in the tileset.
 
Field Summary
protected static boolean DEBUG
          Show debug output?
protected static boolean VERBOSE
          Show lots of debug output?
 
Constructor Summary
TileSet()
          Creates a new TileSet instance.
 
Method Summary
 void drawTile(java.awt.Graphics destination, java.awt.Point coordinates, int tileNum)
          Puts the tile with the specified number onto the graphics context passed in at the specified coordinates.
protected  int findFirstOccurrence(int lowBound, int highBound, int coordinate, java.awt.Color c1, java.awt.Color c2, boolean vertical)
          Finds the coordinate of the first occurrence of one of the test colors.
protected  int findLastOccurrence(int lowBound, int highBound, int coordinate, java.awt.Color c1, java.awt.Color c2, boolean vertical)
          Finds the coordinate of the last occurrence of one of the test colors.
 java.awt.Dimension getDimension(int tileNum)
          Returns the dimensions of the tile with the specified id.
 java.awt.Rectangle getExtent(int tileNum)
          Returns the extent of the tile with the specified id.
 java.lang.String getFileName()
          Returns the name of the file containing the tileset in a string.
protected  TileSet.FrameInformation[] getFrameList()
          Describe getFrameList method here.
protected  java.awt.image.BufferedImage getFramesetImage()
          Describe getFramesetImage method here.
 java.awt.image.BufferedImage getImage()
          Returns the image on which the tileset resides.
 java.awt.Dimension getLargestDimension()
          Returns the dimensions of the largest tile in the tileset.
 int getTileCount()
          Returns the number of tiles in the tileset.
 boolean loadTileset(java.lang.String name)
          Loads the tileset from a file.
 boolean reloadTileset()
          If the surface was lost, reloads it, but does not reparse the file.
protected  boolean specialLoad()
          Describe specialLoad method here.
 boolean unloadTileset()
          Performs all the necessary clean-up operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

protected static final boolean DEBUG
Show debug output?

See Also:
Constant Field Values

VERBOSE

protected static final boolean VERBOSE
Show lots of debug output?

See Also:
Constant Field Values
Constructor Detail

TileSet

public TileSet()
Creates a new TileSet instance.

Method Detail

loadTileset

public boolean loadTileset(java.lang.String name)
Loads the tileset from a file. Returns true upon success or false upon failure.

Parameters:
name - a String value
Returns:
a boolean value

specialLoad

protected boolean specialLoad()
Describe specialLoad method here.

Returns:
a boolean value

getFrameList

protected TileSet.FrameInformation[] getFrameList()
Describe getFrameList method here.

Returns:
a FrameInformation[] value

getFramesetImage

protected java.awt.image.BufferedImage getFramesetImage()
Describe getFramesetImage method here.

Returns:
a BufferedImage value

findFirstOccurrence

protected int findFirstOccurrence(int lowBound,
                                  int highBound,
                                  int coordinate,
                                  java.awt.Color c1,
                                  java.awt.Color c2,
                                  boolean vertical)
Finds the coordinate of the first occurrence of one of the test colors.

Parameters:
lowBound - an int value
highBound - an int value
coordinate - an int value
c1 - a Color value
c2 - a Color value
vertical - a boolean value
Returns:
an int value

findLastOccurrence

protected int findLastOccurrence(int lowBound,
                                 int highBound,
                                 int coordinate,
                                 java.awt.Color c1,
                                 java.awt.Color c2,
                                 boolean vertical)
Finds the coordinate of the last occurrence of one of the test colors.

Parameters:
lowBound - an int value
highBound - an int value
coordinate - an int value
c1 - a Color value
c2 - a Color value
vertical - a boolean value
Returns:
an int value

reloadTileset

public boolean reloadTileset()
If the surface was lost, reloads it, but does not reparse the file.

Returns:
a boolean value

unloadTileset

public boolean unloadTileset()
Performs all the necessary clean-up operations.

Returns:
a boolean value

getTileCount

public int getTileCount()
Returns the number of tiles in the tileset.

Returns:
an int value

getImage

public java.awt.image.BufferedImage getImage()
Returns the image on which the tileset resides.

Returns:
a BufferedImage value

getFileName

public java.lang.String getFileName()
Returns the name of the file containing the tileset in a string.

Returns:
a String value

getLargestDimension

public java.awt.Dimension getLargestDimension()
Returns the dimensions of the largest tile in the tileset.

Returns:
a Dimension value

getDimension

public java.awt.Dimension getDimension(int tileNum)
Returns the dimensions of the tile with the specified id.

Parameters:
tileNum - an int value
Returns:
a Dimension value

getExtent

public java.awt.Rectangle getExtent(int tileNum)
Returns the extent of the tile with the specified id.

Parameters:
tileNum - an int value
Returns:
a Rectangle value

drawTile

public void drawTile(java.awt.Graphics destination,
                     java.awt.Point coordinates,
                     int tileNum)
Puts the tile with the specified number onto the graphics context passed in at the specified coordinates. Note that the position of the tile will depend on its anchor point, which will be put exactly at the coordinates passed in.

Parameters:
destination - the context to which we want to draw the tile.
coordinates - the coordinates at which we want to draw the tile.
tileNum - the number of the tile we want to draw. The tiles will be numbered automatically, from left to right, from top to bottom, when the image file is parsed.