first commit

This commit is contained in:
Jose Caban
2025-06-07 01:59:34 -04:00
commit 388ac241f0
3558 changed files with 9116289 additions and 0 deletions

View File

@@ -0,0 +1,173 @@
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.
*
* <PRE>
* Revision History:
* v1.0 (Mar. 01, 2004) - Created the ImprovedTileSet class
* </PRE>
*
* @author <A HREF="mailto:gtg308i@mail.gatech.edu">Vladimir Urazov</A>
* @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 <code>VERBOSE</code> here.
*
*/
private static final boolean VERBOSE = false;
/**
* Creates a new <code>ImprovedTileSet</code> instance.
*/
public ImprovedTileSet() {
tiles = null;
}
/**
* Describe <code>specialLoad</code> method here.
*
* @return a <code>boolean</code> 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 <code>boolean</code> 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 <code>int</code> value
*/
public synchronized int getTileCount() {
return tiles.length;
}
/**
* Returns the dimensions of the largest tile in the tileset.
*
* @return a <code>Dimension</code> 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 <code>int</code> value
* @return a <code>Dimension</code> 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);
}
}