Пример #1
0
  @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();
      }
    }
  }
Пример #2
0
  @Override
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    Input input = gc.getInput();
    // If the beginning explanation is finished
    if (playTheGame) {
      // if the player is not dead
      if (!dead) {
        if (movingUp) {
          dudeHeight -= ((double) delta) / 10.0;
        } else {
          dudeHeight += ((double) delta) / 10.0;
        }
        float coeff = (wallOffset - dudeSize.width / 2) / WALL_RES;
        actualUpperWall =
            (int)
                (upperWall.get(currentWallNo - 1)
                    - coeff * (upperWall.get(currentWallNo) - upperWall.get(currentWallNo - 1)));
        actualLowerWall =
            (int)
                (lowerWall.get(currentWallNo - 1)
                    - coeff * (lowerWall.get(currentWallNo) - lowerWall.get(currentWallNo - 1)));

        // TODO The speed can be adjusted here
        wallOffset -= (float) delta * speed;
        speed += ((double) delta / 1000000000.0) * 2000;
        if (wallOffset <= -WALL_RES) {
          wallOffset += WALL_RES;
          popWall();
          addToWall();
        }
        distance += delta;
        // detect collisions
        // TODO Improve collision detection to find the edge of the box
        // against the edge of the cave.
        if ((dudeHeight + SENSITIVITY) > actualLowerWall
            || (dudeHeight - SENSITIVITY) < actualUpperWall) {
          dead = true;
          // voix.playText("Le je est terminé, votre score est de "+ distance/1000);
        }
        // the start explosion
        explosion.update(delta * 2);
        // the smoke trail
        trail.update(delta);
      }

      // If we are dead
      else {
        sonD.stop(1);
        sonG.stop();

        // if we are in main game
        if (Globals.returnState != Songe.MAINMENUSTATE) {
          // The score is set
          Globals.score += distance / 1000;
          Globals.nextEvent(sbg);
        }
        // if playing from the stand-alone version
        else {
          sbg.enterState(
              Globals.returnState,
              new FadeOutTransition(Color.black),
              new FadeInTransition(Color.black));
        }
      }
    }
    // if not yet started to play
    else {
      sonG.setVolume(0f, 0);
      sonD.setVolume(0f, 1);
      if (input.isKeyPressed(Input.KEY_UP)) {
        playTheGame = true;
        sonG.setVolume(600f, 0);
        sonD.setVolume(600f, 1);

        // sonG.setPitch(0.8f, 0);
        // sonD.setPitch(0.8f, 1);
        enterSound.stop();
      } else if (input.isKeyPressed(Input.KEY_F1)) {
        enterSound.stop();
        enterSound.play();
      }
    }
    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      sbg.enterState(
          Globals.returnState,
          new FadeOutTransition(Color.black),
          new FadeInTransition(Color.black));
    }
    spX -= delta * 4.0f * speed;
  }