Search in sources :

Example 1 with Dart

use of com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart in project shattered-pixel-dungeon-gdx by 00-Evan.

the class ScorpioSprite method onComplete.

@Override
public void onComplete(Animation anim) {
    if (anim == zap) {
        idle();
        ((MissileSprite) parent.recycle(MissileSprite.class)).reset(ch.pos, cellToAttack, new Dart(), new Callback() {

            @Override
            public void call() {
                ch.onAttackComplete();
            }
        });
    } else {
        super.onComplete(anim);
    }
}
Also used : Callback(com.watabou.utils.Callback) Dart(com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)

Example 2 with Dart

use of com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart in project shattered-pixel-dungeon-gdx by 00-Evan.

the class WornDartTrap method activate.

@Override
public void activate() {
    Char target = Actor.findChar(pos);
    // find the closest char that can be aimed at
    if (target == null) {
        for (Char ch : Actor.chars()) {
            Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE);
            if (bolt.collisionPos == ch.pos && (target == null || Dungeon.level.trueDistance(pos, ch.pos) < Dungeon.level.trueDistance(pos, target.pos))) {
                target = ch;
            }
        }
    }
    if (target != null) {
        final Char finalTarget = target;
        final WornDartTrap trap = this;
        if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[target.pos]) {
            Actor.add(new Actor() {

                {
                    // it's a visual effect, gets priority no matter what
                    actPriority = VFX_PRIO;
                }

                @Override
                protected boolean act() {
                    final Actor toRemove = this;
                    ((MissileSprite) ShatteredPixelDungeon.scene().recycle(MissileSprite.class)).reset(pos, finalTarget.sprite, new Dart(), new Callback() {

                        @Override
                        public void call() {
                            int dmg = Random.NormalIntRange(1, 4) - finalTarget.drRoll();
                            finalTarget.damage(dmg, trap);
                            if (finalTarget == Dungeon.hero && !finalTarget.isAlive()) {
                                Dungeon.fail(trap.getClass());
                            }
                            Sample.INSTANCE.play(Assets.SND_HIT, 1, 1, Random.Float(0.8f, 1.25f));
                            finalTarget.sprite.bloodBurstA(finalTarget.sprite.center(), dmg);
                            finalTarget.sprite.flash();
                            Actor.remove(toRemove);
                            next();
                        }
                    });
                    return false;
                }
            });
        } else {
            finalTarget.damage(Random.NormalIntRange(1, 4) - finalTarget.drRoll(), trap);
        }
    }
}
Also used : Callback(com.watabou.utils.Callback) Char(com.shatteredpixel.shatteredpixeldungeon.actors.Char) Actor(com.shatteredpixel.shatteredpixeldungeon.actors.Actor) Ballistica(com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica) Dart(com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)

Example 3 with Dart

use of com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart in project shattered-pixel-dungeon-gdx by 00-Evan.

the class MissileSprite method setup.

// TODO it might be nice to have a source and destination angle, to improve thrown weapon visuals
private void setup(PointF from, PointF to, Item item, Callback listener) {
    originToCenter();
    this.callback = listener;
    point(from);
    PointF d = PointF.diff(to, from);
    speed.set(d).normalize().scale(SPEED);
    angularSpeed = DEFAULT_ANGULAR_SPEED;
    for (Class<? extends Item> cls : ANGULAR_SPEEDS.keySet()) {
        if (cls.isAssignableFrom(item.getClass())) {
            angularSpeed = ANGULAR_SPEEDS.get(cls);
            break;
        }
    }
    angle = 135 - (float) (Math.atan2(d.x, d.y) / 3.1415926 * 180);
    if (d.x >= 0) {
        flipHorizontal = false;
        updateFrame();
    } else {
        angularSpeed = -angularSpeed;
        angle += 90;
        flipHorizontal = true;
        updateFrame();
    }
    float speed = SPEED;
    if (item instanceof Dart && Dungeon.hero.belongings.weapon instanceof Crossbow) {
        speed *= 3f;
    }
    PosTweener tweener = new PosTweener(this, to, d.length() / speed);
    tweener.listener = this;
    parent.add(tweener);
}
Also used : Crossbow(com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.Crossbow) PosTweener(com.watabou.noosa.tweeners.PosTweener) PointF(com.watabou.utils.PointF) Dart(com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)

Aggregations

Dart (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)3 Callback (com.watabou.utils.Callback)2 Actor (com.shatteredpixel.shatteredpixeldungeon.actors.Actor)1 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)1 Crossbow (com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.Crossbow)1 Ballistica (com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica)1 PosTweener (com.watabou.noosa.tweeners.PosTweener)1 PointF (com.watabou.utils.PointF)1