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);
}
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();
}
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();
}
Aggregations