use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class RasterableModelTest method testModel.
/**
* Test the model.
*/
@Test
void testModel() {
services.add(new ViewerMock());
final SetupSurfaceRastered setup = new SetupSurfaceRastered(Medias.create(OBJECT_XML));
final Featurable featurable = new FeaturableModel(services, setup);
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
final Animatable animatable = featurable.addFeatureAndGet(new AnimatableModel(services, setup));
featurable.addFeature(new MirrorableModel(services, setup));
final Rasterable rasterable = new RasterableModel(services, setup);
rasterable.setFrameOffsets(1, 2);
rasterable.prepare(featurable);
rasterable.setOrigin(Origin.TOP_LEFT);
rasterable.update(1.0);
rasterable.setEnabled(false);
rasterable.update(1.0);
rasterable.render(g);
assertTrue(rasterable.isVisible());
rasterable.setVisibility(false);
rasterable.update(1.0);
rasterable.render(g);
assertFalse(rasterable.isVisible());
assertEquals(1, rasterable.getRasterIndex(0));
assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
assertNotNull(rasterable.getRasterAnim(0));
transformable.teleportY(-100);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterIndex(0));
assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
assertNotNull(rasterable.getRasterAnim(0));
animatable.play(new Animation("default", 1, 5, 1.0, false, false));
animatable.update(1.0);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterAnim(0).getFrame());
rasterable.setAnimOffset(1);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterAnim(0).getFrame());
}
use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class StateHandlerTest method testWithConfig.
/**
* Test state with configuration.
*/
@Test
void testWithConfig() {
Medias.setLoadFromJar(StateHandlerTest.class);
try {
final Setup setup = new Setup(Medias.create("Object.xml"));
final Featurable featurable = new FeaturableModel(services, setup);
final StateHandler handler;
handler = featurable.addFeatureAndGet(new StateHandler(services, setup));
handler.prepare(featurable);
handler.changeState(StateIdle.class);
handler.postUpdate();
assertEquals(new Animation(StateIdle.class.getSimpleName(), 1, 1, 0.125, false, false), StateIdle.animation);
assertNull(StateWalk.animation);
assertTrue(handler.isState(StateIdle.class));
handler.update(1.0);
assertNull(StateWalk.animation);
handler.postUpdate();
assertEquals(new Animation(StateWalk.class.getSimpleName(), 2, 2, 0.125, false, false), StateWalk.animation);
assertTrue(handler.isState(StateWalk.class));
handler.update(1.0);
handler.postUpdate();
assertTrue(handler.isState(StateIdle.class));
} finally {
Medias.setLoadFromJar(null);
}
}
use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class UtilAssignable method createAssignable.
/**
* Create the assignable.
*
* @param services The services.
* @param setup The setup.
* @return The prepared assignable.
*/
public static AssignableModel createAssignable(Services services, Setup setup) {
final Featurable featurable = new FeaturableModel(services, setup);
final AssignableModel assignable = new AssignableModel(services, setup);
assignable.prepare(featurable);
return assignable;
}
use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class UtilActionnable method createActionable.
/**
* Create the actionable.
*
* @param media The media.
* @param services The services.
* @return The prepared actionable.
*/
public static ActionableModel createActionable(Media media, Services services) {
final Setup setup = new Setup(media);
final Featurable featurable = new FeaturableModel(services, setup);
final ActionableModel actionable = new ActionableModel(services, setup);
actionable.prepare(featurable);
return actionable;
}
use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class ProducerModelTest method testProductionListenerSelf.
/**
* Test the production with self listener.
*/
@Test
void testProductionListenerSelf() {
final ProducerObjectSelf object = new ProducerObjectSelf(services, setup);
final ProducerModel producer = new ProducerModel(services, setup);
producer.prepare(object);
producer.recycle();
producer.setStepsSpeed(1.0);
producer.addListener(object);
final Featurable featurable = UtilProducible.createProducible(services);
producer.addToProductionQueue(featurable);
assertEquals(0, object.flag.get());
producer.update(1.0);
assertEquals(1, object.flag.get());
producer.update(1.0);
assertEquals(2, object.flag.get());
producer.update(1.0);
assertEquals(3, object.flag.get());
producer.update(1.0);
object.flag.set(0);
producer.removeListener(object);
producer.update(1.0);
producer.update(1.0);
assertEquals(0, object.flag.get());
}
Aggregations