import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import com.bp.R;
public class BallView extends SurfaceView implements Callback {
public static final int V_MAX=35;
public static final int V_MIN=15;
public static final int WOOD_EDGE=60;
public static final int GROUND_LING=450; //代表地面的Y坐标,小球下落到此会弹起
public static final int UP_ZERO=30; //小球在上升过程中,速度小于该值就算0
public static final int DOWN_ZERO=60; //小球在撞击地面后,速度小于该值就算0
Bitmap[] bitmapArray =new Bitmap[6];
Bitmap bmpBack; //背景图片
Bitmap bmpWood; // 挡板图片
String fps="FPS:N/A"; //用于显示帧速率的字符串
int ballNumber =8; //小球数目
ArrayList<Movable> alMovable=new ArrayList<Movable>(); //小球对象数组
DrawThread dt; //后台屏幕绘制线程
public BallView(Context activity) {
super(activity);
getHolder().addCallback(this);
initBitmaps(getResources()); //初始化图片
initMovables(); //初始化小球
dt=new DrawThread(this,getHolder()); //初始化重绘线程
}
public void initBitmaps(Resources r) {
bitmapArray[0]=BitmapFactory.decodeResource(r, R.drawable.ball_red_small);
bitmapArray[1]=BitmapFactory.decodeResource(r, R.drawable.ball_purple_small);
bitmapArray[2]=BitmapFactory.decodeResource(r, R.drawable.ball_green_small);
bitmapArray[3]=BitmapFactory.decodeResource(r, R.drawable.ball_red);
bitmapArray[4]=BitmapFactory.decodeResource(r, R.drawable.ball_purple);
bitmapArray[5]=BitmapFactory.decodeResource(r, R.drawable.ball_green);