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

namespace ShootingHero.Components.Manager
{
	public class ItemManager : DrawableGameComponent
	{
		List<Item> itemList = new List<Item> ();
		List<Item> removeList = new List<Item> ();

		public ItemManager ( Game game )
			: base ( game )
		{
		
		}

		public void Add ( Item item )
		{
			itemList.Add ( item );
			item.Initialize ();
		}

		public void Remove ( Item item )
		{
			removeList.Add ( item );
		}

		public override void Update ( GameTime gameTime )
		{
			foreach ( Item item in itemList )
			{
				item.Update ( gameTime );
				if ( item.Y >= 850 )
					Remove ( item );
			}
			foreach ( Item item in removeList )
				itemList.Remove ( item );
			removeList.Clear ();
			base.Update ( gameTime );
		}

		public override void Draw ( GameTime gameTime )
		{
			foreach ( Item item in itemList )
				item.Draw ( gameTime );
			base.Draw ( gameTime );
		}
	}
}
