Search in sources :

Example 1 with Callback

use of com.watabou.utils.Callback in project pixel-dungeon by watabou.

the class HuntressArmor method doSpecial.

@Override
public void doSpecial() {
    Item proto = new Shuriken();
    for (Mob mob : Dungeon.level.mobs) {
        if (Level.fieldOfView[mob.pos]) {
            Callback callback = new Callback() {

                @Override
                public void call() {
                    curUser.attack(targets.get(this));
                    targets.remove(this);
                    if (targets.isEmpty()) {
                        curUser.spendAndNext(curUser.attackDelay());
                    }
                }
            };
            ((MissileSprite) curUser.sprite.parent.recycle(MissileSprite.class)).reset(curUser.pos, mob.pos, proto, callback);
            targets.put(callback, mob);
        }
    }
    if (targets.size() == 0) {
        GLog.w(TXT_NO_ENEMIES);
        return;
    }
    curUser.HP -= (curUser.HP / 3);
    curUser.sprite.zap(curUser.pos);
    curUser.busy();
}
Also used : Item(com.watabou.pixeldungeon.items.Item) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) Callback(com.watabou.utils.Callback) Shuriken(com.watabou.pixeldungeon.items.weapon.missiles.Shuriken) MissileSprite(com.watabou.pixeldungeon.sprites.MissileSprite)

Example 2 with Callback

use of com.watabou.utils.Callback in project pixel-dungeon by watabou.

the class Pickaxe method execute.

@Override
public void execute(final Hero hero, String action) {
    if (action == AC_MINE) {
        if (Dungeon.depth < 11 || Dungeon.depth > 15) {
            GLog.w(TXT_NO_VEIN);
            return;
        }
        for (int i = 0; i < Level.NEIGHBOURS8.length; i++) {
            final int pos = hero.pos + Level.NEIGHBOURS8[i];
            if (Dungeon.level.map[pos] == Terrain.WALL_DECO) {
                hero.spend(TIME_TO_MINE);
                hero.busy();
                hero.sprite.attack(pos, new Callback() {

                    @Override
                    public void call() {
                        CellEmitter.center(pos).burst(Speck.factory(Speck.STAR), 7);
                        Sample.INSTANCE.play(Assets.SND_EVOKE);
                        Level.set(pos, Terrain.WALL);
                        GameScene.updateMap(pos);
                        DarkGold gold = new DarkGold();
                        if (gold.doPickUp(Dungeon.hero)) {
                            GLog.i(Hero.TXT_YOU_NOW_HAVE, gold.name());
                        } else {
                            Dungeon.level.drop(gold, hero.pos).sprite.drop();
                        }
                        Hunger hunger = hero.buff(Hunger.class);
                        if (hunger != null && !hunger.isStarving()) {
                            hunger.satisfy(-Hunger.STARVING / 10);
                            BuffIndicator.refreshHero();
                        }
                        hero.onOperateComplete();
                    }
                });
                return;
            }
        }
        GLog.w(TXT_NO_VEIN);
    } else {
        super.execute(hero, action);
    }
}
Also used : Hunger(com.watabou.pixeldungeon.actors.buffs.Hunger) Callback(com.watabou.utils.Callback)

Example 3 with Callback

use of com.watabou.utils.Callback in project pixel-dungeon by watabou.

the class BadgesScene method create.

