diff --git a/core/src/com/mygdx/game/PlatVenture.java b/core/src/com/mygdx/game/PlatVenture.java index b76e8212176382c3abe3d1739fd19370d36b7848..b8d9b8c54eaa560da55e3b7e057f86aecdc62316 100644 --- a/core/src/com/mygdx/game/PlatVenture.java +++ b/core/src/com/mygdx/game/PlatVenture.java @@ -26,13 +26,15 @@ public class PlatVenture extends ApplicationAdapter { private OrthographicCamera cam; private OrthographicCamera hudCam; + private InputProcessorPerso ipp; private GameStateManager gsm; public static Content res; @Override public void create () { - Gdx.input.setInputProcessor(new InputProcessorPerso()); + ipp = new InputProcessorPerso(); + Gdx.input.setInputProcessor(ipp); batch = new SpriteBatch(); res = new Content(); cam = new OrthographicCamera(); @@ -52,6 +54,7 @@ public class PlatVenture extends ApplicationAdapter { gsm.update(STEP); gsm.render(); InputPerso.update(); + ipp.update(STEP); } } diff --git a/core/src/etat/Play.java b/core/src/etat/Play.java index 60aec26979d8caa3bc83662d43d4338e1735e75f..771daaa56889716e2e086664891f985ecda9e36d 100644 --- a/core/src/etat/Play.java +++ b/core/src/etat/Play.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.BodyDef; @@ -21,6 +22,7 @@ import body.Panneau; import body.Platform; import body.Water; import handlers.ContactListenerPerso; +import handlers.Content; import handlers.GameStateManager; import handlers.InputPerso; @@ -31,6 +33,7 @@ public class Play extends GameState { private int largeur; private int hauteur; private int temps; + private char[][] map; private ContactListenerPerso cl; private int score = 0; private float totalTimeSinceAction = 0; @@ -38,9 +41,12 @@ public class Play extends GameState { private boolean isChangingLevel = false; private float timeDoubleTap = 0f; + private Content res; + private Body player; private OrthographicCamera b2dCam; + private OrthographicCamera textCam; public Play(GameStateManager gsm){ super(gsm); @@ -49,18 +55,25 @@ public class Play extends GameState { world.setContactListener(cl); b2dr = new Box2DDebugRenderer(); + res = new Content(); loadLevel(level); createPlayer(); //Init b2dCam b2dCam = new OrthographicCamera(); + textCam = new OrthographicCamera(); b2dCam.setToOrtho(false, PlatVenture.largeur /PPM, PlatVenture.hauteur/PPM); + textCam.setToOrtho(false, Gdx.graphics.getWidth() / PPM, Gdx.graphics.getHeight() / PPM); + //textCam.position.set(Gdx.graphics.getWidth() / PPM / 2, 0, 0); + loadTexture(); + + } public void handleInput() { if (InputPerso.isPressed(0)) { if (cl.isPlayerOnGround()) { - player.applyForceToCenter(0, 2f / PPM, true); + player.applyForceToCenter(0, 3f / PPM, true); } } @@ -76,17 +89,9 @@ public class Play extends GameState { } } - if (InputPerso.isDown()) { - if (InputPerso.x <= Gdx.graphics.getWidth() / 2) { - if (cl.isPlayerOnGround()) { - player.setLinearVelocity(-1 * 0.6f, player.getLinearVelocity().y); - } - } else { - if (cl.isPlayerOnGround()) { - player.setLinearVelocity(0.6f, player.getLinearVelocity().y); - } - } - } + + /*TODO echap pour quitter */ + /*TODO saut écouteur tactile*/ } @Override @@ -124,7 +129,9 @@ public class Play extends GameState { } if (isInside()) { + cl.setTriggerEndLevel(false); // Bouger la caméra en x + /* TODO bloquer la caméra à droite */ if (player.getPosition().x * PPM > (float) (PlatVenture.largeur / 2) && player.getPosition().y * PPM <= (float) (PlatVenture.hauteur / 2) && largeur > 16) { b2dCam.position.set(player.getPosition().x, PlatVenture.hauteur / PPM / 2, 0); @@ -144,6 +151,7 @@ public class Play extends GameState { } b2dCam.update(); + textCam.update(); /*TODO remettre à 1 quand j'aurai bien compris, on a pas besoin d'autant de précisions */ @@ -154,6 +162,11 @@ public class Play extends GameState { public void render() { //Clear l'écran Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); + batch.setProjectionMatrix(b2dCam.combined); + batch.begin(); + drawWorld(); + batch.draw(res.getTexture("idle_001"), player.getPosition().x - 5f/PPM, player.getPosition().y - 2f/PPM, 1/10f, 1/10f); + batch.end(); //dessine le monde box2d b2dr.render(world, b2dCam.combined); } @@ -172,11 +185,12 @@ public class Play extends GameState { hauteur = Integer.parseInt(premiereLigne[1]); temps = Integer.parseInt(premiereLigne[2]); - + map = new char[hauteur][largeur]; for (int i = hauteur; i > 0; i--){ for (int j = 0; j < largeur; j++){ System.out.print(ligne[i].charAt(j)); char current = ligne[i].charAt(j); + map[i-1][j] = current; switch (current){ case 'K': new Platform((j*10)/PPM, ((hauteur-i)*10)/PPM, "rectangle", world); @@ -265,11 +279,13 @@ public class Play extends GameState { } private void death(float dt){ + /*TODO vérifier pourquoi pas de mort niveau 2*/ if (totalTimeSinceAction > 2){ player.setLinearVelocity(0, 0); player.setTransform(15/PPM, 20/PPM, 0); score = 0; // reset du score totalTimeSinceAction = 0; + b2dCam.position.set(PlatVenture.largeur / PPM / 2, PlatVenture.hauteur / PPM / 2, 0); } else{ totalTimeSinceAction += dt; // player.setLinearVelocity(0, 0); @@ -290,6 +306,11 @@ public class Play extends GameState { if (!world.isLocked()) world.destroyBody(bodies.get(i)); } + + // Si on sort du niveau 3 on revient au niveau 1 + if (level == 3){ + level = 0; + } level++; // Incrémente le level loadLevel(level); createPlayer(); @@ -303,4 +324,59 @@ public class Play extends GameState { totalTimeSinceAction += dt; } } + + private void drawWorld(){ + batch.draw(res.getTexture("back"), 0, 0, largeur/10f, hauteur/10f); + String key; + for (int i = hauteur; i > 0; i--){ + for (int j = 0; j < largeur; j++) { + switch (map[i-1][j]){ + case 'J': + batch.draw(res.getTexture("platJ"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); + break; + case 'K': + batch.draw(res.getTexture("platK"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); + break; + case 'L': + batch.draw(res.getTexture("platL"), (j*10)/PPM, ((hauteur-i) * 10)/PPM + 2/PPM, 1/10f, 1/12f); + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + key = "brick" + map[i-1][j]; + batch.draw(res.getTexture(key), (j*10)/PPM, ((hauteur-i) * 10)/PPM, 1/10f, 1/10f); + break; + case 'Z': + batch.draw(res.getTexture("exit"), (j*10)/PPM, ((hauteur-i) * 10)/PPM, 1/10f, 1/10f); + + } + } + // System.out.println(); + } + } + + private void loadTexture(){ + res.loadTexture("assets/Platform_J.png", "platJ"); + res.loadTexture("assets/Platform_K.png", "platK"); + res.loadTexture("assets/Platform_L.png", "platL"); + res.loadTexture("assets/Brick_A.png", "brickA"); + res.loadTexture("assets/Brick_B.png", "brickB"); + res.loadTexture("assets/Brick_C.png", "brickC"); + res.loadTexture("assets/Brick_D.png", "brickD"); + res.loadTexture("assets/Brick_E.png", "brickE"); + res.loadTexture("assets/Brick_F.png", "brickF"); + res.loadTexture("assets/Brick_G.png", "brickG"); + res.loadTexture("assets/Brick_H.png", "brickH"); + res.loadTexture("assets/Brick_I.png", "brickI"); + res.loadTexture("assets/Exit_Z.png", "exit"); + res.loadTexture("assets/Back.png", "back"); + res.loadTexture("assets/Idle__000.png", "idle_001"); + //res.getTexture("platJ"); + } } diff --git a/core/src/handlers/InputProcessorPerso.java b/core/src/handlers/InputProcessorPerso.java index 39881088d68b375eb683841b4db6719341640a48..ec6de7e1d6d1f5d9961a2c6b26f2ecdc837bf9b4 100644 --- a/core/src/handlers/InputProcessorPerso.java +++ b/core/src/handlers/InputProcessorPerso.java @@ -1,10 +1,20 @@ package handlers; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; public class InputProcessorPerso extends InputAdapter { + private float timeTap; + private boolean tapOnRight; + + public InputProcessorPerso(){ + super(); + timeTap = 0; + + } + public boolean touchDragged(int x, int y, int pointer) { InputPerso.x = x; InputPerso.y = y; @@ -16,12 +26,32 @@ public class InputProcessorPerso extends InputAdapter { InputPerso.x = x; InputPerso.y = y; InputPerso.down = true; + if (timeTap < 0.3f){ + if (tapOnRight && InputPerso.x > Gdx.graphics.getWidth() / 2){ + InputPerso.setKey(InputPerso.BUTTON1, true); + } + if (!tapOnRight && InputPerso.x <= Gdx.graphics.getWidth() / 2){ + InputPerso.setKey(InputPerso.BUTTON1, true); + } + } + if (InputPerso.x <= Gdx.graphics.getWidth() / 2) { + InputPerso.setKey(InputPerso.BUTTON2, true); + tapOnRight = false; + } + if (InputPerso.x > Gdx.graphics.getWidth() / 2) { + tapOnRight = true; + InputPerso.setKey(InputPerso.BUTTON3, true); + } return true; } public boolean touchUp(int x, int y, int pointer, int button) { InputPerso.x = x; InputPerso.y = y; + InputPerso.setKey(InputPerso.BUTTON3, false); + InputPerso.setKey(InputPerso.BUTTON2, false); + InputPerso.setKey(InputPerso.BUTTON1, false); + timeTap = 0; InputPerso.down = false; return true; } @@ -53,4 +83,8 @@ public class InputProcessorPerso extends InputAdapter { } return true; } + + public void update(float dt){ + timeTap += dt; + } }