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;

/**   
 * @Title: AnimationChain.java
 * @Package com.backfire.Animation
 * @Description: 顺子动画
 * @author Potter
 * @date 2013-11-26 下午8:19:49
 * @version V2.0   
 */
public class AnimationChain extends Animation {

	private final int[] textures = {
			R.drawable.shunzi_anim_01,
			R.drawable.shunzi_anim_02,
			R.drawable.shunzi_anim_03,
			R.drawable.shunzi_anim_04,
			R.drawable.shunzi_anim_05,
			R.drawable.shunzi_anim_06,
			R.drawable.shunzi_anim_07,
			R.drawable.shunzi_anim_08,
			R.drawable.shunzi_anim_09,
			R.drawable.shunzi_anim_10,
			R.drawable.shunzi_anim_11,
			R.drawable.shunzi_anim_12,
			R.drawable.shunzi_anim_13,
			R.drawable.shunzi_anim_14,
			R.drawable.shunzi_anim_15,
			R.drawable.shunzi_anim_16
	};
	private int index=0;
	private final int windth = ConfigCenter.bomb_anim_W;
	private final int height = ConfigCenter.bomb_anim_H;
	private final int x =(DdzApplication.getApplication().screenWidth - windth)/2;
	private final int y =(DdzApplication.getApplication().screenHeight - height)/2;
	
	
	float statetime=0.0f;
	private Rect srcRect;

	public AnimationChain() {
		srcRect = new Rect();
		srcRect.set(x, y, x + windth, y + height);
	}

	@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;
	}
}