Example #1
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.");
    }
  }
Example #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();
 }
Example #3
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;
    }
  }
Example #4
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;
  }