Search in sources :

Example 11 with Callback

use of com.watabou.utils.Callback in project shattered-pixel-dungeon-gdx by 00-Evan.

the class WarlockSprite method zap.

public void zap(int cell) {
    turnTo(ch.pos, cell);
    play(zap);
    MagicMissile.boltFromChar(parent, MagicMissile.SHADOW, this, cell, new Callback() {

        @Override
        public void call() {
            ((Warlock) ch).onZapComplete();
        }
    });
    Sample.INSTANCE.play(Assets.SND_ZAP);
}
Also used : Callback(com.watabou.utils.Callback)

Example 12 with Callback

use of com.watabou.utils.Callback 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 13 with Callback

use of com.watabou.utils.Callback in project shattered-pixel-dungeon-gdx by 00-Evan.

the class BadgesScene method create.

@Override
public void create() {
    super.create();
    Music.INSTANCE.play(Assets.THEME, true);
    uiCamera.visible = false;
    int w = Camera.main.width;
    int h = Camera.main.height;
    Archs archs = new Archs();
    archs.setSize(w, h);
    add(archs);
    float left = 5;
    float top = 16;
    RenderedText title = PixelScene.renderText(Messages.get(this, "title"), 9);
    title.hardlight(Window.TITLE_COLOR);
    title.x = (w - title.width()) / 2f;
    title.y = (top - title.baseLine()) / 2f;
    align(title);
    add(title);
    Badges.loadGlobal();
    List<Badges.Badge> badges = Badges.filtered(true);
    int blankBadges = 34;
    blankBadges -= badges.size();
    if (badges.contains(Badges.Badge.ALL_ITEMS_IDENTIFIED))
        blankBadges -= 6;
    if (badges.contains(Badges.Badge.YASD))
        blankBadges -= 5;
    blankBadges = Math.max(0, blankBadges);
    // guarantees a max of 5 rows in landscape, and 8 in portrait, assuming a max of 40 buttons
    int nCols = SPDSettings.landscape() ? 7 : 4;
    if (badges.size() + blankBadges > 32 && !SPDSettings.landscape())
        nCols++;
    int nRows = 1 + (blankBadges + badges.size()) / nCols;
    float badgeWidth = (w - 2 * left) / nCols;
    float badgeHeight = (h - 2 * top) / nRows;
    for (int i = 0; i < badges.size() + blankBadges; i++) {
        int row = i / nCols;
        int col = i % nCols;
        Badges.Badge b = i < badges.size() ? badges.get(i) : null;
        BadgeButton button = new BadgeButton(b);
        button.setPos(left + col * badgeWidth + (badgeWidth - button.width()) / 2, top + row * badgeHeight + (badgeHeight - button.height()) / 2);
        align(button);
        add(button);
    }
    ExitButton btnExit = new ExitButton();
    btnExit.setPos(Camera.main.width - btnExit.width(), 0);
    add(btnExit);
    fadeIn();
    Badges.loadingListener = new Callback() {

        @Override
        public void call() {
            if (Game.scene() == BadgesScene.this) {
                ShatteredPixelDungeon.switchNoFade(BadgesScene.class);
            }
        }
    };
}
Also used : ExitButton(com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton) RenderedText(com.watabou.noosa.RenderedText) WndBadge(com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge) Callback(com.watabou.utils.Callback) Archs(com.shatteredpixel.shatteredpixeldungeon.ui.Archs) Badges(com.shatteredpixel.shatteredpixeldungeon.Badges)

Example 14 with Callback

use of com.watabou.utils.Callback in project shattered-pixel-dungeon-gdx by 00-Evan.

the class GrimTrap 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 GrimTrap trap = this;
        int damage;
        // almost kill the player
        if (finalTarget == Dungeon.hero && ((float) finalTarget.HP / finalTarget.HT) >= 0.9f) {
            damage = finalTarget.HP - 1;
        // kill 'em
        } else {
            damage = finalTarget.HP;
        }
        final int finalDmg = damage;
        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;
                ((MagicMissile) finalTarget.sprite.parent.recycle(MagicMissile.class)).reset(MagicMissile.SHADOW, DungeonTilemap.tileCenterToWorld(pos), finalTarget.sprite.center(), new Callback() {

                    @Override
                    public void call() {
                        finalTarget.damage(finalDmg, trap);
                        if (finalTarget == Dungeon.hero) {
                            Sample.INSTANCE.play(Assets.SND_CURSED);
                            if (!finalTarget.isAlive()) {
                                Dungeon.fail(GrimTrap.class);
                                GLog.n(Messages.get(GrimTrap.class, "ondeath"));
                            }
                        } else {
                            Sample.INSTANCE.play(Assets.SND_BURNING);
                        }
                        finalTarget.sprite.emitter().burst(ShadowParticle.UP, 10);
                        Actor.remove(toRemove);
                        next();
                    }
                });
                return false;
            }
        });
    } else {
        CellEmitter.get(pos).burst(ShadowParticle.UP, 10);
        Sample.INSTANCE.play(Assets.SND_BURNING);
    }
}
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)

Example 15 with Callback

use of com.watabou.utils.Callback 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)

Aggregations

Callback (com.watabou.utils.Callback)43 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)8 Pushing (com.shatteredpixel.shatteredpixeldungeon.effects.Pushing)4 Ballistica (com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica)4 Char (com.watabou.pixeldungeon.actors.Char)4 MissileSprite (com.watabou.pixeldungeon.sprites.MissileSprite)4 Actor (com.shatteredpixel.shatteredpixeldungeon.actors.Actor)3 Chains (com.shatteredpixel.shatteredpixeldungeon.effects.Chains)3 Shuriken (com.watabou.pixeldungeon.items.weapon.missiles.Shuriken)3 Mob (com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob)2 Item (com.shatteredpixel.shatteredpixeldungeon.items.Item)2 Shuriken (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Shuriken)2 Dart (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)2 MissileSprite (com.shatteredpixel.shatteredpixeldungeon.sprites.MissileSprite)2 BitmapText (com.watabou.noosa.BitmapText)2 Hunger (com.watabou.pixeldungeon.actors.buffs.Hunger)2 SnipersMark (com.watabou.pixeldungeon.actors.buffs.SnipersMark)2 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)2 Item (com.watabou.pixeldungeon.items.Item)2 MissileWeapon (com.watabou.pixeldungeon.items.weapon.missiles.MissileWeapon)2