Search in sources :

Example 1 with PhysicsParticleComponent

use of com.almasb.fxgl.physics.PhysicsParticleComponent in project FXGL by AlmasB.

the class PhysicsParticlesSample method initCloth.

private void initCloth() {
    // 1. define how particles should behave
    ParticleGroupDef groupDef = new ParticleGroupDef();
    groupDef.setTypes(EnumSet.of(ParticleType.ELASTIC));
    // 2. create component and set data
    PhysicsParticleComponent ppComponent = new PhysicsParticleComponent();
    ppComponent.setDefinition(groupDef);
    ppComponent.setColor(Color.DARKGREEN.brighter());
    // 3. create entity, place it and specify volume of particles via bounding box
    Entity cloth = new Entity();
    cloth.getPositionComponent().setValue(150, 10);
    cloth.getBoundingBoxComponent().addHitBox(new HitBox("MAIN", BoundingShape.box(75, 150)));
    // 4. add component
    cloth.addComponent(ppComponent);
    getGameWorld().addEntity(cloth);
}
Also used : ParticleGroupDef(com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef) PhysicsParticleComponent(com.almasb.fxgl.physics.PhysicsParticleComponent) Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox)

Example 2 with PhysicsParticleComponent

use of com.almasb.fxgl.physics.PhysicsParticleComponent in project FXGL by AlmasB.

the class PhysicsParticlesSample method initLiquid.

private void initLiquid() {
    ParticleGroupDef groupDef = new ParticleGroupDef();
    groupDef.setTypes(EnumSet.of(ParticleType.VISCOUS, ParticleType.TENSILE));
    PhysicsParticleComponent ppComponent = new PhysicsParticleComponent();
    ppComponent.setDefinition(groupDef);
    ppComponent.setColor(Color.BLUE.brighter());
    Entity liquid = new Entity();
    liquid.getPositionComponent().setValue(300, 10);
    liquid.getBoundingBoxComponent().addHitBox(new HitBox("MAIN", BoundingShape.circle(35)));
    liquid.addComponent(ppComponent);
    getGameWorld().addEntities(liquid);
}
Also used : ParticleGroupDef(com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef) PhysicsParticleComponent(com.almasb.fxgl.physics.PhysicsParticleComponent) Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox)

Example 3 with PhysicsParticleComponent

use of com.almasb.fxgl.physics.PhysicsParticleComponent 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);
}
Also used : ParticleGroupDef(com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef) PhysicsParticleComponent(com.almasb.fxgl.physics.PhysicsParticleComponent) Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox) PositionComponent(com.almasb.fxgl.entity.component.PositionComponent)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)3 HitBox (com.almasb.fxgl.physics.HitBox)3 PhysicsParticleComponent (com.almasb.fxgl.physics.PhysicsParticleComponent)3 ParticleGroupDef (com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef)3 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)1