Search in sources :

Example 26 with InteractiveActor

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

the class MoveToSceneAction method run.

@Override
public boolean run(VerbRunner cb) {
    final Scene s = actor.getScene();
    final String actorId = actor.getActorId();
    final World w = World.getInstance();
    if (actorId == null) {
        // if called in a scene verb and no actor is specified, we do nothing
        EngineLogger.error(getClass() + ": No actor specified");
        return false;
    }
    InteractiveActor a = (InteractiveActor) s.getActor(actorId, false);
    s.removeActor(a);
    if (s == w.getCurrentScene() && a instanceof Disposable)
        ((Disposable) a).dispose();
    Scene ts = null;
    if (scene == null)
        ts = w.getCurrentScene();
    else
        ts = w.getScene(scene);
    // the scene is cached.
    if ((ts == w.getCurrentScene() || w.getCachedScene(ts.getId()) != null) && a instanceof AssetConsumer) {
        ((AssetConsumer) a).loadAssets();
        EngineAssetManager.getInstance().finishLoading();
        ((AssetConsumer) a).retrieveAssets();
    }
    ts.addActor(a);
    return false;
}
Also used : Disposable(com.badlogic.gdx.utils.Disposable) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) AssetConsumer(com.bladecoder.engine.assets.AssetConsumer) Scene(com.bladecoder.engine.model.Scene) World(com.bladecoder.engine.model.World)

Example 27 with InteractiveActor

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

the class PickUpAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene scn = this.actor.getScene();
    InteractiveActor actor = (InteractiveActor) scn.getActor(this.actor.getActorId(), false);
    if (actor == null) {
        EngineLogger.error("PickUpAction - Actor not found:" + this.actor.getActorId());
        return false;
    }
    scn.removeActor(actor);
    if (actor instanceof SpriteActor) {
        SpriteActor a = (SpriteActor) actor;
        if (scn != World.getInstance().getCurrentScene() && World.getInstance().getCachedScene(scn.getId()) == null) {
            a.loadAssets();
            EngineAssetManager.getInstance().finishLoading();
            a.retrieveAssets();
        }
        if (a.getRenderer() instanceof AnimationRenderer) {
            if (animation != null)
                a.startAnimation(animation, null);
            else if (((AnimationRenderer) a.getRenderer()).getAnimations().get(a.getId() + ".inventory") != null)
                a.startAnimation(a.getId() + ".inventory", null);
        }
        World.getInstance().getInventory().addItem(a);
    }
    return false;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 28 with InteractiveActor

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

the class PositionAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = actor.getScene();
    BaseActor a = s.getActor(actor.getActorId(), true);
    float x = a.getX();
    float y = a.getY();
    if (target != null) {
        Scene ts = target.getScene();
        BaseActor anchorActor = ts.getActor(target.getActorId(), false);
        x = anchorActor.getX();
        y = anchorActor.getY();
        if (anchorActor instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) anchorActor).getRefPoint();
            x += refPoint.x;
            y += refPoint.y;
        }
        if (position != null) {
            float scale = EngineAssetManager.getInstance().getScale();
            x += position.x * scale;
            y += position.y * scale;
        }
    } else if (position != null) {
        float scale = EngineAssetManager.getInstance().getScale();
        x = position.x * scale;
        y = position.y * scale;
    }
    a.setPosition(x, y);
    return false;
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene)

Example 29 with InteractiveActor

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

the class PositionAnimAction method run.

@Override
public boolean run(VerbRunner cb) {
    float scale = EngineAssetManager.getInstance().getScale();
    BaseActor a = World.getInstance().getCurrentScene().getActor(actor, true);
    float x = a.getX();
    float y = a.getY();
    if (target != null) {
        BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
        x = target.getX();
        y = target.getY();
        if (target instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
            x += refPoint.x;
            y += refPoint.y;
        }
        if (pos != null) {
            x += pos.x * scale;
            y += pos.y * scale;
        }
    } else if (pos != null) {
        x = pos.x * scale;
        y = pos.y * scale;
    }
    if (speed == 0 || !(a instanceof SpriteActor)) {
        a.setPosition(x, y);
        return false;
    } else {
        // WARNING: only spriteactors support animation
        float s;
        if (mode != null && mode == Mode.SPEED) {
            Vector2 p0 = new Vector2(a.getX(), a.getY());
            s = p0.dst(x, y) / (scale * speed);
        } else {
            s = speed;
        }
        SpritePosTween t = new SpritePosTween();
        t.start((SpriteActor) a, repeat, count, x, y, s, interpolation, wait ? cb : null);
        ((SpriteActor) a).addTween(t);
    }
    return wait;
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) SpritePosTween(com.bladecoder.engine.anim.SpritePosTween)

Example 30 with InteractiveActor

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

the class RunVerbAction method getVerb.

private Verb getVerb() {
    Verb v = null;
    Scene s = World.getInstance().getCurrentScene();
    if (actor != null) {
        InteractiveActor a = (InteractiveActor) s.getActor(actor, true);
        v = a.getVerbManager().getVerb(verb, a.getState(), target);
    }
    if (v == null) {
        v = s.getVerbManager().getVerb(verb, s.getState(), target);
    }
    if (v == null) {
        v = World.getInstance().getVerbManager().getVerb(verb, null, target);
    }
    if (v == null)
        EngineLogger.error("Cannot find VERB: " + verb + " for ACTOR: " + actor);
    return v;
}
Also used : Verb(com.bladecoder.engine.model.Verb) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) 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