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

namespace pcd_g1
{
	class HedoronCharacterStageObject : CharacterStageObject
	{
	  private uint character_number = 41; //画像番号nnd-xのうち、nnの部分
												//d == 0:Left
												//d == 1:Right

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


		public HedoronCharacterStageObject(int x, int y, Stage stg):base(x,y,stg)
		{
			isFloating = false;
			hp = DEFAULT_HP;

			X = x; Y = y;
		}


		int hideCount = 0;
		public override void Update(int keyStatus, out int vx, out int vy)
		{
			base.Update(keyStatus, out vx, out vy);

			vx = 0;
			vy = 0;
			
			
			hideCount++;
			if (hideCount > 200)
				hideCount = 0;
		}

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

			string imageName;

			imageName = character_number.ToString();

			if (hideCount < 100)
			{
				imageName = "950-1";

			}
			else {
				if (hideCount < 105 || hideCount > 195)
				{
					imageName = "950-2" ;
				}
				else
				{
					imageName = "950-3";
				}
			}
			animationCount++;
			if (animationCount >= 30) animationCount = 0;

			g.DrawImage(ImageManager.Search(imageName), 0, 0);

			//HPゲージの描画
			if (hideCount >= 100)
			{
				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.Collided:
					
					
					break;
				case EventType.BeTouched:

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

					if (sender is MainCharacterStageObject)
					{
						if (hideCount >= 100)
						{
							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)
			{
				if (hideCount >= 100)
				{
					hp -= arg1;
				}

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