Search in sources :

Example 6 with CollisionHandler

use of com.almasb.fxgl.physics.CollisionHandler 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)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)6 CollisionHandler (com.almasb.fxgl.physics.CollisionHandler)6 Animation (com.almasb.fxgl.animation.Animation)2 HitBox (com.almasb.fxgl.physics.HitBox)2 PhysicsWorld (com.almasb.fxgl.physics.PhysicsWorld)2 CollectibleHandler (com.almasb.fxgl.physics.handler.CollectibleHandler)2 DSLKt.geti (com.almasb.fxgl.app.DSLKt.geti)1 DSLKt.set (com.almasb.fxgl.app.DSLKt.set)1 GameApplication (com.almasb.fxgl.app.GameApplication)1 ParticleControl (com.almasb.fxgl.effect.ParticleControl)1 ParticleEmitter (com.almasb.fxgl.effect.ParticleEmitter)1 ParticleEmitters (com.almasb.fxgl.effect.ParticleEmitters)1 Entities (com.almasb.fxgl.entity.Entities)1 RenderLayer (com.almasb.fxgl.entity.RenderLayer)1 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)1 ParallaxBackgroundView (com.almasb.fxgl.entity.view.ParallaxBackgroundView)1 ParallaxTexture (com.almasb.fxgl.entity.view.ParallaxTexture)1 QTE (com.almasb.fxgl.gameplay.qte.QTE)1 UserAction (com.almasb.fxgl.input.UserAction)1 BoundingShape (com.almasb.fxgl.physics.BoundingShape)1