use of com.almasb.fxgl.physics.box2d.dynamics.BodyDef in project FXGL by AlmasB.
the class ScifiFactory method newPlayer.
@Spawns("player")
public Entity newPlayer(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(ScifiType.PLAYER).bbox(new HitBox("main", BoundingShape.circle(15))).bbox(new HitBox("lower", new Point2D(15 - 5, 30), BoundingShape.box(10, 10))).with(physics, new CollidableComponent(true)).with(new PlayerControl()).build();
}
use of com.almasb.fxgl.physics.box2d.dynamics.BodyDef in project FXGL by AlmasB.
the class MarioFactory method newPlayer.
@Spawns("player")
public Entity newPlayer(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setFixtureDef(new FixtureDef().friction(0).density(0.25f));
physics.setGenerateGroundSensor(true);
BodyDef bd = new BodyDef();
bd.setFixedRotation(true);
physics.setBodyDef(bd);
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().from(data).type(MarioType.PLAYER).bbox(new HitBox("main", BoundingShape.circle(15))).bbox(new HitBox("lower", new Point2D(15 - 5, 30), BoundingShape.box(10, 10))).with(physics, new CollidableComponent(true)).with(new PlayerControl()).build();
}
use of com.almasb.fxgl.physics.box2d.dynamics.BodyDef in project FXGL by AlmasB.
the class SnookerPhysicsSample method spawnBall.
private Entity spawnBall(double x, double y, Color color) {
var bd = new BodyDef();
bd.setBullet(true);
bd.setType(BodyType.DYNAMIC);
var p = new PhysicsComponent();
p.setBodyDef(bd);
p.setFixtureDef(new FixtureDef().density(BALL_DENSITY).restitution(BALL_ELASTICITY));
var shadow = new InnerShadow(3, Color.BLACK);
shadow.setOffsetX(-3);
shadow.setOffsetY(-3);
var c = new Circle(15, 15, 15, color);
c.setEffect(shadow);
var shine = new Circle(3, 3, 3, Color.color(0.7, 0.7, 0.7, 0.7));
shine.setTranslateX(5);
shine.setTranslateY(5);
return entityBuilder().at(x, y).bbox(new HitBox(BoundingShape.circle(15))).view(c).view(shine).with(p).with(new BallComponent()).buildAndAttach();
}
use of com.almasb.fxgl.physics.box2d.dynamics.BodyDef 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.BodyDef 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