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();
}
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;
}
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));
}
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());
}
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();
}
Aggregations