use of com.almasb.fxgl.physics.PhysicsComponent 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.PhysicsComponent 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();
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class SnookerPhysicsSample method spawnTable.
private Entity spawnTable(double x, double y) {
var rect = new Rectangle(getAppWidth() - 200 - 200, getAppHeight() - 150 - 150, Color.LIGHTSEAGREEN);
rect.setArcWidth(15);
rect.setArcHeight(15);
rect.setStroke(Color.BLACK);
rect.setStrokeWidth(10);
rect.setStrokeType(StrokeType.OUTSIDE);
return entityBuilder().at(x, y).bbox(new HitBox(new Point2D(-40, 0), box(40, rect.getHeight()))).bbox(new HitBox(new Point2D(rect.getWidth(), 0), box(40, rect.getHeight()))).bbox(new HitBox(new Point2D(0, -40), box(rect.getWidth(), 40))).bbox(new HitBox(new Point2D(0, rect.getHeight()), box(rect.getWidth(), 40))).view(rect).with(new PhysicsComponent()).buildAndAttach();
}
use of com.almasb.fxgl.physics.PhysicsComponent 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.PhysicsComponent 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();
}
Aggregations