use of com.bladecoder.engine.model.InteractiveActor 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);
}
}
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class VerbUI method createInventoryPanel.
private Table createInventoryPanel() {
Table inventory = new Table();
inventory.defaults().pad(MARGIN);
for (int i = 0; i < INVENTORY_COLS * INVENTORY_ROWS; i++) {
if (i % INVENTORY_COLS == 0)
inventory.row();
ImageButton.ImageButtonStyle s = new ImageButton.ImageButtonStyle(style.inventoryButtonStyle);
RendererDrawable r = new RendererDrawable();
s.imageUp = r;
ImageButton b = new ImageButton(s);
inventory.add(b).fill().expand();
b.setUserObject(i);
inventorySlots.add(b);
b.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
int i = (Integer) event.getListenerActor().getUserObject();
Inventory inv = World.getInstance().getInventory();
target = null;
if (i < inv.getNumItems()) {
InteractiveActor actor = inv.get(i);
if (currentVerb.equals("use") || currentVerb.equals("give")) {
target = actor;
} else {
sceneScreen.runVerb(actor, currentVerb, null);
}
}
}
});
b.getImageCell().pad(MARGIN).expand().fill();
}
return inventory;
}
use of com.bladecoder.engine.model.InteractiveActor 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);
}
}
}
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class ActionCallbackSerialization method find.
private static String find(ActionCallback cb, UIActors uia) {
if (uia == null)
return null;
for (InteractiveActor a : uia.getActors()) {
String id = find(cb, a);
if (id != null) {
StringBuilder stringBuilder = new StringBuilder(UIACTORS_TAG);
stringBuilder.append(SEPARATION_SYMBOL).append(id);
return stringBuilder.toString();
}
}
return null;
}
use of com.bladecoder.engine.model.InteractiveActor in project bladecoder-adventure-engine by bladecoder.
the class ActionCallbackSerialization method find.
/**
* Generates a String for serialization that allows locate the
* ActionCallback
*
* @param cb
* The ActionCallback to serialize
* @return The generated location string
*/
public static String find(ActionCallback cb) {
String id = null;
if (cb == null)
return null;
// search in UIActors
id = find(cb, World.getInstance().getUIActors());
if (id != null)
return id;
// search in inventory
id = find(cb, World.getInstance().getInventory());
if (id != null)
return id;
// search in inkManager actions
id = find(cb, World.getInstance().getInkManager());
if (id != null)
return id;
// search in scene verbs
Scene s = World.getInstance().getCurrentScene();
id = find(cb, s);
if (id != null)
return id;
// search in player
id = find(cb, s.getPlayer());
if (id != null)
return id;
// search in actors
for (BaseActor a : s.getActors().values()) {
if (!(a instanceof InteractiveActor))
continue;
id = find(cb, (InteractiveActor) a);
if (id != null)
return id;
}
// search in worldVerbs
for (Verb v : World.getInstance().getVerbManager().getVerbs().values()) {
id = find(cb, v);
if (id != null) {
StringBuilder stringBuilder = new StringBuilder(DEFAULT_VERB_TAG);
stringBuilder.append(SEPARATION_SYMBOL).append(id);
return stringBuilder.toString();
}
}
return null;
}
Aggregations