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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations