using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace pcd_g1
{
	class SkillItemStageObject : ItemStageObject
	{
		const double MAX_SPEED_Y = 100.0;
		private bool captured = false;
		private double speedY;
		long time;

		public SkillItemStageObject(int x, int y, Stage stg)
			: base(x, y, stg)
		{
			
			image = ImageManager.Search("701");
			Range = new FreeRectangleCollideRange(this);
			((FreeRectangleCollideRange)Range).Rect = new Rectangle(10, 20, 12, 12);
			time = Environment.TickCount;
		}

		long now;
		public override void Update(int keyStatus, out int vx, out int vy)
		{
			base.Update(keyStatus, out vx, out vy);

			bool isSet;

			isSet = owner.IsOn(this, CollideDirection.Down);

			if (isSet)
			{
				//speedY = 0;
			}
			else
			{
					//重力
					if (speedY < MAX_SPEED_Y)
					{
						speedY += 0.5;
					}
			}

			now = Environment.TickCount;
			if (now > time + 10000)
			{
				owner.Remove(this);
			}

			vy = (int)speedY;
		}

		public override void Draw(Graphics g, int width, int height)
		{
			if (now > time + 6000)
			{
				if (now % 2 == 0) base.Draw(g, width, height);
			}
			else
			{
				base.Draw(g, width, height);
			}
		}

		public override bool EventProc(EventType type, IStageObject sender, CollideDirection direction)
		{
			switch (type)
			{
				case EventType.BeTouched:
					if (sender is MainCharacterStageObject && !captured)
					{
						captured = true;
						sender.SignalProc(SignalType.SIGUPSKILL, 1, 0);
						owner.Remove(this);
						MainForm.PlayEffectSound("coin");
					}
					break;
				case EventType.Collided:
					if (direction == CollideDirection.Down || direction == CollideDirection.Up)
					{
						speedY = 0;
					}
					break;
			}


			return base.EventProc(type, sender, direction);
		}
	}
}
