package com.sordid.particly;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import javax.microedition.khronos.opengles.GL10;
import org.anddev.andengine.audio.sound.Sound;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.BoundCamera;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXLayer;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXLoader;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXObject;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXObjectGroup;
import org.anddev.andengine.entity.layer.tiled.tmx.TMXTiledMap;
import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TMXLoadException;
import org.anddev.andengine.entity.particle.ParticleSystem;
import org.anddev.andengine.entity.primitive.Line;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.scene.menu.MenuScene;
import org.anddev.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.anddev.andengine.entity.scene.menu.item.AnimatedSpriteMenuItem;
import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.util.Vector2Pool;
import org.anddev.andengine.input.touch.TouchEvent;
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.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.sordid.particly.ParallaxBackground2d.ParallaxBackground2dEntity;
public class ParticlyActivity extends BaseGameActivity implements IOnSceneTouchListener,IOnMenuItemClickListener {
public static final boolean DEBUG = false;
public static final int CAMERA_WIDTH = 720;
public static final int CAMERA_HEIGHT = 480;
private static final int DIALOG_INTRO_1 = 0;
private static final int DIALOG_INTRO_2 = 1;
private static final float SCALE_FACTOR = 0.1f;
private static final int MENU_WIN = 0;
private static final int MENU_NEXT = 1;
private static final int MENU_RESET = 2;
private static final int MENU_SELECT = 3;
private static final int MENU_SOUND = 4;
public static final int STATE_STOPPED = 1;
public static final int STATE_RUNNING = 2;
public static final int STATE_OVER = 4;
public static final int STATE_MENU = 8;
// Item list
private static final short WALL = 1;
private static final short OBJECT = 2;
private static final short MASK = WALL+OBJECT;
// Fixtures
public static final FixtureDef STATIC_FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.0f, 0.5f, false, WALL, MASK, (short)0);
public static final FixtureDef STATIC_GOAL_FIXTURE_DEF = PhysicsFactory.createFixtureDef(0, 0f, 10f, true, WALL, MASK, (short)0);
public static final FixtureDef OBJECT_FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.7f, 0.4f, false, OBJECT, MASK, (short)0);
public static final FixtureDef OBJECT_LEVEL_FIXTURE_DEF = PhysicsFactory.createFixtureDef(0.2f, 0.1f, 0.4f, false, OBJECT, MASK, (short)0);
// Variables for performance
private Line mLine;
// General variables
private float mLastVelocity = 0.0f;
private ContactListener mContactListener;
public static HashMap<String,TextureRegion> sTextures;
public static HashMap<String,TiledTextureRegion> sTiledTextures;
public static ArrayList<Texture> sTextureHolders;
public static Sound[] sHitVoiceSounds;
public static Sound[] sHitSounds;
public static Sound[] sWinSounds;
public static Sound[] sLoseSounds;
public ArrayList<ParticleSystem> mParticleSystems;
public HashMap<String,Teleporter> mTeleports;
private CustomMenuScene mMenuScene;
private Texture mTexture;
private TextureRegion mParallaxLayerBack;
private TextureRegion mParallaxLayerMid;
private TextureRegion mParallaxLayerFront;
public BoundCamera mCamera;
public AnimatedSprite mBall;
public Random mRandom = new Random();
private Sprite mArrow;
public Body mBallBody;
private ParallaxBackground2d mBackground;
private TMXTiledMap mTMXTiledMap;
public Scene mScene;
private int mLevel = 0;
private int mLevels = 0;
private int mChapter = 0;
public boolean mSound = true;
public HashMap<String,Vector2> mPaths;
public MaxStepPhysicsWorld mPhysicsWorld;
private int mState = STATE_STOPPED;
private boolean mDragReady = false;
private boolean mCanSeeMap = true;
private float mLastScrollX = 0;
private float mLastScrollY = 0;
private int mAttempts = 0;
private long mTime = 0;
public final HashMap<Integer,Boolean>mWayPoints = new HashMap<Integer,Boolean>();
private Vector2 mGravityVector = new Vector2(0, SensorManager.GRAVITY_EARTH);
private boolean mPaused = false;
public static final long[] ANIMATION_DEFAULT = new long[]{3000,150,0};
public static final long[] ANIMATION_CONTACT = new long[]{0,0,1000};
public static Stats sStats;
public Handler data = new Handler(){
@Override
public void handleMessage(Message msg) {
new StatsTask().execute(ParticlyActivity.sStats, getApplicationContext());
}
};
public IUpdateHandler ballUpdateHandler = new IUpdateHandler(){
@SuppressWarnings("unchecked")
@Override
public void onUpdate(float pSecondsElapsed) {
mCamera.onUpdate(1.0f);
mBackground.setParallaxValue(mCamera.getCenterX(), mCamera.getCenterY());
final Body connected = mPhysicsWorld.getPhysicsConnectorManager().findBodyByShape(mBall);
if(connected != null) {
final Vector2 v = connected.getLinearVelocity();
if(mLastVelocity <= 0.5f && Math.abs(v.y) <= 0.5f && v.x != 0.0f) {
connected.setLinearDamping(2.0f);
} else {
connected.setLinearDamping(0.0f);
}
mLastVelocity = Math.abs(v.y);
if(mLine != null) {
mLine.setPosition(mBall.getX()+(mBall.getWidth()/2), mBall.getY()+(mBall.getHeight()/2), mLine.getX2(), mLine.getY2());
}
if(mBall.getX() > mCamera.getBoundsWidth()+50 || mBall.getX() < -100 || mBall.getY() > mCamera.getBoundsHeight()+50) {
gameOver();
} else if(mBall.getY() < -100) {
mArrow.setVisible(true);
mArrow.setPosition(mBall.getX(), -100);
} else {
mArrow.setVisible(false);
}
}
final HashMap<String,String> userData = (HashMap<String, String>) mBall.getUserData();
if(userData.containsKey("teleport")) {
final Teleporter teleporter = mTeleports.get(userData.get("teleport"));
Body body = mPhysicsWorld.getPhysicsConnectorManager().findBodyByShape(mBall);
body.setTransform(teleporter.getVector(), 0.0f);
userData.remove("teleport");
mBall.setUserDat
Geminilyj
- 粉丝: 32
- 资源: 20
最新资源
- 《铭仕基本法》(2006年定稿版)-17页.doc
- 海尔企业文化手册.doc
- xx有限公司企业文化手册.doc
- 【案例分析】企业文化案例精选.doc
- 陕西省地方电力集团公司企业文化手册道德礼仪规范.doc
- 微信小程序 实现计算器代码
- 01-【目标体系构建】-企业文化建设规划与实施细则方案撰写指导说明.doc
- 03-【目标体系构建】-企业文化建设工作任务分解与工作推进表.docx
- 02-【目标体系构建】-企业文化建设三年实施规划甘特图.docx
- 04-【识别体系构建】-员工行为规范制定指导书.doc
- 07-【保障体系构建】-职务说明书——企业文化专员.doc
- 06-【保障体系构建】-职务说明书——企业文化建设职能部门(负责人).doc
- 08-【保障体系构建】-企业文化建设经费预算表(年度).doc.docx
- 12-【保障体系构建】-企业文化培训成本费用预算表.doc.docx
- 10-【保障体系构建】-企业文化培训效果综合评估表.doc.docx
- 11-【保障体系构建】-企业文化培训计划表.doc.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页