Search in sources :

Example 1 with BiomeMapGenerator

use of com.almasb.fxgl.procedural.BiomeMapGenerator in project FXGL by AlmasB.

the class MapGenerationSample method plain.

private void plain() {
    // tile size
    int size = 5;
    int W = (getAppWidth() - 200) / size;
    int H = getAppHeight() / size;
    Grid<BiomeMapGenerator.BiomeData> map = new Grid<>(BiomeMapGenerator.BiomeData.class, W, H, new BiomeMapGenerator(W, H, 2.4));
    map.forEach(cell -> {
        Texture texture;
        if (cell.getElevation() < 0.2) {
            // water
            texture = new ColoredTexture(size, size, Color.BLUE);
        } else if (cell.getElevation() < 0.8) {
            // grass
            texture = texture("grass.png", size, size);
        } else {
            // in-land grass / mud?
            texture = texture("grass.png", size, size).desaturate().brighter().desaturate();
        }
        entityBuilder().at(cell.getX() * size, cell.getY() * size).view(texture).buildAndAttach();
    });
}
Also used : BiomeMapGenerator(com.almasb.fxgl.procedural.BiomeMapGenerator) Grid(com.almasb.fxgl.core.collection.grid.Grid) Texture(com.almasb.fxgl.texture.Texture) ColoredTexture(com.almasb.fxgl.texture.ColoredTexture) ColoredTexture(com.almasb.fxgl.texture.ColoredTexture)

Aggregations

Grid (com.almasb.fxgl.core.collection.grid.Grid)1 BiomeMapGenerator (com.almasb.fxgl.procedural.BiomeMapGenerator)1 ColoredTexture (com.almasb.fxgl.texture.ColoredTexture)1 Texture (com.almasb.fxgl.texture.Texture)1