Search in sources :

Example 11 with CollidableComponent

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

the class PhysicsSample2 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(250, 40))).viewFromNode(new Rectangle(250, 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)

Example 12 with CollidableComponent

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

the class MarioFactory method newRobot.

@Spawns("robot")
public Entity newRobot(SpawnData data) {
    PhysicsComponent physics = new PhysicsComponent();
    physics.setFixtureDef(new FixtureDef().friction(0).density(0.25f));
    BodyDef bd = new BodyDef();
    bd.setFixedRotation(true);
    physics.setBodyDef(bd);
    physics.setBodyType(BodyType.DYNAMIC);
    return Entities.builder().from(data).type(MarioType.ROBOT).bbox(new HitBox("main", new Point2D(275 / 2 - 105 / 2, 275 / 2 - 210 / 2), BoundingShape.box(105, 210))).bbox(new HitBox("lower", new Point2D(275 / 2 - 15, 125 * 2), BoundingShape.box(30, 10))).with(physics, new CollidableComponent(true)).with(new RobotControl()).build();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) Point2D(javafx.geometry.Point2D) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) BodyDef(com.almasb.fxgl.physics.box2d.dynamics.BodyDef) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)

Example 13 with CollidableComponent

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

the class MarioFactory method newPlayer.

@Spawns("player")
public Entity newPlayer(SpawnData data) {
    PhysicsComponent physics = new PhysicsComponent();
    physics.setBodyType(BodyType.DYNAMIC);
    return Entities.builder().type(MarioType.PLAYER).from(data).bbox(new HitBox(BoundingShape.box(32, 42))).with(physics).with(new CollidableComponent(true)).with(new PlayerControl(), new EffectControl()).build();
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) EffectControl(com.almasb.fxgl.entity.control.EffectControl)

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