Search in sources :

Example 1 with Cursor

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

the class UtilAssignable method createServices.

/**
 * Create the services.
 *
 * @param clicked The click flag.
 * @param clickNumber The click number recorded.
 * @return The services.
 */
public static Services createServices(AtomicBoolean clicked, AtomicReference<Integer> clickNumber) {
    final Services services = new Services();
    final Camera camera = services.create(Camera.class);
    camera.setView(0, 0, 32, 32, 32);
    services.add(new ContextMock());
    final Cursor cursor = services.add(new Cursor(services) {

        @Override
        public boolean isPushedOnce(Integer click) {
            clickNumber.set(click);
            return clicked.get();
        }
    });
    cursor.setArea(0, 0, 64, 64);
    cursor.setLocation(0, 1);
    return services;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Camera(com.b3dgs.lionengine.game.feature.Camera) ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor)

Example 2 with Cursor

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

the class UtilActionnable method createServices.

/**
 * Create the services.
 *
 * @param clicked The click flag.
 * @param clickNumber The click number recorded.
 * @return The services.
 */
public static Services createServices(final AtomicBoolean clicked, final AtomicInteger clickNumber) {
    final Services services = new Services();
    final Cursor cursor = new Cursor() {

        @Override
        public boolean hasClickedOnce(int click) {
            clickNumber.set(click);
            return clicked.get();
        }
    };
    cursor.setArea(0, 0, 32, 32);
    cursor.setLocation(0, 1);
    services.add(cursor);
    return services;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Cursor(com.b3dgs.lionengine.game.Cursor)

Example 3 with Cursor

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

the class UtilAssignable method createServices.

/**
 * Create the services.
 *
 * @param clicked The click flag.
 * @param clickNumber The click number recorded.
 * @return The services.
 */
public static Services createServices(final AtomicBoolean clicked, final AtomicInteger clickNumber) {
    final Services services = new Services();
    final Camera camera = services.create(Camera.class);
    camera.setView(0, 0, 32, 32, 32);
    final Cursor cursor = services.add(new Cursor() {

        @Override
        public boolean hasClickedOnce(int click) {
            clickNumber.set(click);
            return clicked.get();
        }
    });
    cursor.setArea(0, 0, 64, 64);
    cursor.setLocation(0, 1);
    return services;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Camera(com.b3dgs.lionengine.game.feature.Camera) Cursor(com.b3dgs.lionengine.game.Cursor)

Example 4 with Cursor

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

the class CameraTest method testIsViewable.

/**
 * Test the camera viewable.
 */
@Test
void testIsViewable() {
    camera.setView(0, 0, 2, 2, 2);
    final Services services = new Services();
    services.add(new ContextMock());
    final Cursor cursor = new Cursor(services);
    cursor.setArea(-2, -2, 4, 4);
    cursor.setLocation(0, 0);
    cursor.update(1.0);
    assertTrue(camera.isViewable((Localizable) cursor, 0, 0));
    assertFalse(camera.isViewable((Localizable) cursor, 0, -1));
    assertFalse(camera.isViewable((Localizable) cursor, -1, 0));
    assertFalse(camera.isViewable((Localizable) cursor, -1, -1));
    assertTrue(camera.isViewable(cursor, 0, 0));
    assertFalse(camera.isViewable(cursor, 0, -2));
    assertFalse(camera.isViewable(cursor, -2, 0));
    assertFalse(camera.isViewable(cursor, -2, -2));
    cursor.setLocation(3, 3);
    cursor.update(1.0);
    assertFalse(camera.isViewable((Localizable) cursor, 0, 0));
    assertFalse(camera.isViewable((Localizable) cursor, 0, 1));
    assertFalse(camera.isViewable((Localizable) cursor, 1, 0));
    assertTrue(camera.isViewable((Localizable) cursor, 1, 1));
    assertFalse(camera.isViewable(cursor, -1, -1));
    assertFalse(camera.isViewable(cursor, 0, -2));
    assertFalse(camera.isViewable(cursor, -2, 0));
    assertTrue(camera.isViewable(cursor, 0, 0));
    assertTrue(camera.isViewable(cursor, 0, 0));
    assertTrue(camera.isViewable(cursor, 1, 3));
    cursor.setLocation(-2, -2);
    cursor.update(1.0);
    assertFalse(camera.isViewable(cursor, 0, 0));
    assertFalse(camera.isViewable(cursor, 0, -1));
    assertFalse(camera.isViewable(cursor, -1, 0));
    assertTrue(camera.isViewable(cursor, 1, 1));
    cursor.setLocation(0, -2);
    cursor.update(1.0);
    assertFalse(camera.isViewable(cursor, 0, 0));
    assertFalse(camera.isViewable(cursor, -1, 0));
    assertFalse(camera.isViewable(cursor, 0, -1));
    assertTrue(camera.isViewable(cursor, 1, 1));
    cursor.setLocation(-2, 0);
    cursor.update(1.0);
    assertFalse(camera.isViewable(cursor, 0, 0));
    assertFalse(camera.isViewable(cursor, 0, -1));
    assertFalse(camera.isViewable(cursor, -1, 0));
    assertTrue(camera.isViewable(cursor, 1, 1));
    cursor.setLocation(-2, 2);
    cursor.update(1.0);
    assertFalse(camera.isViewable(cursor, 0, 0));
    assertFalse(camera.isViewable(cursor, -1, 0));
    assertFalse(camera.isViewable(cursor, 0, -1));
    assertTrue(camera.isViewable(cursor, 1, 1));
    cursor.setLocation(2, -2);
    cursor.update(1.0);
    assertFalse(camera.isViewable(cursor, 0, 0));
    assertTrue(camera.isViewable(cursor, 1, 1));
}
Also used : ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor) Localizable(com.b3dgs.lionengine.Localizable) Test(org.junit.jupiter.api.Test)

Example 5 with Cursor

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

the class SelectorRefresherTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new ContextMock());
    services.add(new Camera());
    services.add(new ViewerMock());
    cursor = services.create(Cursor.class);
    cursor.setSync(mouse);
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new LayerableModel(services, setup));
    featurable.addFeature(new TransformableModel(services, setup));
    featurable.addFeature(new CollidableModel(services, setup));
    refresher = new SelectorRefresher(services, model);
    refresher.addListener(listener);
    refresher.prepare(featurable);
}
Also used : CollidableModel(com.b3dgs.lionengine.game.feature.collidable.CollidableModel) ViewerMock(com.b3dgs.lionengine.ViewerMock) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Camera(com.b3dgs.lionengine.game.feature.Camera) ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor) Featurable(com.b3dgs.lionengine.game.feature.Featurable) SelectorRefresher(com.b3dgs.lionengine.game.feature.collidable.selector.SelectorRefresher) LayerableModel(com.b3dgs.lionengine.game.feature.LayerableModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Cursor (com.b3dgs.lionengine.game.Cursor)7 ContextMock (com.b3dgs.lionengine.ContextMock)5 Services (com.b3dgs.lionengine.game.feature.Services)4 Camera (com.b3dgs.lionengine.game.feature.Camera)3 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Localizable (com.b3dgs.lionengine.Localizable)1 Factory (com.b3dgs.lionengine.game.feature.Factory)1 Featurable (com.b3dgs.lionengine.game.feature.Featurable)1 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)1 Handler (com.b3dgs.lionengine.game.feature.Handler)1 LayerableModel (com.b3dgs.lionengine.game.feature.LayerableModel)1 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)1 CollidableModel (com.b3dgs.lionengine.game.feature.collidable.CollidableModel)1 ComponentCollision (com.b3dgs.lionengine.game.feature.collidable.ComponentCollision)1 SelectorRefresher (com.b3dgs.lionengine.game.feature.collidable.selector.SelectorRefresher)1 Test (org.junit.jupiter.api.Test)1