Search in sources :

Example 41 with Entity

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

the class MarioApp method initPhysics.

@Override
protected void initPhysics() {
    getPhysicsWorld().setGravity(0, 500 * 2.5);
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.GHOST_PLATFORM) {

        @Override
        protected void onCollisionBegin(Entity a, Entity platform) {
            platform.getView().setVisible(true);
        }

        @Override
        protected void onCollisionEnd(Entity a, Entity platform) {
            platform.getView().setVisible(false);
        }
    });
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(MarioType.PLAYER, MarioType.PORTAL) {

        @Override
        protected void onCollisionBegin(Entity a, Entity b) {
            nextLevel = true;
        }
    });
    getPhysicsWorld().addCollisionHandler(new CollectibleHandler(MarioType.PLAYER, MarioType.COIN, "drop.wav"));
}
Also used : CollectibleHandler(com.almasb.fxgl.physics.handler.CollectibleHandler) Entity(com.almasb.fxgl.entity.Entity) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler)

Example 42 with Entity

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

the class PhysicsWorld method raycast.

/**
 * Performs a ray cast from start point to end point.
 *
 * @param start start point
 * @param end end point
 * @return ray cast result
 */
public RaycastResult raycast(Point2D start, Point2D end) {
    raycastCallback.reset();
    jboxWorld.raycast(raycastCallback, toPoint(start), toPoint(end));
    Entity entity = null;
    Point2D point = null;
    if (raycastCallback.getFixture() != null)
        entity = (Entity) raycastCallback.getFixture().getBody().getUserData();
    if (raycastCallback.getPoint() != null)
        point = toPoint(raycastCallback.getPoint());
    if (entity == null && point == null)
        return RaycastResult.NONE;
    return new RaycastResult(entity, point);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Point2D(javafx.geometry.Point2D)

Example 43 with Entity

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

the class PhysicsSample2 method initPhysics.

@Override
protected void initPhysics() {
    // 3. get physics world and register a collision handler
    // between Type.PLAYER and Type.ENEMY
    PhysicsWorld physics = getPhysicsWorld();
    physics.addCollisionHandler(new CollisionHandler(Type.PLAYER, Type.ENEMY) {

        @Override
        protected void onCollision(Entity player, Entity enemy) {
            isColliding = true;
        }
    });
}
Also used : Entity(com.almasb.fxgl.entity.Entity) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler) PhysicsWorld(com.almasb.fxgl.physics.PhysicsWorld)

Example 44 with Entity

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

the class AssetsSample method approach2.

private void approach2() {
    Entity brick2 = new Entity();
    brick2.setPosition(200, 300);
    // if you don't need texture reference
    brick2.setViewFromTexture("brick.png");
    getGameWorld().addEntity(brick2);
}
Also used : Entity(com.almasb.fxgl.entity.Entity)

Example 45 with Entity

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

the class AnimColorSample method initGame.

@Override
protected void initGame() {
    Rectangle playerView = new Rectangle(40, 40);
    Entity player = Entities.builder().at(100, 100).viewFromNode(playerView).with(new ColorComponent()).buildAndAttach();
    playerView.fillProperty().bind(player.getComponent(ColorComponent.class).valueProperty());
    Entities.animationBuilder().duration(Duration.seconds(2)).repeat(4).color(player).fromColor(Color.AQUA).toColor(Color.BURLYWOOD).buildAndPlay();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) ColorComponent(com.almasb.fxgl.entity.component.ColorComponent) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)55 Rectangle (javafx.scene.shape.Rectangle)21 Point2D (javafx.geometry.Point2D)15 HitBox (com.almasb.fxgl.physics.HitBox)12 EntityView (com.almasb.fxgl.entity.view.EntityView)8 UserAction (com.almasb.fxgl.input.UserAction)6 CollisionHandler (com.almasb.fxgl.physics.CollisionHandler)6 Input (com.almasb.fxgl.input.Input)5 GameApplication (com.almasb.fxgl.app.GameApplication)4 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)4 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)4 PhysicsParticleComponent (com.almasb.fxgl.physics.PhysicsParticleComponent)4 ParticleGroupDef (com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef)4 GameSettings (com.almasb.fxgl.settings.GameSettings)4 ParticleControl (com.almasb.fxgl.effect.ParticleControl)3 ParticleEmitter (com.almasb.fxgl.effect.ParticleEmitter)3 Entities (com.almasb.fxgl.entity.Entities)3 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)3 Color (javafx.scene.paint.Color)3 Circle (javafx.scene.shape.Circle)3