@Override
public void create() {
    super.create();
    Music.INSTANCE.play(Assets.THEME, true);
    Music.INSTANCE.volume(1f);
    uiCamera.visible = false;
    int w = Camera.main.width;
    int h = Camera.main.height;
    Archs archs = new Archs();
    archs.setSize(w, h);
    add(archs);
    int pw = (int) Math.min(w, (PixelDungeon.landscape() ? MIN_WIDTH_L : MIN_WIDTH_P) * 3) - 16;
    int ph = (int) Math.min(h, (PixelDungeon.landscape() ? MIN_HEIGHT_L : MIN_HEIGHT_P) * 3) - 32;
    float size = (float) Math.sqrt(pw * ph / 27f);
    int nCols = (int) Math.ceil(pw / size);
    int nRows = (int) Math.ceil(ph / size);
    size = Math.min(pw / nCols, ph / nRows);
    float left = (w - size * nCols) / 2;
    float top = (h - size * nRows) / 2;
    BitmapText title = PixelScene.createText(TXT_TITLE, 9);
    title.hardlight(Window.TITLE_COLOR);
    title.measure();
    title.x = align((w - title.width()) / 2);
    title.y = align((top - title.baseLine()) / 2);
    add(title);
    Badges.loadGlobal();
    List<Badges.Badge> badges = Badges.filtered(true);
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            int index = i * nCols + j;
            Badges.Badge b = index < badges.size() ? badges.get(index) : null;
            BadgeButton button = new BadgeButton(b);
            button.setPos(left + j * size + (size - button.width()) / 2, top + i * size + (size - button.height()) / 2);
            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) {
                PixelDungeon.switchNoFade(BadgesScene.class);
            }
        }
    };
}
Also used : ExitButton(com.watabou.pixeldungeon.ui.ExitButton) WndBadge(com.watabou.pixeldungeon.windows.WndBadge) Callback(com.watabou.utils.Callback) Archs(com.watabou.pixeldungeon.ui.Archs) BitmapText(com.watabou.noosa.BitmapText) Badges(com.watabou.pixeldungeon.Badges)

Example 4 with Callback

use of com.watabou.utils.Callback in project pixel-dungeon by watabou.

the class StartScene method create.

@Override
public void create() {
    super.create();
    Badges.loadGlobal();
    uiCamera.visible = false;
    int w = Camera.main.width;
    int h = Camera.main.height;
    float width, height;
    if (PixelDungeon.landscape()) {
        width = WIDTH_L;
        height = HEIGHT_L;
    } else {
        width = WIDTH_P;
        height = HEIGHT_P;
    }
    float left = (w - width) / 2;
    float top = (h - height) / 2;
    float bottom = h - top;
    Archs archs = new Archs();
    archs.setSize(w, h);
    add(archs);
    Image title = BannerSprites.get(Type.SELECT_YOUR_HERO);
    title.x = align((w - title.width()) / 2);
    title.y = align(top);
    add(title);
    buttonX = left;
    buttonY = bottom - BUTTON_HEIGHT;
    btnNewGame = new GameButton(TXT_NEW) {

        @Override
        protected void onClick() {
            if (GamesInProgress.check(curClass) != null) {
                StartScene.this.add(new WndOptions(TXT_REALLY, TXT_WARNING, TXT_YES, TXT_NO) {

                    @Override
                    protected void onSelect(int index) {
                        if (index == 0) {
                            startNewGame();
                        }
                    }
                });
            } else {
                startNewGame();
            }
        }
    };
    add(btnNewGame);
    btnLoad = new GameButton(TXT_LOAD) {

        @Override
        protected void onClick() {
            InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
            Game.switchScene(InterlevelScene.class);
        }
    };
    add(btnLoad);
    float centralHeight = buttonY - title.y - title.height();
    HeroClass[] classes = { HeroClass.WARRIOR, HeroClass.MAGE, HeroClass.ROGUE, HeroClass.HUNTRESS };
    for (HeroClass cl : classes) {
        ClassShield shield = new ClassShield(cl);
        shields.put(cl, shield);
        add(shield);
    }
    if (PixelDungeon.landscape()) {
        float shieldW = width / 4;
        float shieldH = Math.min(centralHeight, shieldW);
        top = title.y + title.height + (centralHeight - shieldH) / 2;
        for (int i = 0; i < classes.length; i++) {
            ClassShield shield = shields.get(classes[i]);
            shield.setRect(left + i * shieldW, top, shieldW, shieldH);
        }
        ChallengeButton challenge = new ChallengeButton();
        challenge.setPos(w / 2 - challenge.width() / 2, top + shieldH - challenge.height() / 2);
        add(challenge);
    } else {
        float shieldW = width / 2;
        float shieldH = Math.min(centralHeight / 2, shieldW * 1.2f);
        top = title.y + title.height() + centralHeight / 2 - shieldH;
        for (int i = 0; i < classes.length; i++) {
            ClassShield shield = shields.get(classes[i]);
            shield.setRect(left + (i % 2) * shieldW, top + (i / 2) * shieldH, shieldW, shieldH);
        }
        ChallengeButton challenge = new ChallengeButton();
        challenge.setPos(w / 2 - challenge.width() / 2, top + shieldH - challenge.height() / 2);
        add(challenge);
    }
    unlock = new Group();
    add(unlock);
    if (!(huntressUnlocked = Badges.isUnlocked(Badges.Badge.BOSS_SLAIN_3))) {
        BitmapTextMultiline text = PixelScene.createMultiline(TXT_UNLOCK, 9);
        text.maxWidth = (int) width;
        text.measure();
        float pos = (bottom - BUTTON_HEIGHT) + (BUTTON_HEIGHT - text.height()) / 2;
        for (BitmapText line : text.new LineSplitter().split()) {
            line.measure();
            line.hardlight(0xFFFF00);
            line.x = PixelScene.align(w / 2 - line.width() / 2);
            line.y = PixelScene.align(pos);
            unlock.add(line);
            pos += line.height();
        }
    }
    ExitButton btnExit = new ExitButton();
    btnExit.setPos(Camera.main.width - btnExit.width(), 0);
    add(btnExit);
    curClass = null;
    updateClass(HeroClass.values()[PixelDungeon.lastClass()]);
    fadeIn();
    Badges.loadingListener = new Callback() {

        @Override
        public void call() {
            if (Game.scene() == StartScene.this) {
                PixelDungeon.switchNoFade(StartScene.class);
            }
        }
    };
}
Also used : WndOptions(com.watabou.pixeldungeon.windows.WndOptions) Group(com.watabou.noosa.Group) ExitButton(com.watabou.pixeldungeon.ui.ExitButton) Image(com.watabou.noosa.Image) BitmapTextMultiline(com.watabou.noosa.BitmapTextMultiline) Callback(com.watabou.utils.Callback) Archs(com.watabou.pixeldungeon.ui.Archs) BitmapText(com.watabou.noosa.BitmapText) HeroClass(com.watabou.pixeldungeon.actors.hero.HeroClass)

