Search in sources :

Example 1 with Entity

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

the class ScifiSample method initPhysics.

@Override
protected void initPhysics() {
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(ScifiType.PLAYER, ScifiType.PLATFORM) {

        @Override
        protected void onHitBoxTrigger(Entity a, Entity b, HitBox boxA, HitBox boxB) {
            if (boxA.getName().equals("lower")) {
                playerControl.canJump = true;
            }
        }
    });
    getPhysicsWorld().addCollisionHandler(new CollisionHandler(ScifiType.PLAYER, ScifiType.PORTAL) {

        @Override
        protected void onCollisionBegin(Entity a, Entity b) {
            nextLevel();
        }
    });
    getPhysicsWorld().addCollisionHandler(new CollectibleHandler(ScifiType.PLAYER, ScifiType.COIN, "drop.wav", (c) -> set("coins", geti("coins") + 1)));
}
Also used : CollectibleHandler(com.almasb.fxgl.physics.handler.CollectibleHandler) LevelText(com.almasb.fxgl.ui.LevelText) Animation(com.almasb.fxgl.animation.Animation) Arrays(java.util.Arrays) DSLKt.geti(com.almasb.fxgl.app.DSLKt.geti) GameSettings(com.almasb.fxgl.settings.GameSettings) ParallaxBackgroundView(com.almasb.fxgl.entity.view.ParallaxBackgroundView) RenderLayer(com.almasb.fxgl.entity.RenderLayer) InGamePanel(com.almasb.fxgl.ui.InGamePanel) Map(java.util.Map) CollectibleHandler(com.almasb.fxgl.physics.handler.CollectibleHandler) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler) EnumSet(java.util.EnumSet) DSLKt.set(com.almasb.fxgl.app.DSLKt.set) Orientation(javafx.geometry.Orientation) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) ParticleEmitter(com.almasb.fxgl.effect.ParticleEmitter) ParticleType(com.almasb.fxgl.physics.box2d.particle.ParticleType) ParticleEmitters(com.almasb.fxgl.effect.ParticleEmitters) QTE(com.almasb.fxgl.gameplay.qte.QTE) AnimatedTexture(com.almasb.fxgl.texture.AnimatedTexture) ParticleControl(com.almasb.fxgl.effect.ParticleControl) UserAction(com.almasb.fxgl.input.UserAction) ParticleGroupDef(com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef) Text(javafx.scene.text.Text) ParallaxTexture(com.almasb.fxgl.entity.view.ParallaxTexture) BoundingShape(com.almasb.fxgl.physics.BoundingShape) Duration(javafx.util.Duration) PositionComponent(com.almasb.fxgl.entity.component.PositionComponent) Entities(com.almasb.fxgl.entity.Entities) PhysicsParticleComponent(com.almasb.fxgl.physics.PhysicsParticleComponent) HitBox(com.almasb.fxgl.physics.HitBox) GameApplication(com.almasb.fxgl.app.GameApplication) Entity(com.almasb.fxgl.entity.Entity) Entity(com.almasb.fxgl.entity.Entity) HitBox(com.almasb.fxgl.physics.HitBox) CollisionHandler(com.almasb.fxgl.physics.CollisionHandler)

Example 2 with Entity

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

the class FXShooterApp method spawnEnemy.

private void spawnEnemy() {
    Entity enemy = new Entity();
    enemy.getTypeComponent().setValue(EntityType.ENEMY);
    enemy.getPositionComponent().setValue(getWidth(), 460);
    enemy.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.RED)), true);
    enemy.addComponent(new CollidableComponent(true));
    enemy.addComponent(new HPComponent(5));
    enemy.addControl(new EnemyControl(new Point2D(getWidth() / 2, getHeight() / 2)));
    getGameWorld().addEntity(enemy);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle)

Example 3 with Entity

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

the class FXShooterApp method initPlayer.

private void initPlayer() {
    player = new Entity();
    player.getPositionComponent().setValue(getWidth() / 2, getHeight() / 2);
    player.getViewComponent().setView(new Rectangle(40, 40, Color.BLUE));
    WeaponComponent weapon = new WeaponComponent();
    weapon.setDamage(2);
    weapon.setFireRate(1.0);
    weapon.setMaxAmmo(10);
    player.addComponent(weapon);
    playerControl = new PlayerControl();
    player.addControl(playerControl);
    getGameWorld().addEntity(player);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle)

Example 4 with Entity

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

the class PlayerControl method shoot.

public void shoot(Point2D direction) {
    Entity bullet = new Entity();
    bullet.getTypeComponent().setValue(FXShooterApp.EntityType.BULLET);
    bullet.getPositionComponent().setValue(getEntity().getComponent(PositionComponent.class).getValue().add(20, 20));
    bullet.getViewComponent().setView(new EntityView(new Rectangle(10, 2, Color.BLACK)), true);
    bullet.addComponent(new CollidableComponent(true));
    bullet.addControl(new OffscreenCleanControl());
    bullet.addControl(new ProjectileControl(direction, 10 * 60));
    BulletComponent bulletData = new BulletComponent();
    bulletData.setDamage(1);
    bulletData.setHp(1);
    bulletData.setSpeed(10);
    bullet.addComponent(bulletData);
    getEntity().getWorld().addEntity(bullet);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) PositionComponent(com.almasb.fxgl.entity.component.PositionComponent) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) ProjectileControl(com.almasb.fxgl.entity.control.ProjectileControl) OffscreenCleanControl(com.almasb.fxgl.entity.control.OffscreenCleanControl)

Example 5 with Entity

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

the class SelectedEntitySample method initGame.

@Override
protected void initGame() {
    // 2. create entity and attach to world using fluent API
    Entity e1 = Entities.builder().at(100, 100).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(new SelectableComponent(true)).buildAndAttach();
    Entity e2 = Entities.builder().at(300, 100).viewFromNode(new Rectangle(40, 40, Color.RED)).with(new SelectableComponent(true)).buildAndAttach();
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle) SelectableComponent(com.almasb.fxgl.entity.component.SelectableComponent)

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