Search in sources :

Example 1 with GameView

use of com.almasb.fxgl.app.scene.GameView in project FXGL by AlmasB.

the class RaycastSample method initGame.

@Override
protected void initGame() {
    spawnWall(500, 100, 50, 50);
    spawnWall(550, 150, 50, 50);
    spawnWall(600, 200, 50, 50);
    spawnWall(600, 400, 50, 50);
    spawnWall(300, 450, 50, 50);
    spawnWall(500, 550, 50, 50);
    spawnWall(300, 300, 50, 50);
    laser = new Line();
    laser.setStroke(Color.RED);
    laser.setStrokeWidth(2);
    laser.setStartY(300);
    getGameScene().addGameView(new GameView(laser, 0));
    endY = -300;
}
Also used : Line(javafx.scene.shape.Line) GameView(com.almasb.fxgl.app.scene.GameView)

Example 2 with GameView

use of com.almasb.fxgl.app.scene.GameView 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));
}
Also used : AnimatedColor(com.almasb.fxgl.animation.AnimatedColor) Entity(com.almasb.fxgl.entity.Entity) Grid(com.almasb.fxgl.core.collection.grid.Grid) Texture(com.almasb.fxgl.texture.Texture) ColoredTexture(com.almasb.fxgl.texture.ColoredTexture) WritableImage(javafx.scene.image.WritableImage) HeightMapGenerator(com.almasb.fxgl.procedural.HeightMapGenerator) GameView(com.almasb.fxgl.app.scene.GameView)

Example 3 with GameView

use of com.almasb.fxgl.app.scene.GameView in project FXGL by AlmasB.

the class Anim3DSample method initGame.

@Override
protected void initGame() {
    var box = new Box();
    box.setMaterial(new PhongMaterial(Color.BLUE));
    var e = FXGL.entityBuilder().at(-3, 0, 0).view(box).buildAndAttach();
    FXGL.animationBuilder().repeatInfinitely().autoReverse(true).rotate(e).from(new Point3D(0, 0, 0)).to(new Point3D(45, 45, 45)).buildAndPlay();
    var box2 = new Box();
    box2.setMaterial(new PhongMaterial(Color.RED));
    FXGL.getGameScene().addGameView(new GameView(box2, 0));
    FXGL.animationBuilder().repeatInfinitely().autoReverse(true).rotate(box2).from(new Point3D(0, 0, 0)).to(new Point3D(45, 45, 45)).buildAndPlay();
}
Also used : Point3D(javafx.geometry.Point3D) Box(javafx.scene.shape.Box) PhongMaterial(javafx.scene.paint.PhongMaterial) GameView(com.almasb.fxgl.app.scene.GameView)

Aggregations

GameView (com.almasb.fxgl.app.scene.GameView)3 AnimatedColor (com.almasb.fxgl.animation.AnimatedColor)1 Grid (com.almasb.fxgl.core.collection.grid.Grid)1 Entity (com.almasb.fxgl.entity.Entity)1 HeightMapGenerator (com.almasb.fxgl.procedural.HeightMapGenerator)1 ColoredTexture (com.almasb.fxgl.texture.ColoredTexture)1 Texture (com.almasb.fxgl.texture.Texture)1 Point3D (javafx.geometry.Point3D)1 WritableImage (javafx.scene.image.WritableImage)1 PhongMaterial (javafx.scene.paint.PhongMaterial)1 Box (javafx.scene.shape.Box)1 Line (javafx.scene.shape.Line)1