Exemplo n.º 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();
   }
 }
Exemplo n.º 2
0
 public void enter(GameContainer gc, StateBasedGame sbg) throws SlickException {
   // The listener is reset
   AlUtils.resetAlListener();
   // the orientation is changed
   AlUtils.setAlListenerOrientation(0.0f, 0.0f, -1.0f, -1.0f, 0.0f, 0.0f);
   // we set sound context
   AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
   AL10.alDopplerFactor(0.8f);
   // We play the two sounds since we enter
   sonG.loop(1f, 1f, 0f, 0f, 0f);
   sonD.loop(1f, 1f, 0f, 0f, 0f);
   AL10.alSourcef(sonG.getIndex(), AL10.AL_ROLLOFF_FACTOR, 1.5f);
   AL10.alSourcef(sonD.getIndex(), AL10.AL_ROLLOFF_FACTOR, 1.5f);
   // We play the beginning explanation sound
   enterSound.play();
 }
Exemplo n.º 3
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();
   }
 }