use of com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef in project FXGL by AlmasB.
the class PhysicsWorld method createPhysicsParticles.
private void createPhysicsParticles(Entity e) {
double x = e.getX();
double y = e.getY();
double width = e.getWidth();
double height = e.getHeight();
ParticleGroupDef def = e.getComponent(PhysicsParticleComponent.class).getDefinition();
def.setPosition(toMetersF(x + width / 2), toMetersF(appHeight - (y + height / 2)));
Shape shape = null;
BoundingBoxComponent bbox = e.getBoundingBoxComponent();
if (!bbox.hitBoxesProperty().isEmpty()) {
if (bbox.hitBoxesProperty().get(0).getShape().type == ShapeType.POLYGON) {
PolygonShape rectShape = new PolygonShape();
rectShape.setAsBox(toMetersF(width / 2), toMetersF(height / 2));
shape = rectShape;
} else if (bbox.hitBoxesProperty().get(0).getShape().type == ShapeType.CIRCLE) {
CircleShape circleShape = new CircleShape();
circleShape.setRadius(toMetersF(width / 2));
shape = circleShape;
} else {
log.warning("Unknown hit box shape: " + bbox.hitBoxesProperty().get(0).getShape().type);
throw new UnsupportedOperationException();
}
}
if (shape == null) {
PolygonShape rectShape = new PolygonShape();
rectShape.setAsBox(toMetersF(width / 2), toMetersF(height / 2));
shape = rectShape;
}
def.setShape(shape);
ParticleGroup particleGroup = jboxWorld.createParticleGroup(def);
Color color = e.getComponent(PhysicsParticleComponent.class).getColor();
e.addControl(new PhysicsParticleControl(particleGroup, color, this));
}
use of com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef 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);
}
use of com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef 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);
}
use of com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef 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);
}
Aggregations