Beispiel #1
0
 private short[] generateAudio(int sampleRateinHz, int length) {
   short[] audioData = new short[(int) (1000.f / sampleRateinHz * length)];
   for (int i = 0; i < audioData.length; i++) {
     audioData[i] = (short) (sfxGenerator.synthSample() * Short.MAX_VALUE);
   }
   return audioData;
 }
Beispiel #2
0
  /** Update input */
  @Override
  public void updateState() {

    switch (state) {
      case GAME_INIT:
        // create explosion sound
        sfxGenerator.init(100);
        sfxGenerator.random(2);
        sfxGenerator.resetSample(false);
        soundBank[SOUND_EXPLOSION] = new AudioClip(22050, generateAudio(22050, 500));
        // create ship
        ship.generate(0x3CE0EF76);
        // create the robots
        robot = new Robot[10][5];
        for (int i = 0; i < robot.length; i++) {
          for (int j = 0; j < robot[j].length; j++) {
            robot[i][j] = new Robot();
            robot[i][j].generate(mt.generate());
          }
        }

        // set the starting state of the game.
        state = GAME_LEVEL;

        break;
      case GAME_LEVEL:
        if (mAccelX > mSensorBuffer || mAccelX < -mSensorBuffer) {
          ship.updateX(-mAccelX, mCanvasWidth);
          ship.updateY(mCanvasHeight - 20, mCanvasHeight);
        }
        //          if (mAccelY > mSensorBuffer || mAccelY < -mSensorBuffer)

        //          if(!particles.isActive())
        //          	particles.init(mCanvasWidth, mCanvasHeight);
        //          else
        //          	particles.update();
        break;
    }
  }