Search in sources :

Example 1 with InteractiveActor

use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.

the class DefaultSceneScreen method drawDebugText.

private void drawDebugText(SpriteBatch batch) {
    World w = World.getInstance();
    w.getSceneCamera().getInputUnProject(viewport, unprojectTmp);
    Color color;
    sbTmp.setLength(0);
    if (EngineLogger.lastError != null) {
        sbTmp.append(EngineLogger.lastError);
        color = Color.RED;
    } else {
        // sbTmp.append("( ");
        // sbTmp.append((int) unprojectTmp.x);
        // sbTmp.append(", ");
        // sbTmp.append((int) unprojectTmp.y);
        // sbTmp.append(") FPS:");
        // sbTmp.append(Gdx.graphics.getFramesPerSecond());
        // sbTmp.append(" Density:");
        // sbTmp.append(Gdx.graphics.getDensity());
        // sbTmp.append(" UI Multiplier:");
        // sbTmp.append(DPIUtils.getSizeMultiplier());
        sbTmp.append(" ");
        sbTmp.append(state.toString());
        sbTmp.append(' ');
        long millis = w.getTimeOfGame();
        long second = (millis / 1000) % 60;
        long minute = (millis / (1000 * 60)) % 60;
        long hour = (millis / (1000 * 60 * 60));
        String time = String.format("%02d:%02d:%02d", hour, minute, second);
        sbTmp.append(time);
        // if (w.getCurrentScene().getPlayer() != null) {
        // sbTmp.append(" Depth Scl: ");
        // sbTmp.append(w.getCurrentScene().getFakeDepthScale(unprojectTmp.y));
        // }
        color = Color.WHITE;
    }
    String strDebug = sbTmp.toString();
    textLayout.setText(ui.getSkin().getFont("debug"), strDebug, color, viewport.getScreenWidth(), Align.left, true);
    RectangleRenderer.draw(batch, 0, viewport.getScreenHeight() - textLayout.height - 10, textLayout.width, textLayout.height + 10, Color.BLACK);
    ui.getSkin().getFont("debug").draw(batch, textLayout, 0, viewport.getScreenHeight() - 5);
    // Draw actor states when debug
    if (EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) {
        for (BaseActor a : w.getCurrentScene().getActors().values()) {
            if (a instanceof AnchorActor)
                continue;
            Rectangle r = a.getBBox().getBoundingRectangle();
            sbTmp.setLength(0);
            sbTmp.append(a.getId());
            if (a instanceof InteractiveActor && ((InteractiveActor) a).getState() != null)
                sbTmp.append(".").append(((InteractiveActor) a).getState());
            unprojectTmp.set(r.getX(), r.getY(), 0);
            w.getSceneCamera().scene2screen(viewport, unprojectTmp);
            ui.getSkin().getFont("debug").draw(batch, sbTmp.toString(), unprojectTmp.x, unprojectTmp.y);
        }
    }
}
Also used : AnchorActor(com.bladecoder.engine.model.AnchorActor) Color(com.badlogic.gdx.graphics.Color) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Rectangle(com.badlogic.gdx.math.Rectangle) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World)

Example 2 with InteractiveActor

use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.

the class VerbUI method createInventoryPanel.

private Table createInventoryPanel() {
    Table inventory = new Table();
    inventory.defaults().pad(MARGIN);
    for (int i = 0; i < INVENTORY_COLS * INVENTORY_ROWS; i++) {
        if (i % INVENTORY_COLS == 0)
            inventory.row();
        ImageButton.ImageButtonStyle s = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
        RendererDrawable r = new RendererDrawable();
        s.imageUp = r;
        ImageButton b = new ImageButton(s);
        inventory.add(b).fill().expand();
        b.setUserObject(i);
        inventorySlots.add(b);
        b.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                int i = (Integer) event.getListenerActor().getUserObject();
                Inventory inv = World.getInstance().getInventory();
                target = null;
                if (i < inv.getNumItems()) {
                    InteractiveActor actor = inv.get(i);
                    if (currentVerb.equals("use") || currentVerb.equals("give")) {
                        target = actor;
                    } else {
                        sceneScreen.runVerb(actor, currentVerb, null);
                    }
                }
            }
        });
        b.getImageCell().pad(MARGIN).expand().fill();
    }
    return inventory;
}
Also used : ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Inventory(com.bladecoder.engine.model.Inventory)

Example 3 with InteractiveActor

use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.

the class TesterBot method update.

