Java Code Examples for com.badlogic.gdx.graphics.Colors#get()

The following examples show how to use com.badlogic.gdx.graphics.Colors#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Parser.java    From typing-label with MIT License 6 votes vote down vote up
/** Parses a color from the given string. Returns null if the color couldn't be parsed. */
static Color stringToColor(String str) {
    if(str != null) {

        // Try to parse named color
        Color namedColor = Colors.get(str.toUpperCase());
        if(namedColor != null) {
            return new Color(namedColor);
        }

        // Try to parse hex
        if(str.length() >= 6) {
            try {
                return Color.valueOf(str);
            } catch(NumberFormatException ignored) {
            }
        }
    }

    return null;
}
 
Example 2
Source File: Parser.java    From typing-label with MIT License 6 votes vote down vote up
/** Encloses the given string in brackets to work as a regular color markup tag. */
private static String stringToColorMarkup(String str) {
    if(str != null) {
        // Upper case
        str = str.toUpperCase();

        // If color isn't registered by name, try to parse it as an hex code.
        Color namedColor = Colors.get(str);
        if(namedColor == null) {
            boolean isHexWithoutHashChar = str.length() >= 6 && PATTERN_COLOR_HEX_NO_HASH.matches(str);
            if(isHexWithoutHashChar) {
                str = "#" + str;
            }
        }
    }

    // Return color code
    return "[" + str + "]";
}
 
Example 3
Source File: Map.java    From xibalba with MIT License 5 votes vote down vote up
private void paintForest() {
  map = new MapCell[width][height];

  Array<String> floorTypes = new Array<>();
  floorTypes.add("0915");
  floorTypes.add("1202");

  for (int x = 0; x < geometry.length; x++) {
    for (int y = 0; y < geometry[x].length; y++) {
      if (geometry[x][y] == MapCell.Type.FLOOR) {
        Sprite floor = Main.asciiAtlas.createSprite(floorTypes.random());
        floor.setColor(Colors.get("forestFloor"));
        floor.setFlip(MathUtils.randomBoolean(), false);

        map[x][y] = new MapCell(
            floor, MapCell.Type.FLOOR, "the forest floor"
        );
      } else {
        Sprite wall = Main.asciiAtlas.createSprite("0" + MathUtils.random(5, 6) + "00");
        Color color = Colors.get("forestTree-" + MathUtils.random(1, 3));
        wall.setColor(color);

        map[x][y] = new MapCell(wall, MapCell.Type.WALL, "a tree");
      }

      map[x][y].sprite.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT);
    }
  }

  if (MathUtils.random() > .5f) {
    createWater();
    createBridge();
  }
}
 
Example 4
Source File: Map.java    From xibalba with MIT License 5 votes vote down vote up
private void paintCave() {
  map = new MapCell[width][height];

  for (int x = 0; x < geometry.length; x++) {
    for (int y = 0; y < geometry[x].length; y++) {
      if (geometry[x][y] == MapCell.Type.FLOOR) {
        Sprite floor = Main.asciiAtlas.createSprite("0915");
        Color color = Colors.get("caveFloor-" + +MathUtils.random(1, 3));
        floor.setColor(color);
        map[x][y] = new MapCell(floor, MapCell.Type.FLOOR, "a cave floor");
      } else {
        int neighbours = getGroundNeighbours(x, y);

        if (neighbours > 0) {
          Sprite wall = Main.asciiAtlas.createSprite("1113");
          wall.setColor(Colors.get("caveWall"));
          map[x][y] = new MapCell(wall, MapCell.Type.WALL, "a cave wall");
        } else {
          Sprite nothing = Main.asciiAtlas.createSprite("0000");
          map[x][y] = new MapCell(nothing, MapCell.Type.NOTHING, "nothing");
        }
      }

      map[x][y].sprite.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT);
    }
  }

  if (MathUtils.random() > .75f) {
    createWater();
    createBridge();
  }
}
 
Example 5
Source File: Map.java    From xibalba with MIT License 4 votes vote down vote up
private void createWater() {
  hasWater = true;
  flooded = new MapCell.Type[width][height];

  for (MapCell.Type[] row : flooded) {
    Arrays.fill(row, MapCell.Type.WALL);
  }

  int floodStartX;
  int floodStartY;

  do {
    floodStartX = MathUtils.random(0, width - 1);
    floodStartY = MathUtils.random(0, height - 1);
  } while (!map[floodStartX][floodStartY].isFloor());

  flood(floodStartX, floodStartY);

  for (int x = 0; x < flooded.length; x++) {
    for (int y = 0; y < flooded[0].length; y++) {
      if (flooded[x][y] == MapCell.Type.FLOOR) {
        Sprite water = Main.asciiAtlas.createSprite("0715");
        water.setPosition(x * Main.SPRITE_WIDTH, y * Main.SPRITE_HEIGHT);

        MapCell.Type waterType;
        Color lightColor;
        Color darkColor;

        if (getGroundNeighbours(x, y) < 8) {
          waterType = MapCell.Type.SHALLOW_WATER;

          lightColor = Colors.get(
              Objects.equals(type, "forest") ? "waterShallowLightBlue" : "waterShallowLightGreen"
          );

          darkColor = Colors.get(
              Objects.equals(type, "forest") ? "waterShallowDarkBlue" : "waterShallowDarkGreen"
          );
        } else {
          waterType = MapCell.Type.DEEP_WATER;

          lightColor = Colors.get(
              Objects.equals(type, "forest") ? "waterDeepLightBlue" : "waterDeepLightGreen"
          );

          darkColor = Colors.get(
              Objects.equals(type, "forest") ? "waterDeepDarkBlue" : "waterDeepDarkGreen"
          );
        }

        water.setColor(lightColor);
        Tween tween = Tween.to(water, SpriteAccessor.COLOR, .5f).target(
            darkColor.r, darkColor.g, darkColor.b
        ).repeatYoyo(Tween.INFINITY, MathUtils.random());

        map[x][y] = new MapCell(water, waterType, "water", tween);
      }
    }
  }
}