Search in sources :

Example 1 with BodyDef

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();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) BodyDef(com.almasb.fxgl.physics.box2d.dynamics.BodyDef) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 2 with BodyDef

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();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) BodyDef(com.almasb.fxgl.physics.box2d.dynamics.BodyDef) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 3 with BodyDef

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();
}
Also used : Circle(javafx.scene.shape.Circle) HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) InnerShadow(javafx.scene.effect.InnerShadow) BodyDef(com.almasb.fxgl.physics.box2d.dynamics.BodyDef) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 4 with BodyDef

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();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) BodyDef(com.almasb.fxgl.physics.box2d.dynamics.BodyDef) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 5 with BodyDef

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();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) Point2D(javafx.geometry.Point2D) BodyDef(com.almasb.fxgl.physics.box2d.dynamics.BodyDef) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef) StateComponent(com.almasb.fxgl.entity.state.StateComponent) Spawns(com.almasb.fxgl.entity.Spawns)

Aggregations

HitBox (com.almasb.fxgl.physics.HitBox)5 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)5 BodyDef (com.almasb.fxgl.physics.box2d.dynamics.BodyDef)5 FixtureDef (com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)5 Point2D (javafx.geometry.Point2D)4 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)3 Spawns (com.almasb.fxgl.entity.Spawns)1 StateComponent (com.almasb.fxgl.entity.state.StateComponent)1 InnerShadow (javafx.scene.effect.InnerShadow)1 Circle (javafx.scene.shape.Circle)1