Exemple #1
0
  public GameScreen(NinjaGamePrototype game) {

    this.game = game;
    new WorldController();

    WorldModel.get().addObserver(SoundSystem.get());
    WorldModel.get().getNinja().addObserver(SoundSystem.get());

    InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(new SongController());
    multiplexer.addProcessor(new NinjaController());
    Gdx.input.setInputProcessor(multiplexer);

    @SuppressWarnings("rawtypes")
    Iterator it;
    it = WorldModel.get().getEnemies().iterator();

    while (it.hasNext()) {
      EnemyModel enemy = (EnemyModel) it.next();
      enemy.addObserver(SoundSystem.get());
    }
  }
  @Override
  public void update(Observable o, Object arg) {

    if (o instanceof EnemyModel) {
      // Gdx.app.log(NinjaGamePrototype.LOG, "Enemy " + arg.toString());
      if (!enemy_distances.containsKey(o)) {
        enemy_distances.put((EnemyModel) o, 0f);
      }

      for (EnemyModel e : enemy_distances.keySet()) {
        float dist = e.getPosition().dst(WorldModel.get().getNinja().getPosition());
        // if (dist < enemy_distances.get(e) + 5){
        enemy_distances.put(e, dist);
        // }

        if (enemy_distances.get(e) < 100) {

          if (!e.isWalkingSound()) {
            e.setWalkingSound(true);
            soundid = floor_sand.loop();
          }

          if (e.isWalkingSound()) {
            enemy_sound = floor_sand;
            enemy_sound.setVolume(soundid, Math.abs((enemy_distances.get(e) / 100) - 1));
          }

        } else {
          if (e.isWalkingSound()) {
            floor_sand.stop();
            e.setWalkingSound(false);
          }
        }
      }

    } else {

      switch ((ObserverMessage) arg) {
        case Ninja_Walk:
          // Gdx.app.log(NinjaGamePrototype.LOG, "Ninja_Walk " + arg.toString());
          if (WorldModel.get().getNinja().getWalking() == 0) {
            floor_sound = floor_wood;
            floor_sound.loop();
            WorldModel.get().getNinja().setWalking(1);
          }

          break;

        case Ninja_Walk_Stop:
          floor_sound.stop();
          WorldModel.get().getNinja().setWalking(0);
          Gdx.app.log(NinjaGamePrototype.LOG, "Ninja_Walk_Stop " + arg.toString());
          break;

        case Collision_Obstacle:
          Gdx.app.log(NinjaGamePrototype.LOG, "Collision_Obstacle " + arg.toString());
          break;

        case Collision_Obstacle_Stop:
          Gdx.app.log(NinjaGamePrototype.LOG, "Collision_Obstacle_Stop " + arg.toString());
          break;

        case Collision_Enemy:
          Gdx.app.log(NinjaGamePrototype.LOG, "Collision_Enemy " + arg.toString());
          break;

        case Collision_Enemy_Stop:
          Gdx.app.log(NinjaGamePrototype.LOG, "Collision_Enemy_Stop " + arg.toString());
          break;

        default:
          break;
      }
    }
  }