72 lines
1.9 KiB
Java
72 lines
1.9 KiB
Java
package tfg;
|
|
|
|
import org.jsfml.system.Vector2f;
|
|
|
|
/**
|
|
* Enumeration of tiles comprising maps.
|
|
* @author Ritchie Cunningham
|
|
*/
|
|
public enum Tile {
|
|
WATER, /* Wet and wild tile. */
|
|
SAND, /* Urgh, it gets between my toes. */
|
|
GRASS; /* Soft, green, vivid, inviting.. */
|
|
|
|
/**
|
|
* Length or width of a map tile.
|
|
* Each tile *MUST* be a square, therefore the area of
|
|
* the tile is this number squared.
|
|
*/
|
|
private static int tileSize = 32;
|
|
|
|
/**
|
|
* Get the coords of a specific tile from the tile-set image.
|
|
* @param t The tile to get the coordinates of.
|
|
* @return Coords of the tile image in the tile-set.
|
|
*/
|
|
public static Vector2f getTextureCoords(Tile t) {
|
|
Vector2f textureCoordinates = new Vector2f(0, 0);
|
|
switch(t) {
|
|
case WATER:
|
|
textureCoordinates = new Vector2f(480, 544);
|
|
break;
|
|
case SAND:
|
|
textureCoordinates = new Vector2f(576, 352);
|
|
break;
|
|
case GRASS:
|
|
textureCoordinates = new Vector2f(448, 352);
|
|
break;
|
|
}
|
|
return textureCoordinates;
|
|
}
|
|
|
|
/**
|
|
* Get the side length of a square tile.
|
|
* The tile area is tileSize^2.
|
|
* @return Length of a square map tile.
|
|
*/
|
|
public static int getSize() {
|
|
return tileSize;
|
|
}
|
|
|
|
/**
|
|
* Determine if this tile is safe for the player to walk on.
|
|
* @param t Tile to test.
|
|
* @return If the player can walk on it.
|
|
*/
|
|
public static boolean getCanWalkOn(Tile t) {
|
|
boolean canWalk = false;
|
|
switch(t) {
|
|
case WATER:
|
|
canWalk = false;
|
|
break;
|
|
case SAND:
|
|
canWalk = true;
|
|
break;
|
|
case GRASS:
|
|
canWalk = true;
|
|
break;
|
|
}
|
|
return canWalk;
|
|
}
|
|
}
|