Search in sources :

Example 21 with InteractiveActor

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

the class ScnWidgetInputListener method touchDown.

@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
    super.touchDown(event, x, y, pointer, button);
    // EditorLogger.debug("Touch Down - X: " + x + " Y: " + y);
    Scene scn = scnWidget.getScene();
    if (scn == null)
        return false;
    Vector2 p = new Vector2(Gdx.input.getX(), Gdx.input.getY());
    scnWidget.screenToWorldCoords(p);
    org.set(p);
    if (button == Buttons.LEFT) {
        selActor = scnWidget.getSelectedActor();
        if (scn.getPolygonalNavGraph() != null && scnWidget.getShowWalkZone()) {
            // Check
            // WALKZONE
            // CHECK WALKZONE VERTEXS
            Polygon wzPoly = scn.getPolygonalNavGraph().getWalkZone();
            float[] verts = wzPoly.getTransformedVertices();
            for (int i = 0; i < verts.length; i += 2) {
                if (p.dst(verts[i], verts[i + 1]) < CanvasDrawer.CORNER_DIST) {
                    draggingMode = DraggingModes.DRAGGING_WALKZONE_POINT;
                    vertIndex = i;
                    float[] v = wzPoly.getVertices();
                    undoOrg.set(v[i], v[i + 1]);
                    return true;
                }
            }
            // CHECK FOR WALKZONE DRAGGING
            if (wzPoly.contains(p.x, p.y)) {
                draggingMode = DraggingModes.DRAGGING_WALKZONE;
                undoOrg.set(wzPoly.getX(), wzPoly.getY());
                return true;
            }
        }
        // SELACTOR ORIGIN DRAGGING
        if (selActor != null && selActor instanceof InteractiveActor) {
            Vector2 refPoint = ((InteractiveActor) selActor).getRefPoint();
            float orgX = selActor.getX() + refPoint.x;
            float orgY = selActor.getY() + refPoint.y;
            float dst = Vector2.dst(p.x, p.y, orgX, orgY);
            if (dst < Scene.ANCHOR_RADIUS) {
                draggingMode = DraggingModes.DRAGGING_REFPOINT;
                undoOrg.set(refPoint.x, refPoint.y);
                return true;
            }
        }
        // SELACTOR VERTEXs DRAGGING
        if (selActor != null && (!(selActor instanceof SpriteActor) || !((SpriteActor) selActor).isBboxFromRenderer()) && !(scnWidget.getSelectedActor() instanceof AnchorActor)) {
            Polygon bbox = selActor.getBBox();
            float[] verts = bbox.getTransformedVertices();
            for (int i = 0; i < verts.length; i += 2) {
                if (p.dst(verts[i], verts[i + 1]) < CanvasDrawer.CORNER_DIST) {
                    draggingMode = DraggingModes.DRAGGING_BBOX_POINT;
                    vertIndex = i;
                    float[] v = bbox.getVertices();
                    undoOrg.set(v[i], v[i + 1]);
                    return true;
                }
            }
        }
        // CHECK FOR ACTORS
        BaseActor a = scn.getActorAt(p.x, p.y);
        if (a != null && a != selActor) {
            selActor = a;
            BaseActor da = Ctx.project.getActor(selActor.getId());
            Ctx.project.setSelectedActor(da);
            return true;
        }
        if (a != null) {
            draggingMode = DraggingModes.DRAGGING_ACTOR;
            undoOrg.set(selActor.getX(), selActor.getY());
            return true;
        }
        // CHECK FOR DRAGGING DEPTH MARKERS
        Vector2 depthVector = scnWidget.getScene().getDepthVector();
        if (depthVector != null) {
            p.set(0, depthVector.x);
            scnWidget.worldToScreenCoords(p);
            if (Vector2.dst(p.x - 40, p.y, x, y) < 50) {
                draggingMode = DraggingModes.DRAGGING_MARKER_0;
                Vector2 dv = scnWidget.getScene().getDepthVector();
                undoOrg.set(dv.x, dv.y);
                return true;
            }
            p.set(0, depthVector.y);
            scnWidget.worldToScreenCoords(p);
            if (Vector2.dst(p.x - 40, p.y, x, y) < 50) {
                draggingMode = DraggingModes.DRAGGING_MARKER_100;
                Vector2 dv = scnWidget.getScene().getDepthVector();
                undoOrg.set(dv.x, dv.y);
                return true;
            }
        }
    }
    return true;
}
Also used : AnchorActor(com.bladecoder.engine.model.AnchorActor) Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene) Polygon(com.badlogic.gdx.math.Polygon)

Example 22 with InteractiveActor

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

the class ModelWalker method walk.

