// 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.app.*;
import danger.audio.*;
import danger.ui.*;


/**
 * DOCUMENT ME!
 *
 * @author $author$
 * @version $Revision$
 */
public class MissileObject
{
	//~ Instance fields --------------------------------------------------------

	// data
	MotionObject mMotion    = null;
	Object		 mOrigin;
	Rect		 mImageRect = new Rect();

	//~ Constructors -----------------------------------------------------------

	/**
	 * Creates a new MissileObject object.
	 *
	 * @param bounds DOCUMENT ME!
	 */
	public MissileObject(Rect bounds)
	{
		mMotion = new MotionObject(0, 0, 0, 0, bounds, 8, // max frames
				3, // max frame rate
				2, 2);
	}

	//~ Methods ----------------------------------------------------------------

	/**
	 * DOCUMENT ME!
	 *
	 * @param origin DOCUMENT ME!
	 * @param x DOCUMENT ME!
	 * @param y DOCUMENT ME!
	 */
	public void create(Object origin, int x, int y)
	{
		mMotion.setX(x);
		mMotion.setY(y);
		mMotion.setCurrentFrame(0);
		mOrigin = origin;
	}

	/**
	 * DOCUMENT ME!
	 *
	 * @param speed DOCUMENT ME!
	 */
	public void setSpeed(int speed)
	{
		mMotion.setSpeed(speed);
	}

	/**
	 * DOCUMENT ME!
	 *
	 * @param angle DOCUMENT ME!
	 */
	public void setAngle(int angle)
	{
		mMotion.setAngle(angle);
		mMotion.setCurrentFrame(0);
	}

	/**
	 * DOCUMENT ME!
	 *
	 * @param inPen DOCUMENT ME!
	 * @param style DOCUMENT ME!
	 */
	public void draw(Pen inPen, int style)
	{
		inPen.setColor(Color.BLACK);

		if (mMotion != null)
		{
			int x = mMotion.getX();
			int y = mMotion.getY();

			// L, T, R, B
			switch (style)
			{
				case 0:
					inPen.fillRect(x - 2, y - 2, x + 2, y + 2);

					break;

				case 1:
					inPen.fillRect(x - 1, y - 2, x + 1, y + 2);
					inPen.fillRect(x - 2, y - 1, x + 2, y + 1);

					break;
			}
		}
	}

	/**
	 * DOCUMENT ME!
	 *
	 * @return DOCUMENT ME!
	 */
	public Rect getImageRect()
	{
		mImageRect.setTo(0, 0, 4, 4);
		mImageRect.translate(mMotion.getX() - 2, mMotion.getY() - 2);

		return mImageRect;
	}

	/**
	 * DOCUMENT ME!
	 *
	 * @param w DOCUMENT ME!
	 */
	public void update(RockWindow w)
	{
		if (mMotion != null)
		{
			// invalidate old position
			//w.InvalidateThisRect(getImageRect());
			mMotion.Update();

			// invalidate new position
			//w.InvalidateThisRect(getImageRect());
		}
	}
}
