use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class AttackerModelTest method testListener.
/**
* Test the attack.
*
* @throws InterruptedException If error.
*/
@Test
void testListener() throws InterruptedException {
canAttack.set(true);
attacker.setAttackChecker(t -> canAttack.get());
final AtomicBoolean preparing = new AtomicBoolean();
final AtomicReference<Transformable> reaching = new AtomicReference<>();
final AtomicReference<Transformable> started = new AtomicReference<>();
final AtomicBoolean anim = new AtomicBoolean();
final AtomicReference<Transformable> ended = new AtomicReference<>();
final AtomicBoolean stopped = new AtomicBoolean();
final AttackerListener listener;
listener = UtilAttackable.createListener(preparing, reaching, started, ended, anim, stopped);
attacker.addListener(listener);
attacker.recycle();
attacker.update(1.0);
attacker.getFeature(Transformable.class).teleport(0, 0);
attacker.setAttackDelay(5);
attacker.setAttackFrame(1);
attacker.setAttackDistance(new Range(0, 2));
target.setSize(1, 1);
target.teleport(5, 5);
attacker.attack(target);
attacker.update(1.0);
attacker.update(1.0);
// 2 ticks for attack interval
attacker.update(1.0);
attacker.getFeature(Animatable.class).play(new Animation("test", 1, 1, 1.0, false, false));
assertEquals(target, reaching.get());
assertFalse(preparing.get());
assertFalse(attacker.isAttacking());
target.teleport(0, 1);
attacker.update(1.0);
assertNotEquals(target, started.get());
assertNotEquals(target, ended.get());
attacker.update(1.0);
assertTrue(attacker.isAttacking());
attacker.update(1.0);
attacker.getFeature(Animatable.class).update(1.0);
attacker.update(1.0);
assertFalse(preparing.get());
attacker.update(1.0);
attacker.update(1.0);
attacker.update(1.0);
assertTrue(preparing.get());
assertTimeout(1000L, () -> {
while (!target.equals(started.get())) {
attacker.update(1.0);
}
});
assertEquals(target, started.get());
assertEquals(target, ended.get());
attacker.update(1.0);
assertTrue(attacker.isAttacking());
object.getFeature(Animatable.class).update(1.0);
attacker.update(1.0);
assertTrue(anim.get());
assertFalse(stopped.get());
attacker.stopAttack();
assertFalse(stopped.get());
attacker.update(1.0);
assertTrue(stopped.get());
attacker.removeListener(listener);
preparing.set(false);
reaching.set(null);
started.set(null);
ended.set(null);
anim.set(false);
attacker.attack(target);
attacker.update(1.0);
attacker.update(1.0);
assertFalse(preparing.get());
assertNull(reaching.get());
assertNull(started.get());
assertNull(ended.get());
assertFalse(anim.get());
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class StateAnimationBasedTest method setUp.
/**
* Prepare test.
*/
@BeforeClass
public static void setUp() {
Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
media = Medias.create("animations.xml");
final Xml root = new Xml("test");
final Animation idle = new Animation("idle", 1, 2, 3.0, false, true);
AnimationConfig.exports(root, idle);
final Animation walk = new Animation("walk", 1, 2, 3.0, false, true);
AnimationConfig.exports(root, walk);
final Animation jump = new Animation("jump", 1, 2, 3.0, false, true);
AnimationConfig.exports(root, jump);
root.save(media);
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class UtilAttackable method prepare.
/**
* Create the featurable.
*
* @param featurable The featurable to prepare.
*/
public static void prepare(Featurable featurable) {
final Animator animator = new AnimatorMock();
animator.play(new Animation("test", 1, 1, 1.0, false, false));
featurable.addFeature(new AnimatableModel(animator));
featurable.addFeature(new TransformableModel());
}
use of com.b3dgs.lionengine.Animation 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);
}
}
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class AnimatorTest method testUpdateLoopReverse.
/**
* Test update with loop and reverse.
*/
@Test
public void testUpdateLoopReverse() {
final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, true, true);
final Animator animator = new AnimatorImpl();
animator.play(animation);
Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
Assert.assertEquals(1, animator.getFrame());
Assert.assertEquals(1, animator.getFrameAnim());
animator.update(1.0);
Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
Assert.assertEquals(2, animator.getFrame());
Assert.assertEquals(2, animator.getFrameAnim());
animator.update(1.0);
Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
Assert.assertEquals(3, animator.getFrame());
Assert.assertEquals(3, animator.getFrameAnim());
animator.update(1.0);
Assert.assertEquals(AnimState.REVERSING, animator.getAnimState());
Assert.assertEquals(2, animator.getFrame());
Assert.assertEquals(2, animator.getFrameAnim());
animator.update(1.0);
Assert.assertEquals(AnimState.REVERSING, animator.getAnimState());
Assert.assertEquals(1, animator.getFrame());
Assert.assertEquals(1, animator.getFrameAnim());
animator.update(1.0);
Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
Assert.assertEquals(2, animator.getFrame());
Assert.assertEquals(2, animator.getFrameAnim());
animator.update(1.0);
Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
Assert.assertEquals(3, animator.getFrame());
Assert.assertEquals(3, animator.getFrameAnim());
animator.update(1.0);
Assert.assertEquals(AnimState.REVERSING, animator.getAnimState());
Assert.assertEquals(2, animator.getFrame());
Assert.assertEquals(2, animator.getFrameAnim());
}
Aggregations