use of com.almasb.fxgl.core.collection.grid.Grid 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();
});
}
use of com.almasb.fxgl.core.collection.grid.Grid in project FXGL by AlmasB.
the class MapGenerationSample method variety.
private void variety() {
// tile size
int size = 5;
int W = (getAppWidth() - 200) / size;
int H = getAppHeight() / size;
Grid<HeightMapGenerator.HeightData> map = new Grid<>(HeightMapGenerator.HeightData.class, W, H, new CustomHeightMapGenerator(W, H));
map.forEach(cell -> {
Texture texture;
if (cell.getHeight() < 0.2) {
// water
texture = new ColoredTexture(size, size, Color.BLUE);
} else if (cell.getHeight() < 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();
});
}
use of com.almasb.fxgl.core.collection.grid.Grid in project FXGL by AlmasB.
the class MapGenerationSample method coloredMap.
private void coloredMap() {
// tile size
int size = 1;
int W = (getAppWidth() + 200) / size;
int H = (getAppHeight() + 200) / size;
Grid<HeightMapGenerator.HeightData> map = new Grid<>(HeightMapGenerator.HeightData.class, W, H, new CustomHeightMapGenerator(W, H));
AnimatedColor water = new AnimatedColor(Color.DARKBLUE, Color.AQUA);
AnimatedColor land = new AnimatedColor(Color.DARKGREEN, Color.LIGHTGREEN);
AnimatedColor desert = new AnimatedColor(Color.GREENYELLOW, Color.LIGHTYELLOW);
AnimatedColor snow = new AnimatedColor(Color.GREEN, Color.WHITESMOKE);
WritableImage image = new WritableImage(W, H);
map.forEach(cell -> {
AnimatedColor anim;
double adjustedValue;
if (cell.getHeight() < 0.2) {
anim = water;
adjustedValue = map(cell.getHeight(), 0.0, 0.2, 0.0, 1.0);
} else if (cell.getHeight() < 0.4) {
anim = land;
adjustedValue = map(cell.getHeight(), 0.2, 0.4, 0.0, 1.0);
} else if (cell.getHeight() < 0.9) {
anim = desert;
adjustedValue = map(cell.getHeight(), 0.4, 0.9, 0.0, 1.0);
} else {
anim = snow;
adjustedValue = map(cell.getHeight(), 0.9, 1.0, 0.0, 1.0);
}
image.getPixelWriter().setColor(cell.getX(), cell.getY(), anim.getValue(adjustedValue, interpolator.EASE_OUT()));
});
getGameScene().getViewport().bindToEntity(new Entity(), 0, 0);
var t = new Texture(image);
t.setTranslateX(-100);
t.setTranslateY(-100);
getGameScene().addGameView(new GameView(t, 0));
}
Aggregations