use of com.almasb.fxgl.dsl.components.ProjectileComponent 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.ProjectileComponent in project FXGL by AlmasB.
the class CollisionFilterSample method initGame.
@Override
protected void initGame() {
entityBuilder().type(EType.PLAYER).viewWithBBox(new Rectangle(40, 40, Color.BLUE)).view(new Text("PLAYER")).at(100, 100).with(new CollidableComponent(true), new PhysicsComponent()).buildAndAttach();
entityBuilder().type(EType.ENEMY).viewWithBBox(new Rectangle(40, 40, Color.RED)).view(new Text("ENEMY")).at(400, 100).with(new CollidableComponent(true), new PhysicsComponent()).buildAndAttach();
run(() -> {
CollidableComponent collidable = new CollidableComponent(true);
CollidableComponent collidable2 = new CollidableComponent(true);
if (i == 0) {
debug("No collision with player");
collidable.addIgnoredType(EType.PLAYER);
collidable2.addIgnoredType(EType.PLAYER);
} else if (i == 1) {
debug("No collision with enemy");
collidable.addIgnoredType(EType.ENEMY);
collidable2.addIgnoredType(EType.ENEMY);
} else if (i == 2) {
debug("No collision with player and enemy");
collidable.addIgnoredType(EType.PLAYER);
collidable.addIgnoredType(EType.ENEMY);
collidable2.addIgnoredType(EType.PLAYER);
collidable2.addIgnoredType(EType.ENEMY);
}
i++;
if (i == 3)
i = 0;
// a bullet with no physics
entityBuilder().type(EType.BULLET).viewWithBBox(new Rectangle(20, 10, Color.BLACK)).at(0, 100).with(new ProjectileComponent(new Point2D(1, 0), 100)).with(new OffscreenCleanComponent()).with(collidable).buildAndAttach();
// a bullet with physics
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setOnPhysicsInitialized(() -> physics.setLinearVelocity(100, 0));
entityBuilder().type(EType.BULLET).viewWithBBox(new Rectangle(20, 10, Color.BLACK)).at(0, 130).with(physics).with(new OffscreenCleanComponent()).with(collidable2).buildAndAttach();
}, Duration.seconds(4));
}
use of com.almasb.fxgl.dsl.components.ProjectileComponent in project FXGL by AlmasB.
the class EntityActionSample method initGame.
@Override
protected void initGame() {
getGameScene().setBackgroundColor(Color.LIGHTGRAY);
mover = entityBuilder().at(400, 20).viewWithBBox(texture("player2rot.png").multiplyColor(Color.RED)).with(new ProjectileComponent(new Point2D(0, 1), 200)).onClick(e -> {
entity.getComponent(ActionComponent.class).addAction(new FollowAction(mover));
}).buildAndAttach();
mover2 = entityBuilder().at(500, 200).viewWithBBox(texture("player2rot.png").multiplyColor(Color.BLUE)).with(new ProjectileComponent(new Point2D(1, 0), 250)).onClick(e -> {
entity.getComponent(ActionComponent.class).addAction(new FollowAction(mover2));
}).buildAndAttach();
entity = entityBuilder().at(400, 300).viewWithBBox("player2rot.png").with(new ActionComponent()).with(new FollowComponent(null, 150, 40, 100)).with(new FixRotateComponent()).buildAndAttach();
unit = entityBuilder().at(700, 400).viewWithBBox(new Rectangle(40, 40, Color.GREEN)).with(new FollowComponent(null, 100, 30, 50)).onClick(e -> {
entity.getComponent(ActionComponent.class).addAction(new RecruitAction(unit));
}).buildAndAttach();
// unit2 = entityBuilder()
// .at(700, 200)
// .view(new Rectangle(40, 40, Color.GREEN))
// .with(new FollowComponent(null, 50, 60, 130))
// .onClick(() -> {
// entity.getComponent(ActionComponent.class)
// .addAction(new RecruitAction(unit2));
// })
// .buildAndAttach();
}
Aggregations