示例#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();
   }
 }
示例#2
0
 private void soundBump() {
   // we check if the sound should be replayed
   if (bumpWallPlayed || bumpTopPlayed) {
     // if the x position has really changed (3 pixels) and the player is
     // no more facing to wall (useful to avoid problem with pushing
     // crates), the bump can again be played
     if (((Globals.player.getX() - bumpWallX) > 3 || (Globals.player.getX() - bumpWallX) < -3)
         && !Globals.player.isTotallyFacingToWall()) {
       bumpWallPlayed = false;
     }
     if (((Globals.player.getY() - bumpTopY) > 3
         || (Globals.player.getY() - bumpTopY) < -3
         || (Globals.player.getX() - bumpTopX) > 3
         || (Globals.player.getX() - bumpTopX) < -3)) {
       bumpTopPlayed = false;
     }
   }
   // If the player is facing to a wall
   if (Globals.player.isFacingToWall()) {
     // to have the sound from the right or the left depending on the
     // position of the wall and the player
     int decal = 0;
     if (Globals.player.facingRight()) decal = 1;
     else decal = -1;
     // If the sound should be replayed, it will
     if (!bumpWallPlayed) {
       soundBump.playAt(
           1.5f,
           5f,
           Globals.player.getX() - Globals.player.getWidth() / 2 + decal,
           Globals.player.getY() - Globals.player.getHeight() / 2,
           0.0f);
       bumpWallPlayed = true;
       bumpWallX = Globals.player.getX();
     } else {
       soundBump.setSourcePosition(
           Globals.player.getX() - Globals.player.getWidth() / 2 + decal,
           Globals.player.getY() - Globals.player.getHeight() / 2,
           0.0f);
     }
   }
   // If the player is knocking his head somewhere when jumping
   else if (Globals.player.isTopCollided() && Globals.player.jumping()) {
     // If the sound should be replayed, it will
     if (!bumpTopPlayed) {
       soundBump.playAt(
           1.5f,
           1f,
           Globals.player.getX() - Globals.player.getWidth() / 2,
           Globals.player.getY() - Globals.player.getHeight() / 2,
           0.0f);
       bumpTopPlayed = true;
       bumpTopX = Globals.player.getX();
       bumpTopY = Globals.player.getY();
     }
   }
 }
示例#3
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();
 }
示例#4
0
  /* ****** *
   * Events *
   * ****** */
  @Override
  protected void notTimedEvents(GameContainer gc, StateBasedGame sbg, int delta) {

    if (input.isKeyPressed(Input.KEY_R)) {
      try {
        Globals.returnState = -1;
        enter(gc, sbg);
      } catch (SlickException e) {
        System.err.println("Erreur lors du relancement du jeu");
      }
      return;
    }
    if (input.isKeyPressed(Input.KEY_B)) {
      map.showBounds();
    }
    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      currentState = States.GAME_OVER;
    }
    if (input.isKeyPressed(Input.KEY_P)) {
      currentState = States.PAUSE;
    }

    /*if (input.isKeyPressed(Input.KEY_F4)) {
    	map.addEntity(new WalkingIA(Conf.IMG_SPRITES_PATH+"mariowalk_big.png", 3, 0, false, 100, 100, 40, 62, 12,new Node(1)));
    }
    if (input.isKeyPressed(Input.KEY_F5)) {
    	Enemy enemy = new Enemy(Conf.IMG_SPRITES_PATH+"mariowalk_big.png", 3, 100, 100, 40, 62, 2);
    	map.addEntity(enemy);
    	//the ennemies do not collide between each other
    	for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
    		if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Enemy) {
    			enemy.getBody().addExcludedBody(map.getWorld().getBodies().get(i));
    		}
    	}
    }*/
    // determines if the character moves
    Globals.player.setMoving(false);
    if (input.isKeyDown(Input.KEY_LEFT) || input.isKeyDown(Input.KEY_RIGHT)) {
      Globals.player.setMoving(true);
    }
    if (input.isKeyPressed(Input.KEY_F1)) {
      // jouer un son : l'aide
      // TODO
      helpSound.play();
    }
    if (input.isKeyPressed(Input.KEY_F2)) {
      Globals.dialogNextState = Globals.returnState;
      sbg.enterState(
          Songe.DIALOGSTATE, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    }
    if (input.isKeyPressed(Input.KEY_F3)) {
      voix.stop();
      voix.playShortText("Vous avez " + Globals.score + " points.");
    }
  }
示例#5
0
  @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);
  }
示例#6
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();
   }
 }
示例#7
0
  protected void collisions(Enemy enemy, CollisionEvent event) {
    enemy.onCollision();

    // if the enemy is under the feet of the player, it dies
    if ((event.getPoint().getY() < (enemy.getY() + (enemy.getHeight() / 3)))
        && (event.getPoint().getY() > (Globals.player.getY() + (Globals.player.getHeight() / 3)))
    /*&& (event.getPoint().getX() < (other.getX() - 1))
    && (event.getPoint().getX() > (other.getX()
    		- (other.getWidth()) - 1))*/ ) {
      map.removeEntity(enemy);
      killedEnemySound.play();
      ((Enemy) enemy).stopSound();
      Globals.score++;
    }
    // if the enemy is not killed, the player is hurt
    else {
      if (Globals.score > 0) Globals.score--;
      // pain sound
      Globals.player.getPainSound().play(1f, 0.6f);
      Globals.invulnerable = true;
    }
  }
示例#8
0
  @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);
  }
示例#9
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;
  }