diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/CustomCameraActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/CustomCameraActivity.java new file mode 100644 index 00000000..e07f4d81 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/CustomCameraActivity.java @@ -0,0 +1,172 @@ +package skyward.com.camera; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.ImageFormat; +import android.hardware.Camera; +import android.os.Bundle; +import android.util.Log; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.View; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * 自定义相机 + * 1.创建Camera对象 + * 2.创建SurfaceView对象 + * 3.关联Camera对象和SurfaceView对象 + * 4.调整相机的显示效果 + * 5.自定义相机预览界面 + * Created by skyward on 2016/4/29. + */ +public class CustomCameraActivity extends Activity implements SurfaceHolder.Callback{ + private static final String TAG = "CustomCameraActivity"; + private Camera mCamera; + private SurfaceView mPreview; + private SurfaceHolder mHolder; + private Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { + @Override + public void onPictureTaken(byte[] data, Camera camera) { + //生成照片 + File tempFile = new File("/sdcard/temp.png"); + try { + FileOutputStream fos = new FileOutputStream(tempFile); + fos.write(data); + fos.close(); + Intent intent = new Intent(CustomCameraActivity.this, ResultActivity.class); + Log.d(TAG, "onPictureTaken: " + tempFile.getAbsolutePath()); + intent.putExtra("picPath", tempFile.getAbsolutePath()); + startActivity(intent); + CustomCameraActivity.this.finish(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_custom_camera); + //2.创建SurfaceView对象 + mPreview = (SurfaceView) findViewById(R.id.preview); + // 点击屏幕时自动对焦 + mPreview.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mCamera.autoFocus(null); + } + }); + //获取SurfaceHolder对象 + mHolder = mPreview.getHolder(); + mHolder.addCallback(this); + } + + /** + * 拍照 + * @param view + */ + public void capture(View view) { + //4.调整相机的显示效果 + //参数设置 + Camera.Parameters parameters = mCamera.getParameters(); + //设置照片格式 + parameters.setPictureFormat(ImageFormat.JPEG); + parameters.setPreviewSize(1280, 720); + //设置对焦模式为自动对焦 + parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); + mCamera.autoFocus(new Camera.AutoFocusCallback() { + @Override + public void onAutoFocus(boolean success, Camera camera) { + //当对焦成功,则拍照 + if (success) { + mCamera.takePicture(null, null, mPictureCallback); + } + } + }); + } + + @Override + protected void onResume() { + super.onResume(); + if(mCamera == null) { + // 1.创建Camera对象 + mCamera = getCamera(); + if (mHolder != null) { + setStartPreview(mCamera, mHolder); + } + } + } + + @Override + protected void onPause() { + super.onPause(); + releaseCamera(); + } + + /** + * 获取系统Camera对象 + * @return + */ + private Camera getCamera() { + Camera camera; + try { + camera = Camera.open(); + } catch (Exception e) { + camera = null; + e.printStackTrace(); + } + return camera; + } + + /** + * 开始预览相机内容 + */ + private void setStartPreview(Camera camera, SurfaceHolder holder) { + try { + //3.关联Camera对象和SurfaceView对象 + camera.setPreviewDisplay(holder); + //系统默认横屏显示 + //因此要将系统camera预览角度调整90度 + camera.setDisplayOrientation(90); + camera.startPreview(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 释放相机资源 + */ + private void releaseCamera() { + if (mCamera != null) { + mCamera.setPreviewCallback(null); + mCamera.stopPreview(); + mCamera.release(); + mCamera = null; + } + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + setStartPreview(mCamera, mHolder); + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + mCamera.stopPreview(); + setStartPreview(mCamera, mHolder); + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + releaseCamera(); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_BaseActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_BaseActivity.java new file mode 100644 index 00000000..9446dea6 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_BaseActivity.java @@ -0,0 +1,24 @@ +package skyward.com.myapplication; + +import android.app.Activity; +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.view.Window; +import android.view.WindowManager; + +public class FeiJi_BaseActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + this.requestWindowFeature(Window.FEATURE_NO_TITLE); + this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + this.getWindow().setFlags( + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_Main.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_Main.java new file mode 100644 index 00000000..07a508e4 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_Main.java @@ -0,0 +1,73 @@ +package skyward.com.myapplication; + +import org.cocos2d.layers.CCScene; +import org.cocos2d.nodes.CCDirector; +import org.cocos2d.nodes.CCTextureCache; +import org.cocos2d.opengl.CCGLSurfaceView; +import org.cocos2d.types.ccColor4B; + +import com.baidu.mobstat.StatService; + +import android.os.Bundle; + +public class FeiJi_Main extends FeiJi_BaseActivity { + + private CCGLSurfaceView _FeiJi_Surface; + private CCScene _FeiJi_Scene; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + _FeiJi_Surface = new CCGLSurfaceView(this); + setContentView(_FeiJi_Surface); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + CCDirector.sharedDirector().end(); + CCTextureCache.sharedTextureCache().removeAllTextures(); + } + + @Override + protected void onPause() { + super.onPause(); + CCDirector.sharedDirector().pause(); + StatService.onPause(this); + } + + @Override + protected void onResume() { + super.onResume(); + CCDirector.sharedDirector().resume(); + StatService.onResume(this); + } + + @Override + protected void onStart() { + super.onStart(); + // cocos2d��ϰ�������½���Ϊԭ��,ʱ�䵥λ���� + CCDirector.sharedDirector().attachInView(_FeiJi_Surface);// ��cocos2d����GLSurfaceView��������� + // CCDirector.sharedDirector().setDeviceOrientation( + // CCDirector.kCCDeviceOrientationLandscapeLeft); + // CCDirector.sharedDirector().setDisplayFPS(true);//��ʾ FPS + // CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);// + // ÿ������� + _FeiJi_Scene = CCScene.node(); + + FeiJi_PlayActivity _Layer = new FeiJi_PlayActivity(ccColor4B.ccc4(255, 255, 255, 255)); +// _Layer.GetContext(FeiJi_Main.this); + _FeiJi_Scene.addChild(_Layer); + + CCDirector.sharedDirector().runWithScene(_FeiJi_Scene);// ���г��� + + CCDirector.sharedDirector().pause(); + } + + @Override + protected void onStop() { + // TODO Auto-generated method stub + super.onStop(); + CCDirector.sharedDirector().end(); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_MenuActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_MenuActivity.java new file mode 100644 index 00000000..035d7e4d --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_MenuActivity.java @@ -0,0 +1,78 @@ +package skyward.com.myapplication; + +import com.baidu.mobstat.StatService; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; + +public class FeiJi_MenuActivity extends FeiJi_BaseActivity { + + private Button _FeiJi_Button_New, _FeiJi_Button_Score, + _FeiJi_Button_Exit; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.feiji_menu); + Init(); + } + + private void Init() { + // TODO Auto-generated method stub + _FeiJi_Button_New = (Button) findViewById(R.id.feiji_bu_new); + _FeiJi_Button_Score = (Button) findViewById(R.id.feiji_bu_score); + _FeiJi_Button_Exit = (Button) findViewById(R.id.feiji_bu_exit); + + _FeiJi_Button_New.setOnClickListener(new OnClick()); + _FeiJi_Button_Score.setOnClickListener(new OnClick()); + _FeiJi_Button_Exit.setOnClickListener(new OnClick()); + } + + private class OnClick implements OnClickListener { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + switch (v.getId()) { + case R.id.feiji_bu_new: + Intent intent = new Intent(FeiJi_MenuActivity.this, FeiJi_Main.class); + startActivity(intent); + finish(); + break; + + case R.id.feiji_bu_score: + Intent i = new Intent(FeiJi_MenuActivity.this, FeiJi_ScoreActivity.class); + startActivity(i); + break; + + case R.id.feiji_bu_exit: + finish(); + break; + } + } + + } + + public void onResume() { + super.onResume(); + + /** + * ҳ����ʼ��ÿ��Activity�ж���Ҫ��ӣ�����м̳еĸ�Activity���Ѿ�����˸õ��ã���ô��Activity����ز�����ӣ� + * ������StatService.onPageStartһ��onPageEnd��������ʹ�� + */ + StatService.onResume(this); + } + + public void onPause() { + super.onPause(); + + /** + * ҳ�������ÿ��Activity�ж���Ҫ��ӣ�����м̳еĸ�Activity���Ѿ�����˸õ��ã���ô��Activity����ز�����ӣ� + * ������StatService.onPageStartһ��onPageEnd��������ʹ�� + */ + StatService.onPause(this); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_PlayActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_PlayActivity.java new file mode 100644 index 00000000..05ceb042 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_PlayActivity.java @@ -0,0 +1,982 @@ +package skyward.com.myapplication; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.cocos2d.actions.base.CCFiniteTimeAction; +import org.cocos2d.actions.instant.CCCallFuncN; +import org.cocos2d.actions.interval.CCAnimate; +import org.cocos2d.actions.interval.CCMoveBy; +import org.cocos2d.actions.interval.CCMoveTo; +import org.cocos2d.actions.interval.CCSequence; +import org.cocos2d.layers.CCColorLayer; +import org.cocos2d.nodes.CCAnimation; +import org.cocos2d.nodes.CCDirector; +import org.cocos2d.nodes.CCLabel; +import org.cocos2d.nodes.CCSprite; +import org.cocos2d.nodes.CCSpriteFrame; +import org.cocos2d.nodes.CCSpriteSheet; +import org.cocos2d.types.CGPoint; +import org.cocos2d.types.CGRect; +import org.cocos2d.types.CGSize; +import org.cocos2d.types.ccColor3B; +import org.cocos2d.types.ccColor4B; + +import android.app.Dialog; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.TextView; + +public class FeiJi_PlayActivity extends CCColorLayer { + + private List _Foes = new CopyOnWriteArrayList(); + private List _BigFoes = new CopyOnWriteArrayList(); + private List _Shots = new CopyOnWriteArrayList(); + private List _Red_Bombs = new CopyOnWriteArrayList(); + private List _AllFoes = new CopyOnWriteArrayList(); + private CCLabel _ScoreLabel; + private CCLabel _Red_Bomb_Num; + private CCSprite _Red_Bomb; + private CCSprite _FeiJi_Play; + private CCSprite _FeiJi_Pause; + private CGPoint _Touch_Location; + private String _Font_Path = "Cookies.ttf"; + private String _FeiJi_Back_Path = "images/feiji_background.png"; + private String _MiddleFoe_Path_2 = "images/middlefoe_2.png"; + private String _SmallFoe_Path = "images/smallfoe.png"; + private String _MiddleFoe_Path = "images/middlefoe.png"; + private String _BigFoe_Path = "images/bigfoe.png"; + private String _BigFoe_Path2 = "images/bigfoe2.png"; + private String _BigFoe_Path_2 = "images/bigfoe_2.png"; + private String _Play_Path = "images/play.png"; + private String _Play_Path2 = "images/play2.png"; + private String _Shot_Path = "images/shot.png"; + private String _Pause_Path = "images/pause.png"; + private String _Red_Bomb_Down_Path = "images/red_bomb_down.png"; + private String _Red_Bomb_Path = "images/red_bomb.png"; + private String _Blue_Shot_Down_Path = "images/blue_shot_down.png"; + private String _Blue_Shot = "images/blue_shot.png"; + private int _Get_Score = 0;// ��õķ��� + private float _Shot_Du = 0.5f;// �ӵ��ٶ� + private boolean _Can_Move = false;// �Ƿ��ڶ������ƶ� + private CGSize _WinSize; + private int _Play_Image_Chage = 1;// �ɻ�ͼƬ�ж� + private int _BigFoe_Image_Chage = 1;// ���͵л�ͼƬ�ж� + private String _SmallFoe_Sequence_Path = "images/smallfoe_seq.png"; + private String _MiddleFoe_Sequence_Path = "images/middlefoe_seq.png"; + private String _BigFoe_Sequence_Path = "images/bigfoe_seq.png"; + private String _Play_Sequence_Path = "images/play_seq.png"; + private int _Big_Life = 16, _Middle_Life = 8, _Small_life = 2;// �л����� + private int _ChangeImage_Delay = -1;// ͼƬ�ı���ʱ + private int _Pause_OR = -1;// ��ͣ����ж� + private int Red_Bomb_Num = 0;// ��ը������ + private boolean Blue_Shot_Change = false;// �Ƿ����ӵ� + private long Blue_Shot_Last_Time = 0;// ���ӵ�����ʱ�� + private int Blue_Red_Down_Time = 30;// ���ӵ��ͺ�ը��������� + private int FoeDown_Time = 8;// �л��������ٶ� + private SharedPreferences _Share; + private String ScoreList = "0;0;0;0;0;0;0;0;0;0"; + private Dialog _Dialog; + private boolean _Invincible = false; + + protected FeiJi_PlayActivity(ccColor4B color) { + super(color); + Init(); + } + + private void Init() { + _Share = CCDirector.sharedDirector().getActivity() + .getSharedPreferences("Share", Context.MODE_PRIVATE); + _WinSize = CCDirector.sharedDirector().displaySize();// ��ȡ��Ļ��С + setIsTouchEnabled(true); + + CCSprite _FeiJi_Back = CCSprite.sprite(_FeiJi_Back_Path); + // ��������Ļ�����Ŵ� + _FeiJi_Back.setScaleX(_WinSize.width + / _FeiJi_Back.getTexture().getWidth()); + _FeiJi_Back.setScaleY(_WinSize.height + / _FeiJi_Back.getTexture().getHeight()); + _FeiJi_Back.setPosition(CGPoint.make(_WinSize.width / 2, + _WinSize.height / 2));// Ĭ�����ĵ�Ϊ���½ǣ����������ĵ��Ƶ���Ļ�м� + addChild(_FeiJi_Back);// ��������ӵ����� + + _FeiJi_Pause = CCSprite.sprite(_Pause_Path); + _FeiJi_Pause.setPosition(CGPoint.make( + _FeiJi_Pause.getContentSize().width / 2 + 1, _WinSize.height + - _FeiJi_Pause.getContentSize().height / 2 - 1)); + addChild(_FeiJi_Pause);// �����ͣ + + AddScore(); + + this.schedule("GameFoes", 0.5f);// һ��ִ��һ�� + this.schedule("GameShot", 0.2f); + GamePlay(); + this.schedule("AddPlay", 0.2f); + this.schedule("Detection", 0f); + this.schedule("AddRedBlueDown", 2.0f); + this.schedule("AddBigFoe", 0.2f); + + AddRedBomb(); + } + + public void GameFoes(float t) { + + AddFoes(); + + } + + public void GamePlay() { + + AddPlay(); + + } + + public void GameShot(float t) { + AddShot(); + } + + /** + * ��Ӻ�ɫը����ɫ�ӵ����� + */ + public void AddRedBlueDown(float t) { + // TODO Auto-generated method stub + Random rand = new Random(); + int randomValue = rand.nextInt(Blue_Red_Down_Time); + CCSprite _Red_Blue_Down = null; + + if (randomValue != 0 && randomValue != 1) { + return; + } + if (_Red_Bombs.size() >= 1) { + return; + } + + if (randomValue == 0 && _Red_Bombs.size() < 1) { + _Red_Blue_Down = CCSprite.sprite(_Red_Bomb_Down_Path); + _Red_Blue_Down.setTag(0); + } else if (randomValue == 1 && _Red_Bombs.size() < 1) { + _Red_Blue_Down = CCSprite.sprite(_Blue_Shot_Down_Path); + _Red_Blue_Down.setTag(1); + } + int minX = (int) (_Red_Blue_Down.getContentSize().width / 2.0f); + int maxX = (int) (_WinSize.width - _Red_Blue_Down.getContentSize().width / 2.0f); + int rangeX = maxX - minX; + int actualX = rand.nextInt(rangeX) + minX; + _Red_Blue_Down + .setPosition(actualX, _Red_Blue_Down.getContentSize().height + / 2.0f + _WinSize.height); + addChild(_Red_Blue_Down); + _Red_Bombs.add(_Red_Blue_Down); + CCFiniteTimeAction fs_timeAction = CCMoveTo.action(1, + CGPoint.ccp(actualX, _WinSize.height / 3 * 2));// ʱ�����ƶ� + + CCCallFuncN fs_back = CCCallFuncN.action(this, "Red_Bomb_Back"); + CCSequence fs_actions = CCSequence.actions(fs_timeAction, fs_back); + _Red_Blue_Down.runAction(fs_actions); + + } + + /** + * ��Ӻ�ɫը�� + */ + private void AddRedBomb() { + // TODO Auto-generated method stub + if (_Red_Bomb_Num != null) + _Red_Bomb_Num.removeSelf(); + if (_Red_Bomb != null) + _Red_Bomb.removeSelf(); + if (Red_Bomb_Num > 0) { + _Red_Bomb = CCSprite.sprite(_Red_Bomb_Path); + _Red_Bomb.setPosition(CGPoint.make( + _Red_Bomb.getContentSize().width / 2 + 1, + _Red_Bomb.getContentSize().height / 2 + 1)); + addChild(_Red_Bomb); + + _Red_Bomb_Num = CCLabel.makeLabel("x" + Red_Bomb_Num, _Font_Path, + 30); + _Red_Bomb_Num.setColor(ccColor3B.ccBLACK); + _Red_Bomb_Num.setPosition(CGPoint.ccp( + _Red_Bomb.getContentSize().width + 5 + + _Red_Bomb_Num.getContentSize().width / 2, + _Red_Bomb.getContentSize().height / 2)); + addChild(_Red_Bomb_Num);// ��������ӵ����� + } + + } + + /** + * ��Ӻ�ɫը�����·��� + */ + public void Red_Bomb_Back(Object sender) { + CCSprite Red_Bomb = (CCSprite) sender; + Red_Bomb.setPosition(Red_Bomb.getPosition().x, _WinSize.height / 3 * 2); + CCFiniteTimeAction fs_timeAction = CCMoveTo.action( + 0.5f, + CGPoint.ccp(Red_Bomb.getPosition().x, _WinSize.height / 3 * 2 + + _WinSize.height / 6));// ʱ�����ƶ� + CCCallFuncN fs_back = CCCallFuncN.action(this, "Red_Bomb_Back2"); + CCSequence fs_actions = CCSequence.actions(fs_timeAction, fs_back); + Red_Bomb.runAction(fs_actions); + } + + /** + * ��Ӻ�ɫը�����·��غ��½� + */ + public void Red_Bomb_Back2(Object sender) { + CCSprite Red_Bomb = (CCSprite) sender; + Red_Bomb.setPosition(Red_Bomb.getPosition().x, + _WinSize.height / 3 * 2 + 50); + CCFiniteTimeAction fs_timeAction = CCMoveTo.action( + 1.0f, + CGPoint.ccp(Red_Bomb.getPosition().x, + -(Red_Bomb.getContentSize().height / 2)));// ʱ�����ƶ� + CCCallFuncN fs_Over = CCCallFuncN.action(this, "Red_Bomb_Over"); + CCSequence fs_actions = CCSequence.actions(fs_timeAction, fs_Over); + Red_Bomb.runAction(fs_actions); + } + + /** + * ��ӵл� + */ + private void AddFoes() { + + Random rand = new Random(); + int randomValue = rand.nextInt(30); + FeiJi_SpriteActivity _FeiJi_Foe = new FeiJi_SpriteActivity(); + _FeiJi_Foe.setClicked_Or(false); + if (randomValue == 0 && _BigFoes.size() < 1) { + _FeiJi_Foe.setLift(_Big_Life); + _FeiJi_Foe.setMax_Life(_Big_Life); + _FeiJi_Foe.setCCSprite(_BigFoe_Path); + FoeDown(_FeiJi_Foe, 0); + } else if (randomValue == 1 || randomValue == 2) { + _FeiJi_Foe.setLift(_Middle_Life); + _FeiJi_Foe.setMax_Life(_Middle_Life); + _FeiJi_Foe.setCCSprite(_MiddleFoe_Path); + FoeDown(_FeiJi_Foe, 1); + } else { + _FeiJi_Foe.setLift(_Small_life); + _FeiJi_Foe.setMax_Life(_Small_life); + _FeiJi_Foe.setCCSprite(_SmallFoe_Path); + FoeDown(_FeiJi_Foe, 2); + } + _AllFoes.add(_FeiJi_Foe); + + } + + /** + * �ı���ҿ��Ʒɻ�ͼƬ + */ + public void AddPlay(float t) { + _Play_Image_Chage = -_Play_Image_Chage; + if (_FeiJi_Play != null) { + _FeiJi_Play.removeSelf(); + } + if (_Play_Image_Chage == 1) { + _FeiJi_Play = CCSprite.sprite(_Play_Path); + } else { + _FeiJi_Play = CCSprite.sprite(_Play_Path2); + } + if (_Touch_Location == null) { + _Touch_Location = CCDirector.sharedDirector().convertToGL( + CGPoint.ccp(_WinSize.width / 2, _WinSize.height + - _FeiJi_Play.getContentSize().height / 2)); + } + _FeiJi_Play.setPosition(_Touch_Location.x, _Touch_Location.y); + addChild(_FeiJi_Play); + } + + /** + * �����ҿ��Ʒɻ� + */ + private void AddPlay() { + _FeiJi_Play = CCSprite.sprite(_Play_Path); + _FeiJi_Play.setPosition(_WinSize.width / 2, + _FeiJi_Play.getContentSize().height / 2); + addChild(_FeiJi_Play); + } + + /** + * �ı���͵л�ͼƬ + */ + public void AddBigFoe(float t) { + if (_BigFoes.size() > 0) { + _BigFoe_Image_Chage = -_BigFoe_Image_Chage; + FeiJi_SpriteActivity BigFoe = (FeiJi_SpriteActivity) _BigFoes.get(0); + if (_Play_Image_Chage == 1) + ChageSpriteBack(BigFoe, false, _BigFoe_Path, 0); + else + ChageSpriteBack(BigFoe, false, _BigFoe_Path2, 0); + BigFoe.getCCSprite().removeSelf(); + _BigFoes.remove(0); + } + + } + + /** + * ��ӷɻ��ӵ� + */ + private void AddShot() { + CCSprite _FeiJi_Shot = null; + + if (Blue_Shot_Change) { + _FeiJi_Shot = CCSprite.sprite(_Blue_Shot); + _FeiJi_Shot.setTag(1); + if (System.currentTimeMillis() - Blue_Shot_Last_Time > 10000) { + Blue_Shot_Change = false; + } + } else { + _FeiJi_Shot = CCSprite.sprite(_Shot_Path); + _FeiJi_Shot.setTag(0); + } + + float localX = 0, localY = 0; + + if (_Touch_Location == null) { + localX = _WinSize.width / 2; + localY = _FeiJi_Play.getContentSize().height + + _FeiJi_Shot.getContentSize().height / 2; + } else { + localX = _Touch_Location.x; + localY = _Touch_Location.y + _FeiJi_Play.getContentSize().height + / 2 + _FeiJi_Shot.getContentSize().height / 2; + } + + _FeiJi_Shot.setPosition(localX, localY); + addChild(_FeiJi_Shot); + + _Shots.add(_FeiJi_Shot); + + // ��ʱ�����ƶ���Ŀ�ĵ� + CCFiniteTimeAction fs_timeAction = CCMoveBy.action(_Shot_Du, CGPoint + .ccp(localX - localX, _FeiJi_Shot.getContentSize().height / 2 + + _WinSize.height));// CCMoveBy���������൱�ڴӵ�ǰ�㿪ʼ������ĵ�Ĵ�С�����ƶ������λ�� + CCCallFuncN fs_Over = null; + fs_Over = CCCallFuncN.action(this, "Shot_Over"); + + CCSequence fs_actions = CCSequence.actions(fs_timeAction, fs_Over);// ѭ������ + _FeiJi_Shot.runAction(fs_actions); + } + + /** + * ��ӵл����� + */ + private void FoeDown(FeiJi_SpriteActivity _FeiJi_Foe2, int i) { + Random rand = new Random(); + int minX = (int) (_FeiJi_Foe2.getCCSprite().getContentSize().width / 2.0f); + int maxX = (int) (_WinSize.width - _FeiJi_Foe2.getCCSprite() + .getContentSize().width / 2.0f); + int rangeX = maxX - minX; + int actualX = rand.nextInt(rangeX) + minX; + int minDuration = FoeDown_Time - 4; + int maxDuration = FoeDown_Time; + if (_Get_Score > 1000000) { + maxDuration = FoeDown_Time - 2; + minDuration = FoeDown_Time - 5; + } + int rangeDuration = maxDuration - minDuration; + int actualDuration = rand.nextInt(rangeDuration) + minDuration; + if (actualDuration < 0) { + actualDuration = rand.nextInt(2) + 2; + } + + _FeiJi_Foe2.setInitX(actualX); + _FeiJi_Foe2.setInitDuration(actualDuration); + _FeiJi_Foe2.setInitY(_FeiJi_Foe2.getCCSprite().getContentSize().height + / 2.0f + _WinSize.height); + + _FeiJi_Foe2.getCCSprite().setPosition( + actualX, + _FeiJi_Foe2.getCCSprite().getContentSize().height / 2.0f + + _WinSize.height); + addChild(_FeiJi_Foe2.getCCSprite()); + + if (i == 0) { + _FeiJi_Foe2.getCCSprite().setTag(0); + _BigFoes.add(_FeiJi_Foe2); + } else { + if (i == 1) { + _FeiJi_Foe2.getCCSprite().setTag(1); + } else { + _FeiJi_Foe2.getCCSprite().setTag(2); + } + _Foes.add(_FeiJi_Foe2); + } + + CCFiniteTimeAction fs_timeAction = CCMoveTo.action(actualDuration, + CGPoint.ccp(actualX, -(_FeiJi_Foe2.getCCSprite() + .getContentSize().height / 2)));// ʱ�����ƶ� + CCCallFuncN fs_Over = null; + if (i == 0) + fs_Over = CCCallFuncN.action(this, "BigFoe_Over"); + else + fs_Over = CCCallFuncN.action(this, "Foe_Over"); + + CCSequence fs_actions = CCSequence.actions(fs_timeAction, fs_Over); + _FeiJi_Foe2.getCCSprite().runAction(fs_actions); + } + + /** + * ����ʱ���λ�ã���ӵл����� + */ + private void Down(FeiJi_SpriteActivity _FeiJi_Foe, int i, float y) { + + _FeiJi_Foe.getCCSprite().setPosition(_FeiJi_Foe.getInitX(), y); + addChild(_FeiJi_Foe.getCCSprite()); + + if (i == 0) { + _FeiJi_Foe.getCCSprite().setTag(0); + _BigFoes.add(_FeiJi_Foe); + } else { + if (i == 1) { + _FeiJi_Foe.getCCSprite().setTag(1); + } else { + _FeiJi_Foe.getCCSprite().setTag(2); + } + _Foes.add(_FeiJi_Foe); + } + + CCFiniteTimeAction fs_timeAction = CCMoveTo.action(_FeiJi_Foe + .getInitDuration(), CGPoint.ccp(_FeiJi_Foe.getInitX(), + -(_FeiJi_Foe.getCCSprite().getContentSize().height / 2)));// ʱ�����ƶ� + CCCallFuncN fs_Over = null; + if (i == 0) + fs_Over = CCCallFuncN.action(this, "BigFoe_Over"); + else + fs_Over = CCCallFuncN.action(this, "Foe_Over"); + + CCSequence fs_actions = CCSequence.actions(fs_timeAction, fs_Over); + _FeiJi_Foe.getCCSprite().runAction(fs_actions); + } + + /** + * ��ӽ�������л� + */ + public void Foe_Over(Object sender) { + CCSprite foe_over = (CCSprite) sender; + foe_over.removeSelf(); + + for (int i = 0; i < _Foes.size(); i++) { + FeiJi_SpriteActivity foe = _Foes.get(i); + if (foe.getCCSprite() == foe_over) { + _Foes.remove(i); + break; + } + } + } + + /** + * ��ӽ�������л� + */ + public void BigFoe_Over(Object sender) { + CCSprite bigfoe_over = (CCSprite) sender; + bigfoe_over.removeSelf(); + + for (int i = 0; i < _BigFoes.size(); i++) { + FeiJi_SpriteActivity foe = _BigFoes.get(i); + if (foe.getCCSprite() == bigfoe_over) { + _BigFoes.remove(i); + break; + } + } + + } + + /** + * ��ӽ�������ӵ� + */ + public void Shot_Over(Object sender) { + CCSprite shot_over = (CCSprite) sender; + _Shots.remove(shot_over); + shot_over.removeSelf(); + } + + /** + * ��ӽ��������ɫը�� + */ + public void Red_Bomb_Over(Object sender) { + CCSprite bomb_over = (CCSprite) sender; + bomb_over.removeSelf(); + _Red_Bombs.remove(bomb_over); + } + + @Override + public boolean ccTouchesBegan(MotionEvent event) { + // TODO Auto-generated method stub + CGPoint Location = CCDirector.sharedDirector().convertToGL( + CGPoint.ccp(event.getX(), event.getY()));// ��ȡ���λ�� + CGRect Rect = _FeiJi_Play.getBoundingBox(); + CGRect Rect2 = _FeiJi_Pause.getBoundingBox(); + CGRect Rect3 = null; + if (_Red_Bomb != null) + Rect3 = _Red_Bomb.getBoundingBox(); + if (CGRect.containsPoint(Rect, Location) && _Pause_OR != 1) {// �ж��Ƿ��������Ʒɻ� + _Can_Move = true; + } else { + _Can_Move = false; + if (CGRect.containsPoint(Rect2, Location)) { + _Pause_OR = -_Pause_OR; + if (_Pause_OR == 1) { + CCDirector.sharedDirector().pause(); + } else { + CCDirector.sharedDirector().resume(); + } + } + if (_Pause_OR != 1) { + if (_Red_Bomb != null && CGRect.containsPoint(Rect3, Location) + && Red_Bomb_Num > 0) { + Red_Bomb_Num--; + AddRedBomb(); + ReMoveAll(); + } + } + } + + return super.ccTouchesBegan(event); + } + + @Override + public boolean ccTouchesEnded(MotionEvent event) { + // TODO Auto-generated method stub + return super.ccTouchesEnded(event); + } + + @Override + public boolean ccTouchesMoved(MotionEvent event) { + // TODO Auto-generated method stub + if (_Can_Move) { + _Touch_Location = CCDirector.sharedDirector().convertToGL( + CGPoint.ccp(event.getX(), event.getY())); + _FeiJi_Play.setPosition(_Touch_Location.x, _Touch_Location.y); + } + return super.ccTouchesMoved(event); + } + + /** + * ���Ʒɻ�����ײ + */ + private void PlayOver() { + CGRect Rect = _FeiJi_Play.getBoundingBox(); + CGRect Rect3 = CGRect.make(Rect.origin.x + (Rect.size.width / 3.2f), + Rect.origin.y, (Rect.size.width / 3.2f), Rect.size.height); + for (int j = 0; j < _BigFoes.size(); j++) { + FeiJi_SpriteActivity BigFoe = (FeiJi_SpriteActivity) _BigFoes.get(j); + CGRect Rect2 = BigFoe.getCCSprite().getBoundingBox(); + if (CGRect.intersects(Rect2, Rect3)) { + StopSchedule(); + AddSpriteAnimal(BigFoe.getCCSprite().getPosition(), + _BigFoe_Sequence_Path, 164, 245, 6); + BigFoe.getCCSprite().removeSelf(); + _BigFoes.remove(j); + AddPlaySpriteAnimal(_FeiJi_Play.getPosition(), + _Play_Sequence_Path, 99, 123, 4); + _FeiJi_Play.removeSelf(); + } + } + for (int j = 0; j < _Foes.size(); j++) { + FeiJi_SpriteActivity Foe = _Foes.get(j); + CGRect Rect2 = Foe.getCCSprite().getBoundingBox(); + if (CGRect.intersects(Rect2, Rect3)) { + StopSchedule(); + if (Foe.getCCSprite().getTag() == 2) { + AddSpriteAnimal(Foe.getCCSprite().getPosition(), + _SmallFoe_Sequence_Path, 52, 52, 3); + } else { + AddSpriteAnimal(Foe.getCCSprite().getPosition(), + _MiddleFoe_Sequence_Path, 69, 87, 4); + } + Foe.getCCSprite().removeSelf(); + _Foes.remove(j); + AddPlaySpriteAnimal(_FeiJi_Play.getPosition(), + _Play_Sequence_Path, 99, 123, 4); + _FeiJi_Play.removeSelf(); + } + } + } + + /** + * ֹͣ�����ķ��� + */ + private void StopSchedule() { + this.unschedule("GameFoes"); + this.unschedule("GameShot"); + this.unschedule("AddPlay"); + this.unschedule("Detection"); + this.unschedule("AddRedBlueDown"); + } + + /** + * ��ײ���� + * + * @param t + */ + public void Detection(float t) { + + for (int i = 0; i < _Shots.size(); i++) { + CCSprite Shot = _Shots.get(i); + CGRect Rect = Shot.getBoundingBox(); + for (int j = 0; j < _BigFoes.size(); j++) { + FeiJi_SpriteActivity BigFoe = (FeiJi_SpriteActivity) _BigFoes.get(j); + CGRect Rect2 = BigFoe.getCCSprite().getBoundingBox(); + if (CGRect.intersects(Rect2, Rect)) {// �ж���ײ + _ChangeImage_Delay = 0; + if (Shot.getTag() == 1) + BigFoe.Life -= 2; + else + BigFoe.Life--; + _Shots.remove(Shot); + Shot.removeSelf(); + if (BigFoe.Life <= 0) {// �������� �ɻ���ʧ + BigFoe.getCCSprite().removeSelf(); + _BigFoes.remove(j); + ChageScore(30000); + AddSpriteAnimal(BigFoe.getCCSprite().getPosition(), + _BigFoe_Sequence_Path, 164, 245, 6); + } else { + ChageSpriteBack(BigFoe, true, _BigFoe_Path_2, 0); + BigFoe.getCCSprite().removeSelf(); + _BigFoes.remove(j); + } + } else { + _ChangeImage_Delay++; + if (BigFoe.getClicked_Or() && _ChangeImage_Delay >= 10) { + ChageSpriteBack(BigFoe, false, _BigFoe_Path, 0); + BigFoe.getCCSprite().removeSelf(); + _BigFoes.remove(j); + } + } + } + for (int j = 0; j < _Foes.size(); j++) { + FeiJi_SpriteActivity Foe = _Foes.get(j); + CGRect Rect2 = Foe.getCCSprite().getBoundingBox(); + if (CGRect.intersects(Rect2, Rect)) { + _ChangeImage_Delay = 0; + if (Shot.getTag() == 1) + Foe.Life -= 2; + else + Foe.Life--; + _Shots.remove(Shot); + Shot.removeSelf(); + if (Foe.Life <= 0) { + if (Foe.getCCSprite().getTag() == 2) { + ChageScore(1000); + AddSpriteAnimal(Foe.getCCSprite().getPosition(), + _SmallFoe_Sequence_Path, 52, 52, 3); + } else { + ChageScore(6000); + AddSpriteAnimal(Foe.getCCSprite().getPosition(), + _MiddleFoe_Sequence_Path, 69, 87, 4); + } + Foe.getCCSprite().removeSelf(); + _Foes.remove(j); + } else { + if (Foe.getCCSprite().getTag() == 2) { + + } else { + ChageSpriteBack(Foe, true, _MiddleFoe_Path_2, 1); + Foe.getCCSprite().removeSelf(); + _Foes.remove(j); + } + } + } else { + _ChangeImage_Delay++; + if (Foe.getClicked_Or() && _ChangeImage_Delay >= 10) { + if (Foe.getCCSprite().getTag() == 2) { + + } else { + ChageSpriteBack(Foe, false, _MiddleFoe_Path, 1); + Foe.getCCSprite().removeSelf(); + _Foes.remove(j); + } + } + } + + } + } + + for (int i = 0; i < _Red_Bombs.size(); i++) { + CCSprite bomb = _Red_Bombs.get(i); + CGRect Rect = bomb.getBoundingBox(); + CGRect Rect2 = _FeiJi_Play.getBoundingBox(); + if (CGRect.intersects(Rect2, Rect)) { + bomb.removeSelf(); + _Red_Bombs.remove(bomb); + if (bomb.getTag() == 0) { + Red_Bomb_Num++; + AddRedBomb(); + } else { + Blue_Shot_Change = true; + Blue_Shot_Last_Time = System.currentTimeMillis(); + } + } + } + if (!_Invincible) { + PlayOver(); + } + } + + /** + * �����ǰ���ел� + */ + private void ReMoveAll() { + List _FoesAll = _Foes; + List _BigFoesAll = _BigFoes; + for (int j = 0; j < _FoesAll.size(); j++) { + FeiJi_SpriteActivity Foe = _FoesAll.get(j); + Foe.Life = 0; + if (Foe.Life <= 0) { + if (Foe.getCCSprite().getTag() == 2) { + ChageScore(1000); + AddSpriteAnimal(Foe.getCCSprite().getPosition(), + _SmallFoe_Sequence_Path, 52, 52, 3); + } else { + ChageScore(6000); + AddSpriteAnimal(Foe.getCCSprite().getPosition(), + _MiddleFoe_Sequence_Path, 69, 87, 4); + } + Foe.getCCSprite().removeSelf(); + } + } + _Foes.removeAll(_FoesAll); + for (int j = 0; j < _BigFoesAll.size(); j++) { + FeiJi_SpriteActivity BigFoe = (FeiJi_SpriteActivity) _BigFoesAll.get(j); + BigFoe.Life = 0; + if (BigFoe.Life <= 0) { + BigFoe.getCCSprite().removeSelf(); + ChageScore(30000); + AddSpriteAnimal(BigFoe.getCCSprite().getPosition(), + _BigFoe_Sequence_Path, 164, 245, 6); + } + } + _BigFoes.removeAll(_BigFoesAll); + } + + /** + * �����ı� + * + * @param score + */ + private void ChageScore(int score) { + _Get_Score += score; + AddScore(); + + } + + /** + * ��ӷ��� + */ + private void AddScore() { + if (_ScoreLabel != null) + _ScoreLabel.removeSelf(); + _ScoreLabel = CCLabel.makeLabel("SCORE:" + _Get_Score, _Font_Path, 30); + _ScoreLabel.setColor(ccColor3B.ccWHITE); + _ScoreLabel.setString("SCORE:" + _Get_Score); + _ScoreLabel.setPosition(CGPoint.ccp(_FeiJi_Pause.getContentSize().width + + 5 + _ScoreLabel.getTexture().getWidth() / 2, _WinSize.height + - _FeiJi_Pause.getContentSize().height / 2)); + addChild(_ScoreLabel);// ��������ӵ����� + } + + /** + * ��ӵл���ʧ���� + */ + private void AddSpriteAnimal(CGPoint touchRect, String Path, int CutW, + int CutH, int Cut) { + + CCSpriteSheet boomSheet = CCSpriteSheet.spriteSheet(Path); + + this.addChild(boomSheet); + + CCSprite Sprite = CCSprite.sprite(boomSheet.getTexture(), + CGRect.make(0, 0, CutW, CutH)); + boomSheet.addChild(Sprite); + Sprite.setPosition(touchRect.x, touchRect.y); + int frameCount = 0; + + ArrayList boomAnimFrames = new ArrayList(); + + for (int y = 0; y < 1; y++) { + for (int x = 0; x < Cut; x++) { + CCSpriteFrame frame = CCSpriteFrame.frame( + boomSheet.getTexture(), + CGRect.make(x * CutW, y * CutH, CutW, CutH), + CGPoint.ccp(0, 0)); + boomAnimFrames.add(frame); + frameCount++; + if (frameCount == Cut) + break; + } + } + CCAnimation boomAnimation = CCAnimation.animation("", (float) 0.1, + boomAnimFrames); + + CCAnimate boomAction = CCAnimate.action(boomAnimation); + + CCCallFuncN actionAnimateDone = CCCallFuncN.action(this, + "SpriteAnimationFinished"); + CCSequence actions = CCSequence.actions(boomAction, actionAnimateDone); + + Sprite.runAction(actions); + } + + /** + * ���������ʧ���� + */ + private void AddPlaySpriteAnimal(CGPoint touchRect, String Path, int CutW, + int CutH, int Cut) { + + CCSpriteSheet boomSheet = CCSpriteSheet.spriteSheet(Path); + + this.addChild(boomSheet); + + CCSprite Sprite = CCSprite.sprite(boomSheet.getTexture(), + CGRect.make(0, 0, CutW, CutH)); + boomSheet.addChild(Sprite); + Sprite.setPosition(touchRect.x, touchRect.y); + int frameCount = 0; + + ArrayList boomAnimFrames = new ArrayList(); + + for (int y = 0; y < 1; y++) { + for (int x = 0; x < Cut; x++) { + CCSpriteFrame frame = CCSpriteFrame.frame( + boomSheet.getTexture(), + CGRect.make(x * CutW, y * CutH, CutW, CutH), + CGPoint.ccp(0, 0)); + boomAnimFrames.add(frame); + frameCount++; + if (frameCount == Cut) + break; + } + } + CCAnimation boomAnimation = CCAnimation.animation("", (float) 0.2, + boomAnimFrames); + + CCAnimate boomAction = CCAnimate.action(boomAnimation); + + CCCallFuncN actionAnimateDone = CCCallFuncN.action(this, + "PlaySpriteAnimationFinished"); + CCSequence actions = CCSequence.actions(boomAction, actionAnimateDone); + + Sprite.runAction(actions); + } + + /** + * �����л���ʧ���� + */ + public void SpriteAnimationFinished(Object sender) { + CCSprite SpriteFinished = (CCSprite) sender; + SpriteFinished.removeSelf(); + } + + /** + * ����������ʧ���� + */ + public void PlaySpriteAnimationFinished(Object sender) { + if (_Share != null) { + if (_Share != null) + ScoreList = _Share.getString("SCORE", "0;0;0;0;0;0;0;0;0;0"); + String[] Scores = ScoreList.split(";"); + String[] Scores2 = ScoreList.split(";"); + String _Score_Value = ""; + boolean or = false; + for (int i = 0; i < Scores.length; i++) { + if (_Get_Score > Integer.valueOf(Scores[i]) && !or) { + Scores[i] = _Get_Score + ""; + or = true; + int j = i; + while (j < Scores.length - 1) { + Scores[j + 1] = Scores2[j]; + j++; + } + } + if (i >= Scores.length - 1) + _Score_Value += Scores[i]; + else + _Score_Value += Scores[i] + ";"; + } + Editor e = _Share.edit(); + e.putString("SCORE", _Score_Value); + e.commit(); + } + CCSprite SpriteFinished = (CCSprite) sender; + SpriteFinished.removeSelf(); + ShowDialog(); + } + + /** + * ���и����л�ͼƬ + * + * @param Foe + * @param Click + * @param Path + * @param i + */ + private void ChageSpriteBack(FeiJi_SpriteActivity Foe, boolean Click, String Path, + int i) { + FeiJi_SpriteActivity _FeiJi_Foe = new FeiJi_SpriteActivity(); + _FeiJi_Foe.setClicked_Or(Click); + _FeiJi_Foe.setLift(Foe.Life); + _FeiJi_Foe.setCCSprite(Path); + _FeiJi_Foe.setInitX(Foe.getInitX()); + _FeiJi_Foe.setInitY(Foe.getCCSprite().getPosition().y); + float _sudu = (Foe.getInitY() + _FeiJi_Foe.getCCSprite() + .getContentSize().height / 2.0f) + / (float) Foe.getInitDuration(); + float time = ((Foe.getCCSprite().getPosition().y + _FeiJi_Foe + .getCCSprite().getContentSize().height / 2.0f) / _sudu); + _FeiJi_Foe.setInitDuration(time); + Down(_FeiJi_Foe, i, Foe.getCCSprite().getPosition().y); + Foe.getCCSprite().removeSelf(); + } + + private void ShowDialog() { + CCDirector.sharedDirector().getActivity().runOnUiThread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + LayoutInflater inflater = LayoutInflater.from(CCDirector + .sharedDirector().getActivity()); + View v = inflater.inflate(R.layout.feiji_dialog, null);// �õ�����view + _Dialog = new Dialog(CCDirector.sharedDirector().getActivity(), + R.style.Dialog_Style); + _Dialog.setCancelable(false); + _Dialog.setCanceledOnTouchOutside(false); + _Dialog.setContentView(v);// ���ò��� + _Dialog.show(); + TextView _Score_TV = (TextView) v + .findViewById(R.id.feiji_dialog_score); + _Score_TV.setText(_Get_Score + ""); + Button _Return = (Button) v + .findViewById(R.id.feiji_dialog_return); + _Return.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + IntentToBack(); + _Dialog.dismiss(); + } + }); + } + }); + + } + + private void IntentToBack() { + Intent mainScore = new Intent( + CCDirector.sharedDirector().getActivity(), FeiJi_MenuActivity.class); + CCDirector.sharedDirector().getActivity().startActivity(mainScore); + CCDirector.sharedDirector().getActivity().finish(); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_ScoreActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_ScoreActivity.java new file mode 100644 index 00000000..19acff0e --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_ScoreActivity.java @@ -0,0 +1,117 @@ +package skyward.com.myapplication; + +import com.baidu.mobstat.StatService; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.TextView; + +public class FeiJi_ScoreActivity extends FeiJi_BaseActivity { + + private SharedPreferences _Share; + private ListView _ListView; + private ScoreListAda _Adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.feiji_score); + Init(); + } + + private void Init() { + _Share = getSharedPreferences("Share", Context.MODE_PRIVATE); + String _Score = _Share.getString("SCORE", "0;0;0;0;0;0;0;0;0;0"); + String[] _Scores = _Score.split(";"); + + _ListView = (ListView) findViewById(R.id.feiji_score_list); + _Adapter = new ScoreListAda(FeiJi_ScoreActivity.this, _Scores); + _ListView.setAdapter(_Adapter); + } + + private class ScoreListAda extends BaseAdapter { + + private Item _Item; + private LayoutInflater _Inflater; + private String[] _Lists; + + public ScoreListAda(Context c, String[] lists) { + _Inflater = (LayoutInflater) c + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + _Lists = lists; + } + + @Override + public int getCount() { + return _Lists.length; + } + + @Override + public Object getItem(int position) { + return null; + } + + @Override + public long getItemId(int position) { + return 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = _Inflater + .inflate(R.layout.feiji_score_item, null); + _Item = new Item(); + _Item.tv1 = (TextView) convertView + .findViewById(R.id.feiji_score_list_item1); + _Item.tv2 = (TextView) convertView + .findViewById(R.id.feiji_score_list_item2); + _Item.bu = (Button) convertView + .findViewById(R.id.feiji_score_list_return); + convertView.setTag(_Item); + } else { + _Item = (Item) convertView.getTag(); + } + if (_Item != null) { + _Item.tv1.setText("" + (position + 1)); + _Item.tv2.setText("" + _Lists[position]); + if (position >= _Lists.length - 1) { + _Item.bu.setVisibility(View.VISIBLE); + _Item.bu.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + finish(); + } + }); + } + } + + return convertView; + } + + public class Item { + public TextView tv1; + public TextView tv2; + public Button bu; + } + } + + public void onResume() { + super.onResume(); + StatService.onResume(this); + } + + public void onPause() { + super.onPause(); + StatService.onPause(this); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_SpriteActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_SpriteActivity.java new file mode 100644 index 00000000..49fb0c7f --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_SpriteActivity.java @@ -0,0 +1,67 @@ +package skyward.com.myapplication; + +import org.cocos2d.nodes.CCSprite; + +public class FeiJi_SpriteActivity { + + public int Life = 0, Max_Life = 0; + public CCSprite _FeiJi_Foe; + public float Init_X = 0, Init_Y = 0, Init_Duration = 0; + public boolean Clicked_Or = false; + + public void setMax_Life(int _Max_Life) { + Max_Life = _Max_Life; + } + + public int getMax_Life() { + return Max_Life; + } + + public void setLift(int _Life) { + Life = _Life; + } + + public int getLift() { + return Life; + } + + public void setInitX(float _Init_X) { + Init_X = _Init_X; + } + + public float getInitX() { + return Init_X; + } + + public void setInitY(float _Init_Y) { + Init_Y = _Init_Y; + } + + public float getInitY() { + return Init_Y; + } + + public void setInitDuration(float _Init_Duration) { + Init_Duration = _Init_Duration; + } + + public float getInitDuration() { + return Init_Duration; + } + + public void setCCSprite(String Path) { + _FeiJi_Foe = CCSprite.sprite(Path); + } + + public CCSprite getCCSprite() { + return _FeiJi_Foe; + } + + public void setClicked_Or(boolean _Clicked_Or) { + Clicked_Or = _Clicked_Or; + } + + public boolean getClicked_Or() { + return Clicked_Or; + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_WelActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_WelActivity.java new file mode 100644 index 00000000..9355e987 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/FeiJi_WelActivity.java @@ -0,0 +1,60 @@ +package skyward.com.myapplication; + +import com.baidu.mobstat.StatService; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.widget.ImageView; + +public class FeiJi_WelActivity extends FeiJi_BaseActivity { + + private ImageView _FeiJi_Wel_Animal; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.feiji_wel); + + _FeiJi_Wel_Animal = (ImageView) findViewById(R.id.feiji_wel_animal); + + _FeiJi_Wel_Animal.setBackgroundResource(R.drawable.feiji_back_1); + + Handle_Delay(0, 1000); + Handle_Delay(1, 2000); + Handle_Delay(2, 2500); + + } + + private void Handle_Delay(int chage, int time) { + + final int _Chage = chage; + Handler _Animal_Handler = new Handler(); + _Animal_Handler.postDelayed(new Runnable() { + + @Override + public void run() { + if (_Chage == 0) { + _FeiJi_Wel_Animal + .setBackgroundResource(R.drawable.feiji_back_2); + } else if (_Chage == 1) { + _FeiJi_Wel_Animal + .setBackgroundResource(R.drawable.feiji_back_3); + } else { + Intent intent = new Intent(FeiJi_WelActivity.this, FeiJi_MenuActivity.class); + startActivity(intent); + finish(); + } + } + }, time); + } + public void onResume() { + super.onResume(); + StatService.onResume(this); + } + + public void onPause() { + super.onPause(); + StatService.onPause(this); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/MActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/MActivity.java new file mode 100644 index 00000000..9c7ad100 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/MActivity.java @@ -0,0 +1,119 @@ +package skyward.com.camera; + +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Environment; +import android.provider.MediaStore; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +/** + * + */ +public class MActivity extends AppCompatActivity { + public static final int REQUEST_CODE_1 = 1; + public static final int REQUEST_CODE_2 = 2; + private static final String TAG = "MActivity"; + //文件路径 + private String mFilePath; + + private ImageView iv; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_m); + iv = (ImageView) findViewById(R.id.iv); + //获取SD卡路径(外部存储路径) /storage/emulated/0 + mFilePath = Environment.getExternalStorageDirectory().getPath(); + Log.d(TAG, "onCreate: " + mFilePath); + //获取公共外部存储空间路径 /storage/emulated/0/Pictures +// File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); +// Log.d(TAG, "onCreate: " + file.getAbsolutePath()); + mFilePath = mFilePath + "/temp.png"; + } + + /** + * 调用系统相机(返回缩略图) + * @param view + */ + public void startCamera1(View view) { + //通过隐式intent启动相机应用 + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + startActivityForResult(intent, REQUEST_CODE_1); + } + + /** + * 调用系统相机(返回原图) + * @param view + */ + public void startCamera2(View view) { + //通过隐式intent启动相机应用 + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + Uri photoUri = Uri.fromFile(new File(mFilePath)); + //修改系统保存图片的路径 + intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); + startActivityForResult(intent, REQUEST_CODE_2); + } + + /** + * 调用自定义相机 + * @param view + */ + public void customCamera(View view) { + Intent intent = new Intent(MActivity.this, CustomCameraActivity.class); + startActivity(intent); + } + + //将照片添加至系统相册 + private void galleryAddPic() { + Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + File f = new File(mFilePath); + Uri contentUri = Uri.fromFile(f); + mediaScanIntent.setData(contentUri); + this.sendBroadcast(mediaScanIntent); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(resultCode == RESULT_OK) { + if(requestCode == REQUEST_CODE_1) { + /** + * 系统相机默认返回的bitmap为缩略图 + */ + Bundle bundle = data.getExtras(); + Bitmap bitmap = (Bitmap) bundle.get("data"); + iv.setImageBitmap(bitmap); + } else if(requestCode == REQUEST_CODE_2) { + /** + * 要想使系统相机返回原图 + * 1.修改系统默认保存照片路径 + * 2.自定义照片文件保存路径,在调用系统相机之前,将路径作为参数传递给系统相机 + * 3.创建文件输入流,读取照片文件并转换为Bitmap,显示在ImageView中 + * + * 有可能会因为照片文件过大以致抛出内存溢出异常,不能够将照片显示在ImageView中 + */ + try { + FileInputStream fis = new FileInputStream(mFilePath); + Bitmap bitmap = BitmapFactory.decodeStream(fis); + Log.d(TAG, "onActivityResult: 读取图片"); + iv.setImageBitmap(bitmap); + galleryAddPic(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } finally { + + } + } + } + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/ResultActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/ResultActivity.java new file mode 100644 index 00000000..deba2341 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903208/ResultActivity.java @@ -0,0 +1,41 @@ +package skyward.com.camera; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.ImageView; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +/** + * 5.自定义相机预览界面 + * 相片预览界面 + */ +public class ResultActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_result); + //获取相片所在的路径 + String path = getIntent().getStringExtra("picPath"); + ImageView pic = (ImageView) findViewById(R.id.pic); + //系统默认拍摄的相片为横屏显示,因此要将图片旋转90度后再显示 + try { + FileInputStream fis = new FileInputStream(path); + Bitmap bitmap = BitmapFactory.decodeStream(fis); + Matrix matrix = new Matrix(); + //将图片旋转90度 + matrix.setRotate(90); + bitmap = Bitmap.createBitmap(bitmap, 0,0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); + pic.setImageBitmap(bitmap); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } +// Bitmap bitmap = BitmapFactory.decodeFile(path); +// pic.setImageBitmap(bitmap); + } +} diff --git a/app/src/main/res/drawable/button_bg.png b/app/src/main/res/drawable/button_bg.png new file mode 100644 index 00000000..eb47a7a7 Binary files /dev/null and b/app/src/main/res/drawable/button_bg.png differ diff --git a/app/src/main/res/drawable/button_bg_2.png b/app/src/main/res/drawable/button_bg_2.png new file mode 100644 index 00000000..4fdb0f3e Binary files /dev/null and b/app/src/main/res/drawable/button_bg_2.png differ diff --git a/app/src/main/res/drawable/button_pressed.xml b/app/src/main/res/drawable/button_pressed.xml new file mode 100644 index 00000000..716f53bb --- /dev/null +++ b/app/src/main/res/drawable/button_pressed.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/feiji_back_1.png b/app/src/main/res/drawable/feiji_back_1.png new file mode 100644 index 00000000..24f1f308 Binary files /dev/null and b/app/src/main/res/drawable/feiji_back_1.png differ diff --git a/app/src/main/res/drawable/feiji_back_2.png b/app/src/main/res/drawable/feiji_back_2.png new file mode 100644 index 00000000..06cb70f7 Binary files /dev/null and b/app/src/main/res/drawable/feiji_back_2.png differ diff --git a/app/src/main/res/drawable/feiji_back_3.png b/app/src/main/res/drawable/feiji_back_3.png new file mode 100644 index 00000000..cf9f958b Binary files /dev/null and b/app/src/main/res/drawable/feiji_back_3.png differ diff --git a/app/src/main/res/drawable/feiji_back_text.png b/app/src/main/res/drawable/feiji_back_text.png new file mode 100644 index 00000000..0c5ee827 Binary files /dev/null and b/app/src/main/res/drawable/feiji_back_text.png differ diff --git a/app/src/main/res/drawable/feiji_background.png b/app/src/main/res/drawable/feiji_background.png new file mode 100644 index 00000000..90aedd21 Binary files /dev/null and b/app/src/main/res/drawable/feiji_background.png differ diff --git a/app/src/main/res/drawable/logo.png b/app/src/main/res/drawable/logo.png new file mode 100644 index 00000000..a2870ff6 Binary files /dev/null and b/app/src/main/res/drawable/logo.png differ diff --git a/app/src/main/res/drawable/round_back.xml b/app/src/main/res/drawable/round_back.xml new file mode 100644 index 00000000..71e7f9a6 --- /dev/null +++ b/app/src/main/res/drawable/round_back.xml @@ -0,0 +1,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_custom_camera.xml b/app/src/main/res/layout/activity_custom_camera.xml new file mode 100644 index 00000000..245766e1 --- /dev/null +++ b/app/src/main/res/layout/activity_custom_camera.xml @@ -0,0 +1,33 @@ + + + +