use of com.almasb.fxgl.physics.PhysicsComponent 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.PhysicsComponent 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.PhysicsComponent in project FXGL by AlmasB.
the class MarioFactory method newEnemy.
@Spawns("enemy")
public Entity newEnemy(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().type(MarioType.ENEMY).from(data).viewFromNodeWithBBox(new Rectangle(30, 30, Color.RED)).with(physics).with(new EnemyControl()).build();
}
use of com.almasb.fxgl.physics.PhysicsComponent in project FXGL by AlmasB.
the class MarioFactory method newPlayer.
@Spawns("player")
public Entity newPlayer(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().type(MarioType.PLAYER).from(data).bbox(new HitBox(BoundingShape.box(32, 42))).with(physics).with(new CollidableComponent(true)).with(new PlayerControl(), new EffectControl()).build();
}
use of com.almasb.fxgl.physics.PhysicsComponent 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();
}
Aggregations