using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ShootingHero.Components.Backgrounds
{
	public class FloatingObject : DrawableGameComponent
	{
		Texture2D texture;
		float scale;
		float x, y;
		float angle;
		bool rotateEnable;
		byte transparent;
		float speed;

		public float X { get { return x; } set { x = value; } }
		public float Y { get { return y; } set { y = value; } }

		public FloatingObject ( Game game, Texture2D texture, bool rotateEnable, bool transparent )
			: base ( game )
		{
			this.texture = texture;
			x = ( Game as ShootingHero ).Random.Next ( 0, 480 );
			y = -50;
			this.rotateEnable = rotateEnable;
			this.transparent = ( byte ) ( ( transparent ) ? 100 : 255 );
			this.scale = ( Game as ShootingHero ).Random.Next ( 20, 100 ) / 100.0f;
			this.speed = ( Game as ShootingHero ).Random.Next ( 1, 5 );
		}

		public override void Update ( GameTime gameTime )
		{
			y += gameTime.ElapsedGameTime.Milliseconds / 20.0f * speed;
			if ( rotateEnable )
				angle += gameTime.ElapsedGameTime.Milliseconds / 1000.0f;

			base.Update ( gameTime );
		}

		public override void Draw ( GameTime gameTime )
		{
			SpriteBatch spriteBatch = ( Game as ShootingHero ).SpriteBatch;

			spriteBatch.Draw ( texture,
				new Vector2 ( x, y ),
				null, new Color ( 255, 255, 255, transparent ),
				angle,
				new Vector2 ( texture.Width / 2, texture.Height / 2 ),
				scale,
				SpriteEffects.None, 0 );

			base.Draw ( gameTime );
		}
	}
}