public void walk(World w) {
    Map<String, Scene> scenes = World.getInstance().getScenes();
    for (StartVisitor sv : startVisitors) sv.start(w);
    for (Scene scn : scenes.values()) {
        for (SceneVisitor sv : sceneVisitors) sv.visit(scn);
        Map<String, BaseActor> actors = scn.getActors();
        // SCENE VERBS
        HashMap<String, Verb> verbs = scn.getVerbManager().getVerbs();
        for (Verb v : verbs.values()) {
            for (VerbVisitor vv : verbVisitors) vv.visit(scn, null, v);
            ArrayList<Action> actions = v.getActions();
            for (Action act : actions) {
                for (ActionVisitor av : actionVisitors) av.visit(scn, null, v, act);
            }
        }
        for (BaseActor a : actors.values()) {
            for (ActorVisitor av : actorVisitors) av.visit(a);
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                // ACTOR VERBS
                verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    for (VerbVisitor vv : verbVisitors) vv.visit(scn, ia, v);
                    ArrayList<Action> actions = v.getActions();
                    for (Action act : actions) {
                        for (ActionVisitor av : actionVisitors) av.visit(scn, ia, v, act);
                    }
                }
            }
            // DIALOGS
            if (a instanceof CharacterActor) {
                HashMap<String, Dialog> dialogs = ((CharacterActor) a).getDialogs();
                if (dialogs != null) {
                    for (Dialog d : dialogs.values()) {
                        for (DialogVisitor dv : dialogVisitors) dv.visit((CharacterActor) a, d);
                        ArrayList<DialogOption> options = d.getOptions();
                        for (DialogOption o : options) {
                            for (DialogOptionVisitor ov : optionVisitors) ov.visit((CharacterActor) a, d, o);
                        }
                    }
                }
            }
        }
    }
    for (EndVisitor ev : endVisitors) ev.end(w);
}
Also used : Action(com.bladecoder.engine.actions.Action) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor) Dialog(com.bladecoder.engine.model.Dialog) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor) DialogOption(com.bladecoder.engine.model.DialogOption)

Example 23 with InteractiveActor

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

the class CheckInteractionVerbs method visit.

@Override
public void visit(BaseActor a) {
    if (a instanceof InteractiveActor) {
        ia = (InteractiveActor) a;
        hasLookat = false;
        hasPickup = false;
        hasTalkto = false;
        hasLeave = false;
        hasEnterExit = false;
        hasUse = false;
        if (ia.getInteraction()) {
            HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
            for (Verb v : verbs.values()) checkVerb(v);
            if (hasLeave || hasEnterExit)
                return;
            // discard inventory actors
            if (hasLookat) {
                if (ia instanceof SpriteActor) {
                    SpriteActor sa = (SpriteActor) ia;
                    if (sa.getRenderer() instanceof AtlasRenderer) {
                        AtlasRenderer r = (AtlasRenderer) sa.getRenderer();
                        HashMap<String, AnimationDesc> animations = r.getAnimations();
                        if (animations.size() == 0) {
                            EditorLogger.error("CheckInteractionVerbs: Actor with no animations! - " + sa.getScene().getId() + "." + sa.getId());
                        }
                        if (animations.get(r.getInitAnimation()).source.contains("inventory")) {
                            if (!hasUse)
                                EditorLogger.msg("CheckInteractionVerbs: Inventory item should has default 'use' - " + sa.getScene().getId() + "." + sa.getId());
                            return;
                        }
                    }
                }
            }
            // check for lookat and pickup/talk verbs
            if (!hasLookat || (!hasPickup && !hasTalkto)) {
                String msg = "CheckInteractionVerbs: " + a.getScene().getId() + "." + a.getId();
                if (!hasLookat)
                    EditorLogger.error(msg);
                else
                    EditorLogger.msg(msg);
            }
        }
    }
}
Also used : AtlasRenderer(com.bladecoder.engine.model.AtlasRenderer) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb) SpriteActor(com.bladecoder.engine.model.SpriteActor) AnimationDesc(com.bladecoder.engine.anim.AnimationDesc)

Example 24 with InteractiveActor

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

the class SceneActorInputPanel method getActorValues.

private String[] getActorValues(Scene scn) {
    Map<String, BaseActor> actors = scn.getActors();
    ArrayList<BaseActor> filteredActors = new ArrayList<BaseActor>();
    for (BaseActor a : actors.values()) {
        if (type == Param.Type.SCENE_CHARACTER_ACTOR) {
            if (a instanceof CharacterActor)
                filteredActors.add(a);
        } else if (type == Param.Type.SCENE_INTERACTIVE_ACTOR) {
            if (a instanceof InteractiveActor)
                filteredActors.add(a);
        } else if (type == Param.Type.SCENE_SPRITE_ACTOR) {
            if (a instanceof SpriteActor)
                filteredActors.add(a);
        } else {
            filteredActors.add(a);
        }
    }
    String[] result = new String[isMandatory() ? filteredActors.size() + 1 : filteredActors.size() + 2];
    // Add player variable to the list
    result[0] = Scene.VAR_PLAYER;
    if (!isMandatory())
        result[filteredActors.size() + 1] = "";
    for (int i = 0; i < filteredActors.size(); i++) {
        result[i + 1] = filteredActors.get(i).getId();
    }
    Arrays.sort(result);
    return result;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) ArrayList(java.util.ArrayList) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 25 with InteractiveActor

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

the class LookAtAction method run.

@Override
public boolean run(VerbRunner cb) {
    // EngineLogger.debug("LOOKAT ACTION");
    InteractiveActor a = (InteractiveActor) World.getInstance().getCurrentScene().getActor(actor, true);
    if (World.getInstance().getInventory().get(actor) == null) {
        CharacterActor player = World.getInstance().getCurrentScene().getPlayer();
        if (direction != null && player != null)
            player.lookat(direction.getDirection());
        else if (a != null && player != null) {
            Rectangle bbox = a.getBBox().getBoundingRectangle();
            player.lookat(new Vector2(bbox.x, bbox.y));
        }
    }
    if (text != null) {
        String actorId = World.getInstance().getCurrentScene().getPlayer() != null ? World.getInstance().getCurrentScene().getPlayer().getId() : null;
        World.getInstance().getTextManager().addText(text, TextManager.POS_SUBTITLE, TextManager.POS_SUBTITLE, false, Text.Type.SUBTITLE, null, null, actorId, voiceId, wait ? cb : null);
        return wait;
    }
    return false;
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Rectangle(com.badlogic.gdx.math.Rectangle) CharacterActor(com.bladecoder.engine.model.CharacterActor)

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