Search in sources :

Example 31 with Entity

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

the class ViewportTest method initGame.

@Override
protected void initGame() {
    Entity entity = Entities.builder().at(100, 100).viewFromNodeWithBBox(new Rectangle(40, 40)).buildAndAttach(getGameWorld());
    playerPosition = entity.getPositionComponent();
    bbox = entity.getBoundingBoxComponent();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle)

Example 32 with Entity

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

the class BoundingBoxComponentTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    Entity entity = new Entity();
    position = entity.getPositionComponent();
    bbox = entity.getBoundingBoxComponent();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 33 with Entity

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

the class ParticlesSample method initInput.

@Override
protected void initInput() {
    Input input = getInput();
    input.addAction(new UserAction("Spawn Explosion") {

        @Override
        protected void onActionBegin() {
            // 1. create entity
            Entity explosion = new Entity();
            explosion.setPosition(input.getMousePositionWorld());
            // 2. create and configure emitter + control
            ParticleEmitter emitter = ParticleEmitters.newExplosionEmitter(400);
            ParticleControl control = new ParticleControl(emitter);
            // we also want the entity to destroy itself when particle control is done
            control.setOnFinished(explosion::removeFromWorld);
            // 3. add control to entity
            explosion.addControl(control);
            // 4. add entity to game world
            getGameWorld().addEntity(explosion);
        }
    }, MouseButton.PRIMARY);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) ParticleEmitter(com.almasb.fxgl.effect.ParticleEmitter) Entity(com.almasb.fxgl.entity.Entity) Input(com.almasb.fxgl.input.Input) ParticleControl(com.almasb.fxgl.effect.ParticleControl)

Example 34 with Entity

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

the class PhysicsParticlesSample method initGround.

private void initGround() {
    Entity ground = new Entity();
    ground.getPositionComponent().setValue(100, 500);
    ground.getViewComponent().setView(new EntityView(new Rectangle(800, 100)), true);
    ground.addComponent(new PhysicsComponent());
    getGameWorld().addEntity(ground);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle)

Example 35 with Entity

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

the class PhysicsParticlesSample method initLiquid.

private void initLiquid() {
    ParticleGroupDef groupDef = new ParticleGroupDef();
    groupDef.setTypes(EnumSet.of(ParticleType.VISCOUS, ParticleType.TENSILE));
    PhysicsParticleComponent ppComponent = new PhysicsParticleComponent();
    ppComponent.setDefinition(groupDef);
    ppComponent.setColor(Color.BLUE.brighter());
    Entity liquid = new Entity();
    liquid.getPositionComponent().setValue(300, 10);
    liquid.getBoundingBoxComponent().addHitBox(new HitBox("MAIN", BoundingShape.circle(35)));
    liquid.addComponent(ppComponent);
    getGameWorld().addEntities(liquid);
}
Also used : ParticleGroupDef(com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef) PhysicsParticleComponent(com.almasb.fxgl.physics.PhysicsParticleComponent) Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)55 Rectangle (javafx.scene.shape.Rectangle)21 Point2D (javafx.geometry.Point2D)15 HitBox (com.almasb.fxgl.physics.HitBox)12 EntityView (com.almasb.fxgl.entity.view.EntityView)8 UserAction (com.almasb.fxgl.input.UserAction)6 CollisionHandler (com.almasb.fxgl.physics.CollisionHandler)6 Input (com.almasb.fxgl.input.Input)5 GameApplication (com.almasb.fxgl.app.GameApplication)4 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)4 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)4 PhysicsParticleComponent (com.almasb.fxgl.physics.PhysicsParticleComponent)4 ParticleGroupDef (com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef)4 GameSettings (com.almasb.fxgl.settings.GameSettings)4 ParticleControl (com.almasb.fxgl.effect.ParticleControl)3 ParticleEmitter (com.almasb.fxgl.effect.ParticleEmitter)3 Entities (com.almasb.fxgl.entity.Entities)3 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)3 Color (javafx.scene.paint.Color)3 Circle (javafx.scene.shape.Circle)3