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 AnimationRocket extends Animation {

	private final int[] textures = {
			R.drawable.rocket_1,
			R.drawable.rocket_2,
			R.drawable.rocket_3,
			R.drawable.rocket_4,
			R.drawable.rocket_5,
			R.drawable.rocket_6,
			R.drawable.rocket_7,
			R.drawable.rocket_8,
			R.drawable.rocket_9,
			R.drawable.rocket_10,
			R.drawable.rocket_11,
			R.drawable.rocket_12,
			R.drawable.rocket_13,
			R.drawable.rocket_14,
			R.drawable.rocket_15,
			R.drawable.rocket_16
	};
	private int index=0;
	private final int windth = ConfigCenter.rocket_anim_W;
	private final int height = ConfigCenter.rocket_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 AnimationRocket() {
		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;
	}
}