Example 5 with Callback

use of com.watabou.utils.Callback in project pixel-dungeon by watabou.

the class BurningFistSprite method onComplete.

@Override
public void onComplete(Animation anim) {
    if (anim == attack) {
        Sample.INSTANCE.play(Assets.SND_ZAP);
        MagicMissile.shadow(parent, ch.pos, posToShoot, new Callback() {

            @Override
            public void call() {
                ch.onAttackComplete();
            }
        });
        idle();
    } else {
        super.onComplete(anim);
    }
}
Also used : Callback(com.watabou.utils.Callback)

Aggregations

Callback (com.watabou.utils.Callback)11 BitmapText (com.watabou.noosa.BitmapText)2 Shuriken (com.watabou.pixeldungeon.items.weapon.missiles.Shuriken)2 MissileSprite (com.watabou.pixeldungeon.sprites.MissileSprite)2 Archs (com.watabou.pixeldungeon.ui.Archs)2 ExitButton (com.watabou.pixeldungeon.ui.ExitButton)2 BitmapTextMultiline (com.watabou.noosa.BitmapTextMultiline)1 Group (com.watabou.noosa.Group)1 Image (com.watabou.noosa.Image)1 Badges (com.watabou.pixeldungeon.Badges)1 Char (com.watabou.pixeldungeon.actors.Char)1 Hunger (com.watabou.pixeldungeon.actors.buffs.Hunger)1 SnipersMark (com.watabou.pixeldungeon.actors.buffs.SnipersMark)1 HeroClass (com.watabou.pixeldungeon.actors.hero.HeroClass)1 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)1 Item (com.watabou.pixeldungeon.items.Item)1 Dart (com.watabou.pixeldungeon.items.weapon.missiles.Dart)1 MissileWeapon (com.watabou.pixeldungeon.items.weapon.missiles.MissileWeapon)1 WndBadge (com.watabou.pixeldungeon.windows.WndBadge)1 WndOptions (com.watabou.pixeldungeon.windows.WndOptions)1