Search in sources :

Example 1 with ShieldBlock

use of io.anuke.mindustry.world.blocks.types.defense.ShieldBlock in project Mindustry by Anuken.

the class Shield method update.

@Override
public void update() {
    float alpha = 0.1f;
    Interpolation interp = Interpolation.fade;
    if (active) {
        uptime = interp.apply(uptime, 1f, alpha * Timers.delta());
    } else {
        uptime = interp.apply(uptime, 0f, alpha * Timers.delta());
        if (uptime <= 0.05f)
            remove();
    }
    uptime = Mathf.clamp(uptime);
    if (!(tile.block() instanceof ShieldBlock)) {
        remove();
        return;
    }
    ShieldBlock block = (ShieldBlock) tile.block();
    Entities.getNearby(bulletGroup, x, y, block.shieldRadius * 2 * uptime + 10, entity -> {
        BulletEntity bullet = (BulletEntity) entity;
        if ((bullet.owner instanceof Enemy || hitPlayers)) {
            float dst = entity.distanceTo(this);
            if (dst < drawRadius() / 2f) {
                ((ShieldBlock) tile.block()).handleBullet(tile, bullet);
            }
        }
    });
}
Also used : Interpolation(com.badlogic.gdx.math.Interpolation) Enemy(io.anuke.mindustry.entities.enemies.Enemy) ShieldBlock(io.anuke.mindustry.world.blocks.types.defense.ShieldBlock) BulletEntity(io.anuke.ucore.entities.BulletEntity)

Aggregations

Interpolation (com.badlogic.gdx.math.Interpolation)1 Enemy (io.anuke.mindustry.entities.enemies.Enemy)1 ShieldBlock (io.anuke.mindustry.world.blocks.types.defense.ShieldBlock)1 BulletEntity (io.anuke.ucore.entities.BulletEntity)1