Search in sources :

Example 1 with BaseActor

use of com.bladecoder.engine.model.BaseActor 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 BaseActor

use of com.bladecoder.engine.model.BaseActor 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 3 with BaseActor

use of com.bladecoder.engine.model.BaseActor 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)

Example 4 with BaseActor

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

the class SayDialogAction method resume.

@Override
public void resume() {
    World w = World.getInstance();
    BaseActor actor = w.getCurrentScene().getActor(characterName, false);
    if (characterTurn) {
        characterTurn = false;
        if (previousAnim != null) {
            SpriteActor player = World.getInstance().getCurrentScene().getPlayer();
            player.startAnimation(previousAnim, null);
        }
        if (responseText != null) {
            Rectangle boundingRectangle = actor.getBBox().getBoundingRectangle();
            float x = boundingRectangle.getX() + boundingRectangle.getWidth() / 2;
            float y = boundingRectangle.getY() + boundingRectangle.getHeight();
            World.getInstance().getTextManager().addText(responseText, x, y, false, Text.Type.TALK, ((CharacterActor) actor).getTextColor(), null, actor.getId(), responseVoiceId, this);
            if (actor instanceof CharacterActor) {
                startTalkAnim((CharacterActor) actor);
            }
        } else {
            previousAnim = null;
            super.resume();
        }
    } else {
        if (actor instanceof SpriteActor && previousAnim != null) {
            ((SpriteActor) actor).startAnimation(previousAnim, null);
        }
        super.resume();
    }
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) World(com.bladecoder.engine.model.World) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 5 with BaseActor

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

the class CameraAction method run.

@Override
public boolean run(VerbRunner cb) {
    Vector2 pos2 = null;
    Float zoom2 = zoom;
    if (pos != null)
        pos2 = new Vector2(pos);
    float scale = EngineAssetManager.getInstance().getScale();
    SceneCamera camera = World.getInstance().getSceneCamera();
    if (zoom2 == null || zoom2 < 0)
        zoom2 = camera.getZoom();
    if (pos == null && target == null) {
        pos2 = new Vector2(camera.getPosition());
        pos2.x /= scale;
        pos2.y /= scale;
    }
    if (target != null) {
        BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
        float x = target.getX();
        float y = target.getY();
        if (target instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
            x += refPoint.x;
            y += refPoint.y;
        }
        if (pos2 != null) {
            pos2.x += x;
            pos2.y += y;
        } else {
            pos2 = new Vector2(x, y);
        }
    }
    if (followActor != null) {
        if (followActor.equals("none"))
            World.getInstance().getCurrentScene().setCameraFollowActor(null);
        else {
            World.getInstance().getCurrentScene().setCameraFollowActor((SpriteActor) World.getInstance().getCurrentScene().getActor(followActor, false));
        }
    }
    if (duration == null || duration == 0) {
        camera.setZoom(zoom2);
        camera.setPosition(pos2.x * scale, pos2.y * scale);
        return false;
    } else {
        camera.startAnimation(pos2.x * scale, pos2.y * scale, zoom2, duration, interpolation, wait ? cb : null);
    }
    return wait;
}
Also used : SceneCamera(com.bladecoder.engine.model.SceneCamera) Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor)

Aggregations

BaseActor (com.bladecoder.engine.model.BaseActor)40 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)26 Scene (com.bladecoder.engine.model.Scene)16 SpriteActor (com.bladecoder.engine.model.SpriteActor)13 CharacterActor (com.bladecoder.engine.model.CharacterActor)12 Vector2 (com.badlogic.gdx.math.Vector2)8 Verb (com.bladecoder.engine.model.Verb)8 Polygon (com.badlogic.gdx.math.Polygon)7 World (com.bladecoder.engine.model.World)7 Rectangle (com.badlogic.gdx.math.Rectangle)5 Action (com.bladecoder.engine.actions.Action)5 AnchorActor (com.bladecoder.engine.model.AnchorActor)5 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 Dialog (com.bladecoder.engine.model.Dialog)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)4 SceneLayer (com.bladecoder.engine.model.SceneLayer)4 Color (com.badlogic.gdx.graphics.Color)3