package edu.gatech.cs2335.lemmings.graphics; //import java.util.List; //import java.util.Vector; //import java.net.URL; import java.awt.Point; //import java.awt.Color; import java.awt.Graphics; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.image.Raster; //import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; /** * Class ImprovedTileSet: This tileset is essentially an improved * version of the regular tileset. * *
 * Revision History:
 *     v1.0 (Mar. 01, 2004) - Created the ImprovedTileSet class
 * 
* * @author Vladimir Urazov * @version Version 1.0, Mar. 01, 2004 */ public class ImprovedTileSet extends TileSet { /** * The list of tiles in this tileset, accelerated and ready to * render. */ private BufferedImage[] tiles; /** * Describe constant VERBOSE here. * */ private static final boolean VERBOSE = false; /** * Creates a new ImprovedTileSet instance. */ public ImprovedTileSet() { tiles = null; } /** * Describe specialLoad method here. * * @return a boolean value */ protected boolean specialLoad() { if (VERBOSE) { System.out.println("How can we NOT use Verbose? "); } //Now, create the images and stuff: tiles = new BufferedImage[getFrameList().length]; for (int k = 0; k < tiles.length; k++) { //Fetch raster: Rectangle src = getFrameList()[k].getSource(); Raster data = getFramesetImage().getData(src); tiles[k] = new BufferedImage(data.getWidth(), data.getHeight(), getFramesetImage().getType()); tiles[k].setData(data.createRaster(data.getSampleModel(), data.getDataBuffer(), null)); } return true; } /** * Performs all the necessary clean-up operations. * * @return a boolean value */ public synchronized boolean unloadTileset() { //Clean up the tile list if necessary: if (tiles != null) { tiles = null; } return true; } /** * Returns the number of tiles in the tileset. * @return an int value */ public synchronized int getTileCount() { return tiles.length; } /** * Returns the dimensions of the largest tile in the tileset. * * @return a Dimension value */ public synchronized Dimension getLargestDimension() { Dimension result = new Dimension(); for (int i = 0; i < tiles.length; i++) { int width = tiles[i].getWidth(); int height = tiles[i].getHeight(); if (width > result.width) { result.width = width; } if (height > result.height) { result.height = height; } } return result; } /** * Returns the dimensions of the tile with the specified id. * * @param tileNum an int value * @return a Dimension value */ public synchronized Dimension getDimension(int tileNum) { Dimension result = new Dimension(); result.width = tiles[tileNum].getWidth(); result.height = tiles[tileNum].getHeight(); return result; } /** * 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. * * @param destination the context to which we want to draw the tile. * @param coordinates the coordinates at which we want to draw the tile. * @param 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. */ public synchronized void drawTile(Graphics destination, Point coordinates, int tileNum) { if (DEBUG) { System.out.println("TileSet.drawTile - Drawing tile " + tileNum + " at (" + coordinates.x + ", " + coordinates.y + ")"); System.out.flush(); } coordinates.translate(getFrameList()[tileNum].getExtent().x, getFrameList()[tileNum].getExtent().y); //Render tile: destination.drawImage(tiles[tileNum], coordinates.x, coordinates.y, null); coordinates.translate(-getFrameList()[tileNum].getExtent().x, -getFrameList()[tileNum].getExtent().y); } }