Android Open Source - AndroidGameDev Android Game






From Project

Back to project page AndroidGameDev.

License

The source code is released under:

Apache License

If you think the Android project AndroidGameDev 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 cc.rafazz.framework.implementation;
//w  ww.j  a v a2s. c om
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Window;
import android.view.WindowManager;

import cc.rafazz.framework.Audio;
import cc.rafazz.framework.FileIO;
import cc.rafazz.framework.Game;
import cc.rafazz.framework.Graphics;
import cc.rafazz.framework.Input;
import cc.rafazz.framework.Screen;

public abstract class AndroidGame extends Activity implements Game {
  AndroidFastRenderView renderView;
  Graphics graphics;
  Audio audio;
  Input input;
  FileIO fileIO;
  Screen screen;
  WakeLock wakeLock;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    int frameBufferWidth = isPortrait ? 800 : 1280;
    int frameBufferHeight = isPortrait ? 1280 : 800;
    Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
        frameBufferHeight, Config.RGB_565);

    float scaleX = (float) frameBufferWidth
        / getWindowManager().getDefaultDisplay().getWidth();
    float scaleY = (float) frameBufferHeight
        / getWindowManager().getDefaultDisplay().getHeight();

    renderView = new AndroidFastRenderView(this, frameBuffer);
    graphics = new AndroidGraphics(getAssets(), frameBuffer);
    fileIO = new AndroidFileIO(this);
    audio = new AndroidAudio(this);
    input = new AndroidInput(this, renderView, scaleX, scaleY);
    screen = getInitScreen();
    setContentView(renderView);

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK,
        "MyGame");
  }

  @Override
  public void onResume() {
    super.onResume();
    wakeLock.acquire();
    screen.resume();
    renderView.resume();
  }

  @Override
  public void onPause() {
    super.onPause();
    wakeLock.release();
    renderView.pause();
    screen.pause();

    if (isFinishing())
      screen.dispose();
  }

  @Override
  public Input getInput() {
    return input;
  }

  @Override
  public FileIO getFileIO() {
    return fileIO;
  }

  @Override
  public Graphics getGraphics() {
    return graphics;
  }

  @Override
  public Audio getAudio() {
    return audio;
  }

  @Override
  public void setScreen(Screen screen) {
    if (screen == null)
      throw new IllegalArgumentException("Screen must not be null");

    this.screen.pause();
    this.screen.dispose();
    screen.resume();
    screen.update(0);
    this.screen = screen;
  }

  public Screen getCurrentScreen() {

    return screen;
  }
}




Java Source Code List

cc.rafazz.framework.Audio.java
cc.rafazz.framework.FileIO.java
cc.rafazz.framework.Game.java
cc.rafazz.framework.Graphics.java
cc.rafazz.framework.Image.java
cc.rafazz.framework.Input.java
cc.rafazz.framework.Music.java
cc.rafazz.framework.Pool.java
cc.rafazz.framework.Screen.java
cc.rafazz.framework.Sound.java
cc.rafazz.framework.implementation.AndroidAudio.java
cc.rafazz.framework.implementation.AndroidFastRenderView.java
cc.rafazz.framework.implementation.AndroidFileIO.java
cc.rafazz.framework.implementation.AndroidGame.java
cc.rafazz.framework.implementation.AndroidGraphics.java
cc.rafazz.framework.implementation.AndroidImage.java
cc.rafazz.framework.implementation.AndroidInput.java
cc.rafazz.framework.implementation.AndroidMusic.java
cc.rafazz.framework.implementation.AndroidSound.java
cc.rafazz.framework.implementation.MultiTouchHandler.java
cc.rafazz.framework.implementation.SingleTouchHandler.java
cc.rafazz.framework.implementation.TouchHandler.java