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

namespace pcd_g1
{
	class ZoukinCharacterStageObject : CharacterStageObject
	{
		private int movespeed_max = 2;

		private int hp;//ヒットポイント
		private const int DEFAULT_HP = 2;//初期のヒットポイント


		public ZoukinCharacterStageObject(int x, int y, Stage stg):base(x,y,stg)
		{
			isFloating = true;

			hp = DEFAULT_HP;

			X = x; Y = y;
		}

		private enum Direction
		{
			Left = 2, Right = 1, Null = 0
		}

		string pict = "970";
		public override void Update(int keyStatus, out int vx, out int vy)
		{
			base.Update(keyStatus, out vx, out vy);

			vx = 0;
			vy = 0;

			if (Math.Pow(owner.MainCharacter.X - this.X,2) + Math.Pow(owner.MainCharacter.Y - this.Y,2) < 36864)
			{
				if (owner.MainCharacter.X < this.X)
				{
					vx = -movespeed_max;
					pict = "970";
				}
				else if (owner.MainCharacter.X > this.X)
				{
					vx = movespeed_max;
					pict = "971";
				}
				if (owner.MainCharacter.Y < this.Y)
				{
					vy = -movespeed_max;
				}
				else if (owner.MainCharacter.Y > this.Y)
				{
					vy = movespeed_max;
				}
			}
		}
		

		int animationCount = 0;
		public override void Draw(Graphics g, int width, int height)
		{
			animationCount++;
			if (animationCount >= 30) animationCount = 0;

			g.DrawImage(ImageManager.Search(pict + (animationCount < 15 ? "-1" : "-2")), 0, 0);

			//HPゲージの描画
			g.FillRectangle(Brushes.White, 0, -10, width, 5);
			g.FillRectangle(new SolidBrush(Color.FromArgb((int)(255f*(1-hp/DEFAULT_HP)),(int)(255f*hp/DEFAULT_HP),0)), 0, -10, (float)width * hp / DEFAULT_HP, 5);
		}

		public override bool EventProc(EventType type, IStageObject sender, CollideDirection direction)
		{
			switch (type)
			{
				case EventType.BeTouched:

					if (sender is MainCharacterStageObject)
					{
						sender.SignalProc(SignalType.SIGDAMAGE, 10, 0);
					}
					break;
				case EventType.Touched:

					if (sender is MainCharacterStageObject)
					{
						sender.SignalProc(SignalType.SIGDAMAGE, 10, 0);
					}
					break;
			}
			

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

		bool putskill = false;
		public override void SignalProc(SignalType type, int arg1, int arg2)
		{
			base.SignalProc(type,arg1,arg2);

			if (type == SignalType.SIGDAMAGE)
			{
					hp -= arg1;
					if (hp <= 0)
					{
						owner.Remove(this);
						if (!putskill)
						{
							putskill = true;
							owner.Add(new SkillItemStageObject(X, Y, owner));
						}
					}
			}
		}
	}
}
