use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class PlatformerSample method createPlatforms.
private void createPlatforms() {
Entities.builder().at(0, 500).viewFromNode(new Rectangle(120, 100, Color.GRAY)).bbox(new HitBox("Main", BoundingShape.chain(new Point2D(0, 0), new Point2D(120, 0), new Point2D(120, 100), new Point2D(0, 100)))).with(new PhysicsComponent()).buildAndAttach(getGameWorld());
Entities.builder().at(180, 500).viewFromNode(new Rectangle(400, 100, Color.GRAY)).bbox(new HitBox("Main", BoundingShape.chain(new Point2D(0, 0), new Point2D(400, 0), new Point2D(400, 100), new Point2D(0, 100)))).with(new PhysicsComponent()).buildAndAttach(getGameWorld());
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class RealPhysicsSample method createPhysicsEntity.
private Entity createPhysicsEntity() {
// 1. create and configure physics component
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setFixtureDef(new FixtureDef().density(0.7f).restitution(0.3f));
return Entities.builder().at(getInput().getMousePositionWorld()).with(physics).build();
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class FlyingKeysSample 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(getWidth() / 2, getHeight() / 2).with(physics).build();
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class JointSample method initGame.
@Override
protected void initGame() {
getGameWorld().addEntity(Entities.makeScreenBounds(50));
PhysicsComponent physics = new PhysicsComponent();
Entity block = Entities.builder().at(200, 200).viewFromNodeWithBBox(new Rectangle(50, 50)).with(physics).buildAndAttach(getGameWorld());
PhysicsComponent physics2 = new PhysicsComponent();
physics2.setBodyType(BodyType.DYNAMIC);
FixtureDef fd = new FixtureDef();
fd.setDensity(1.0f);
physics2.setFixtureDef(fd);
Entity ball = Entities.builder().at(200, 300).bbox(new HitBox("main", BoundingShape.circle(15))).viewFromNode(getAssetLoader().loadTexture("ball.png", 30, 30)).with(physics2).buildAndAttach(getGameWorld());
Line line = new Line();
line.setStartX(block.getCenter().getX());
line.setStartY(block.getCenter().getY());
// line.startXProperty().bind(block.getPositionComponent().xProperty());
// line.startYProperty().bind(block.getPositionComponent().yProperty());
line.endXProperty().bind(ball.getPositionComponent().xProperty().add(15));
line.endYProperty().bind(ball.getPositionComponent().yProperty().add(15));
getGameScene().addGameView(new EntityView(line));
RevoluteJointDef rDef = new RevoluteJointDef();
rDef.bodyA = physics.getBody();
rDef.bodyB = physics2.getBody();
rDef.collideConnected = false;
rDef.localAnchorA = new Vec2(0, 0);
rDef.localAnchorB = new Vec2(0, 5);
rDef.enableLimit = true;
rDef.lowerAngle = (float) (FXGLMath.toRadians(-180.0f));
rDef.upperAngle = (float) (FXGLMath.toRadians(180.0f));
rDef.enableMotor = true;
rDef.motorSpeed = (float) (FXGLMath.toRadians(30));
rDef.maxMotorTorque = 15.0f;
joint = (RevoluteJoint) getPhysicsWorld().getJBox2DWorld().createJoint(rDef);
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class PhysicsParticlesSample method initGround.
private void initGround() {
Entity ground = new Entity();
ground.getPositionComponent().setValue(100, 500);
ground.getViewComponent().setView(new EntityView(new Rectangle(800, 100)), true);
ground.addComponent(new PhysicsComponent());
getGameWorld().addEntity(ground);
}
Aggregations