Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
0
 @Override
 public void leave(GameContainer gc, StateBasedGame sb) throws SlickException {
   super.leave(gc, sb);
   // If coming in game again, the player will be moved
   Globals.player.setPosition(Globals.player.getX() + 200, Globals.player.getY() - 120);
   AlUtils.stopAllSounds();
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 4
0
 @Override
 public void leave(GameContainer gc, StateBasedGame sbg) throws SlickException {
   reset();
   AlUtils.stopAllSounds();
   AlUtils.resetAlListener();
 }
Ejemplo n.º 5
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);
  }