use of com.almasb.fxgl.entity.component.CollidableComponent in project FXGL by AlmasB.
the class ScifiFactory method newPlayer.
@Spawns("player")
public Entity newPlayer(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(ScifiType.PLAYER).bbox(new HitBox("main", BoundingShape.circle(15))).bbox(new HitBox("lower", new Point2D(15 - 5, 30), BoundingShape.box(10, 10))).with(physics, new CollidableComponent(true)).with(new PlayerControl()).build();
}
use of com.almasb.fxgl.entity.component.CollidableComponent 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);
}
use of com.almasb.fxgl.entity.component.CollidableComponent 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);
}
use of com.almasb.fxgl.entity.component.CollidableComponent in project FXGL by AlmasB.
the class MarioApp method initInput.
@Override
protected void initInput() {
DSLKt.onKeyDown(KeyCode.K, "G+", () -> {
getPhysicsWorld().setGravity(0, -getPhysicsWorld().getJBox2DWorld().getGravity().y * 50 + 10);
System.out.println(-getPhysicsWorld().getJBox2DWorld().getGravity().y * 50);
});
DSLKt.onKeyDown(KeyCode.I, "G-", () -> {
getPhysicsWorld().setGravity(0, -getPhysicsWorld().getJBox2DWorld().getGravity().y * 50 - 10);
System.out.println(-getPhysicsWorld().getJBox2DWorld().getGravity().y * 50);
});
getInput().addAction(new UserAction("Left") {
@Override
protected void onAction() {
playerControl.left();
}
@Override
protected void onActionEnd() {
playerControl.stop();
}
}, KeyCode.A);
getInput().addAction(new UserAction("Right") {
@Override
protected void onAction() {
playerControl.right();
}
@Override
protected void onActionEnd() {
playerControl.stop();
}
}, KeyCode.D);
getInput().addAction(new UserAction("Jump") {
@Override
protected void onActionBegin() {
playerControl.jump();
}
}, KeyCode.W);
getInput().addAction(new UserAction("Enter") {
@Override
protected void onActionBegin() {
stepLoop();
}
}, KeyCode.L);
getInput().addAction(new UserAction("Drop rectangle") {
@Override
protected void onActionBegin() {
Entities.builder().type(MarioType.OBSTACLE).at(getInput().getMousePositionWorld()).viewFromNodeWithBBox(new Rectangle(40, 40)).with(new CollidableComponent(true)).with(new ExpireCleanControl(Duration.seconds(2)).animateOpacity()).buildAndAttach();
}
}, MouseButton.PRIMARY);
}
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.setFixtureDef(new FixtureDef().friction(0).density(0.25f));
physics.setGenerateGroundSensor(true);
BodyDef bd = new BodyDef();
bd.setFixedRotation(true);
physics.setBodyDef(bd);
physics.setBodyType(BodyType.DYNAMIC);
return Entities.builder().from(data).type(MarioType.PLAYER).bbox(new HitBox("main", BoundingShape.circle(15))).bbox(new HitBox("lower", new Point2D(15 - 5, 30), BoundingShape.box(10, 10))).with(physics, new CollidableComponent(true)).with(new PlayerControl()).build();
}
Aggregations