diff --git a/core/src/etat/Play.java b/core/src/etat/Play.java index dd32f80fae31f5d78135a0cdbb54253a579f4f4f..08734e32535c827ffc8efa13741c0199d9d660ca 100644 --- a/core/src/etat/Play.java +++ b/core/src/etat/Play.java @@ -32,8 +32,9 @@ public class Play extends GameState { private int temps; private ContactListenerPerso cl; private int score = 0; - private boolean dead = false; - private float totalTimeSinceDeath = 0; + private float totalTimeSinceAction = 0; + private int level = 1; + private boolean isChangingLevel = false; private Body player; @@ -46,8 +47,7 @@ public class Play extends GameState { world.setContactListener(cl); b2dr = new Box2DDebugRenderer(); - - createWorld("assets/level_001.txt"); + loadLevel(level); createPlayer(); //Init b2dCam @@ -88,7 +88,19 @@ public class Play extends GameState { } joyauToRemove.clear(); - death(dt); + // death(dt); + + if (!isInside()){ + if (cl.isTriggerEndLevel()){ + isChangingLevel = true; + }else{ + death(dt); + } + } + + if (isChangingLevel){ + changeLevel(dt); + } // Bouger la caméra en x if (player.getPosition().x * PPM > (float) (PlatVenture.largeur / 2) && player.getPosition().y * PPM <= (float) (PlatVenture.hauteur / 2) && largeur > 16) { @@ -219,18 +231,32 @@ public class Play extends GameState { } private void death(float dt){ - if (!isInside() && !cl.isTriggerEndLevel()){ - dead = true; - } - if (dead){ - if (totalTimeSinceDeath > 2){ + if (totalTimeSinceAction > 2){ player.setLinearVelocity(0, 0); player.setTransform(15/PPM, 20/PPM, 0); - dead = false; - totalTimeSinceDeath = 0; + totalTimeSinceAction = 0; } else{ - totalTimeSinceDeath += dt; + totalTimeSinceAction += dt; } + } + + private void loadLevel(int current){ + String path = "assets/level_00" + current + ".txt"; + createWorld(path); + } + + private void changeLevel(float dt){ + if (totalTimeSinceAction > 2) { + Array<Body> bodies = new Array<>(); + world.getBodies(bodies); + for (int i = 0; i < bodies.size; i++) { + if (!world.isLocked()) + world.destroyBody(bodies.get(i)); + } + isChangingLevel = false; + } + else{ + totalTimeSinceAction += dt; } } }