Search in sources :

Example 36 with BaseActor

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

the class Project method setSelectedActor.

public void setSelectedActor(BaseActor a) {
    BaseActor old = null;
    old = selectedActor;
    selectedActor = a;
    selectedFA = null;
    firePropertyChange(NOTIFY_ACTOR_SELECTED, old, selectedActor);
}
Also used : BaseActor(com.bladecoder.engine.model.BaseActor)

Example 37 with BaseActor

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

the class PolygonalNavGraph method createInitialGraph.

public void createInitialGraph(Collection<BaseActor> actors) {
    graphNodes.clear();
    // 1.- Add WalkZone convex nodes
    float[] verts = walkZone.getTransformedVertices();
    for (int i = 0; i < verts.length; i += 2) {
        if (!PolygonUtils.isVertexConcave(walkZone, i)) {
            graphNodes.add(new NavNodePolygonal(verts[i], verts[i + 1]));
        }
    }
    // 2.- Add obstacles concave nodes
    obstacles.clear();
    for (BaseActor a : actors) {
        if (a instanceof ObstacleActor && a.isVisible())
            obstacles.add(a.getBBox());
    }
    for (Polygon o : obstacles) {
        verts = o.getTransformedVertices();
        for (int i = 0; i < verts.length; i += 2) {
            if (PolygonUtils.isVertexConcave(o, i) && PolygonUtils.isPointInside(walkZone, verts[i], verts[i + 1], false)) {
                graphNodes.add(new NavNodePolygonal(verts[i], verts[i + 1]));
            }
        }
    }
    // 3.- CALC LINE OF SIGHTs
    for (int i = 0; i < graphNodes.size() - 1; i++) {
        NavNodePolygonal n1 = graphNodes.get(i);
        for (int j = i + 1; j < graphNodes.size(); j++) {
            NavNodePolygonal n2 = graphNodes.get(j);
            if (inLineOfSight(n1.x, n1.y, n2.x, n2.y)) {
                n1.neighbors.add(n2);
                n2.neighbors.add(n1);
            }
        }
    }
}
Also used : ObstacleActor(com.bladecoder.engine.model.ObstacleActor) BaseActor(com.bladecoder.engine.model.BaseActor) Polygon(com.badlogic.gdx.math.Polygon)

Example 38 with BaseActor

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

the class DefaultSceneScreen method drawHotspots.

private void drawHotspots(SpriteBatch batch) {
    final World world = World.getInstance();
    for (BaseActor a : world.getCurrentScene().getActors().values()) {
        if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer())
            continue;
        InteractiveActor ia = (InteractiveActor) a;
        if (!ia.canInteract())
            continue;
        Polygon p = a.getBBox();
        if (p == null) {
            EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId());
        }
        Rectangle r = a.getBBox().getBoundingRectangle();
        unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0);
        world.getSceneCamera().scene2screen(viewport, unprojectTmp);
        if (!showDesc || ia.getDesc() == null) {
            float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier();
            if (ia.getVerb("leave") != null) {
                TransformDrawable drawable = (TransformDrawable) getUI().getSkin().getDrawable("leave");
                drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size / 2, size / 2, size, size, 1.0f, 1.0f, calcLeaveArrowRotation(ia));
            } else {
                Drawable drawable = getUI().getSkin().getDrawable("hotspot");
                if (drawable != null)
                    drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size);
            }
        } else {
            BitmapFont font = getUI().getSkin().getFont("desc");
            String desc = ia.getDesc();
            if (desc.charAt(0) == I18N.PREFIX)
                desc = I18N.getString(desc.substring(1));
            textLayout.setText(font, desc);
            float textX = unprojectTmp.x - textLayout.width / 2;
            float textY = unprojectTmp.y + textLayout.height;
            RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK);
            font.draw(batch, textLayout, textX, textY);
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) Rectangle(com.badlogic.gdx.math.Rectangle) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Polygon(com.badlogic.gdx.math.Polygon) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 39 with BaseActor

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

the class RetroSceneScreen method drawDebugText.

private void drawDebugText(SpriteBatch batch) {
    World w = World.getInstance();
    w.getSceneCamera().getInputUnProject(worldViewport, 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(" UI STATE: ");
        sbTmp.append(state.toString());
        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, worldViewport.getScreenWidth(), Align.left, true);
    RectangleRenderer.draw(batch, 0, worldViewport.getScreenHeight() - textLayout.height - 10, textLayout.width, textLayout.height + 10, Color.BLACK);
    ui.getSkin().getFont("debug").draw(batch, textLayout, 0, worldViewport.getScreenHeight() - 5);
    // Draw actor states when debug
    if (EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) {
        for (BaseActor a : w.getCurrentScene().getActors().values()) {
            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(worldViewport, unprojectTmp);
            if (w.getInventory().isVisible()) {
            // unprojectTmp.y += verbUI.getHeight();
            }
            ui.getSkin().getFont("debug").draw(batch, sbTmp.toString(), unprojectTmp.x, unprojectTmp.y);
        }
    }
}
Also used : 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 40 with BaseActor

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

the class RetroSceneScreen method drawHotspots.

private void drawHotspots(SpriteBatch batch) {
    final World world = World.getInstance();
    for (BaseActor a : world.getCurrentScene().getActors().values()) {
        if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer())
            continue;
        InteractiveActor ia = (InteractiveActor) a;
        if (!ia.canInteract())
            continue;
        Polygon p = a.getBBox();
        if (p == null) {
            EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId());
        }
        Rectangle r = a.getBBox().getBoundingRectangle();
        unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0);
        world.getSceneCamera().scene2screen(worldViewport, unprojectTmp);
        if (world.getInventory().isVisible()) {
        // unprojectTmp.y += verbUI.getHeight();
        }
        if (ia.getDesc() == null) {
            float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier();
            Drawable drawable = ((TextureRegionDrawable) getUI().getSkin().getDrawable("circle")).tint(Color.RED);
            drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size);
        } else {
            BitmapFont font = getUI().getSkin().getFont("desc");
            String desc = ia.getDesc();
            if (desc.charAt(0) == I18N.PREFIX)
                desc = I18N.getString(desc.substring(1));
            textLayout.setText(font, desc);
            float textX = unprojectTmp.x - textLayout.width / 2;
            float textY = unprojectTmp.y + textLayout.height;
            RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK);
            font.draw(batch, textLayout, textX, textY);
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Rectangle(com.badlogic.gdx.math.Rectangle) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Polygon(com.badlogic.gdx.math.Polygon) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

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