Search in sources :

Example 1 with TimeComponent

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

the class BBoxSample method initGame.

@Override
protected void initGame() {
    // entity 1
    player = entityBuilder().type(Type.PLAYER).at(100, 150).viewWithBBox("brick.png").with(new CollidableComponent(true), new DeveloperWASDControl()).with(new RandomMoveComponent(new Rectangle2D(0, 0, getAppWidth(), getAppHeight()), 500)).with(new EffectComponent()).with(new TimeComponent(1.0)).zIndex(250).buildAndAttach();
    player.getTransformComponent().setRotationOrigin(new Point2D(64, 64));
    player.getTransformComponent().scaleOriginXProperty().setValue(64);
    player.getTransformComponent().scaleOriginYProperty().setValue(64);
    // entity 2
    entityBuilder().at(100, 100).viewWithBBox(new Rectangle(40, 40, Color.RED)).with(new CollidableComponent(true)).with(new LiftComponent().yAxisSpeedDuration(150, Duration.seconds(3)).xAxisSpeedDuration(100, Duration.seconds(3))).with(new EffectComponent()).zIndex(250).buildAndAttach();
    // entity 3
    entityBuilder().type(Type.NPC).at(400, 150).bbox(new HitBox(new Point2D(5, 5), BoundingShape.circle(20))).view(texture("enemy1.png").toAnimatedTexture(2, Duration.seconds(1)).loop()).with(new EffectComponent()).buildAndAttach();
}
Also used : DeveloperWASDControl(dev.DeveloperWASDControl) RandomMoveComponent(com.almasb.fxgl.dsl.components.RandomMoveComponent) HitBox(com.almasb.fxgl.physics.HitBox) TimeComponent(com.almasb.fxgl.entity.components.TimeComponent) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.components.CollidableComponent) Rectangle2D(javafx.geometry.Rectangle2D) Rectangle(javafx.scene.shape.Rectangle) LiftComponent(com.almasb.fxgl.dsl.components.LiftComponent) EffectComponent(com.almasb.fxgl.dsl.components.EffectComponent)

Example 2 with TimeComponent

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

Aggregations

TimeComponent (com.almasb.fxgl.entity.components.TimeComponent)2 HitBox (com.almasb.fxgl.physics.HitBox)2 Rectangle2D (javafx.geometry.Rectangle2D)2 EffectComponent (com.almasb.fxgl.dsl.components.EffectComponent)1 LiftComponent (com.almasb.fxgl.dsl.components.LiftComponent)1 RandomMoveComponent (com.almasb.fxgl.dsl.components.RandomMoveComponent)1 Spawns (com.almasb.fxgl.entity.Spawns)1 CollidableComponent (com.almasb.fxgl.entity.components.CollidableComponent)1 DeveloperWASDControl (dev.DeveloperWASDControl)1 Point2D (javafx.geometry.Point2D)1 Circle (javafx.scene.shape.Circle)1 Rectangle (javafx.scene.shape.Rectangle)1