package me.codeand.ahahpah_en;
import java.util.Random;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.engine.handler.timer.ITimerCallback;
import org.anddev.andengine.engine.handler.timer.TimerHandler;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.font.FontFactory;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.ui.activity.LayoutGameActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.widget.FrameLayout;
/**
* @author Chengzhi Yang
* @email coding.game[at]gmail.com
*/
public class MainGame extends LayoutGameActivity {
// ===========================================================
// Constants
// ===========================================================
private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 320;
private static final int STATE_MENU = 0;
private static final int STATE_GAME = STATE_MENU + 1;
private static final int STATE_INFO = STATE_GAME + 1;
private static final int ROCK_NUM = 4;
private static final int BULLET_NUM = 3;
private static final int SMOOK_NUM = 4;
private static final int FONT_SIZE = 30;
private static final String HISCORE_PREFS = "hiscore";
// ===========================================================
// Fields
// ===========================================================
private static Camera mCamera;
public static boolean ahh = false;
public static boolean pahh = false;
private Texture mMenuTX;
private TextureRegion mBackGroundTR;
private Sprite mBackGround;
private TextureRegion mTitleTR;
private Sprite mTitleSP;
private TextureRegion mScoresTR;
private Sprite mScoresSP;
private TextureRegion mHiScoresTR;
private Sprite mHiScoresSP;
private TextureRegion mStartTR;
private Sprite mStartSP;
private Texture mGameTX;
private TextureRegion mAirPlaneTR;
private Aircraft mAirPlane;
private TextureRegion mRock1TR;
private TextureRegion mRock2TR;
private TextureRegion mRock3TR;
private TextureRegion mBulletTR;
private Texture mFoldTX;
private TextureRegion mFoldTR;
private Sprite mFold;
private Rock[] mRock;
private Bullet[] mBullet;
private int mBulletIndex = 0;
private long mLastLaunch = 0;
private Texture mSmookTX;
private TextureRegion mSmookTR;
private Smoke[] mSmoke;
private int mSmokeIndex = 0;
//Update Handler
private IUpdateHandler mGameUpdate;
//private static final Handler ScoreLoopHandler = new Handler();
//private static final Handler AdsHandler = new Handler();
//Recoder
private Recorder mRecorder;
private boolean mLimitRecorder = true;
private int mGameState = STATE_MENU;
private boolean readyOver = false;
private float overTime = 0.0f;
private float mSpeed = 0.0f;
private float mAcceleration = 0.0f;
public static float mVoicePoint = 0.0f;
public static float mMaxUp = 0.0f;
public static float mLastState = 0;
private float mTargetPoint = 0.0f;
private float mTargetArray[];
private int mTargetNum = 0;
private int mTargetIndex = 0;
private boolean mFirstMenu = true;
private boolean mFirstGame = true;
private float mAirPlaneSpeedX = 0.0f;
private float mLastRock = -1.0f;
//Button
private Texture mMenuButtonTX;
private TextureRegion mInfoButtonTR;
private TextureRegion mBoardButtonTR;
private TextureRegion mSettingsButtonTR;
private TextureRegion mCloseButtonTR;
private Sprite mInfoButton;
private Sprite mBoardButton;
private Sprite mSettingsButton;
private Sprite mCloseButton;
//Infomation
private Texture mInformationTX;
private TextureRegion mInformationTR;
private Sprite mInformation;
//Fonts
private Font mScoreFont;
private Texture mFontTX;
private Typeface mScoreTF;
private ChangeableText mScoreText;
private ChangeableText mHiScoreText;
private static int mScore = 0;
//Random
final Random mRandom = new Random (SystemClock.uptimeMillis());
final static Scene MainScene = new Scene(1);
//Perference.
static public SharedPreferences mPrefs;
//Ads
/*
private static AdView mAdView;
*/
//Ah Pah sensitivity
public static int mAh = 500;
public static int mPah = 7000;
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
protected int getLayoutID() {
return R.layout.gamelayout;
}
@Override
protected int getRenderSurfaceViewID() {
return R.id.game_rendersurfaceview;
}
@Override
public void onLoadComplete() {
}
@Override
public Engine onLoadEngine() {
this.mCamera = new Camera( 0, 0, CAMERA_WIDTH, CAMERA_HEIGHT );
//return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera));
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new FillResolutionPolicy(), mCamera));
}
@Override
public void onLoadResources() {
TextureRegionFactory.setAssetBasePath("gfx/");
mMenuTX = new Texture ( 512, 512, TextureOptions.DEFAULT );
mBackGroundTR = TextureRegionFactory.createFromAsset(mMenuTX, this, "background.png", 0, 0);
mTitleTR = TextureRegionFactory.createFromAsset(mMenuTX, this, "title.png", 0, 321 );
mStartTR = TextureRegionFactory.createFromAsset(mMenuTX, this, "start.png", 0, 400 );
mScoresTR = TextureRegionFactory.createFromAsset(mMenuTX, this, "scores.png", 0, 480 );
mHiScoresTR = TextureRegionFactory.createFromAsset(mMenuTX, this, "hiscores.png", 81, 480 );
mBulletTR = TextureRegionFactory.createFromAsset(mMenuTX, this, "bullet.png", 200, 480 );
mGameTX = new Texture ( 256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA );
mAirPlaneTR = TextureRegionFactory.createFromAsset(mGameTX, this, "airplane.png", 0, 0);
mRock1TR = TextureRegionFactory.createFromAsset(mGameTX, this, "rock1.png", 90, 0);
mRock2TR = TextureRegionFactory.createFromAsset(mGameTX, this, "rock2.png", 157, 0);
mRock3TR = TextureRegionFactory.createFromAsset(mGameTX, this, "rock3.png", 0, 50);
mSmookTX = new Texture ( 64, 64, TextureOptions.BILINEAR_PREMULTIPLYALPHA );
mSmookTR = TextureRegionFactory.createFromAsset(mSmookTX, this, "smoke.png", 0, 0);
mFoldTX= new Texture ( 256, 512, TextureOptions.DEFAULT );
mFoldTR = TextureRegionFactory.createFromAsset(mFoldTX, this, "fold.png", 0, 0);
mMenuButtonTX = new Texture ( 256, 128, TextureOptions.DEFAULT );
mInfoButtonTR = TextureRegionFactory.createFromAsset(mMenuButtonTX, this, "info.png", 0, 0);
- 1
- 2
- 3
- 4
- 5
前往页