Search in sources :

Example 26 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.

the class ComponentCollision method notifyHandlableAdded.

/*
     * HandlerListener
     */
@Override
public void notifyHandlableAdded(Featurable featurable) {
    if (featurable.hasFeature(Collidable.class)) {
        final Transformable transformable = featurable.getFeature(Transformable.class);
        transformable.addListener(this);
    }
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable)

Example 27 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.

the class MapTileFog method reset.

/**
 * Reset the revealed tiles to fogged.
 *
 * @param fovable The fovable reference.
 */
void reset(Fovable fovable) {
    final Transformable transformable = fovable.getFeature(Transformable.class);
    final int tx = (int) Math.floor(transformable.getOldX() / map.getTileWidth());
    final int ty = (int) Math.floor(transformable.getOldY() / map.getTileHeight());
    final int tw = map.getInTileHeight(transformable) / 2;
    final int th = map.getInTileHeight(transformable) / 2;
    final int ray = fovable.getInTileFov() - 1;
    final int sx = UtilMath.clamp(tx - ray - tw, 0, map.getInTileWidth() - 1);
    final int ex = UtilMath.clamp(tx + ray + tw, 0, map.getInTileWidth() - 1);
    final int sy = UtilMath.clamp(ty - ray - th, 0, map.getInTileHeight() - 1);
    final int ey = UtilMath.clamp(ty + ray + th, 0, map.getInTileHeight() - 1);
    for (int x = sx; x < ex + 1; x++) {
        for (int y = sy; y < ey + 1; y++) {
            if (map.getTile(x, y).getNumber() != FOG) {
                map.setTile(x, y, FOG);
                transition.resolve(map.getTile(x, y));
            }
        }
    }
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable)

Example 28 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.

the class LauncherModelTest method testLauncherInitial.

/**
 * Test the launcher with initial speed.
 *
 * @throws InterruptedException If error.
 */
@Test
void testLauncherInitial() throws InterruptedException {
    final AtomicBoolean fired = new AtomicBoolean();
    final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
    launcher.addListener(UtilLaunchable.createListener(fired));
    launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
    final Force force = new Force(1.0, 2.0);
    assertTimeout(1000L, () -> {
        while (!launcher.fire(force)) {
            launcher.update(1.0);
            continue;
        }
    });
    assertTrue(fired.get());
    assertNotNull(firedLaunchable.get());
    final Transformable transformable = firedLaunchable.get().getFeature(Transformable.class);
    assertEquals(2.0, transformable.getX());
    assertEquals(4.0, transformable.getY());
    final Handler handler = services.get(Handler.class);
    handler.update(1.0);
    assertEquals(1, handler.size());
    handler.removeAll();
    handler.update(1.0);
    assertEquals(0, handler.size());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Force(com.b3dgs.lionengine.game.Force) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Handler(com.b3dgs.lionengine.game.feature.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 29 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.

the class MapTileCollisionModelComplexTest method createObject.

/**
 * Create object test.
 *
 * @return The object test.
 */
private Transformable createObject() {
    final Setup setup = new Setup(config);
    CollisionCategoryConfig.exports(setup.getRoot(), category);
    final FeaturableModel object = new FeaturableModel(services, setup);
    final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.setSize(1, 1);
    final TileCollidable collidable = object.addFeatureAndGet(new TileCollidableModel(services, setup));
    collidable.setEnabled(true);
    return transformable;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup)

Example 30 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.

the class MapTileCollisionModelTest method createObject.

/**
 * Create object test.
 *
 * @return The object test.
 */
private Transformable createObject() {
    final Setup setup = new Setup(config);
    CollisionCategoryConfig.exports(setup.getRoot(), categoryY);
    CollisionCategoryConfig.exports(setup.getRoot(), categoryX);
    final FeaturableModel object = new FeaturableModel(services, setup);
    final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.setSize(1, 1);
    final TileCollidable collidable = object.addFeatureAndGet(new TileCollidableModel(services, setup));
    collidable.setEnabled(true);
    return transformable;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup)

Aggregations

Transformable (com.b3dgs.lionengine.game.feature.Transformable)30 Test (org.junit.jupiter.api.Test)17 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)16 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Setup (com.b3dgs.lionengine.game.feature.Setup)8 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)7 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)6 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)6 Featurable (com.b3dgs.lionengine.game.feature.Featurable)4 Media (com.b3dgs.lionengine.Media)3 Medias (com.b3dgs.lionengine.Medias)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 Handler (com.b3dgs.lionengine.game.feature.Handler)3 Services (com.b3dgs.lionengine.game.feature.Services)3 Animation (com.b3dgs.lionengine.Animation)2 Range (com.b3dgs.lionengine.Range)2 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)2 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)2 Force (com.b3dgs.lionengine.game.Force)2