Search in sources :

Example 1 with ProjectileControl

use of com.almasb.fxgl.entity.control.ProjectileControl 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);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) PositionComponent(com.almasb.fxgl.entity.component.PositionComponent) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) ProjectileControl(com.almasb.fxgl.entity.control.ProjectileControl) OffscreenCleanControl(com.almasb.fxgl.entity.control.OffscreenCleanControl)

Aggregations

Entity (com.almasb.fxgl.entity.Entity)1 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)1 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)1 OffscreenCleanControl (com.almasb.fxgl.entity.control.OffscreenCleanControl)1 ProjectileControl (com.almasb.fxgl.entity.control.ProjectileControl)1 EntityView (com.almasb.fxgl.entity.view.EntityView)1 Rectangle (javafx.scene.shape.Rectangle)1