Search in sources :

Example 6 with CollidableComponent

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

the class MarioFactory method newGhostPlatform.

@Spawns("ghost_platform")
public Entity newGhostPlatform(SpawnData data) {
    Entity platform = Entities.builder().from(data).type(MarioType.GHOST_PLATFORM).viewFromTexture("ghost_platform.png").bbox(new HitBox("main", BoundingShape.box(data.<Integer>get("width"), data.<Integer>get("height")))).with(new PhysicsComponent(), new CollidableComponent(true)).build();
    platform.getView().setVisible(false);
    return platform;
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent)

Example 7 with CollidableComponent

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

the class ScriptSample method initGame.

@Override
protected void initGame() {
    Entity e = Entities.builder().type(EntityType.PC).at(300, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.BLUE)).with(new CollidableComponent(true)).with(new DeveloperWASDControl()).buildAndAttach(getGameWorld());
    Entities.builder().type(EntityType.NPC).at(400, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
    for (int i = 0; i < 3; i++) {
        Entities.builder().type(EntityType.COIN).at(FXGLMath.random(100, 450), 500).viewFromNodeWithBBox(new Circle(20, Color.GOLD)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
    }
    getMasterTimer().runAtInterval(() -> {
        getAudioPlayer().playPositionalSound("drop.wav", new Point2D(400, 300), e.getCenter(), 600);
    }, Duration.seconds(2));
}
Also used : DeveloperWASDControl(com.almasb.fxgl.devtools.DeveloperWASDControl) Entity(com.almasb.fxgl.entity.Entity) Circle(javafx.scene.shape.Circle) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle)

Example 8 with CollidableComponent

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

the class ScriptSample2 method initGame.

@Override
protected void initGame() {
    Entity e = Entities.builder().type(EntityType.PC).at(300, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.BLUE)).with(new CollidableComponent(true)).with(new DeveloperWASDControl()).buildAndAttach(getGameWorld());
    Entities.builder().type(EntityType.NPC).at(400, 300).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
}
Also used : DeveloperWASDControl(com.almasb.fxgl.devtools.DeveloperWASDControl) Entity(com.almasb.fxgl.entity.Entity) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle)

Example 9 with CollidableComponent

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

the class BasicGameApp3 method initGame.

@Override
protected void initGame() {
    player = Entities.builder().type(EntityType.PLAYER).at(300, 300).viewFromTextureWithBBox("brick.png").with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
    Entities.builder().type(EntityType.COIN).at(500, 200).viewFromNodeWithBBox(new Circle(15, Color.YELLOW)).with(new CollidableComponent(true)).buildAndAttach(getGameWorld());
}
Also used : Circle(javafx.scene.shape.Circle) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent)

Example 10 with CollidableComponent

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

the class PhysicsSample method initGame.

@Override
protected void initGame() {
    playerControl = new PlayerControl();
    player = Entities.builder().type(Type.PLAYER).at(100, 100).bbox(new HitBox("PLAYER_BODY", BoundingShape.box(40, 40))).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(playerControl).build();
    enemy = Entities.builder().type(Type.ENEMY).at(200, 100).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).build();
    // 2. we need to add Collidable component and set its value to true
    // so that collision system can 'see' our entities
    player.addComponent(new CollidableComponent(true));
    enemy.addComponent(new CollidableComponent(true));
    getGameWorld().addEntities(player, enemy);
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

Aggregations

CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)13 HitBox (com.almasb.fxgl.physics.HitBox)7 Rectangle (javafx.scene.shape.Rectangle)7 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)5 Point2D (javafx.geometry.Point2D)5 Entity (com.almasb.fxgl.entity.Entity)4 BodyDef (com.almasb.fxgl.physics.box2d.dynamics.BodyDef)3 FixtureDef (com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)3 DeveloperWASDControl (com.almasb.fxgl.devtools.DeveloperWASDControl)2 EntityView (com.almasb.fxgl.entity.view.EntityView)2 PlayerControl (common.PlayerControl)2 Circle (javafx.scene.shape.Circle)2 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)1 EffectControl (com.almasb.fxgl.entity.control.EffectControl)1 ExpireCleanControl (com.almasb.fxgl.entity.control.ExpireCleanControl)1 OffscreenCleanControl (com.almasb.fxgl.entity.control.OffscreenCleanControl)1 ProjectileControl (com.almasb.fxgl.entity.control.ProjectileControl)1 UserAction (com.almasb.fxgl.input.UserAction)1