Example #1
0
 private void soundWalk() {
   // if the player is moving and not jumping we play the walk sound
   if (Globals.player.moving() && !Globals.player.jumping() && !Globals.player.falling()) {
     // if the sound is still playing we let it play
     if (!soundWalk.playing()) {
       soundWalk.loop();
     }
     // We modulate the sound speed depending on the speed of movement of
     // the character
     float pitchVel = 0;
     if (Globals.player.facingRight()) {
       pitchVel = 0.5f + 1 / (1 / (Globals.player.getVelX() / Globals.player.stepRate()));
       // System.out.println(pitchVel+" lol");
     } else {
       pitchVel = 0.5f + -1 / (1 / (Globals.player.getVelX() / Globals.player.stepRate()));
       // System.out.println(pitchVel+" lool");
     }
     // for security
     if (pitchVel > 10) pitchVel = 10;
     if (pitchVel < 0.001) pitchVel = 0.001f;
     soundWalk.setPitch(pitchVel);
   }
   // we stop the sound because the character is no more walking
   else {
     soundWalk.stop();
   }
 }
Example #2
0
 private void soundJump() {
   // if the player is jumping or falling we play the jump sound
   if (Globals.player.jumping() || Globals.player.falling()) {
     // if the sound is still playing we let it play
     if (!soundJump.playing()) {
       soundJump.loop(
           1f,
           0.5f,
           Globals.player.getX() - Globals.player.getWidth() / 2,
           Globals.player.getY() - Globals.player.getHeight() / 2,
           0.0f);
       soundJumpPlaying = true;
     } else {
       soundJump.setSourcePosition(
           Globals.player.getX() - Globals.player.getWidth() / 2,
           Globals.player.getY() - Globals.player.getHeight() / 2,
           0.0f);
     }
     // We modulate the sound pitch depending on the y speed of movement
     // of the character
     float pitchVel = 0;
     pitchVel = 0.1f + Globals.player.getVelY() / 120f;
     // System.out.println(pitchVel+" lol");
     // because the y velocity can be positive or negative depending on
     // falling or jumping
     if (pitchVel < 0) pitchVel = -pitchVel;
     // for security
     if (pitchVel > 10) pitchVel = 10;
     if (pitchVel < 0.0001) pitchVel = 0.0001f;
     soundJump.setPitch(pitchVel);
   }
   // we stop the sound because the character is no more jumping
   else {
     soundJump.stop();
   }
 }
Example #3
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;
  }