Compare commits

...

1 Commits

Author SHA1 Message Date
Davy Hélard
f6eafb32a0 [Platformer] Add a test about landing on jumpthru while overlapping another one. 2022-02-18 18:23:47 +01:00

View File

@@ -1328,12 +1328,11 @@ describe('gdjs.PlatformerObjectRuntimeBehavior', function () {
}); });
it('can fall through the jumpthru from the left side', function () { it('can fall through the jumpthru from the left side', function () {
jumpthru.setPosition(0, -33);
object.setPosition(0, -100); object.setPosition(0, -100);
jumpthru.setPosition(12, -90); jumpthru.setPosition(12, -90);
jumpthru.setCustomWidthAndHeight(60, 100); jumpthru.setCustomWidthAndHeight(60, 100);
// Check the jumpthru let the platformer object go through. // The jumpthru lets the character go through.
for (let i = 0; i < 10; ++i) { for (let i = 0; i < 10; ++i) {
object.getBehavior('auto1').simulateRightKey(); object.getBehavior('auto1').simulateRightKey();
runtimeScene.renderAndStep(1000 / 60); runtimeScene.renderAndStep(1000 / 60);
@@ -1343,9 +1342,50 @@ describe('gdjs.PlatformerObjectRuntimeBehavior', function () {
); );
expect(object.getBehavior('auto1').isMoving()).to.be(true); expect(object.getBehavior('auto1').isMoving()).to.be(true);
} }
// Overlapping the jumpthru // The character is overlapping the jumpthru.
expect(object.getX()).to.above(5); expect(object.getX()).to.above(jumpthru.getX() - object.getWidth() + 3);
expect(object.getY()).to.be.within(-100, -80); expect(object.getY()).to.be.within(
jumpthru.getY() - object.getHeight() + 10,
jumpthru.getY() + jumpthru.getHeight() - 10
);
});
it('can fall through a jumpthru from the left side and land on another jumpthru', function () {
object.setPosition(0, -100);
jumpthru.setPosition(1, -90);
jumpthru.setCustomWidthAndHeight(60, 20);
// Add another jumpthu under with a 10 pixels interleave (less than object height).
bottomJumpthru = addJumpThroughPlatformObject(runtimeScene);
bottomJumpthru.setPosition(1, -70);
bottomJumpthru.setCustomWidthAndHeight(60, 20);
// The jumpthru lets the character go through.
for (let i = 0; i < 7; ++i) {
object.getBehavior('auto1').simulateRightKey();
runtimeScene.renderAndStep(1000 / 60);
expect(object.getBehavior('auto1').isFalling()).to.be(true);
expect(object.getBehavior('auto1').isFallingWithoutJumping()).to.be(
true
);
expect(object.getBehavior('auto1').isMoving()).to.be(true);
}
// The character is overlapping the jumpthru.
expect(object.getX()).to.above(jumpthru.getX() - object.getWidth() + 3);
expect(object.getY()).to.be.within(
jumpthru.getY() - object.getHeight() + 1,
jumpthru.getY() + jumpthru.getHeight() - 1
);
// The character lands on the other jumpthru
// while still overlapping the other one.
for (let i = 0; i < 5; ++i) {
runtimeScene.renderAndStep(1000 / 60);
}
expect(object.getBehavior('auto1').isOnFloor()).to.be(true);
expect(object.getBehavior('auto1').isFalling()).to.be(false);
expect(object.getBehavior('auto1').isMoving()).to.be(false);
expect(object.getY()).to.be(bottomJumpthru.getY() - object.getHeight());
}); });
}); });