Search in sources :

Example 6 with Spawns

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

the class CircleNNFactory method newCircle.

@Spawns("circle")
public Entity newCircle(SpawnData data) {
    var circleComponent = new CircleComponent();
    var color = FXGLMath.randomColor().brighter();
    var view = new Circle(32, 32, 30, null);
    view.setStrokeWidth(2);
    view.setStroke(color);
    var hp = new HealthIntComponent(49);
    var viewHP = new Circle(32, 32, 30);
    viewHP.radiusProperty().bind(hp.valueProperty().divide(49.0).multiply(30));
    var viewRank = getUIFactoryService().newText("", Color.MIDNIGHTBLUE, 12.0);
    viewRank.setTranslateX(32);
    viewRank.setTranslateY(32);
    var e = entityBuilder(data).type(CIRCLE).bbox(new HitBox(BoundingShape.box(64, 64))).view(view).view(viewHP).collidable().with("isShielded", false).with("rank", 1).with(new TimeComponent()).with(new EffectComponent()).with(hp).with(new RandomMoveComponent(new Rectangle2D(0, 0, getAppWidth(), getAppHeight()), 300)).with(circleComponent).with(new BlockCollisionComponent()).build();
    viewHP.fillProperty().bind(Bindings.when(e.getProperties().booleanProperty("isShielded")).then(Color.WHITE).otherwise(Color.color(0.5, 0.78, 0.2, 0.5).brighter()));
    viewRank.textProperty().bind(e.getProperties().intProperty("rank").asString());
    return e;
}
Also used : Circle(javafx.scene.shape.Circle) HitBox(com.almasb.fxgl.physics.HitBox) TimeComponent(com.almasb.fxgl.entity.components.TimeComponent) Rectangle2D(javafx.geometry.Rectangle2D) Spawns(com.almasb.fxgl.entity.Spawns)

Example 7 with Spawns

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

the class FiringRangeFactory method newLevelBox.

@Spawns("levelBox")
public Entity newLevelBox(SpawnData data) {
    var ground = new Box(50, 0.5, 150);
    ground.setMaterial(new PhongMaterial(Color.BROWN));
    var WALL_HEIGHT = 20;
    var wallL = new Box(0.5, WALL_HEIGHT, 150);
    wallL.setMaterial(new PhongMaterial(Color.LIGHTCORAL));
    wallL.setTranslateY(-WALL_HEIGHT / 2.0);
    wallL.setTranslateX(-ground.getWidth() / 2.0);
    var wallR = new Box(0.5, WALL_HEIGHT, 150);
    wallR.setMaterial(new PhongMaterial(Color.LIGHTCORAL));
    wallR.setTranslateY(-WALL_HEIGHT / 2.0);
    wallR.setTranslateX(+ground.getWidth() / 2.0);
    var wallT = new Box(50, WALL_HEIGHT, 0.5);
    wallT.setMaterial(new PhongMaterial(Color.LIGHTCORAL));
    wallT.setTranslateY(-WALL_HEIGHT / 2.0);
    wallT.setTranslateZ(+wallL.getDepth() / 2.0);
    var wallB = new Box(50, WALL_HEIGHT, 0.5);
    wallB.setMaterial(new PhongMaterial(Color.LIGHTCORAL));
    wallB.setTranslateY(-WALL_HEIGHT / 2.0);
    wallB.setTranslateZ(-25);
    return entityBuilder(data).view(new Group(ground, wallL, wallR, wallT, wallB)).build();
}
Also used : Group(javafx.scene.Group) Box(javafx.scene.shape.Box) HitBox(com.almasb.fxgl.physics.HitBox) PhongMaterial(javafx.scene.paint.PhongMaterial) Spawns(com.almasb.fxgl.entity.Spawns)

Example 8 with Spawns

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

the class FiringRangeFactory method newTarget.

@Spawns("target")
public Entity newTarget(SpawnData data) {
    var box = new Box(5, 5, 0.2);
    box.setMaterial(new PhongMaterial(Color.DARKKHAKI));
    var e = entityBuilder(data).type(FiringRangeEntityType.TARGET).bbox(new HitBox(BoundingShape.box3D(5, 5, 0.2))).view(box).collidable().with(new Projectile3DComponent(new Point3D(1, 0, 0), 15)).with(new ExpireCleanComponent(Duration.seconds(6))).build();
    animationBuilder().duration(Duration.seconds(0.6)).interpolator(Interpolators.ELASTIC.EASE_OUT()).scale(e).from(new Point3D(0, 0, 0)).to(new Point3D(1, 1, 1)).buildAndPlay();
    return e;
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) ExpireCleanComponent(com.almasb.fxgl.dsl.components.ExpireCleanComponent) Point3D(javafx.geometry.Point3D) Box(javafx.scene.shape.Box) HitBox(com.almasb.fxgl.physics.HitBox) PhongMaterial(javafx.scene.paint.PhongMaterial) 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