Beispiel #1
0
 // Gets the topmost unit in the array and that location, or null if empty
 public BufferedImage getUnitSprite(MapLocation mapLocation) {
   ArrayList<Unit> units = world.getUnitList(mapLocation);
   if (units.isEmpty()) {
     return null;
   }
   return unitMap.get(units.get(0).getUnitType());
 }
Beispiel #2
0
  // Gets the appropriate city sprite based on the city level or null if no city at that location
  public BufferedImage getCitySprite(MapLocation mapLocation) {
    City city = world.getCity(mapLocation);
    if (city == null) {
      return null;
    }

    return cityMap.get(city.getStyle().toString() + "_" + city.getLevel());
  }
Beispiel #3
0
 // Tries to retrieve the appropriate sprite given a set of
 // coords as a map location, if it can't find it, the method
 // will return null;
 public BufferedImage getTerrainSprite(MapLocation coords) {
   try {
     // Get the tile that we want to look around for ease of use later.
     Tile tile = world.getTile(coords);
     TerrainType tileType = tile.getTerrainType();
     // IF the tile is grass, then we dont care whats around, it we just
     // return the grass sprite, otherwise we need to look.
     if (tile.getTerrainType() == TerrainType.GRASSLAND) return this.terrainMap.get("GRASSLAND");
     int y = coords.y;
     int x = coords.x;
     int my = world.getMap().getMapHeight();
     int mx = world.getMap().getMapWidth();
     // get the base key for the sprite, ex "DESERT"
     String key = tile.getTerrainType().toString();
     // Check whats around the tile :D
     boolean north = (y > 0 ? world.getTile(x, y - 1).getTerrainType() == tileType : true);
     boolean east =
         (world.getTile(x + 1 > mx - 1 ? (x + 1) - mx : x + 1, y).getTerrainType() == tileType);
     boolean south = (y < my - 1 ? world.getTile(x, y + 1).getTerrainType() == tileType : true);
     boolean west =
         (world.getTile(x - 1 < 0 ? (x - 1) + mx : x - 1, y).getTerrainType() == tileType);
     // if the terrain is a hill, mountain or forest, we only care what
     // is east and west of it (we dont have sprites for N and S)
     if (tileType == TerrainType.HILLS
         || tileType == TerrainType.MOUNTAINS
         || tileType == TerrainType.FOREST) north = south = false;
     // Append the appropriate key to the type of it has surrounding types
     if (north || east || south || west)
       key +=
           "_" + (north ? "N" : "") + (east ? "E" : "") + (south ? "S" : "") + (west ? "W" : "");
     // Return the sprite.
     return this.terrainMap.get(key);
   } catch (Exception e) {
     return null;
   }
 }