use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class JointSample method createPhysicsEntity.
private Entity createPhysicsEntity() {
// 1. create and configure physics component
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(0.7f);
fd.setRestitution(0.3f);
physics.setFixtureDef(fd);
return Entities.builder().at(getInput().getMousePositionWorld()).with(physics).build();
}
use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class MarioFactory method newRobot.
@Spawns("robot")
public Entity newRobot(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().friction(0).density(0.25f));
BodyDef bd = new BodyDef();
bd.setFixedRotation(true);
physics.setBodyDef(bd);
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().from(data).type(MarioType.ROBOT).bbox(new HitBox("main", new Point2D(275 / 2 - 105 / 2, 275 / 2 - 210 / 2), BoundingShape.box(105, 210))).bbox(new HitBox("lower", new Point2D(275 / 2 - 15, 125 * 2), BoundingShape.box(30, 10))).with(physics, new CollidableComponent(true)).with(new RobotControl()).build();
}
use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class RigidBodyPhysicsSample 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 RigidBodyPhysicsSample method spawnHorizontal.
private void spawnHorizontal(double x, double y) {
var physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().density(4.5f).friction(1.0f).restitution(0.05f));
physics.setBodyType(BodyType.DYNAMIC);
var t = texture("brick.png").subTexture(new Rectangle2D(0, 0, 64, 5));
entityBuilder().at(x, y).viewWithBBox(t).with(physics).buildAndAttach();
}
use of com.almasb.fxgl.physics.box2d.dynamics.FixtureDef in project FXGL by AlmasB.
the class RobotFactory method newRobot.
@Spawns("robot")
public Entity newRobot(SpawnData data) {
BodyDef bd = new BodyDef();
bd.setFixedRotation(true);
bd.setType(BodyType.DYNAMIC);
PhysicsComponent physics = new PhysicsComponent();
// friction 0 to avoid sticking to walls
physics.setFixtureDef(new FixtureDef().friction(0).density(0.25f));
physics.setBodyDef(bd);
physics.addGroundSensor(new HitBox("GROUND_SENSOR", new Point2D(275 / 2 - 3, 260 - 5), BoundingShape.box(6, 10)));
return entityBuilder(data).from(data).bbox(new HitBox("head", new Point2D(110, 50), BoundingShape.box(70, 70))).bbox(new HitBox("body", new Point2D(110, 120), BoundingShape.box(40, 130))).bbox(new HitBox("legs", new Point2D(275 / 2 - 25, 125 * 2), BoundingShape.box(40, 10))).scaleOrigin(275 / 2, 125 * 2).collidable().with(new StateComponent()).with(physics).with(new RobotComponent()).build();
}
Aggregations