diff --git a/core/src/com/mygdx/game/PlatVenture.java b/core/src/com/mygdx/game/PlatVenture.java index 062bc8156646ab4fbfd26e61d925007585baf5a0..768e58ea19b8f39997a63e271a0813e34f150aff 100644 --- a/core/src/com/mygdx/game/PlatVenture.java +++ b/core/src/com/mygdx/game/PlatVenture.java @@ -7,6 +7,8 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.ScreenUtils; import handlers.GameStateManager; +import handlers.InputPerso; +import handlers.InputProcessorPerso; public class PlatVenture extends ApplicationAdapter { @@ -26,6 +28,7 @@ public class PlatVenture extends ApplicationAdapter { @Override public void create () { + Gdx.input.setInputProcessor(new InputProcessorPerso()); batch = new SpriteBatch(); cam = new OrthographicCamera(); cam.setToOrtho(false, largeur, hauteur); @@ -43,6 +46,7 @@ public class PlatVenture extends ApplicationAdapter { accum -= STEP; gsm.update(STEP); gsm.render(); + InputPerso.update(); } } diff --git a/core/src/etat/Play.java b/core/src/etat/Play.java index 66692cbc450de3c35227bbe646f3166b0d524a9e..2508bd8cfe62608949ef9d56ae9de1f4a1c3c279 100644 --- a/core/src/etat/Play.java +++ b/core/src/etat/Play.java @@ -14,6 +14,7 @@ import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World; import com.mygdx.game.PlatVenture; +import handlers.ContactListenerPerso; import handlers.GameStateManager; public class Play extends GameState { @@ -26,6 +27,7 @@ public class Play extends GameState { public Play(GameStateManager gsm){ super(gsm); world = new World(new Vector2(0, -10f), true); + world.setContactListener(new ContactListenerPerso()); b2dr = new Box2DDebugRenderer(); BodyDef bdef = new BodyDef(); diff --git a/core/src/handlers/ContactListenerPerso.java b/core/src/handlers/ContactListenerPerso.java new file mode 100644 index 0000000000000000000000000000000000000000..fe6758a339d3bd0506210d2f08a22105b1c5b987 --- /dev/null +++ b/core/src/handlers/ContactListenerPerso.java @@ -0,0 +1,47 @@ +package handlers; + +import com.badlogic.gdx.physics.box2d.Contact; +import com.badlogic.gdx.physics.box2d.ContactImpulse; +import com.badlogic.gdx.physics.box2d.ContactListener; +import com.badlogic.gdx.physics.box2d.Manifold; + +public class ContactListenerPerso implements ContactListener { + + /** + * Appeler quand 2 fixtures rentre en collision + * @param c + */ + @Override + public void beginContact(Contact c) { + System.out.println("contact"); + } + + /** + * Appeler quand 2 fixtures sorte de collision + * @param c + */ + @Override + public void endContact(Contact c) { + + } + + /** + * Ce qu'il se passe entre la détection de collision et son handling + * @param c + * @param m + */ + @Override + public void preSolve(Contact c, Manifold m) { + + } + + /** + * Ce qu'il se passe après le handling d'une collision + * @param c + * @param ContactImpulse + */ + @Override + public void postSolve(Contact c, ContactImpulse ContactImpulse) { + + } +} diff --git a/core/src/handlers/InputPerso.java b/core/src/handlers/InputPerso.java new file mode 100644 index 0000000000000000000000000000000000000000..7ffb00f457760b681dda92554f47f8c1c1c228a5 --- /dev/null +++ b/core/src/handlers/InputPerso.java @@ -0,0 +1,49 @@ +package handlers; + +public class InputPerso { + public static boolean[] keys; + public static boolean[] pkeys; + + public static final int NUM_KEYS = 3; + + /** + * Saut + */ + public static final int BUTTON1 = 0; + /** + * Gauche + */ + public static final int BUTTON2 = 1; + /** + * Droite + */ + public static final int BUTTON3 = 2; + + static{ + keys = new boolean[NUM_KEYS]; + pkeys = new boolean[NUM_KEYS]; + } + + public static void update(){ + for (int i = 0; i <NUM_KEYS; i++){ + pkeys[i] = keys[i]; + } + } + + public static void setKey(int i, boolean b){ + keys[i] = b; + } + + public static boolean isDown(int i){ + return keys[i]; + } + + /** + * Savoir si une touche a été appuyé une fois + * @param i touche à regarder + * @return vrai si la touche est appuyé et ne l'était pas à l'état d'avant + */ + public static boolean isPressed(int i){ + return keys[i] && !pkeys[i]; + } +} diff --git a/core/src/handlers/InputProcessorPerso.java b/core/src/handlers/InputProcessorPerso.java new file mode 100644 index 0000000000000000000000000000000000000000..37c884681cb7e4ff9ff2188d521008cd710b5245 --- /dev/null +++ b/core/src/handlers/InputProcessorPerso.java @@ -0,0 +1,35 @@ +package handlers; + +import com.badlogic.gdx.Input; +import com.badlogic.gdx.InputAdapter; + +public class InputProcessorPerso extends InputAdapter { + + @Override + public boolean keyDown(int k){ + if (k == Input.Keys.UP){ + InputPerso.setKey(InputPerso.BUTTON1, true); + } + if (k == Input.Keys.LEFT){ + InputPerso.setKey(InputPerso.BUTTON2, true); + } + if (k == Input.Keys.RIGHT){ + InputPerso.setKey(InputPerso.BUTTON3, true); + } + return true; + } + + @Override + public boolean keyUp(int k){ + if (k == Input.Keys.UP){ + InputPerso.setKey(InputPerso.BUTTON1, false); + } + if (k == Input.Keys.LEFT){ + InputPerso.setKey(InputPerso.BUTTON2, false); + } + if (k == Input.Keys.RIGHT){ + InputPerso.setKey(InputPerso.BUTTON3, false); + } + return true; + } +}