初次提交

This commit is contained in:
2022-09-19 18:05:01 +08:00
commit 57051fc44b
5401 changed files with 325410 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Sample2_8</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Fri Jul 01 08:06:54 CST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="com.bn.pp8">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Sample2_8_Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-7

View File

@@ -0,0 +1,39 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.bn.pp8;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int bg=0x7f020000;
public static final int bullet=0x7f020001;
public static final int explode0=0x7f020002;
public static final int explode1=0x7f020003;
public static final int explode2=0x7f020004;
public static final int explode3=0x7f020005;
public static final int explode4=0x7f020006;
public static final int explode5=0x7f020007;
public static final int icon=0x7f020008;
}
public static final class id {
public static final int Button01=0x7f050003;
public static final int EditText01=0x7f050002;
public static final int EditText02=0x7f050005;
public static final int LinearLayout01=0x7f050000;
public static final int ScrollView01=0x7f050004;
public static final int TextView01=0x7f050001;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="文件IO--读取Assets文件"
android:layout_width="fill_parent"
android:textSize="16dip"
android:layout_height="wrap_content"
android:gravity="center"
/>
<LinearLayout
android:id="@+id/LinearLayout01"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="文件名:"
android:textSize="18dip"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:text="AndroidIO.txt"
android:id="@+id/EditText01"
android:singleLine="true"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
<Button
android:text="打开文件"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:text=""
android:id="@+id/EditText02"
android:editable="false"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</EditText>
</ScrollView>
</LinearLayout>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Sample3_3_Activity!</string>
<string name="app_name">Sample2_8</string>
</resources>

View File

@@ -0,0 +1,55 @@
package com.bn.pp8;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
public class Bullet {
MySurfaceView gameView;
private Bitmap bitmap;// 位图
private Bitmap[] bitmaps;// 爆炸动画图组
float x;// x方向位移
float y;// y方向位移
float vx;// x方向速度
float vy;// y方向速度
private float t = 0;// 时间
private float timeSpan = 0.5f;// 时间间隔
int size;// 子弹尺寸
boolean explodeFlag = false;// 是否绘制子弹的标记
Explosion mExplosion;// 爆炸对象引用
// 构造器
public Bullet(MySurfaceView gameView, Bitmap bitmap, Bitmap[] bitmaps,
float x, float y, float vx, float vy) {
this.gameView = gameView;// 成员变量赋值
this.bitmap = bitmap;
this.bitmaps = bitmaps;
this.x = x;// 成员变量赋值
this.y = y;
this.vx = vx;
this.vy = vy;
size = bitmap.getHeight();// 获得图片的高度
}
// 绘制子弹的方法
public void drawSelf(Canvas canvas, Paint paint) {
if (explodeFlag && mExplosion != null) {// 如果已经爆炸,绘制爆炸动画
mExplosion.drawSelf(canvas, paint);
} else {
go();// 子弹前进
canvas.drawBitmap(bitmap, x, y, paint);// 绘制子弹
}
}
// 子弹前进的方法
public void go() {
x += vx * t;// 水平方向匀速直线运动
y += vy * t + 0.5f * Constant.G * t * t;// 竖直方向匀加速直线运动
if (x >= Constant.EXPLOSION_X || y >= Constant.SCREEN_HEIGHT) {// 子弹在特定位置爆炸
mExplosion = new Explosion(gameView, bitmaps, x, y);// 创建爆炸对象
explodeFlag = true;// 不再绘制子弹
return;
}
t += timeSpan;// 时间间隔
}
}

View File

@@ -0,0 +1,8 @@
package com.bn.pp8;
//用于统一管理常量的类
public class Constant {
public static final int SCREEN_WIDTH=480;//屏幕宽度
public static final int SCREEN_HEIGHT=320;//屏幕高度
public static final int EXPLOSION_X=270;//爆炸X位置
public static final float G = 1.0f;//重力加速度的值
}

View File

@@ -0,0 +1,43 @@
package com.bn.pp8;
import android.graphics.Canvas;
import android.view.SurfaceHolder;
public class DrawThread extends Thread {
private boolean flag = true;//线程工作标志位
private int sleepSpan = 100;//线程休眠时间
MySurfaceView gameView;//父界面引用
SurfaceHolder surfaceHolder;//surfaceHolder引用
public DrawThread(MySurfaceView gameView) {//构造器
this.gameView = gameView;
this.surfaceHolder = gameView.getHolder();
}
public void run() {
Canvas c;//声明画布
while (this.flag) {
c = null;
try {
// 锁定整个画布在内存要求比较高的情况下建议参数不要为null
c = this.surfaceHolder.lockCanvas(null);
synchronized (this.surfaceHolder) {
gameView.onDraw(c);// 绘制
}
} finally {
if (c != null) {// 并释放锁
this.surfaceHolder.unlockCanvasAndPost(c);
}
}
try {
Thread.sleep(sleepSpan);// 睡眠指定毫秒数
} catch (Exception e) {
e.printStackTrace();// 打印堆栈信息
}
}
}
public void setFlag(boolean flag) {//设置标志位的方法
this.flag = flag;
}
}

View File

@@ -0,0 +1,29 @@
package com.bn.pp8;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
public class Explosion {
MySurfaceView gameView;
private Bitmap[] bitmaps;// 位图
float x;// x方向位移
float y;// y方向位移
private int anmiIndex = 0;// 爆炸动画帧索引
public Explosion(MySurfaceView gameView, Bitmap[] bitmaps, float x, float y) {
this.gameView = gameView;
this.bitmaps = bitmaps;
this.x = x;
this.y = y;
}
// 绘制背景的方法
public void drawSelf(Canvas canvas, Paint paint) {
if (anmiIndex >= bitmaps.length - 1) {// 如果动画播放完毕,不再绘制爆炸效果
return;
}
canvas.drawBitmap(bitmaps[anmiIndex], x, y, paint);// 绘制数组中某一幅图
anmiIndex++;// 当前下标加1
}
}

View File

@@ -0,0 +1,68 @@
package com.bn.pp8;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
/**
*
* 2D SurfaceView
*
*/
public class MySurfaceView extends SurfaceView implements
SurfaceHolder.Callback {
Sample2_8_Activity activity;// activity的引用
Paint paint;// 画笔引用
DrawThread drawThread;// 绘制线程引用
Bitmap bgBmp;//背景图片
Bitmap bulletBmp;// 子弹位图
Bitmap[] explodeBmps;//爆炸位图数组
Bullet bullet;//子弹对象引用
public MySurfaceView(Sample2_8_Activity activity) {//构造器
super(activity);
this.activity = activity;
// 获得焦点并设置为可触控
this.requestFocus();
this.setFocusableInTouchMode(true);
getHolder().addCallback(this);// 注册回调接口
}
@Override
protected void onDraw(Canvas canvas) {//绘制界面的方法
super.onDraw(canvas);
canvas.drawBitmap(bgBmp, 0, 0, paint);//绘制背景
bullet.drawSelf(canvas, paint);//绘制子弹
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {//界面变化时调用的方法
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
paint = new Paint();// 创建画笔
paint.setAntiAlias(true);// 打开抗锯齿
//加载图片资源
bulletBmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.bullet);
bgBmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg);
explodeBmps=new Bitmap[]{
BitmapFactory.decodeResource(this.getResources(), R.drawable.explode0),
BitmapFactory.decodeResource(this.getResources(), R.drawable.explode1),
BitmapFactory.decodeResource(this.getResources(), R.drawable.explode2),
BitmapFactory.decodeResource(this.getResources(), R.drawable.explode3),
BitmapFactory.decodeResource(this.getResources(), R.drawable.explode4),
BitmapFactory.decodeResource(this.getResources(), R.drawable.explode5),
};
bullet = new Bullet(this, bulletBmp,explodeBmps,0,290,1.3f,-5.9f);//创建子弹对象
drawThread = new DrawThread(this);//创建绘制线程
drawThread.start();//启动绘制线程
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {//界面销毁时调用的方法
drawThread.setFlag(false);//停止绘制线程
}
}

View File

@@ -0,0 +1,20 @@
package com.bn.pp8;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Sample2_8_Activity extends Activity {
MySurfaceView gameView;//游戏界面
@Override
public void onCreate(Bundle savedInstanceState) {//重写onCreate方法
super.onCreate(savedInstanceState);
//全屏
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN ,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置为横屏
gameView = new MySurfaceView(this);//创建游戏界面对象
this.setContentView(gameView);//将该界面设置为窗体内容
}
}