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

namespace pcd_g1
{
	class BombStageObject : IStageObject
	{
		public int X { get; set; }
		public int Y { get; set; }
		public int Width { get; protected set; }
		public int Height { get; protected set; }
		public bool Visibility { get; protected set; }
		public bool CanCrash { get { return false; } }
		public bool KilledByBlock { get; protected set; }
		public bool KilledByCharacter { get; protected set; }
		public int Damage { get; set; }

		public CollideRange Range { get; protected set; }
		protected Stage owner;
		protected IStageObject ownerCharacter;
		protected int TTL = 10000;
		protected string sound = "";

		public static void Go(BombStageObject bomb)
		{
			if(bomb.sound != "") MainForm.PlayEffectSound(bomb.sound);
			bomb.owner.Add(bomb);
		}

		public BombStageObject(int x, int y, Stage stg, IStageObject  character)
		{
			X = x;
			Y = y;
			owner = stg;
			ownerCharacter = character;
		}

		protected int SpeedX = 0;
		protected int SpeedY = 0;
		public virtual void Update(int keyStatus, out int vx, out int vy)
		{
			vx = SpeedX;
			vy = SpeedY;
			if (--TTL <= 0) Die();
		}

		protected Bitmap picture = null;
		public virtual void Draw(Graphics g, int width, int height)
		{
			if (picture != null)
			{
				g.DrawImage(picture, 0, 0);
			}
		}

		public virtual bool EventProc(EventType type, IStageObject sender, CollideDirection direction)
		{
			switch (type)
			{
				case EventType.Collided: case EventType.BeCollided:
					if(KilledByBlock)
					{
						Die();
					}
					break;
				case EventType.Touched: case EventType.BeTouched:
					if (!(sender == ownerCharacter) &&
						sender is CharacterStageObject)
					{
						if((ownerCharacter is MainCharacterStageObject && !(sender is MainCharacterStageObject)) ||
							(!(ownerCharacter is MainCharacterStageObject) && sender is MainCharacterStageObject))
							((CharacterStageObject)sender).SignalProc(SignalType.SIGDAMAGE, Damage, 0);
					}
					if(KilledByCharacter && sender != ownerCharacter)
					{
						Die();
					}
					break;
			}
			return true;
		}

		public virtual void SignalProc(SignalType type, int arg1, int arg2)
		{
			
			
		}

		protected void Die()
		{
			owner.Remove(this);
		}
	}
}
