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(); } }
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(); } }
@Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { // TODO Graphics? g.drawString("Distance: " + distance, 10, 25); g.drawString("Speed: " + ((double) ((int) (speed * 10000.0))) / 10000.0, 10, 40); // all the graphics below will be affected by the translation g.translate(spX, 0); // The smoke ((ConfigurableEmitter) trail.getEmitter(0)) .setPosition(dudeWidth - dudeSize.width / 2 - spX, dudeHeight); trail.render(); // the death explosion ((ConfigurableEmitter) explosion.getEmitter(0)) .setPosition(dudeWidth - dudeSize.width / 2 - spX, dudeHeight); ((ConfigurableEmitter) explosion.getEmitter(1)) .setPosition(dudeWidth - dudeSize.width / 2 - spX, dudeHeight); explosion.render(); // the walls // upper wall for (int i = 0; i < upperWall.size() - 1; i++) { for (int j = 0; j < 5; j++) { g.drawLine( i * WALL_RES + wallOffset - spX, upperWall.get(i) - j, (i + 1) * WALL_RES + wallOffset - spX, upperWall.get(i + 1) - j); } } // lower wall for (int i = 0; i < lowerWall.size() - 1; i++) { for (int j = 0; j < 5; j++) { g.drawLine( i * WALL_RES + wallOffset - spX, lowerWall.get(i) + j, (i + 1) * WALL_RES + wallOffset - spX, lowerWall.get(i + 1) + j); } } // The object g.fillRect( dudeWidth - dudeSize.width / 2 - spX, (int) dudeHeight - dudeSize.height / 2, dudeSize.width, dudeSize.height); // if(dead) g.drawString("Le jeu est terminé, appuyez sur Entrée pour continuer", 250, 150); // Sounds AlUtils.setAlListenerPosition((float) (WALL_RES + dudeSize.width / 2), dudeHeight, 0f); if (movingUp) AlUtils.setAlListenerVelocity((float) (WALL_RES + dudeSize.width / 2), -20, 0f); else AlUtils.setAlListenerVelocity((float) (WALL_RES + dudeSize.width / 2), 20, 0f); enterSound.setSourcePosition((float) (WALL_RES + dudeSize.width / 2), dudeHeight, 0f, 0); sonG.setSourcePosition((float) (WALL_RES + dudeSize.width / 2), actualUpperWall, 0f, 0); sonD.setSourcePosition((float) (WALL_RES + dudeSize.width / 2), actualLowerWall, 0f, 1); sonG.setSourceVelocity( (float) (WALL_RES + dudeSize.width / 2), upperWall.get(currentWallNo - 1) - upperWall.get(currentWallNo), 0f, 0); sonD.setSourceVelocity( (float) (WALL_RES + dudeSize.width / 2), lowerWall.get(currentWallNo) - lowerWall.get(currentWallNo - 1), 0f, 1); distSonBas = (float) (1.0 / ((actualLowerWall - dudeHeight) / 50.0)); distSonHaut = (float) (1.0 / ((dudeHeight - actualUpperWall) / 50.0)); sonG.setPitch(distSonHaut); sonD.setPitch(distSonBas, 1); }