Search in sources :

Example 56 with Entity

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

the class MarioApp method initPhysics.

@Override
protected void initPhysics() {
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.COIN) {

        @Override
        protected void onCollisionBegin(Entity player, Entity coin) {
            coin.getComponent(CollidableComponent.class).setValue(false);
            Animation<?> anim = Entities.animationBuilder().duration(Duration.seconds(0.5)).interpolator(Interpolators.ELASTIC.EASE_IN()).scale(coin).from(new Point2D(1, 1)).to(new Point2D(0, 0)).buildAndPlay();
            anim.setOnFinished(() -> coin.removeFromWorld());
        }
    });
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.DOOR) {

        @Override
        protected void onCollisionBegin(Entity player, Entity door) {
            getDisplay().showMessageBox("Level Complete!", () -> {
                System.out.println("Dialog closed!");
            });
        }
    });
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Point2D(javafx.geometry.Point2D) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler) Animation(com.almasb.fxgl.animation.Animation)

Example 57 with Entity

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

the class ScifiSample method initLiquid.

private void initLiquid() {
    ParticleGroupDef groupDef = new ParticleGroupDef();
    groupDef.setTypes(EnumSet.of(ParticleType.WATER));
    PhysicsParticleComponent ppComponent = new PhysicsParticleComponent();
    ppComponent.setDefinition(groupDef);
    ppComponent.setColor(Color.BLUE.brighter());
    Entity liquid = new Entity();
    liquid.setPosition(playerControl.getEntity().getComponent(PositionComponent.class).getValue().subtract(0, 650));
    liquid.getBoundingBoxComponent().addHitBox(new HitBox("MAIN", BoundingShape.circle(55)));
    liquid.addComponent(ppComponent);
    getGameWorld().addEntities(liquid);
}
Also used : ParticleGroupDef(com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef) PhysicsParticleComponent(com.almasb.fxgl.physics.PhysicsParticleComponent) Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox) PositionComponent(com.almasb.fxgl.entity.component.PositionComponent)

Example 58 with Entity

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

the class ScifiSample method nextLevel.

private void nextLevel() {
    getGameWorld().setLevelFromMap("mario" + level + ".json");
    Entity player = getGameWorld().getEntitiesByType(ScifiType.PLAYER).get(0);
    playerControl = player.getControl(PlayerControl.class);
    getGameScene().getViewport().setBounds(0, 0, 3000, getHeight());
    getGameScene().getViewport().bindToEntity(player, 500, 0);
    level++;
    if (level == 4)
        level = 1;
    initUI();
}
Also used : Entity(com.almasb.fxgl.entity.Entity)

Example 59 with Entity

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

the class ScifiSample method addRain.

private void addRain() {
    ParticleEmitter emitter = ParticleEmitters.newRainEmitter(getWidth());
    emitter.setSourceImage(getAssetLoader().loadTexture("rain.png").multiplyColor(Color.LIGHTBLUE).getImage());
    Entity rain = Entities.builder().with(new ParticleControl(emitter)).buildAndAttach(getGameWorld());
    rain.getPositionComponent().xProperty().bind(getGameScene().getViewport().xProperty());
    rain.getPositionComponent().yProperty().bind(getGameScene().getViewport().yProperty());
}
Also used : ParticleEmitter(com.almasb.fxgl.effect.ParticleEmitter) Entity(com.almasb.fxgl.entity.Entity) ParticleControl(com.almasb.fxgl.effect.ParticleControl)

Example 60 with Entity

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

the class FXShooterApp method initTreasure.

private void initTreasure() {
    Entity treasure = new Entity();
    treasure.getPositionComponent().setValue(getWidth() / 2, getHeight() / 2);
    treasure.getViewComponent().setView(new Rectangle(40, 40, Color.YELLOW));
    getGameWorld().addEntity(treasure);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)80 Rectangle (javafx.scene.shape.Rectangle)27 Point2D (javafx.geometry.Point2D)24 HitBox (com.almasb.fxgl.physics.HitBox)20 GameApplication (com.almasb.fxgl.app.GameApplication)8 EntityView (com.almasb.fxgl.entity.view.EntityView)8 UserAction (com.almasb.fxgl.input.UserAction)8 CollisionHandler (com.almasb.fxgl.physics.CollisionHandler)8 Color (javafx.scene.paint.Color)7 Input (com.almasb.fxgl.input.Input)5 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)5 Circle (javafx.scene.shape.Circle)5 Line (javafx.scene.shape.Line)5 GameSettings (com.almasb.fxgl.app.GameSettings)4 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)4 FXGL (com.almasb.fxgl.dsl.FXGL)4 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)4 PhysicsParticleComponent (com.almasb.fxgl.physics.PhysicsParticleComponent)4 ParticleGroupDef (com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef)4 Text (javafx.scene.text.Text)4