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

namespace pcd_g1
{

	class RakusekiBlockStageObject : BlockStageObject
	{
		bool isFloating = true;
		Stage owner;
		int beforeY = 0;

		const double MAX_SPEED_Y = 100.0;

		public RakusekiBlockStageObject(int x, int y, Stage stg): base(x, y)
		{
			owner = stg;
			image = ImageManager.Search("861");
			beforeY = y;
		}

		double speedY = 0;

		public override void Update(int keyStatus, out int vx, out int vy)
		{

			if (!isFloating)
			{
				//重力
				if (speedY < MAX_SPEED_Y)
				{
					speedY += owner.IsLake ? 0.3 : 0.5;
				}
			}

			vx = 0;
			vy = (int) speedY;

			if (owner.MainCharacter.X >= this.X - owner.MainCharacter.Width && owner.MainCharacter.X <= this.X + this.Width)
			{
				if (!owner.IsOn(this, CollideDirection.Down))
				{
					isFloating = false;
				}
				
			}

			if (owner.MainCharacter.X > this.X + 960 || owner.MainCharacter.X < this.X - 960)
			{
				this.Y = beforeY;
				isFloating = true;
				speedY = 0;
			}

		}

		public override bool EventProc(EventType type, IStageObject sender, CollideDirection direction)
		{
			if (type == EventType.Collided && direction == CollideDirection.Down)
			{
				if (!isFloating && speedY > 0)
				{
					if(!(MainForm.form.Effects.AvailableEffect is PEarthquakeEffect))
						MainForm.form.Effects.Add(new PEarthquakeEffect());
					isFloating = true;
					speedY = 0;
				}
				
			}
			else if (type == EventType.Touched)
			{
				if (sender is MainCharacterStageObject)
				{
					sender.SignalProc(SignalType.SIGKILL, 9999, 0);
				}
			}
			
			return base.EventProc(type, sender, direction);
		}


	}
}
