Search in sources :

Example 6 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class MapTileSurfaceModel method getTilesHit.

@Override
public Collection<Tile> getTilesHit(double ox, double oy, double x, double y) {
    final Force force = Force.fromVector(ox, oy, x, y);
    final double sx = force.getDirectionHorizontal();
    final double sy = force.getDirectionVertical();
    double h = ox;
    double v = oy;
    final Collection<Tile> found = new ArrayList<>();
    for (int count = 0; count < force.getVelocity(); count++) {
        v += sy;
        Tile tile = getTileAt(UtilMath.getRound(sx, h), UtilMath.getRound(sy, v));
        if (tile != null && !found.contains(tile)) {
            found.add(tile);
        }
        h += sx;
        tile = getTileAt(UtilMath.getRound(sx, h), UtilMath.getRound(sy, v));
        if (tile != null && !found.contains(tile)) {
            found.add(tile);
        }
    }
    return found;
}
Also used : Force(com.b3dgs.lionengine.game.Force) ArrayList(java.util.ArrayList) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 7 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class LaunchableConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final LaunchableConfig launchable = new LaunchableConfig("media", "sfx", 10, 1, 2, new Force(1.0, 2.0));
    final Xml root = new Xml("test");
    root.add(LaunchableConfig.exports(launchable));
    final Media media = Medias.create("launchable.xml");
    root.save(media);
    assertEquals(launchable, LaunchableConfig.imports(new Xml(media).getChild(LaunchableConfig.NODE_LAUNCHABLE)));
    assertTrue(media.getFile().delete());
}
Also used : Force(com.b3dgs.lionengine.game.Force) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Example 8 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class LauncherConfigTest method testData.

/**
 * Test data.
 */
@Test
void testData() {
    final LaunchableConfig launchable = new LaunchableConfig("media", "sfx", 10, 1, 2, new Force(1.0, 2.0));
    final LauncherConfig launcher = new LauncherConfig(1, 2, true, Arrays.asList(launchable));
    assertEquals("media", launchable.getMedia());
    assertEquals("sfx", launchable.getSfx().get());
    assertEquals(10, launchable.getDelay());
    assertEquals(1, launchable.getOffsetX());
    assertEquals(2, launchable.getOffsetY());
    assertEquals(new Force(1.0, 2.0), launchable.getVector());
    assertEquals(1, launcher.getLevel());
    assertEquals(2, launcher.getDelay());
    assertTrue(launcher.hasMirrorable());
}
Also used : Force(com.b3dgs.lionengine.game.Force) Test(org.junit.jupiter.api.Test)

Example 9 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class LauncherConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final LaunchableConfig launchable = new LaunchableConfig("media", "sfx", 10, 1, 2, new Force(1.0, 2.0));
    final LauncherConfig launcher = new LauncherConfig(10, 10, true, Arrays.asList(launchable));
    final Xml root = new Xml("test");
    root.add(LauncherConfig.exports(launcher));
    final Media media = Medias.create("launcher.xml");
    root.save(media);
    assertEquals(launcher, LauncherConfig.imports(new Xml(media).getChild(LauncherConfig.NODE_LAUNCHER)));
    assertEquals(Arrays.asList(launcher), LauncherConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : Force(com.b3dgs.lionengine.game.Force) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 10 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class UtilLaunchable method createLauncherMedia.

/**
 * Create the media.
 *
 * @param launchableMedia The launchable.
 * @param delay The desired delay.
 * @return The media.
 */
public static Media createLauncherMedia(Media launchableMedia, int delay) {
    final Media media = Medias.create("launcher.xml");
    final LaunchableConfig launchableConfig = new LaunchableConfig(launchableMedia.getPath(), null, delay, 1, 2, new Force(1.0, 2.0));
    final LauncherConfig launcherConfig = new LauncherConfig(0, 10, false, Arrays.asList(launchableConfig));
    final Xml root = new Xml("test");
    root.add(LauncherConfig.exports(launcherConfig));
    root.add(LauncherConfig.exports(new LauncherConfig(1, 50, false, Arrays.asList(launchableConfig))));
    root.save(media);
    return media;
}
Also used : Force(com.b3dgs.lionengine.game.Force) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media)

Aggregations

Force (com.b3dgs.lionengine.game.Force)23 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)4 Media (com.b3dgs.lionengine.Media)3 Xml (com.b3dgs.lionengine.Xml)3 Test (org.junit.Test)3 Transformable (com.b3dgs.lionengine.game.feature.Transformable)2 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)2 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)2 Configurer (com.b3dgs.lionengine.game.Configurer)1 Handler (com.b3dgs.lionengine.game.feature.Handler)1 IdentifiableModel (com.b3dgs.lionengine.game.feature.IdentifiableModel)1 Mirrorable (com.b3dgs.lionengine.game.feature.Mirrorable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1