// Copyright 2001-2003, Danger, Inc.  All Rights Reserved.
// This file is subject to the Danger, Inc. Sample Code License,
// which is provided in the file SAMPLE_CODE_LICENSE.
// Copies are also available from http://developer.danger.com/

package com.danger.rocks;

import danger.audio.*;
import danger.app.*;
import danger.ui.*;

public class AntagonistImage implements Resources
{
	public	AntagonistImage()
	{
		int mImages[] = {	ID_antagonist_f01, ID_antagonist_f02, ID_antagonist_f03, ID_antagonist_f04, 
							ID_antagonist_f05, ID_antagonist_f06
							};
		int mImages2[] = {	ID_antagonist2_f01, ID_antagonist2_f02, ID_antagonist2_f03, ID_antagonist2_f04, 
							ID_antagonist2_f05, ID_antagonist2_f06
							};

		int mCrashImages[] = {	kExplode_f02, kExplode_f03, kExplode_f04, 
								kExplode_f05, kExplode_f06, kExplode_f07, kExplode_f08, 
								kExplode_f09, kExplode_f10, kExplode_f11, kExplode_f12,
								kExplode_f13, kExplode_f14, kExplode_f15, kExplode_f16,
								kExplode_f17, kExplode_f18, kExplode_f19, kExplode_f01
								};

		for (int count = 0; count < TOTAL_FRAMES; count++)
		{
			mAntagonist[count] = rocks.mMe.getBitmap(mImages[count]);
			mAntagonist2[count] = rocks.mMe.getBitmap(mImages2[count]);
		}

		for (int count = 0; count < TOTAL_CRASH_FRAMES; count++)
		{
			mAntagonistCrash[count] = rocks.mMe.getBitmap(mCrashImages[count]);
		}

		mFrame = 0;
		mImagesReady = true;
	}

	public	void draw(Pen inPen, int cx, int cy, int frame)
	{
		if (mCrashFrame < TOTAL_CRASH_FRAMES/2)
		{
			if (mAlt == false)
			{
				inPen.drawBitmap(cx + OFFSET_X, cy + OFFSET_Y, mAntagonist[mFrame]);
			}
			else
			{
				inPen.drawBitmap(cx + OFFSET_X, cy + OFFSET_Y, mAntagonist2[mFrame]);
			}
		}

		if (mCrashed)
		{
			if (mCrashFrame < TOTAL_CRASH_FRAMES)
			{
				inPen.drawBitmap(cx + CRASH_OFFSET_X, cy + CRASH_OFFSET_Y, mAntagonistCrash[mCrashFrame]);
				mCrashFrame++;
			}
		}	


		mFrame++;
		if (mFrame >= TOTAL_FRAMES)
		{
			mFrame = 0;
		}
	}

	public int getSizeX()
	{
		int	max = 0;
		int size = 0;

		if (mCachedSizeX == -1)
		{
			for (int count = 0; count < TOTAL_FRAMES; count++)
			{
				if (mAlt == false)
				{
					size = mAntagonist[count].getWidth();
				}
				else
				{
					size = mAntagonist2[count].getWidth();
				}
				if (max < size)
				{
					max = size;
				}
			}
			mCachedSizeX = max;
		}
		return mCachedSizeX;
	}

	public int getSizeY()
	{
		int	max = 0;
		int size = 0;

		if (mCachedSizeY == -1)
		{
			for (int count = 0; count < TOTAL_FRAMES; count++)
			{
				if (mAlt == false)
				{
					size = mAntagonist[count].getHeight();
				}
				else
				{
					size = mAntagonist2[count].getHeight();
				}
				if (max < size)
				{
					max = size;
				}
			}
			mCachedSizeY = max;
		}
		return mCachedSizeY;
	}

	public Rect getRectForAntagonist(int frame)
	{
		if (mImagesReady == true)
		{
			if (mCachedAntagonistRect == null)
			{
				mCachedAntagonistRect = new Rect();
			}
			mCachedAntagonistRect.setTo(0, 0, getSizeX(), getSizeY());
			return mCachedAntagonistRect;
		}
		return null;
	}

	public void setAlt(boolean on)
	{
		if (mAlt != on)
		{
			mAlt = on;
			mCachedSizeX = -1;
			mCachedSizeY = -1;
			mFrame = 0;
		}
	}

	public boolean isAltOn()
	{
		return mAlt;
	}

	public void setCrash(boolean crashed)
	{
		mCrashFrame = 0;
		mCrashed = crashed;
	}

	public static final int	TOTAL_FRAMES = 6;

	boolean				mImagesReady = false;
	static Bitmap		mAntagonist[] =	{null, null, null, null, null, null};
	static Bitmap		mAntagonist2[] = {null, null, null, null, null, null};

	Rect				mCachedAntagonistRect = null;
	int					mCachedSizeX = -1;
	int					mCachedSizeY = -1;

	int					mFrame;
	static final int	OFFSET_X = 0;
	static final int	OFFSET_Y = 0;

	boolean				mAlt;
	boolean				mCrashed;
	int					mCrashFrame;
	static final int	TOTAL_CRASH_FRAMES	= 19;
	static final int	CRASH_OFFSET_X = -9;
	static final int	CRASH_OFFSET_Y = -9;
	static Bitmap		mAntagonistCrash[] =	{null, null, null, null, null, null, null, null,
												null, null, null, null, null, null, null, null,
												null, null, null};


 	static int			mAntagonistMissileOffsetX[] = {14, 15, 17, 18, 21, 18};
	static int			mAntagonistMissileOffsetY[] = {8, 10, 8, 11, 10, 12};
}


