@Override
 public void leave(GameContainer gc, StateBasedGame sb) throws SlickException {
   super.leave(gc, sb);
   // If coming in game again, the player will be moved
   Globals.player.setPosition(Globals.player.getX() + 200, Globals.player.getY() - 120);
   AlUtils.stopAllSounds();
 }
  @Override
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    super.update(gc, sbg, delta);
    //// Invulnerability
    // the first frame the player is invulnerable
    if (Globals.invulnerable && Globals.invulnerableTimer > delta * 5) {

      for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
        if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Enemy) {
          Globals.player.getBody().addExcludedBody(map.getWorld().getBodies().get(i));
        }
      }
    }
    // the invulnerability is time limited
    if (Globals.invulnerable) {
      Globals.invulnerableTimer += delta;
      if (Globals.invulnerableTimer >= 1500) {
        Globals.invulnerable = false;
        Globals.invulnerableTimer = 0;
        for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
          if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Enemy) {
            Globals.player.getBody().removeExcludedBody(map.getWorld().getBodies().get(i));
          }
        }
      }
    }
  }
  @Override
  public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
    if (map != null) super.render(gc, sbg, g);
    font.drawString(4 * gc.getWidth() / 5, 30, "" + Globals.score);
    Utils.drawCenteredString(
        g,
        "Cursors - Move   Ctrl - Jump   B - Show Bounds   R - Restart",
        gc.getWidth(),
        gc.getHeight() - 20,
        Color.black);

    /*for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
    	if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof HomerIA) {
    		sound.setSourcePosition((map.getEntityByBody(
    				map.getWorld().getBodies().get(i)).getX() - map
    				.getEntityByBody(map.getWorld().getBodies().get(i))
    				.getWidth() / 2), (map.getEntityByBody(
    				map.getWorld().getBodies().get(i)).getY() - map
    				.getEntityByBody(map.getWorld().getBodies().get(i))
    				.getHeight() / 2), 0f);
    	}
    }*/
    // We put the openAl listener's position and velocity
    AlUtils.setAlListenerPosition(
        Globals.player.getX() - Globals.player.getWidth() / 2,
        Globals.player.getY() - Globals.player.getHeight() / 2,
        0.0f);
    AlUtils.setAlListenerVelocity(Globals.player.getVelX() * 5, -Globals.player.getVelY(), 0.0f);
    // sound.setSourceVelocity(10f, 0f, 0f, soundIndex);
    // AlUtils.resetAlListener();
    if (AL10.alGetError() != AL10.AL_NO_ERROR)
      System.out.println("Erreur d'OpenAL" + AL10.alGetError());

    // Environment sounds
    if (soundWalk != null) soundWalk();
    soundBump();
    soundGround();
    soundJump();

    // we execute permanentSound method for all the enemy
    for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
      if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Enemy) {
        ((Enemy) map.getEntityByBody(map.getWorld().getBodies().get(i))).permanentSound(i);
      }
    }
    // the help sound if executed
    helpSound.setSourcePosition(
        Globals.player.getX() - Globals.player.getWidth() / 2,
        Globals.player.getY() - Globals.player.getHeight() / 2,
        0.0f);
  }
  @Override
  public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
    super.init(gc, sbg);
    input = gc.getInput();
    soundJump = new Sound2(Conf.SND_BIP_PATH + "bip6.ogg");
    soundJump2 = new Sound2(Conf.SND_DEPLACEMENT_PATH + "saut.ogg");
    soundBump = new Sound2(Conf.SND_DEPLACEMENT_PATH + "bump.ogg");
    killedEnemySound = new Sound2(Conf.SND_PERSOS_PATH + "hurt_light2.ogg");
    helpSound = new Sound2(Conf.getVoice("jeuf1"));

    font = new AngelCodeFont(Conf.FONTS_PATH + "hiero.fnt", Conf.FONTS_PATH + "hiero.png");
    // We set Open Al constants about physical world
    AL10.alDopplerFactor(1.0f); // Doppler effect
    AL10.alDopplerVelocity(1.0f); // Sound speed
    AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
    AL10.alDopplerFactor(50.0f);
  }
  @Override
  public void enter(GameContainer gc, StateBasedGame sbg) throws SlickException {
    currentState = States.IN_GAME;

    Globals.score_submitted = false;

    // If the "main" previous state was not the game state, then it's
    // probably the menu state
    if (Globals.returnState != stateID) {
      // Globals.stateToGoTo.clear();
      Globals.nodes.clear();
      Globals.initQuestionsNotAsked();
      Globals.started = true;

      createMap();

      LoadingList.setDeferredLoading(false);
      soundWalk = new Sound2(Globals.player.getSoundWalk());
      LoadingList.setDeferredLoading(true);

      Globals.score = 0;
      map.setMainPlayer(Globals.player);
      Globals.player.reinitPosition();
      voix = new t2s.SIVOXDevint();

      Globals.nodeHasChanged = true;
    }

    super.enter(gc, sbg);

    if (Globals.nodeHasChanged) {

      // map.addEntity(Globals.getEntityFromCurrentNode());
      PhysicalEntity ia = Globals.node.getIA();
      if (ia != null) {
        // we set the ia's position
        Dimension d = Globals.nodes.poll();
        if (d != null) {
          ia.setPosition((float) d.getWidth(), (float) d.getHeight());
        } else {
          System.err.println("No more node locations available.");
        }
        // we set the ia
        map.addEntity(ia);
      } else {
        System.err.println("The current node (" + Globals.node.getID() + ") doesn't have an ia.");
        Globals.nextEvent(sbg);
      }

      Globals.nodeHasChanged = false;
    }

    // this state is important so we put it in Globals
    Globals.returnState = stateID;

    AL10.alDopplerFactor(1.0f);
    // we execute enter methods for all the IA
    for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
      if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof IA) {
        ((IA) map.getEntityByBody(map.getWorld().getBodies().get(i))).enter();
      } else if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Enemy) {
        ((Enemy) map.getEntityByBody(map.getWorld().getBodies().get(i))).enter();
      } else if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Spirit) {
        ((Spirit) map.getEntityByBody(map.getWorld().getBodies().get(i))).enter();
      }
    }
  }