Search in sources :

Example 1 with Spawns

use of com.almasb.fxgl.entity.Spawns in project FXGL by AlmasB.

the class FiringRangeFactory method newBullet.

@Spawns("bullet")
public Entity newBullet(SpawnData data) {
    var sphere = new Sphere(0.5);
    sphere.setMaterial(new PhongMaterial(Color.YELLOW));
    Point3D dir = data.get("dir");
    return entityBuilder(data).type(FiringRangeEntityType.BULLET).bbox(new HitBox(BoundingShape.box3D(1, 1, 1))).view(sphere).with(new Projectile3DComponent(dir, 50)).with(new ExpireCleanComponent(Duration.seconds(5))).collidable().build();
}
Also used : Sphere(javafx.scene.shape.Sphere) HitBox(com.almasb.fxgl.physics.HitBox) ExpireCleanComponent(com.almasb.fxgl.dsl.components.ExpireCleanComponent) Point3D(javafx.geometry.Point3D) PhongMaterial(javafx.scene.paint.PhongMaterial) Spawns(com.almasb.fxgl.entity.Spawns)

Example 2 with Spawns

use of com.almasb.fxgl.entity.Spawns in project FXGL by AlmasB.

the class SnakeFactory method newPlayer.

@Spawns("player")
public Entity newPlayer(SpawnData data) {
    Box box = new Box(1, 1, 1);
    box.setMaterial(new PhongMaterial(Color.BLUE));
    return entityBuilder(data).type(SnakeApp.SnakeType.SNAKE).bbox(new HitBox(BoundingShape.box3D(1, 1, 1))).view(box).collidable().with(new SnakeComponent()).build();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) Box(javafx.scene.shape.Box) HitBox(com.almasb.fxgl.physics.HitBox) PhongMaterial(javafx.scene.paint.PhongMaterial) Spawns(com.almasb.fxgl.entity.Spawns)

Example 3 with Spawns

use of com.almasb.fxgl.entity.Spawns in project FXGL by AlmasB.

the class SnakeFactory method newFood.

@Spawns("food")
public Entity newFood(SpawnData data) {
    Box box = new Box(1, 1, 1);
    box.setMaterial(new PhongMaterial(Color.YELLOW));
    return entityBuilder(data).type(SnakeApp.SnakeType.FOOD).bbox(new HitBox(BoundingShape.box3D(1, 1, 1))).view(box).collidable().build();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) Box(javafx.scene.shape.Box) HitBox(com.almasb.fxgl.physics.HitBox) PhongMaterial(javafx.scene.paint.PhongMaterial) Spawns(com.almasb.fxgl.entity.Spawns)

Example 4 with Spawns

use of com.almasb.fxgl.entity.Spawns 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)

Example 5 with Spawns

use of com.almasb.fxgl.entity.Spawns in project FXGL by AlmasB.

the class CircleNNFactory method newBullet.

@Spawns("bullet")
public Entity newBullet(SpawnData data) {
    Point2D dir = data.get("dir");
    var view = new Rectangle(30, 2, Color.WHITE);
    view.setArcWidth(15);
    view.setArcHeight(15);
    return entityBuilder(data).type(BULLET).viewWithBBox(view).collidable().with(new ProjectileComponent(dir, 800)).with(new OffscreenCleanComponent()).with("damage", data.hasKey("damage") ? data.get("damage") : 1).build();
}
Also used : Point2D(javafx.geometry.Point2D) Rectangle(javafx.scene.shape.Rectangle) Spawns(com.almasb.fxgl.entity.Spawns)

Aggregations

Spawns (com.almasb.fxgl.entity.Spawns)8 HitBox (com.almasb.fxgl.physics.HitBox)7 PhongMaterial (javafx.scene.paint.PhongMaterial)5 Box (javafx.scene.shape.Box)4 ExpireCleanComponent (com.almasb.fxgl.dsl.components.ExpireCleanComponent)2 Point2D (javafx.geometry.Point2D)2 Point3D (javafx.geometry.Point3D)2 TimeComponent (com.almasb.fxgl.entity.components.TimeComponent)1 StateComponent (com.almasb.fxgl.entity.state.StateComponent)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 Rectangle2D (javafx.geometry.Rectangle2D)1 Group (javafx.scene.Group)1 Circle (javafx.scene.shape.Circle)1 Rectangle (javafx.scene.shape.Rectangle)1 Sphere (javafx.scene.shape.Sphere)1