/*
 * Land Sea Air -- an interactive music game
 * demonstrating the "secret yanni" techique, with key changes
 * design, animation, audio, and code by peter "pdx" drescher
 * twittering machine
 * 
 */
package com.twittering.landseaair;

import com.twittering.landseaair.R;
import com.twittering.landseaair.GameSurfaceView.GameThread;

import java.io.File;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Environment;
import android.view.Window;

public class LSAland extends Activity {
	
	private GameThread mGameThread;
	private GameSurfaceView mGameView;
	private boolean gamePaused;
	FMODaudio mFMODaudio = new FMODaudio();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        createSurfaceView(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    
    @Override
    protected void onPause() {
    	mFMODaudio.stopLandAudio();
    	mGameView.pauseAnimation();
    	gamePaused = true;
        super.onPause();
    }
	
	@Override
    protected void onResume() {
    	File sdCard = Environment.getExternalStorageDirectory();
    	File mediaDir = new File (sdCard.getAbsolutePath() + "/fmod");
    	String mediaPath = mediaDir.getPath();
    	mediaPath += "/";
    	mFMODaudio.initLandAudio(mediaPath);
    	if (gamePaused) {
    		mGameView.restartLandAnimation();
    		gamePaused = false;
    	}
    	super.onResume();
    }
	
	private void createSurfaceView(Bundle savedInstanceState) {
		setContentView(R.layout.game);        
		mGameView = (GameSurfaceView) findViewById(R.id.gameview);
        mGameThread = mGameView.getThread(GameSurfaceView.LAND_LEVEL);        
        mGameView.setPlayActivity(this);
        mGameView.initLand();
    }
	    
	@Override
    protected void onStop() {
    	mGameView.stopLandAnimation();
        super.onStop();
    }
	
	@Override
    protected void onRestart() {
    	super.onRestart();
    	createSurfaceView(null);
     }
}