/**
 * Copyright 2011 The ForPlay Authors
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package forplay.sample.noise.core;

import forplay.core.ForPlay;
import forplay.core.Game;
import forplay.core.Sound;

public class NoiseGame implements Game {

  private Sound[] sounds = new Sound[45];
  private int count;
  private Sound bgSound;

  @Override
  public void init() {
    for (int i = 0; i < sounds.length; i++) {
      ForPlay.log().info("Create sound " + i + "...");
      // Currently:
      // - Java Platform will search for freesoundproject_28917__junggle__btn107.wav
      // - HTML Platform will search for freesoundproject_28917__junggle__btn107.mp3
      sounds[i] = ForPlay.assetManager().getSound("freesoundproject_28917__junggle__btn107");
    }

    bgSound = ForPlay.assetManager().getSound("freesoundproject_12742__Leady__reverse_fill_effect");
    bgSound.setLooping(true);
    bgSound.play();
  }

  @Override
  public void update(float delta) {
    count++;

    // ForPlay.log().info("update(" + count + ")");
    if (count < 3) {
      playSound(count % sounds.length);
    } else {
      try {
        int i = 0;
        playSound(i);
      } catch (Throwable e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    // sound.stop();
  }

  private void playSound(int idx) {
    // ForPlay.log().info("play " + idx + "...");
    sounds[idx].play();
  }

  @Override
  public void paint(float alpha) {
  }

  @Override
  public int updateRate() {
    return 500;
  }

}

@@ -1256,24 +1256,56 @@
 __btn107%22);%0A
+      sounds%5Bi%5D.setVolume(.8f);%0A
     %7D%0A%0A    b
@@ -1584,16 +1584,17 @@
 (count %3C
+=
  3) %7B%0A  
@@ -1640,205 +1640,8 @@
    %7D
- else %7B%0A      try %7B%0A        int i = 0;%0A        playSound(i);%0A      %7D catch (Throwable e) %7B%0A        // TODO Auto-generated catch block%0A        e.printStackTrace();%0A      %7D%0A    %7D%0A    // sound.stop();
 %0A  %7D

make some noise