public void update(float d) {
    if (!enabled)
        return;
    World w = World.getInstance();
    deltaTime += d;
    inSceneTimeDelta += d;
    if (w.inCutMode() && isPassTexts())
        w.getTextManager().next();
    if (deltaTime > waitInverval && !w.inCutMode()) {
        deltaTime = 0;
        waitInverval = MathUtils.random(maxWaitInverval);
        boolean isWalking = false;
        SpriteActor player = w.getCurrentScene().getPlayer();
        if (player != null) {
            if (((AnimationRenderer) player.getRenderer()).getCurrentAnimationId().startsWith(CharacterActor.DEFAULT_WALK_ANIM))
                isWalking = true;
        }
        if (isWaitWhenWalking() && isWalking)
            return;
        Scene s = w.getCurrentScene();
        if (w.getCurrentDialog() == null) {
            // Select actor or goto
            boolean chooseActor = MathUtils.randomBoolean(.75f);
            if (!isRunGoto() || chooseActor) {
                // Select scene or actor inventory
                boolean chooseSceneActor = MathUtils.randomBoolean();
                if (chooseSceneActor && s.getActors().size() > 0) {
                    // SCENE ACTOR
                    int pos = MathUtils.random(s.getActors().size() - 1);
                    BaseActor a = (BaseActor) (s.getActors().values().toArray()[pos]);
                    if (!(a instanceof InteractiveActor))
                        return;
                    InteractiveActor scnActor = (InteractiveActor) a;
                    if (excludeList.contains(scnActor.getId()) || !scnActor.isVisible() || !scnActor.canInteract())
                        return;
                    String verb;
                    if (scnActor.getVerb(Verb.LEAVE_VERB) != null) {
                        verb = Verb.LEAVE_VERB;
                    } else if (MathUtils.randomBoolean(0.33f)) {
                        // LOOKAT
                        verb = Verb.LOOKAT_VERB;
                    } else {
                        // ACTION
                        verb = scnActor.getVerb(Verb.TALKTO_VERB) != null ? Verb.TALKTO_VERB : Verb.ACTION_VERB;
                    }
                    if (!(verb.equals(Verb.LEAVE_VERB) && (!runLeaveVerbs || inSceneTime > inSceneTimeDelta))) {
                        EngineLogger.debug("<TESTERBOT>: " + scnActor.getId() + "::" + verb);
                        scnActor.runVerb(verb);
                        if (verb.equals(Verb.LEAVE_VERB))
                            inSceneTimeDelta = 0;
                    }
                } else if (w.getInventory().getNumItems() > 0 && w.getInventory().isVisible()) {
                    // INVENTORY ACTOR
                    int pos = MathUtils.random(w.getInventory().getNumItems() - 1);
                    SpriteActor invActor = w.getInventory().get(pos);
                    if (excludeList.contains(invActor.getId()))
                        return;
                    // Select lookat, action or use
                    int choosedVerb = MathUtils.random(3);
                    if (choosedVerb == 0) {
                        EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.LOOKAT_VERB);
                        invActor.runVerb(Verb.LOOKAT_VERB);
                    } else if (choosedVerb == 1 && inventoryAction) {
                        EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.ACTION_VERB);
                        invActor.runVerb(Verb.ACTION_VERB);
                    } else {
                        // 2 and 3
                        InteractiveActor targetActor = null;
                        if (w.getInventory().getNumItems() > 1 && MathUtils.randomBoolean(0.33f)) {
                            // CHOOSE TARGET FROM INVENTORY
                            int pos2 = MathUtils.random(w.getInventory().getNumItems() - 1);
                            if (pos2 == pos)
                                pos2 = (pos2 + 1) % w.getInventory().getNumItems();
                            targetActor = w.getInventory().get(pos2);
                            if (excludeList.contains(targetActor.getId()))
                                return;
                            EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.USE_VERB + "::" + targetActor.getId());
                            if (invActor.getVerb(Verb.USE_VERB, targetActor.getId()) != null)
                                invActor.runVerb(Verb.USE_VERB, targetActor.getId());
                            else
                                targetActor.runVerb(Verb.USE_VERB, invActor.getId());
                        } else {
                            int pos2 = MathUtils.random(s.getActors().size() - 1);
                            if (!(s.getActors().values().toArray()[pos2] instanceof InteractiveActor))
                                return;
                            targetActor = (InteractiveActor) (s.getActors().values().toArray()[pos2]);
                            if (!excludeList.contains(targetActor.getId()) && targetActor.isVisible() && targetActor.canInteract()) {
                                EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.USE_VERB + "::" + targetActor.getId());
                                if (invActor.getVerb(Verb.USE_VERB, targetActor.getId()) != null)
                                    invActor.runVerb(Verb.USE_VERB, targetActor.getId());
                                else
                                    targetActor.runVerb(Verb.USE_VERB, invActor.getId());
                            }
                        }
                    }
                }
            } else if (s.getPlayer() != null) {
                gotoVector.x = MathUtils.random() * w.getCurrentScene().getCamera().getScrollingWidth();
                gotoVector.y = MathUtils.random() * w.getCurrentScene().getCamera().getScrollingHeight();
                if (s.getPlayer().getVerb(Verb.GOTO_VERB) != null) {
                    EngineLogger.debug("<TESTERBOT> GOTO: GOTO VERB");
                    s.getPlayer().runVerb(Verb.GOTO_VERB);
                } else {
                    EngineLogger.debug("<TESTERBOT> GOTO: " + gotoVector);
                    s.getPlayer().goTo(gotoVector, null, false);
                }
            }
        } else {
            // DIALOG MODE
            List<String> visibleOptions = w.getDialogOptions();
            if (visibleOptions.size() > 0) {
                int pos = MathUtils.random(visibleOptions.size() - 1);
                EngineLogger.debug("<TESTERBOT> SELECT OPTION: " + pos);
                w.selectDialogOption(pos);
            }
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Scene(com.bladecoder.engine.model.Scene)

Example 4 with InteractiveActor

use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.

the class ActionCallbackSerialization method find.

private static String find(ActionCallback cb, UIActors uia) {
    if (uia == null)
        return null;
    for (InteractiveActor a : uia.getActors()) {
        String id = find(cb, a);
        if (id != null) {
            StringBuilder stringBuilder = new StringBuilder(UIACTORS_TAG);
            stringBuilder.append(SEPARATION_SYMBOL).append(id);
            return stringBuilder.toString();
        }
    }
    return null;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor)

Example 5 with InteractiveActor

use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.

the class ActionCallbackSerialization method find.

/**
 * Generates a String for serialization that allows locate the
 * ActionCallback
 *
 * @param cb
 *            The ActionCallback to serialize
 * @return The generated location string
 */
public static String find(ActionCallback cb) {
    String id = null;
    if (cb == null)
        return null;
    // search in UIActors
    id = find(cb, World.getInstance().getUIActors());
    if (id != null)
        return id;
    // search in inventory
    id = find(cb, World.getInstance().getInventory());
    if (id != null)
        return id;
    // search in inkManager actions
    id = find(cb, World.getInstance().getInkManager());
    if (id != null)
        return id;
    // search in scene verbs
    Scene s = World.getInstance().getCurrentScene();
    id = find(cb, s);
    if (id != null)
        return id;
    // search in player
    id = find(cb, s.getPlayer());
    if (id != null)
        return id;
    // search in actors
    for (BaseActor a : s.getActors().values()) {
        if (!(a instanceof InteractiveActor))
            continue;
        id = find(cb, (InteractiveActor) a);
        if (id != null)
            return id;
    }
    // search in worldVerbs
    for (Verb v : World.getInstance().getVerbManager().getVerbs().values()) {
        id = find(cb, v);
        if (id != null) {
            StringBuilder stringBuilder = new StringBuilder(DEFAULT_VERB_TAG);
            stringBuilder.append(SEPARATION_SYMBOL).append(id);
            return stringBuilder.toString();
        }
    }
    return null;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene)

Aggregations

InteractiveActor (com.bladecoder.engine.model.InteractiveActor)43 BaseActor (com.bladecoder.engine.model.BaseActor)25 Scene (com.bladecoder.engine.model.Scene)17 SpriteActor (com.bladecoder.engine.model.SpriteActor)16 Verb (com.bladecoder.engine.model.Verb)14 CharacterActor (com.bladecoder.engine.model.CharacterActor)13 Vector2 (com.badlogic.gdx.math.Vector2)11 Rectangle (com.badlogic.gdx.math.Rectangle)7 Polygon (com.badlogic.gdx.math.Polygon)6 Action (com.bladecoder.engine.actions.Action)6 AnchorActor (com.bladecoder.engine.model.AnchorActor)6 Dialog (com.bladecoder.engine.model.Dialog)6 World (com.bladecoder.engine.model.World)6 TextRenderer (com.bladecoder.engine.model.TextRenderer)5 Color (com.badlogic.gdx.graphics.Color)4 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)3