package com.backfire.Animation;

import net.yeeyo.doudizhu.feiyu.R;
import android.graphics.Bitmap;
import android.graphics.Rect;

import com.backfire.doudizhu.common.BitmapManager;
import com.backfire.doudizhu.common.DdzApplication;
import com.backfire.graphics.PCanvas;
import com.backfire.room.data.ConfigCenter;
import com.backfire.utils.Log;

/**
 * 爆炸动画
 * @author Potter
 */
public class AnimationBomb extends Animation {

	private final int[] textures = {
			R.drawable.bomb_1,
			R.drawable.bomb_2,
			R.drawable.bomb_3,
			R.drawable.bomb_4,
			R.drawable.bomb_5,
			R.drawable.bomb_6,
			R.drawable.bomb_7,
			R.drawable.bomb_8
	};
	private int index=0;
	private final int width = ConfigCenter.bomb_anim_W;
	private final int hight = ConfigCenter.bomb_anim_H;
	private final int x =(DdzApplication.getApplication().screenWidth - width)/2;
	private final int y =(DdzApplication.getApplication().screenHeight - hight)/2;
	
	
	float statetime=0.0f;
	private Rect srcRect;

	public AnimationBomb() {
		srcRect = new Rect();
		srcRect.set(x, y, x + width, y + hight);
	}

	@Override
	public void exec(PCanvas canvas,long sleep) {
		super.exec(canvas,sleep);
		statetime+=this.sleep;
		Log.i("休眠时间："+this.sleep);
		index=getCurrentBitmap(statetime, textures);
		BitmapManager bpool = DdzApplication.getApplication().getBmpPool();
		Bitmap texture = bpool.getBitmap(textures[index], 0, 0);
		if (null != texture) {
			canvas.drawBitmap(texture, null, srcRect, null);
		}
		if (index == textures.length-1) {
			index = 0;
			this.deleteFlag = true;
		}
	}

	@Override
	public void unload() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void overstatue() {
		this.deleteFlag = true;
	}
}