use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class FlyingKeysPhysicsSample method addButtonEntity.
private void addButtonEntity(double x, double y, char c) {
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setFixtureDef(new FixtureDef().density(0.7f).restitution(0.3f));
Button button = new Button(c + "");
button.setFont(Font.font(18));
button.setPrefWidth(BUTTON_WIDTH);
button.setPrefHeight(BUTTON_HEIGHT);
entityBuilder().at(x, y).bbox(BoundingShape.box(BUTTON_WIDTH, BUTTON_HEIGHT)).view(button).with(physics).buildAndAttach();
}
use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class RopeJointSample 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();
}
use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class RevoluteJointSample method initGame.
@Override
protected void initGame() {
getGameScene().setBackgroundColor(Color.LIGHTGRAY);
entityBuilder().buildScreenBoundsAndAttach(50);
// platform
entityBuilder().at(400, 400).viewWithBBox(new Rectangle(500, 20, Color.BROWN)).with(new PhysicsComponent()).buildAndAttach();
PhysicsComponent physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().density(1.1f));
physics.setBodyType(BodyType.DYNAMIC);
Entity block = entityBuilder().at(600, 100).viewWithBBox(new Rectangle(80, 50)).with(physics).buildAndAttach();
PhysicsComponent physics2 = new PhysicsComponent();
physics2.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(1.0f);
physics2.setFixtureDef(fd);
Entity ball1 = entityBuilder().at(600, 360).bbox(new HitBox("main", BoundingShape.circle(15))).view(texture("ball.png", 30, 30)).with(physics2).buildAndAttach();
PhysicsComponent physics3 = new PhysicsComponent();
physics3.setBodyType(BodyType.DYNAMIC);
physics3.setFixtureDef(fd);
Entity ball2 = entityBuilder().at(700, 360).bbox(new HitBox("main", BoundingShape.circle(15))).view(texture("ball.png", 30, 30)).with(physics3).buildAndAttach();
physics2.getBody().setAngularDamping(1f);
physics3.getBody().setAngularDamping(1f);
getPhysicsWorld().addRevoluteJoint(block, ball1, new Point2D(80, 50), new Point2D(15, 15));
getPhysicsWorld().addRevoluteJoint(block, ball2, new Point2D(0, 50), new Point2D(15, 15));
}
use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class RevoluteJointSample method createPhysicsEntity.
private Entity createPhysicsEntity() {
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setFixtureDef(new FixtureDef().density(0.1f).restitution(0.3f));
return entityBuilder().at(getInput().getMousePositionWorld()).with(physics).build();
}
Aggregations