use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.
the class FiringRangeFactory method newBullet.
@Spawns("bullet")
public Entity newBullet(SpawnData data) {
var sphere = new Sphere(0.5);
sphere.setMaterial(new PhongMaterial(Color.YELLOW));
Point3D dir = data.get("dir");
return entityBuilder(data).type(FiringRangeEntityType.BULLET).bbox(new HitBox(BoundingShape.box3D(1, 1, 1))).view(sphere).with(new Projectile3DComponent(dir, 50)).with(new ExpireCleanComponent(Duration.seconds(5))).collidable().build();
}
use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.
the class ParticleShowcaseSample2 method spawnParticles.
private void spawnParticles(Entity enemy) {
var emitter1 = ParticleEmitters.newExplosionEmitter(30);
emitter1.setMaxEmissions(1);
emitter1.setNumParticles(650);
emitter1.setEmissionRate(0.86);
emitter1.setSize(1, 14);
emitter1.setScaleFunction(i -> FXGLMath.randomPoint2D().multiply(0.01));
emitter1.setExpireFunction(i -> Duration.seconds(random(0.25, 3)));
emitter1.setInterpolator(Interpolators.EXPONENTIAL.EASE_OUT());
emitter1.setAccelerationFunction(() -> new Point2D(0, random(0, 1)));
// emitter1.setVelocityFunction(i -> Point2D.ZERO);
// emitter1.setVelocityFunction(i -> FXGLMath.randomPoint2D().multiply(random(5, 25)));
var name = names[index++];
System.out.println("Using " + name);
if (index == names.length) {
index = 0;
}
// var c = FXGLMath.randomColor();
var c = Color.ORANGERED;
emitter1.setSourceImage(texture("particles/" + "circle_05.png", 32, 32).multiplyColor(c));
emitter1.setAllowParticleRotation(true);
emitter1.setControl(p -> {
var x = p.position.x;
var y = p.position.y;
var noiseValue = FXGLMath.noise2D(x * 0.002 * t, y * 0.002 * t);
var angle = FXGLMath.toDegrees((noiseValue + 1) * Math.PI * 1.5);
angle %= 360.0;
var v = Vec2.fromAngle(angle).normalizeLocal().mulLocal(FXGLMath.random(1.0, 5));
var vx = p.velocity.x * 0.8f + v.x * 0.2f;
var vy = p.velocity.y * 0.8f + v.y * 0.2f;
p.velocity.x = vx;
p.velocity.y = vy;
});
entityBuilder().at(enemy.getPosition().add(16, 16)).with(new ParticleComponent(emitter1)).with(new ExpireCleanComponent(Duration.seconds(6))).buildAndAttach();
}
use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.
the class ParticleShowcaseSample2 method initInput.
@Override
protected void initInput() {
onBtnDown(MouseButton.SECONDARY, () -> {
var c = FXGLMath.randomColor();
emitter.setStartColor(c);
emitter.setEndColor(c.invert());
var name = names[index++];
System.out.println("Using " + name);
emitter.setSourceImage(texture("particles/" + name, 32, 32).multiplyColor(c));
if (index == names.length) {
index = 0;
}
});
onKeyDown(KeyCode.R, () -> {
emitter.setAllowParticleRotation(!emitter.isAllowParticleRotation());
});
onBtnDown(MouseButton.PRIMARY, () -> {
emitter = ParticleEmitters.newExplosionEmitter(60);
emitter.setMaxEmissions(3);
emitter.setNumParticles(350);
emitter.setEmissionRate(0.86);
emitter.setSize(1, 24);
emitter.setScaleFunction(i -> FXGLMath.randomPoint2D().multiply(0.02));
emitter.setExpireFunction(i -> Duration.seconds(random(1.25, 3.5)));
var i = Interpolators.values()[interpolatorIndex++];
if (interpolatorIndex == Interpolators.values().length)
interpolatorIndex = 0;
debug.setText("Easing (out): " + i.toString());
emitter.setInterpolator(i.EASE_OUT());
emitter.setAccelerationFunction(() -> new Point2D(0, random(1, 3)));
// emitter.setVelocityFunction(i -> Point2D.ZERO);
// emitter.setVelocityFunction(i -> FXGLMath.randomPoint2D().multiply(random(1, 15)));
var name = names[index++];
System.out.println("Using " + name);
if (index == names.length) {
index = 0;
}
// FXGLMath.randomColor();
var c = Color.YELLOW;
// name before
emitter.setSourceImage(texture("particles/" + "flare_01.png", 32, 32).multiplyColor(c));
emitter.setAllowParticleRotation(true);
// emitter.setControl(p -> {
// var x = p.position.x;
// var y = p.position.y;
//
// var noiseValue = FXGLMath.noise2D(x * 0.002 * t, y * 0.002 * t);
// var angle = FXGLMath.toDegrees((noiseValue + 1) * Math.PI * 1.5);
//
// angle %= 360.0;
//
// var v = Vec2.fromAngle(angle).normalizeLocal().mulLocal(FXGLMath.random(1.0, 15));
//
// var vx = p.velocity.x * 0.8f + v.x * 0.2f;
// var vy = p.velocity.y * 0.8f + v.y * 0.2f;
//
// p.velocity.x = vx;
// p.velocity.y = vy;
// });
e = entityBuilder().at(getAppWidth() / 2, getAppHeight() / 2).with(new ParticleComponent(emitter)).with(new ExpireCleanComponent(Duration.seconds(6))).buildAndAttach();
// e.xProperty().bind(getInput().mouseXWorldProperty().subtract(10));
// e.yProperty().bind(getInput().mouseYWorldProperty().subtract(10));
// var tank = entityBuilder()
// .type(Type.PLAYER)
// .at(e.getPosition().subtract(16, 16))
// .viewWithBBox(texture("tank_player.png"))
// .with(new ExpireCleanComponent(Duration.seconds(3)))
// .scale(0, 0)
// .buildAndAttach();
//
// tank.getViewComponent().setOpacity(0);
//
// animationBuilder()
// .delay(Duration.seconds(0.5))
// .fadeIn(tank)
// .buildAndPlay();
//
// animationBuilder()
// .delay(Duration.seconds(0.5))
// .scale(tank)
// .from(new Point2D(0, 0))
// .to(new Point2D(1, 1))
// .buildAndPlay();
});
onKeyDown(KeyCode.F, () -> {
entityBuilder().type(Type.BULLET).at(getInput().getMouseXWorld(), getInput().getMouseYWorld()).viewWithBBox("tank_bullet.png").with(new ProjectileComponent(new Point2D(1, 0), 870)).collidable().buildAndAttach();
});
}
use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.
the class UnoSample method playCard.
/**
* Move a valid card from a hand to the center.
*
* @param hand the hand from which the card is being played
* @param cardEntity the card being played
* @param onFinished action to perform once the card has been played
*/
private void playCard(Hand hand, Entity cardEntity, Runnable onFinished) {
Entity currentCard = geto("currentCard");
currentCard.setZIndex(-1);
Card card = cardEntity.getObject("card");
animationBuilder().onFinished(() -> {
hand.removeCard(cardEntity);
currentCard.addComponent(new ExpireCleanComponent(Duration.seconds(0.5)));
set("currentCard", cardEntity);
boolean wasSpecialUsed = false;
switch(card.getRank()) {
case SP_PLUS2:
{
for (int i = 0; i < 2; i++) {
nextHand.addCard(spawnCard(deck.drawCard()));
}
wasSpecialUsed = true;
break;
}
case SP_PLUS4:
{
for (int i = 0; i < 4; i++) {
nextHand.addCard(spawnCard(deck.drawCard()));
}
wasSpecialUsed = true;
break;
}
case SP_SKIP:
{
wasSpecialUsed = true;
break;
}
default:
break;
}
if (hand.cardsProperty().isEmpty()) {
getDialogService().showMessageBox("Hand wins: " + hand, getGameController()::exit);
} else {
if (!wasSpecialUsed) {
onFinished.run();
} else {
if (nextHand == player) {
aiMove();
} else {
isPlayerTurn = true;
}
}
}
}).duration(Duration.seconds(0.35)).translate(cardEntity).from(cardEntity.getPosition()).to(centerCardPosition).buildAndPlay();
}
use of com.almasb.fxgl.dsl.components.ExpireCleanComponent in project FXGL by AlmasB.
the class RevoluteJointSample method spawnBullet.
private void spawnBullet(double x, double y, double vx, double vy) {
var physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().density(25.5f).restitution(0.5f));
physics.setBodyType(BodyType.DYNAMIC);
physics.setOnPhysicsInitialized(() -> {
physics.setLinearVelocity(vx * 10, vy * 10);
});
entityBuilder().at(x, y).bbox(new HitBox(BoundingShape.circle(450 / 15.0 / 2.0))).view(texture("ball.png", 450 / 15.0, 449 / 15.0)).with(physics).with(new ExpireCleanComponent(Duration.seconds(5)).animateOpacity()).buildAndAttach();
}
Aggregations