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