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