Search in sources :

Example 1 with StateComponent

use of com.almasb.fxgl.entity.state.StateComponent 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

Spawns (com.almasb.fxgl.entity.Spawns)1 StateComponent (com.almasb.fxgl.entity.state.StateComponent)1 HitBox (com.almasb.fxgl.physics.HitBox)1 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)1 BodyDef (com.almasb.fxgl.physics.box2d.dynamics.BodyDef)1 FixtureDef (com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)1 Point2D (javafx.geometry.Point2D)1