use of com.b3dgs.lionengine.game.feature.MirrorableModel 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.MirrorableModel in project lionengine by b3dgs.
the class CollidableModelTest method testDifferentSizes.
/**
* Test collidable class with different sizes.
*/
@Test
void testDifferentSizes() {
featurable1.addFeature(new MirrorableModel(services, setup));
featurable2.addFeature(new MirrorableModel(services, setup));
final AtomicBoolean auto = new AtomicBoolean();
collidable1.checkListener((CollidableListener) (collidable, with, by) -> auto.set(true));
final Collision collision1 = new Collision("test1", 1, 1, 1, 1, true);
final Collision collision2 = new Collision("test2", 0, 0, 3, 3, false);
collidable1.notifyCollided(collidable2, collision1, collision2);
assertTrue(auto.get());
collidable1.addCollision(collision1);
collidable2.addCollision(collision2);
transformable1.moveLocation(1.0, 1, 1);
transformable2.moveLocation(1.0, 0, 0);
assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
transformable1.teleport(0.5, 3.5);
assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
}
use of com.b3dgs.lionengine.game.feature.MirrorableModel in project lionengine by b3dgs.
the class ComponentCollisionTest method prepare.
/**
* Prepare test.
*/
@BeforeEach
public void prepare() {
services.add(new Camera());
featurable1 = new ObjectSelf(services, setup);
transformable1 = featurable1.addFeatureAndGet(new TransformableModel(services, setup));
collidable1 = featurable1.addFeatureAndGet(new CollidableModel(services, setup));
collidable1.setGroup(Integer.valueOf(1));
collidable1.addAccept(Integer.valueOf(0));
final Collision collision1 = new Collision("test1", 0, 0, 3, 3, false);
collidable1.addCollision(collision1);
featurable2 = CollidableModelTest.createFeaturable(config, services);
transformable2 = featurable2.getFeature(Transformable.class);
collidable2 = featurable2.getFeature(Collidable.class);
collidable2.addAccept(Integer.valueOf(1));
collidable2.setGroup(Integer.valueOf(0));
featurable1.addFeature(new MirrorableModel(services, setup));
featurable2.addFeature(new MirrorableModel(services, setup));
final Collision collision2 = new Collision("test2", 0, 0, 3, 3, true);
collidable2.addCollision(collision2);
handler.addComponent(component);
handler.add(featurable1);
handler.add(featurable2);
handler.add(nonCollidable);
final CollidableListener listener = (collidable, with, by) -> collide.set(collidable);
collidable2.addListener(listener);
}
use of com.b3dgs.lionengine.game.feature.MirrorableModel in project lionengine by b3dgs.
the class SceneRasterable method add.
private void add(SetupSurfaceRastered setup, int offsetX) {
final SpriteAnimated surface = Drawable.loadSpriteAnimated(setup.getSurface(), 4, 4);
final Featurable featurable = new FeaturableModel(services, setup);
featurable.addFeature(new MirrorableModel(services, setup));
featurable.addFeature(new AnimatableModel(services, setup, surface));
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
final Rasterable rasterable = new RasterableModel(services, setup);
rasterable.setOrigin(Origin.MIDDLE);
rasterable.setFrameOffsets(1, 2);
featurable.addFeature(rasterable);
featurable.addFeature(new RefreshableModel(extrp -> {
transformable.setLocationY(UtilMath.sin(count) * 240);
surface.setLocation(camera, transformable);
rasterable.update(extrp);
surface.update(extrp);
}));
featurable.addFeature(new DisplayableModel(g -> rasterable.render(g)));
transformable.setLocationX(120 + offsetX);
handler.add(featurable);
}
use of com.b3dgs.lionengine.game.feature.MirrorableModel in project lionengine by b3dgs.
the class CollidableModelTest method testMirror.
/**
* Test collidable class with mirror.
*/
@Test
void testMirror() {
final Mirrorable mirror1 = featurable1.addFeatureAndGet(new MirrorableModel(services, setup));
mirror1.mirror(Mirror.HORIZONTAL);
mirror1.update(1.0);
final Mirrorable mirror2 = featurable2.addFeatureAndGet(new MirrorableModel(services, setup));
mirror2.mirror(Mirror.VERTICAL);
mirror2.update(1.0);
final Collision collision1 = new Collision("test1", 1, 1, 1, 1, true);
collidable1.addCollision(collision1);
final Collision collision2 = new Collision("test2", 0, 0, 3, 3, true);
collidable2.addCollision(collision2);
transformable1.teleport(0.0, 0.0);
transformable2.moveLocation(0.0, 0.0, 0.0);
assertTrue(collidable1.collide(collidable2).isEmpty());
assertTrue(collidable2.collide(collidable1).isEmpty());
transformable1.teleport(1.5, 2.5);
assertEquals(Arrays.asList(new CollisionCouple(collision1, collision2)), collidable1.collide(collidable2));
assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
}
Aggregations