Search in sources :

Example 1 with SpawnData

use of com.almasb.fxgl.entity.SpawnData in project FXGL by AlmasB.

the class CircleNNApp method initGame.

@Override
protected void initGame() {
    getGameWorld().addEntityFactory(new CircleNNFactory());
    getGameScene().setBackgroundColor(Color.BLACK);
    spawn("block", 200, 200);
    spawn("block", getAppWidth() - 200 - 64, 200);
    spawn("block", 200, getAppHeight() - 200 - 64);
    spawn("block", getAppWidth() - 200 - 64, getAppHeight() - 200 - 64);
    var spawnPoints = List.of(new Point2D(100, 100), new Point2D(getAppWidth() - 100 - 64, 100), new Point2D(getAppWidth() / 2.0 - 32, 100), new Point2D(100, getAppHeight() / 2.0 - 32), new Point2D(getAppWidth() - 100 - 64, getAppHeight() / 2.0 - 32), new Point2D(getAppWidth() / 2.0 - 32, getAppHeight() / 2.0 - 32), new Point2D(100, getAppHeight() - 100 - 64), new Point2D(getAppWidth() - 100 - 64, getAppHeight() - 100 - 64), new Point2D(getAppWidth() / 2.0 - 32, getAppHeight() - 100 - 64));
    spawn("circle", 500.0, 600.0);
    spawn("circle", 500.0, 600.0);
    // spawnPoints.forEach(point -> {
    // for (int i = 0; i < 11; i++) {
    // spawn("circle", point);
    // }
    // });
    player = getGameWorld().getRandom(CIRCLE).get();
    player.removeComponent(RandomMoveComponent.class);
    player.removeComponent(BlockCollisionComponent.class);
    player.addComponent(new KeepOnScreenComponent());
    player.addComponent(new PlayerComponent());
    getGameWorld().getEntitiesByType(CIRCLE).stream().filter(e -> e != player).forEach(e -> {
        e.getComponent(RandomMoveComponent.class).pause();
        e.getComponent(BlockCollisionComponent.class).pause();
        Bundle bundle = getFileSystemService().<Bundle>readDataTask("editor_json/input/input0.dat").run();
        var input = new InputCapture();
        input.read(bundle);
        e.getComponent(CircleComponent.class).getInput().applyCapture(input);
    });
    place = getGameWorld().getEntitiesByType(CIRCLE).size();
    run(() -> {
        var powerupType = PowerupType.SHIELD;
        // var powerupType = FXGLMath.random(PowerupType.values()).get();
        spawn("powerup", new SpawnData(FXGLMath.randomPoint(new Rectangle2D(0, 0, getAppWidth(), getAppHeight()))).put("powerupType", powerupType));
    }, Duration.seconds(3));
    capture = getInput().startCapture();
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Rectangle2D(javafx.geometry.Rectangle2D) MouseButton(javafx.scene.input.MouseButton) Bundle(com.almasb.fxgl.core.serialization.Bundle) RandomMoveComponent(com.almasb.fxgl.dsl.components.RandomMoveComponent) KeepOnScreenComponent(com.almasb.fxgl.dsl.components.KeepOnScreenComponent) FXGLMath(com.almasb.fxgl.core.math.FXGLMath) InputCapture(com.almasb.fxgl.input.InputCapture) CircleNNType(sandbox.circlegame.CircleNNType) Text(javafx.scene.text.Text) Duration(javafx.util.Duration) List(java.util.List) Interpolators(com.almasb.fxgl.animation.Interpolators) GameSettings(com.almasb.fxgl.app.GameSettings) Point2D(javafx.geometry.Point2D) SpawnData(com.almasb.fxgl.entity.SpawnData) GameApplication(com.almasb.fxgl.app.GameApplication) Entity(com.almasb.fxgl.entity.Entity) FXGL(com.almasb.fxgl.dsl.FXGL) RandomMoveComponent(com.almasb.fxgl.dsl.components.RandomMoveComponent) KeepOnScreenComponent(com.almasb.fxgl.dsl.components.KeepOnScreenComponent) Point2D(javafx.geometry.Point2D) Bundle(com.almasb.fxgl.core.serialization.Bundle) Rectangle2D(javafx.geometry.Rectangle2D) InputCapture(com.almasb.fxgl.input.InputCapture) SpawnData(com.almasb.fxgl.entity.SpawnData)

Example 2 with SpawnData

use of com.almasb.fxgl.entity.SpawnData in project FXGL by AlmasB.

the class PlayerControl method shoot.

public void shoot(Point2D endPoint) {
    double x = position.getX();
    double y = position.getY();
    Point2D velocity = endPoint.subtract(x, y).normalize().multiply(500);
    getEntity().getWorld().spawn("Arrow", new SpawnData(x, y).put("velocity", velocity).put("shooter", getEntity()));
}
Also used : Point2D(javafx.geometry.Point2D) SpawnData(com.almasb.fxgl.entity.SpawnData)

Example 3 with SpawnData

use of com.almasb.fxgl.entity.SpawnData in project FXGL by AlmasB.

the class UnoSample method spawn.

private Entity spawn(Card card, int x, int y) {
    Entity cardEntity = (Entity) getGameWorld().spawn("Card", new SpawnData(x, y).put("card", card));
    cardEntity.getView().setOnMouseClicked(e -> {
        if (card.canUseOn(currentCard.getComponent(CardComponent.class).getValue())) {
            Animation<?> animation = Entities.animationBuilder().duration(Duration.seconds(0.35)).translate(cardEntity).from(cardEntity.getPosition()).to(new Point2D(350, 225)).build();
            animation.setOnFinished(() -> {
                player.removeCard(cardEntity);
                playerHandChanged = true;
                currentCard.addControl(new ExpireCleanControl(Duration.seconds(0.5)));
                currentCard = cardEntity;
                currentCard.setRenderLayer(RenderLayer.BACKGROUND);
                // apply special effect
                switch(card.getRank()) {
                    case SP_PLUS2:
                        break;
                    case SP_PLUS4:
                        break;
                    case SP_SKIP:
                        break;
                    default:
                }
                aiMove();
            });
            animation.startInPlayState();
        }
    });
    return cardEntity;
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Point2D(javafx.geometry.Point2D) SpawnData(com.almasb.fxgl.entity.SpawnData) ExpireCleanControl(com.almasb.fxgl.entity.control.ExpireCleanControl)

Aggregations

SpawnData (com.almasb.fxgl.entity.SpawnData)3 Point2D (javafx.geometry.Point2D)3 Entity (com.almasb.fxgl.entity.Entity)2 Interpolators (com.almasb.fxgl.animation.Interpolators)1 GameApplication (com.almasb.fxgl.app.GameApplication)1 GameSettings (com.almasb.fxgl.app.GameSettings)1 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)1 Bundle (com.almasb.fxgl.core.serialization.Bundle)1 FXGL (com.almasb.fxgl.dsl.FXGL)1 KeepOnScreenComponent (com.almasb.fxgl.dsl.components.KeepOnScreenComponent)1 RandomMoveComponent (com.almasb.fxgl.dsl.components.RandomMoveComponent)1 ExpireCleanControl (com.almasb.fxgl.entity.control.ExpireCleanControl)1 InputCapture (com.almasb.fxgl.input.InputCapture)1 List (java.util.List)1 Rectangle2D (javafx.geometry.Rectangle2D)1 KeyCode (javafx.scene.input.KeyCode)1 MouseButton (javafx.scene.input.MouseButton)1 Color (javafx.scene.paint.Color)1 Text (javafx.scene.text.Text)1 Duration (javafx.util.Duration)1