Search in sources :

Example 1 with World

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

the class DefaultSceneScreen method render.

@Override
public void render(float delta) {
    final World world = World.getInstance();
    update(delta);
    if (world.getAssetState() != AssetState.LOADED) {
        return;
    }
    SpriteBatch batch = ui.getBatch();
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    // WORLD CAMERA
    world.draw();
    // DRAW DEBUG BBOXES
    if (EngineLogger.debugMode() && EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) {
        renderer.setProjectionMatrix(world.getSceneCamera().combined);
        world.getCurrentScene().drawBBoxLines(renderer);
        renderer.end();
    }
    // STAGE
    stage.draw();
    // SCREEN CAMERA
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    if (!world.inCutMode() && !recorder.isPlaying() && !testerBot.isEnabled()) {
        pointer.draw(batch, viewport);
    }
    Transition t = world.getTransition();
    t.draw(batch, viewport.getScreenWidth(), viewport.getScreenHeight());
    recorder.draw(batch);
    testerBot.draw(batch);
    if (drawHotspots)
        drawHotspots(batch);
    // DRAW DEBUG STRING
    if (EngineLogger.debugMode()) {
        drawDebugText(batch);
    }
    batch.end();
}
Also used : Transition(com.bladecoder.engine.model.Transition) World(com.bladecoder.engine.model.World) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 2 with World

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

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

the class DefaultSceneScreen method sceneClick.

private void sceneClick(int button, int count) {
    World w = World.getInstance();
    w.getSceneCamera().getInputUnProject(viewport, unprojectTmp);
    Scene s = w.getCurrentScene();
    CharacterActor player = s.getPlayer();
    if (currentActor != null) {
        if (EngineLogger.debugMode()) {
            EngineLogger.debug(currentActor.toString());
        }
        // DOUBLE CLICK: Fastwalk when leaving scene.
        if (count > 1) {
            if (count == 2 && fastLeave && !recorder.isRecording() && player != null && currentActor.getVerb(Verb.LEAVE_VERB) != null) {
                player.fastWalk();
            }
            return;
        }
        actorClick(currentActor, button);
    } else if (player != null) {
        if (count > 1)
            return;
        if (s.getPlayer().getVerb("goto") != null) {
            runVerb(s.getPlayer(), "goto", null);
        } else {
            Vector2 pos = new Vector2(unprojectTmp.x, unprojectTmp.y);
            if (recorder.isRecording()) {
                recorder.add(pos);
            }
            player.goTo(pos, null, false);
        }
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) World(com.bladecoder.engine.model.World) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 4 with World

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

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

the class RetroSceneScreen method render.

@Override
public void render(float delta) {
    final World world = World.getInstance();
    update(delta);
    if (world.getAssetState() != AssetState.LOADED)
        return;
    SpriteBatch batch = ui.getBatch();
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    // WORLD CAMERA
    if (world.getInventory().isVisible()) {
        worldViewport.setScreenY(screenViewport.getScreenY() + (int) verbUI.getHeight());
        worldViewport.setScreenHeight(screenViewport.getScreenHeight() - (int) verbUI.getHeight());
        world.resize(world.getWidth(), world.getHeight() * (1 - UI_SCREEN_PERCENT));
    } else {
        worldViewport.setScreenY(screenViewport.getScreenY());
        worldViewport.setScreenHeight(screenViewport.getScreenHeight());
        world.resize(world.getWidth(), world.getHeight());
    }
    worldViewport.apply(true);
    world.draw();
    // DRAW DEBUG BBOXES
    if (EngineLogger.debugMode() && EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) {
        renderer.setProjectionMatrix(world.getSceneCamera().combined);
        world.getCurrentScene().drawBBoxLines(renderer);
        renderer.end();
    }
    // SCREEN CAMERA
    batch.setProjectionMatrix(worldViewport.getCamera().combined);
    batch.begin();
    // DRAW DEBUG STRING
    if (EngineLogger.debugMode()) {
        drawDebugText(batch);
    }
    Transition t = world.getTransition();
    t.draw(batch, worldViewport.getScreenWidth(), worldViewport.getScreenHeight());
    recorder.draw(batch);
    testerBot.draw(batch);
    if (drawHotspots)
        drawHotspots(batch);
    batch.end();
    worldViewportStage.draw();
    // STAGE CAMERA
    screenViewport.apply(true);
    stage.draw();
}
Also used : Transition(com.bladecoder.engine.model.Transition) World(com.bladecoder.engine.model.World) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Aggregations

World (com.bladecoder.engine.model.World)20 BaseActor (com.bladecoder.engine.model.BaseActor)7 Rectangle (com.badlogic.gdx.math.Rectangle)6 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)6 Scene (com.bladecoder.engine.model.Scene)5 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)3 CharacterActor (com.bladecoder.engine.model.CharacterActor)3 SpriteActor (com.bladecoder.engine.model.SpriteActor)3 Color (com.badlogic.gdx.graphics.Color)2 Texture (com.badlogic.gdx.graphics.Texture)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Polygon (com.badlogic.gdx.math.Polygon)2 Vector2 (com.badlogic.gdx.math.Vector2)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Stage (com.badlogic.gdx.scenes.scene2d.Stage)2 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)2