Search in sources :

Example 1 with SpriteActor

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

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

the class RemoveInventoryItemAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = World.getInstance().getScene(scene);
    if (id != null) {
        SpriteActor a = World.getInstance().getInventory().removeItem(id);
        if (a != null) {
            if (s != World.getInstance().getCurrentScene())
                a.dispose();
            s.addActor(a);
        } else {
            EngineLogger.debug("RemoveInventoryAction - Inventory actor not found: " + id);
        }
    } else {
        int n = World.getInstance().getInventory().getNumItems();
        for (int i = 0; i < n; i++) {
            SpriteActor a = World.getInstance().getInventory().get(i);
            s.addActor(a);
        }
        World.getInstance().getInventory().removeAllItems();
    }
    return false;
}
Also used : SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene)

Example 3 with SpriteActor

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

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

the class ScaleAction method run.

@Override
public boolean run(VerbRunner cb) {
    SpriteActor a = (SpriteActor) World.getInstance().getCurrentScene().getActor(actor, false);
    SpriteScaleTween t = new SpriteScaleTween();
    t.start(a, repeat, count, scale, speed, interpolation, wait ? cb : null);
    a.addTween(t);
    return wait;
}
Also used : SpriteScaleTween(com.bladecoder.engine.anim.SpriteScaleTween) SpriteActor(com.bladecoder.engine.model.SpriteActor)

Example 5 with SpriteActor

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

the class IfAttrAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = actor.getScene();
    final String actorId = actor.getActorId();
    if (actorId == null) {
        // if called inside a scene verb and no actor is specified, return
        EngineLogger.error(getClass() + ": No actor specified");
        return false;
    }
    BaseActor a = s.getActor(actorId, true);
    if (attr.equals(ActorAttribute.STATE) && a instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) a;
        if (!ActionUtils.compareNullStr(value, ia.getState())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.VISIBLE)) {
        boolean val = Boolean.parseBoolean(value);
        if (val != a.isVisible()) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.INTERACTIVE)) {
        boolean val = Boolean.parseBoolean(value);
        if (a instanceof InteractiveActor) {
            if (val != ((InteractiveActor) a).getInteraction()) {
                gotoElse((VerbRunner) cb);
            }
        } else if (val == true) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.IN_INVENTORY)) {
        boolean val = Boolean.parseBoolean(value);
        SpriteActor item = null;
        if (a != null)
            item = World.getInstance().getInventory().get(a.getId());
        if ((val && item == null) || (!val && item != null)) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.TARGET)) {
        if (!ActionUtils.compareNullStr(value, cb.getCurrentTarget())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.IN_SCENE)) {
        boolean val = Boolean.parseBoolean(value);
        BaseActor a2 = s.getActor(actorId, false);
        if ((val && a2 == null) || (!val && a2 != null))
            gotoElse((VerbRunner) cb);
    } else if (attr.equals(ActorAttribute.LAYER) && a instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) a;
        if (!ActionUtils.compareNullStr(value, ia.getLayer())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.DIRECTION) && a instanceof SpriteActor) {
        SpriteActor sa = (SpriteActor) a;
        if (sa.getRenderer() instanceof AnimationRenderer) {
            String dir = null;
            String anim = ((AnimationRenderer) sa.getRenderer()).getCurrentAnimationId();
            int idx = anim.lastIndexOf('.');
            if (idx != -1)
                dir = anim.substring(idx + 1);
            if (!ActionUtils.compareNullStr(value, dir)) {
                gotoElse((VerbRunner) cb);
            }
        }
    }
    return false;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) VerbRunner(com.bladecoder.engine.model.VerbRunner) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Aggregations

SpriteActor (com.bladecoder.engine.model.SpriteActor)32 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)16 BaseActor (com.bladecoder.engine.model.BaseActor)12 CharacterActor (com.bladecoder.engine.model.CharacterActor)10 Vector2 (com.badlogic.gdx.math.Vector2)8 Scene (com.bladecoder.engine.model.Scene)7 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)6 SpineRenderer (com.bladecoder.engine.spine.SpineRenderer)6 AnchorActor (com.bladecoder.engine.model.AnchorActor)5 TextRenderer (com.bladecoder.engine.model.TextRenderer)5 Verb (com.bladecoder.engine.model.Verb)5 Polygon (com.badlogic.gdx.math.Polygon)4 AtlasRenderer (com.bladecoder.engine.model.AtlasRenderer)4 Rectangle (com.badlogic.gdx.math.Rectangle)3 ActorRenderer (com.bladecoder.engine.model.ActorRenderer)3 Dialog (com.bladecoder.engine.model.Dialog)3 ImageRenderer (com.bladecoder.engine.model.ImageRenderer)3 SceneLayer (com.bladecoder.engine.model.SceneLayer)3 Sprite3DRenderer (com.bladecoder.engine.model.Sprite3DRenderer)3 World (com.bladecoder.engine.model.World)3