Search in sources :

Example 6 with Entity

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

the class ViewportSample method cinematicViewportBezier.

private void cinematicViewportBezier() {
    // 1. get viewport
    Viewport viewport = getGameScene().getViewport();
    viewport.setX(-getWidth() / 2);
    viewport.setY(-getHeight() / 2);
    // 2. define "waypoints"
    Vec2[] points = { new Vec2(98, 80), new Vec2(1520, 90), new Vec2(1470, 272), new Vec2(171, 293), new Vec2(154, 485), new Vec2(1500, 483), new Vec2(1474, 683), new Vec2(144, 698), new Vec2(161, 892), new Vec2(1475, 888), new Vec2(1477, 1064), new Vec2(108, 1066) };
    BezierSpline spline = FXGLMath.closedBezierSpline(points);
    Path path = new Path();
    path.getElements().add(new MoveTo(98, 80));
    for (BezierSpline.BezierCurve c : spline.getCurves()) {
        path.getElements().add(new CubicCurveTo(c.getControl1().x, c.getControl1().y, c.getControl2().x, c.getControl2().y, c.getEnd().x, c.getEnd().y));
    }
    // if open bezier is needed
    path.getElements().remove(path.getElements().size() - 1);
    Entity camera = Entities.builder().build();
    viewport.xProperty().bind(camera.getPositionComponent().xProperty().subtract(getWidth() / 2));
    viewport.yProperty().bind(camera.getPositionComponent().yProperty().subtract(getHeight() / 2));
    Entities.animationBuilder().duration(Duration.seconds(24)).translate(camera).buildAndPlay();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) BezierSpline(com.almasb.fxgl.core.math.BezierSpline) Vec2(com.almasb.fxgl.core.math.Vec2) Viewport(com.almasb.fxgl.scene.Viewport)

Example 7 with Entity

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

the class MarioApp method nextLevel.

private void nextLevel() {
    getGameWorld().setLevelFromMap("mario" + 0 + ".json");
    getGameWorld().spawn("player", 350, 0);
    Entity player = getGameWorld().getEntitiesByType(MarioType.PLAYER).get(0);
    playerControl = player.getControl(PlayerControl.class);
    // player.addControl(new AIControl("robot.tree"));
    getGameScene().getViewport().setBounds(0, 0, 30 * 70, 11 * 70);
    getGameScene().getViewport().bindToEntity(player, 500, 0);
    // getGameWorld().spawn("robot", 1500, 24 * 70 - 1300);
    level++;
    if (level == 4)
        level = 1;
}
Also used : Entity(com.almasb.fxgl.entity.Entity)

Example 8 with Entity

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

the class ScriptSample method initGame.

@Override
protected void initGame() {
    Entity e = Entities.builder().type(EntityType.PC).at(300, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.BLUE)).with(new CollidableComponent(true)).with(new DeveloperWASDControl()).buildAndAttach(getGameWorld());
    Entities.builder().type(EntityType.NPC).at(400, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
    for (int i = 0; i < 3; i++) {
        Entities.builder().type(EntityType.COIN).at(FXGLMath.random(100, 450), 500).viewFromNodeWithBBox(new Circle(20, Color.GOLD)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
    }
    getMasterTimer().runAtInterval(() -> {
        getAudioPlayer().playPositionalSound("drop.wav", new Point2D(400, 300), e.getCenter(), 600);
    }, Duration.seconds(2));
}
Also used : DeveloperWASDControl(com.almasb.fxgl.devtools.DeveloperWASDControl) Entity(com.almasb.fxgl.entity.Entity) Circle(javafx.scene.shape.Circle) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle)

Example 9 with Entity

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

the class ScriptSample2 method initGame.

@Override
protected void initGame() {
    Entity e = Entities.builder().type(EntityType.PC).at(300, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.BLUE)).with(new CollidableComponent(true)).with(new DeveloperWASDControl()).buildAndAttach(getGameWorld());
    Entities.builder().type(EntityType.NPC).at(400, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
}
Also used : DeveloperWASDControl(com.almasb.fxgl.devtools.DeveloperWASDControl) Entity(com.almasb.fxgl.entity.Entity) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle)

Example 10 with Entity

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

the class PhysicsWorld method postStep.

private void postStep() {
    for (Entity e : delayedBodiesAdd) createBody(e);
    delayedBodiesAdd.clear();
    for (Entity e : delayedParticlesAdd) createPhysicsParticles(e);
    delayedParticlesAdd.clear();
    for (Body body : delayedBodiesRemove) jboxWorld.destroyBody(body);
    delayedBodiesRemove.clear();
}
Also used : Entity(com.almasb.fxgl.entity.Entity)

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