Search in sources :

Example 1 with MirrorableModel

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());
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Animatable(com.b3dgs.lionengine.game.feature.Animatable) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Animation(com.b3dgs.lionengine.Animation) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 2 with MirrorableModel

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));
}
Also used : Medias(com.b3dgs.lionengine.Medias) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Mirrorable(com.b3dgs.lionengine.game.feature.Mirrorable) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) AfterAll(org.junit.jupiter.api.AfterAll) Graphics(com.b3dgs.lionengine.graphic.Graphics) Services(com.b3dgs.lionengine.game.feature.Services) UtilAssert.assertNotNull(com.b3dgs.lionengine.UtilAssert.assertNotNull) BeforeAll(org.junit.jupiter.api.BeforeAll) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) UtilAssert.assertPrivateConstructor(com.b3dgs.lionengine.UtilAssert.assertPrivateConstructor) Graphic(com.b3dgs.lionengine.graphic.Graphic) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Test(org.junit.jupiter.api.Test) Mirror(com.b3dgs.lionengine.Mirror) AfterEach(org.junit.jupiter.api.AfterEach) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Origin(com.b3dgs.lionengine.Origin) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Camera(com.b3dgs.lionengine.game.feature.Camera) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Test(org.junit.jupiter.api.Test)

Example 3 with MirrorableModel

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);
}
Also used : Medias(com.b3dgs.lionengine.Medias) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) BeforeEach(org.junit.jupiter.api.BeforeEach) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) UtilAssert.assertNull(com.b3dgs.lionengine.UtilAssert.assertNull) Graphics(com.b3dgs.lionengine.graphic.Graphics) Services(com.b3dgs.lionengine.game.feature.Services) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) Geom(com.b3dgs.lionengine.geom.Geom) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Camera(com.b3dgs.lionengine.game.feature.Camera) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Camera(com.b3dgs.lionengine.game.feature.Camera) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with MirrorableModel

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);
}
Also used : Medias(com.b3dgs.lionengine.Medias) ComponentRefreshable(com.b3dgs.lionengine.game.feature.ComponentRefreshable) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) ComponentDisplayable(com.b3dgs.lionengine.game.feature.ComponentDisplayable) Drawable(com.b3dgs.lionengine.graphic.drawable.Drawable) Resolution(com.b3dgs.lionengine.Resolution) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) Services(com.b3dgs.lionengine.game.feature.Services) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) SetupSurfaceRastered(com.b3dgs.lionengine.game.feature.rasterable.SetupSurfaceRastered) Handler(com.b3dgs.lionengine.game.feature.Handler) UtilMath(com.b3dgs.lionengine.UtilMath) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Graphic(com.b3dgs.lionengine.graphic.Graphic) Sequence(com.b3dgs.lionengine.graphic.engine.Sequence) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Engine(com.b3dgs.lionengine.Engine) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Context(com.b3dgs.lionengine.Context) Tick(com.b3dgs.lionengine.Tick) Origin(com.b3dgs.lionengine.Origin) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Camera(com.b3dgs.lionengine.game.feature.Camera) SpriteAnimated(com.b3dgs.lionengine.graphic.drawable.SpriteAnimated) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) SpriteAnimated(com.b3dgs.lionengine.graphic.drawable.SpriteAnimated) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 5 with MirrorableModel

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));
}
Also used : MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Mirrorable(com.b3dgs.lionengine.game.feature.Mirrorable) Test(org.junit.jupiter.api.Test)

Aggregations

MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)5 Featurable (com.b3dgs.lionengine.game.feature.Featurable)4 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)4 Transformable (com.b3dgs.lionengine.game.feature.Transformable)4 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)4 Test (org.junit.jupiter.api.Test)4 Medias (com.b3dgs.lionengine.Medias)3 Camera (com.b3dgs.lionengine.game.feature.Camera)3 Services (com.b3dgs.lionengine.game.feature.Services)3 Media (com.b3dgs.lionengine.Media)2 Origin (com.b3dgs.lionengine.Origin)2 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)2 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)2 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)2 Handler (com.b3dgs.lionengine.game.feature.Handler)2 Setup (com.b3dgs.lionengine.game.feature.Setup)2 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)2 FactoryGraphicMock (com.b3dgs.lionengine.graphic.FactoryGraphicMock)2 Graphic (com.b3dgs.lionengine.graphic.Graphic)2 Graphics (com.b3dgs.lionengine.graphic.Graphics)2