Search in sources :

Example 1 with State

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

the class StateHandler method update.

/*
     * Updatable
     */
@Override
public void update(double extrp) {
    if (current != null) {
        for (final InputDevice input : inputs) {
            updateInput(StateInputDirectionalUpdater.class, InputDeviceDirectional.class, input);
            updateInput(StateInputPointerUpdater.class, InputDevicePointer.class, input);
        }
        current.update(extrp);
        final State old = current;
        for (final InputDevice input : inputs) {
            current = checkNext(InputDeviceDirectional.class, input);
            if (!old.equals(current)) {
                break;
            }
            current = checkNext(InputDevicePointer.class, input);
            if (!old.equals(current)) {
                break;
            }
        }
        if (!old.equals(current)) {
            old.exit();
        }
    }
}
Also used : InputDevice(com.b3dgs.lionengine.InputDevice) State(com.b3dgs.lionengine.game.State) InputDeviceDirectional(com.b3dgs.lionengine.io.InputDeviceDirectional) InputDevicePointer(com.b3dgs.lionengine.io.InputDevicePointer)

Example 2 with State

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

the class StateHandlerTest method testTransition.

/**
 * Test the state transitions.
 */
@Test
public void testTransition() {
    final State idle = new StateIdle();
    factory.addState(idle);
    factory.addState(new StateWalk());
    handler.addInput(new InputDirectionalMock());
    handler.addInput(new InputPointerMock());
    handler.changeState(StateType.IDLE);
    Assert.assertTrue(handler.isState(StateType.IDLE));
    handler.update(1.0);
    Assert.assertTrue(handler.isState(StateType.WALK));
    handler.update(1.0);
    Assert.assertTrue(handler.isState(StateType.IDLE));
    idle.clearTransitions();
    handler.update(1.0);
    Assert.assertTrue(handler.isState(StateType.IDLE));
}
Also used : State(com.b3dgs.lionengine.game.State) Test(org.junit.Test)

Example 3 with State

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

the class StateAnimationUtil method loadStates.

/**
 * Load all existing animations defined in the xml file.
 *
 * @param states The states values.
 * @param factory The factory reference.
 * @param provider The featurable reference.
 * @param setup The setup reference.
 */
public static void loadStates(StateAnimationBased[] states, StateFactory factory, FeatureProvider provider, Setup setup) {
    final AnimationConfig configAnimations = AnimationConfig.imports(setup);
    for (final StateAnimationBased type : states) {
        try {
            final Animation animation = configAnimations.getAnimation(type.getAnimationName());
            final State state = UtilReflection.create(type.getStateClass(), UtilReflection.getParamTypes(provider, animation), provider, animation);
            factory.addState(state);
        } catch (final NoSuchMethodException exception) {
            throw new LionEngineException(exception);
        }
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) State(com.b3dgs.lionengine.game.State) Animation(com.b3dgs.lionengine.Animation) AnimationConfig(com.b3dgs.lionengine.game.AnimationConfig)

Aggregations

State (com.b3dgs.lionengine.game.State)3 Animation (com.b3dgs.lionengine.Animation)1 InputDevice (com.b3dgs.lionengine.InputDevice)1 LionEngineException (com.b3dgs.lionengine.LionEngineException)1 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)1 InputDeviceDirectional (com.b3dgs.lionengine.io.InputDeviceDirectional)1 InputDevicePointer (com.b3dgs.lionengine.io.InputDevicePointer)1 Test (org.junit.Test)1