Android Open Source - BulletsForever Menu Home






From Project

Back to project page BulletsForever.

License

The source code is released under:

GNU General Public License

If you think the Android project BulletsForever listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bulletsforever.bullets;
/*from   ww  w .j  ava2 s  .co  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;

/**
 * This is the app's main menu Activity
 * This should be started as the launcher Activity
 * Only a single instance should exist per app session
 */
public class MenuHome extends Activity {
  
  private static final int RESUME_MUSIC = 111;
  private AudioMusicPlayer mp;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    // Fullscreen
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    Settings.reload(this);
    
    // Splash screen
    setContentView(R.layout.main);
    findViewById(R.id.splash).setOnClickListener(
      new OnClickListener() {
        public void onClick(View v) {
          startGame();
        }
      }
    );
    
    startMusic();
  }
  
  private void startMusic() {
    // Music Player
    int bgmusic = -1;
    switch (Settings.getInt(R.string.bgmusic)) {
      case 1: //Techno
        bgmusic = R.raw.techno_splash;
        break;
      case 2:  //Classical
        bgmusic = R.raw.classical_splash;
        break;
      case 0:
      default:
        break;
    }
    if (bgmusic != -1) {
      try {
        mp = new AudioMusicPlayer();
        mp.load(getBaseContext(), bgmusic);
        mp.start();
      } catch (Exception e) {
        Log.v(e.getClass().getName(), e.getMessage());
      }
    }
  }
  
  private void stopMusic() {
    if (mp != null) mp.onDestroy();
    mp = null;
  }
  
  // Launch!
  private void startGame() {
    Settings.setScreenDimensions(this);
    stopMusic();
    Intent intent = new Intent();
    intent.setClass(MenuHome.this, GameMain.class);
    startActivityForResult(intent, RESUME_MUSIC);
  }
  
  // Resume menu music
  protected void onActivityResult(int requestCode, int resultCode, Intent data){
    switch (requestCode) {
      case RESUME_MUSIC:
        Settings.reload(this);
        startMusic();
        break;
      default:
        break;
    }
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
      stopMusic();
      Intent intent = new Intent();
      intent.setClass(MenuHome.this, MenuSettings.class);
      startActivityForResult(intent, RESUME_MUSIC);
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
      AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
      alertBuilder
        .setCancelable(true)
        .setTitle("Instructions")
        .setMessage(
          "Move the player and shoot using the touch screen.\n" +
          "Destroy all the boss parts before killing the core.\n" +
          "Player starts off with 3 lives. Get to level 8 to win!\n"
          )
        .setPositiveButton(
            "OK",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
              }
            }
            )
        .show()
        .setOwnerActivity(this);
      return true;
    } else {
      return super.onKeyDown(keyCode, event);
    }
  }
  
  @Override
  public void onDestroy() {
    stopMusic();
    super.onDestroy();
  }
}




Java Source Code List

com.bulletsforever.bullets.AudioMusicPlayer.java
com.bulletsforever.bullets.AudioSoundPool.java
com.bulletsforever.bullets.DrawBitmapLoader.java
com.bulletsforever.bullets.DrawKeyHandler.java
com.bulletsforever.bullets.DrawObjectBackground.java
com.bulletsforever.bullets.DrawObjectBoss.java
com.bulletsforever.bullets.DrawObjectBullet.java
com.bulletsforever.bullets.DrawObjectDynamicArm.java
com.bulletsforever.bullets.DrawObjectDynamicBoss.java
com.bulletsforever.bullets.DrawObjectHUD.java
com.bulletsforever.bullets.DrawObjectPlayer.java
com.bulletsforever.bullets.DrawObject.java
com.bulletsforever.bullets.DrawRefreshHandler.java
com.bulletsforever.bullets.DrawTouchHandler.java
com.bulletsforever.bullets.DrawWorld.java
com.bulletsforever.bullets.GameMain.java
com.bulletsforever.bullets.GameScore.java
com.bulletsforever.bullets.MenuHome.java
com.bulletsforever.bullets.MenuSettings.java
com.bulletsforever.bullets.Settings.java
com.bulletsforever.bullets.ToolsFPSCounter.java
com.bulletsforever.bullets.ToolsRandomizer.java
com.bulletsforever.bullets.ToolsScoreboard.java
com.bulletsforever.bullets.ToolsTracker.java
com.bulletsforever.bullets.ToolsVibrator.java